]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: Add functions to init and uninit the test state
authorSimon Glass <sjg@chromium.org>
Mon, 20 Jan 2025 21:25:25 +0000 (14:25 -0700)
committerTom Rini <trini@konsulko.com>
Fri, 24 Jan 2025 20:34:39 +0000 (14:34 -0600)
Move these operations into separate functions so that it is clearer what
is needed. These functions can also be called from somewhere other than
ut_run_list().

Signed-off-by: Simon Glass <sjg@chromium.org>
test/test-main.c

index cfb3504941d00d7da9be44ef459ee9c518e0a898..871fc1f22b4e2c470ccc1540e83bceefed7b3392 100644 (file)
@@ -73,6 +73,19 @@ void ut_set_state(struct unit_test_state *uts)
        cur_test_state = uts;
 }
 
+void ut_init_state(struct unit_test_state *uts)
+{
+       memset(uts, '\0', sizeof(*uts));
+}
+
+void ut_uninit_state(struct unit_test_state *uts)
+{
+       if (IS_ENABLED(CONFIG_SANDBOX)) {
+               os_free(uts->fdt_copy);
+               os_free(uts->other_fdt);
+       }
+}
+
 /**
  * dm_test_pre_run() - Get ready to run a driver model test
  *
@@ -664,10 +677,11 @@ int ut_run_list(const char *category, const char *prefix,
                struct unit_test *tests, int count, const char *select_name,
                int runs_per_test, bool force_run, const char *test_insert)
 {
-       struct unit_test_state uts = { .fail_count = 0 };
+       struct unit_test_state uts;
        bool has_dm_tests = false;
        int ret;
 
+       ut_init_state(&uts);
        if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
            ut_list_has_dm_tests(tests, count, prefix, select_name)) {
                has_dm_tests = true;
@@ -703,10 +717,6 @@ int ut_run_list(const char *category, const char *prefix,
        /* Best efforts only...ignore errors */
        if (has_dm_tests)
                dm_test_restore(uts.of_root);
-       if (IS_ENABLED(CONFIG_SANDBOX)) {
-               os_free(uts.fdt_copy);
-               os_free(uts.other_fdt);
-       }
 
        if (uts.skip_count)
                printf("Skipped: %d, ", uts.skip_count);
@@ -714,6 +724,7 @@ int ut_run_list(const char *category, const char *prefix,
                printf("Test '%s' not found\n", select_name);
        else
                printf("Failures: %d\n", uts.fail_count);
+       ut_uninit_state(&uts);
 
        return ret;
 }