Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop Greentea tests if a fatal error occurs #432

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion TESTS/configs/greentea_baremetal.json5
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// Allow lots of reboots so that we don't get in a situation where the MCU refuses to boot
// after crashing and being reflashed (since some MCUs/flash tools don't reset the
// crash data RAM)
"platform.error-reboot-max": 99999,
"platform.error-reboot-max": 2147483648,

// Emit a KV pair when an assert fail or hardfault occurs
"platform.mbed-error-emit-greentea-kv": true,

// Enable mbed trace prints for tests that use it
"mbed-trace.enable": true,
Expand Down
5 changes: 4 additions & 1 deletion TESTS/configs/greentea_full.json5
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
// Allow lots of reboots so that we don't get in a situation where the MCU refuses to boot
// after crashing and being reflashed (since some MCUs/flash tools don't reset the
// crash data RAM)
"platform.error-reboot-max": 99999,
"platform.error-reboot-max": 2147483648,

// Emit a KV pair when an assert fail or hardfault occurs
"platform.mbed-error-emit-greentea-kv": true,

// Enable mbed trace prints for tests that use it
"mbed-trace.enable": true,
Expand Down
4 changes: 4 additions & 0 deletions platform/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
"minimal-printf-set-floating-point-max-decimals": {
"help": "Maximum number of decimals to be printed when using minimal printf library",
"value": 6
},
"mbed-error-emit-greentea-kv": {
"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.",
"value": null
}
},
"target_overrides": {
Expand Down
12 changes: 12 additions & 0 deletions platform/source/mbed_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,18 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
#endif

mbed_error_printf("\n-- MbedOS Error Info --\n");

// Print error summary for Greentea tests if desired.
#ifdef MBED_CONF_PLATFORM_MBED_ERROR_EMIT_GREENTEA_KV
// Flag that error occurred. Print this first because the default test runner
// just ends the test right away when it sees this.
mbed_error_printf("{{mbed_error;1}}\r\n");

mbed_error_printf("{{mbed_error_module;%d}}\r\n", error_module);
mbed_error_printf("{{mbed_error_code;%d}}\r\n", error_code);
mbed_error_printf("{{mbed_error_message;%s}}\r\n", error_msg);
mbed_error_printf("{{mbed_error_location;0x%" PRIx32 "}}\r\n", ctx->error_address);
#endif
}
#endif //ifndef NDEBUG

Expand Down
12 changes: 12 additions & 0 deletions tools/python/mbed_os_tools/test/host_tests/base_host_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,24 @@ def __default_end_callback(self, key, value, timestamp):
"""
self.notify_complete(value == 'success')

def _default_mbed_error_callback(self, key: str, value: str, timestamp: float):
# End the test immediately on error by default. This prevents wasting test runner time
# by waiting for the timeout to expire!
self.log("Detected target fatal error. Failing test...")
self.notify_complete(False)

def __assign_default_callbacks(self):
"""! Assigns default callback handlers """
for key in self.__consume_by_default:
self.__callbacks[key] = self.__callback_default
# Register default handler for event 'end' before assigning user defined callbacks to let users over write it.
self.register_callback('end', self.__default_end_callback)
self.register_callback("mbed_error", self._default_mbed_error_callback)

# Register empty callbacks for the error details, to prevent "orphan event" warnings
self.register_callback("mbed_error_module", self.__callback_default)
self.register_callback("mbed_error_code", self.__callback_default)
self.register_callback("mbed_error_message", self.__callback_default)

def __assign_decorated_callbacks(self):
"""
Expand Down
Loading