Skip to content

Commit b68997b

Browse files
author
Jamie Smith
authored
Stop Greentea tests if a fatal error occurs (#432)
* Stop Greentea tests if a fatal error occurs * Style
1 parent 86f430b commit b68997b

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

TESTS/configs/greentea_baremetal.json5

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
// Allow lots of reboots so that we don't get in a situation where the MCU refuses to boot
1616
// after crashing and being reflashed (since some MCUs/flash tools don't reset the
1717
// crash data RAM)
18-
"platform.error-reboot-max": 99999,
18+
"platform.error-reboot-max": 2147483648,
19+
20+
// Emit a KV pair when an assert fail or hardfault occurs
21+
"platform.mbed-error-emit-greentea-kv": true,
1922

2023
// Enable mbed trace prints for tests that use it
2124
"mbed-trace.enable": true,

TESTS/configs/greentea_full.json5

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
// Allow lots of reboots so that we don't get in a situation where the MCU refuses to boot
1010
// after crashing and being reflashed (since some MCUs/flash tools don't reset the
1111
// crash data RAM)
12-
"platform.error-reboot-max": 99999,
12+
"platform.error-reboot-max": 2147483648,
13+
14+
// Emit a KV pair when an assert fail or hardfault occurs
15+
"platform.mbed-error-emit-greentea-kv": true,
1316

1417
// Enable mbed trace prints for tests that use it
1518
"mbed-trace.enable": true,

platform/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@
164164
"minimal-printf-set-floating-point-max-decimals": {
165165
"help": "Maximum number of decimals to be printed when using minimal printf library",
166166
"value": 6
167+
},
168+
"mbed-error-emit-greentea-kv": {
169+
"help": "Option that can be used when building Greentea tests. Causes the mbed_error() function (caused by assert failures and HardFaults) to emit a Greentea key-value pair indicating that an error has occurred.",
170+
"value": null
167171
}
168172
},
169173
"target_overrides": {

platform/source/mbed_error.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,18 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
661661
#endif
662662

663663
mbed_error_printf("\n-- MbedOS Error Info --\n");
664+
665+
// Print error summary for Greentea tests if desired.
666+
#ifdef MBED_CONF_PLATFORM_MBED_ERROR_EMIT_GREENTEA_KV
667+
// Flag that error occurred. Print this first because the default test runner
668+
// just ends the test right away when it sees this.
669+
mbed_error_printf("{{mbed_error;1}}\r\n");
670+
671+
mbed_error_printf("{{mbed_error_module;%d}}\r\n", error_module);
672+
mbed_error_printf("{{mbed_error_code;%d}}\r\n", error_code);
673+
mbed_error_printf("{{mbed_error_message;%s}}\r\n", error_msg);
674+
mbed_error_printf("{{mbed_error_location;0x%" PRIx32 "}}\r\n", ctx->error_address);
675+
#endif
664676
}
665677
#endif //ifndef NDEBUG
666678

tools/python/mbed_os_tools/test/host_tests/base_host_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,24 @@ def __default_end_callback(self, key, value, timestamp):
171171
"""
172172
self.notify_complete(value == 'success')
173173

174+
def _default_mbed_error_callback(self, key: str, value: str, timestamp: float):
175+
# End the test immediately on error by default. This prevents wasting test runner time
176+
# by waiting for the timeout to expire!
177+
self.log("Detected target fatal error. Failing test...")
178+
self.notify_complete(False)
179+
174180
def __assign_default_callbacks(self):
175181
"""! Assigns default callback handlers """
176182
for key in self.__consume_by_default:
177183
self.__callbacks[key] = self.__callback_default
178184
# Register default handler for event 'end' before assigning user defined callbacks to let users over write it.
179185
self.register_callback('end', self.__default_end_callback)
186+
self.register_callback("mbed_error", self._default_mbed_error_callback)
187+
188+
# Register empty callbacks for the error details, to prevent "orphan event" warnings
189+
self.register_callback("mbed_error_module", self.__callback_default)
190+
self.register_callback("mbed_error_code", self.__callback_default)
191+
self.register_callback("mbed_error_message", self.__callback_default)
180192

181193
def __assign_decorated_callbacks(self):
182194
"""

0 commit comments

Comments
 (0)