summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-09-30 16:35:13 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-14 17:02:19 +0000
commitb4f0811e04c5ca362162a97ece79bcd41be48287 (patch)
treed5a738c768ceebadb9ecf6515b7d67dd95fccad2
parent8918cd6b953a2c93c09f9e9154ef96b3b95152dc (diff)
downloadchrome-ec-b4f0811e04c5ca362162a97ece79bcd41be48287.tar.gz
test: Add on-device exception test
BRANCH=none BUG=b:234181908 TEST=./test/run_device_tests.py --board bloonchipper -t exception Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I4d5651be6048af357b68956097deea255551a6db Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3932262 Reviewed-by: Andrea Grandi <agrandi@google.com>
-rw-r--r--board/hatch_fp/build.mk1
-rw-r--r--board/nocturne_fp/build.mk1
-rw-r--r--board/nucleo-dartmonkey/build.mk1
-rw-r--r--board/nucleo-f412zg/build.mk1
-rw-r--r--board/nucleo-h743zi/build.mk1
-rw-r--r--test/build.mk5
-rw-r--r--test/exception.cc89
-rw-r--r--test/exception.tasklist10
-rwxr-xr-xtest/run_device_tests.py1
9 files changed, 110 insertions, 0 deletions
diff --git a/board/hatch_fp/build.mk b/board/hatch_fp/build.mk
index 4f6f098455..317c6c08eb 100644
--- a/board/hatch_fp/build.mk
+++ b/board/hatch_fp/build.mk
@@ -34,6 +34,7 @@ test-list-y=\
cortexm_fpu \
crc \
debug \
+ exception \
flash_physical \
flash_write_protect \
fpsensor \
diff --git a/board/nocturne_fp/build.mk b/board/nocturne_fp/build.mk
index abf8fa3e6b..358bd13093 100644
--- a/board/nocturne_fp/build.mk
+++ b/board/nocturne_fp/build.mk
@@ -34,6 +34,7 @@ test-list-y=\
cortexm_fpu \
crc \
debug \
+ exception \
flash_physical \
flash_write_protect \
fpsensor \
diff --git a/board/nucleo-dartmonkey/build.mk b/board/nucleo-dartmonkey/build.mk
index 3788ce9b7e..2e3e1f31d2 100644
--- a/board/nucleo-dartmonkey/build.mk
+++ b/board/nucleo-dartmonkey/build.mk
@@ -17,6 +17,7 @@ test-list-y=\
compile_time_macros \
crc \
debug \
+ exception \
flash_physical \
flash_write_protect \
fpsensor \
diff --git a/board/nucleo-f412zg/build.mk b/board/nucleo-f412zg/build.mk
index 125b3c3378..21a2955bc4 100644
--- a/board/nucleo-f412zg/build.mk
+++ b/board/nucleo-f412zg/build.mk
@@ -16,6 +16,7 @@ test-list-y=\
compile_time_macros \
crc \
debug \
+ exception \
flash_physical \
flash_write_protect \
mpu \
diff --git a/board/nucleo-h743zi/build.mk b/board/nucleo-h743zi/build.mk
index 4b2617608b..6153d85d8a 100644
--- a/board/nucleo-h743zi/build.mk
+++ b/board/nucleo-h743zi/build.mk
@@ -16,6 +16,7 @@ test-list-y=\
compile_time_macros \
crc \
debug \
+ exception \
flash_physical \
flash_write_protect \
mpu \
diff --git a/test/build.mk b/test/build.mk
index 3070e05aae..aeb6fdf956 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -185,6 +185,7 @@ cortexm_fpu-y=cortexm_fpu.o
crc-y=crc.o
debug-y=debug.o
entropy-y=entropy.o
+exception-y=exception.o
extpwr_gpio-y=extpwr_gpio.o
fan-y=fan.o
flash-y=flash.o
@@ -308,3 +309,7 @@ static_if_error-y=static_if_error.o.cmd
run-genvif_test:
@echo " TEST genvif_test"
@test/genvif/genvif.sh
+
+# This test requires C++ exceptions to be enabled.
+$(out)/RW/test/exception.o: CXXFLAGS+=-fexceptions
+$(out)/RO/test/exception.o: CXXFLAGS+=-fexceptions
diff --git a/test/exception.cc b/test/exception.cc
new file mode 100644
index 0000000000..bedc1c6f14
--- /dev/null
+++ b/test/exception.cc
@@ -0,0 +1,89 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <exception>
+
+extern "C" {
+#include "common.h"
+#include "panic.h"
+#include "system.h"
+#include "task.h"
+#include "test_util.h"
+}
+
+test_static int test_exception()
+{
+ try {
+ ccprintf("Throwing an exception\n");
+ throw std::exception();
+ } catch (std::exception &e) {
+ /*
+ * Since we have exceptions disabled, we should not reach this.
+ * Instead, the exception should cause a reboot.
+ */
+ ccprintf("Caught exception\n");
+ return EC_ERROR_UNKNOWN;
+ }
+ return EC_ERROR_UNKNOWN;
+}
+
+test_static int test_panic_data()
+{
+ const uint32_t expected_reason = PANIC_SW_EXIT;
+ /* Note: The task_id can be found with the "taskinfo" command. */
+ const uint32_t expected_task_id = 5;
+ const uint8_t expected_exception = 0;
+
+ uint32_t reason = 0;
+ uint32_t info = 0;
+ uint8_t exception = UINT8_MAX;
+
+ panic_get_reason(&reason, &info, &exception);
+
+ TEST_EQ(reason, expected_reason, "%08x");
+ TEST_EQ(info, expected_task_id, "%d");
+ TEST_EQ(exception, expected_exception, "%d");
+
+ return EC_SUCCESS;
+}
+
+test_static void run_test_step1()
+{
+ test_set_next_step(TEST_STATE_STEP_2);
+ RUN_TEST(test_exception);
+}
+
+test_static void run_test_step2()
+{
+ RUN_TEST(test_panic_data);
+
+ if (test_get_error_count())
+ test_reboot_to_next_step(TEST_STATE_FAILED);
+ else
+ test_reboot_to_next_step(TEST_STATE_PASSED);
+}
+
+void test_run_step(uint32_t state)
+{
+ if (state & TEST_STATE_MASK(TEST_STATE_STEP_1)) {
+ run_test_step1();
+ } else if (state & TEST_STATE_MASK(TEST_STATE_STEP_2)) {
+ run_test_step2();
+ }
+}
+
+extern "C" int task_test(void *unused)
+{
+ if (IS_ENABLED(SECTION_IS_RW))
+ test_run_multistep();
+ return EC_SUCCESS;
+}
+
+extern "C" void run_test(int argc, const char **argv)
+{
+ test_reset();
+ msleep(30); /* Wait for TASK_ID_TEST to initialize */
+ task_wake(TASK_ID_TEST);
+}
diff --git a/test/exception.tasklist b/test/exception.tasklist
new file mode 100644
index 0000000000..273a9664c0
--- /dev/null
+++ b/test/exception.tasklist
@@ -0,0 +1,10 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST \
+ TASK_TEST(TEST, task_test, NULL, TASK_STACK_SIZE)
diff --git a/test/run_device_tests.py b/test/run_device_tests.py
index b30f115509..55a6def594 100755
--- a/test/run_device_tests.py
+++ b/test/run_device_tests.py
@@ -199,6 +199,7 @@ class AllTests:
TestConfig(test_name="cec"),
TestConfig(test_name="cortexm_fpu"),
TestConfig(test_name="crc"),
+ TestConfig(test_name="exception"),
TestConfig(
test_name="flash_physical",
image_to_use=ImageType.RO,