diff options
-rw-r--r-- | common/test_util.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/common/test_util.c b/common/test_util.c index 3b64b16fec..c5c238d42d 100644 --- a/common/test_util.c +++ b/common/test_util.c @@ -9,12 +9,20 @@ #include <stdlib.h> #include "console.h" +#include "hooks.h" #include "host_command.h" #include "system.h" #include "task.h" #include "test_util.h" #include "util.h" +struct test_util_tag { + uint8_t error_count; +}; + +#define TEST_UTIL_SYSJUMP_TAG 0x5455 /* "TU" */ +#define TEST_UTIL_SYSJUMP_VERSION 1 + int __test_error_count; /* Weak reference function as an entry point for unit test */ @@ -53,7 +61,8 @@ void register_test_end_hook(void) void test_reset(void) { - __test_error_count = 0; + if (!system_jumped_to_this_image()) + __test_error_count = 0; } void test_pass(void) @@ -152,6 +161,30 @@ uint32_t prng_no_seed(void) return seed = prng(seed); } +static void restore_state(void) +{ + const struct test_util_tag *tag; + int version, size; + + tag = (const struct test_util_tag *)system_get_jump_tag( + TEST_UTIL_SYSJUMP_TAG, &version, &size); + if (tag && version == TEST_UTIL_SYSJUMP_VERSION && + size == sizeof(*tag)) + __test_error_count = tag->error_count; + else + __test_error_count = 0; +} +DECLARE_HOOK(HOOK_INIT, restore_state, HOOK_PRIO_DEFAULT); + +static void preserve_state(void) +{ + struct test_util_tag tag; + tag.error_count = __test_error_count; + system_add_jump_tag(TEST_UTIL_SYSJUMP_TAG, TEST_UTIL_SYSJUMP_VERSION, + sizeof(tag), &tag); +} +DECLARE_HOOK(HOOK_SYSJUMP, preserve_state, HOOK_PRIO_DEFAULT); + static int command_run_test(int argc, char **argv) { run_test(); |