cyclic: Add a simple test
[platform/kernel/u-boot.git] / test / test-main.c
index ee38d1f..ae34002 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <console.h>
+#include <cyclic.h>
 #include <dm.h>
 #include <event.h>
 #include <dm/root.h>
@@ -220,6 +221,7 @@ static int dm_test_restore(struct device_node *of_root)
 static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 {
        ut_assertok(event_init());
+       ut_assertok(cyclic_init());
 
        if (test->flags & UT_TESTF_DM)
                ut_assertok(dm_test_pre_run(uts));
@@ -228,8 +230,10 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 
        uts->start = mallinfo();
 
-       if (test->flags & UT_TESTF_SCAN_PDATA)
+       if (test->flags & UT_TESTF_SCAN_PDATA) {
                ut_assertok(dm_scan_plat(false));
+               ut_assertok(dm_scan_other(false));
+       }
 
        if (test->flags & UT_TESTF_PROBE_TEST)
                ut_assertok(do_autoprobe(uts));
@@ -263,6 +267,7 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
        ut_unsilence_console(uts);
        if (test->flags & UT_TESTF_DM)
                ut_assertok(dm_test_post_run(uts));
+       ut_assertok(cyclic_uninit());
        ut_assertok(event_uninit());
 
        return 0;
@@ -338,7 +343,8 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
        /* Run with the live tree if possible */
        runs = 0;
        if (CONFIG_IS_ENABLED(OF_LIVE)) {
-               if (!(test->flags & UT_TESTF_FLAT_TREE)) {
+               if (!(test->flags &
+                   (UT_TESTF_FLAT_TREE | UT_TESTF_LIVE_OR_FLAT))) {
                        uts->of_live = true;
                        ut_assertok(ut_run_test(uts, test, test->name));
                        runs++;
@@ -387,11 +393,17 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 
        for (test = tests; test < tests + count; test++) {
                const char *test_name = test->name;
-               int ret;
+               int ret, i, old_fail_count;
 
                if (!test_matches(prefix, test_name, select_name))
                        continue;
-               ret = ut_run_test_live_flat(uts, test, select_name);
+               old_fail_count = uts->fail_count;
+               for (i = 0; i < uts->runs_per_test; i++)
+                       ret = ut_run_test_live_flat(uts, test, select_name);
+               if (uts->fail_count != old_fail_count) {
+                       printf("Test %s failed %d times\n", select_name,
+                              uts->fail_count - old_fail_count);
+               }
                found++;
                if (ret == -EAGAIN)
                        continue;
@@ -405,7 +417,8 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
 }
 
 int ut_run_list(const char *category, const char *prefix,
-               struct unit_test *tests, int count, const char *select_name)
+               struct unit_test *tests, int count, const char *select_name,
+               int runs_per_test)
 {
        struct unit_test_state uts = { .fail_count = 0 };
        bool has_dm_tests = false;
@@ -429,6 +442,7 @@ int ut_run_list(const char *category, const char *prefix,
                printf("Running %d %s tests\n", count, category);
 
        uts.of_root = gd_of_root();
+       uts.runs_per_test = runs_per_test;
        ret = ut_run_tests(&uts, prefix, tests, count, select_name);
 
        if (ret == -ENOENT)