]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blobdiff - tools/testing/selftests/bpf/test_progs.c
selftests/bpf: Make a copy of subtest name
[mirror_ubuntu-focal-kernel.git] / tools / testing / selftests / bpf / test_progs.c
index af75a1c7a4587253d36c68f4bd0bd9f68798593b..3bf18364c67c9beff81f4ba81d11aa7b79cbd46b 100644 (file)
@@ -20,7 +20,7 @@ struct prog_test_def {
        bool tested;
        bool need_cgroup_cleanup;
 
-       const char *subtest_name;
+       char *subtest_name;
        int subtest_num;
 
        /* store counts before subtest started */
@@ -81,16 +81,17 @@ void test__end_subtest()
        fprintf(env.stdout, "#%d/%d %s:%s\n",
               test->test_num, test->subtest_num,
               test->subtest_name, sub_error_cnt ? "FAIL" : "OK");
+
+       free(test->subtest_name);
+       test->subtest_name = NULL;
 }
 
 bool test__start_subtest(const char *name)
 {
        struct prog_test_def *test = env.test;
 
-       if (test->subtest_name) {
+       if (test->subtest_name)
                test__end_subtest();
-               test->subtest_name = NULL;
-       }
 
        test->subtest_num++;
 
@@ -104,7 +105,13 @@ bool test__start_subtest(const char *name)
        if (!should_run(&env.subtest_selector, test->subtest_num, name))
                return false;
 
-       test->subtest_name = name;
+       test->subtest_name = strdup(name);
+       if (!test->subtest_name) {
+               fprintf(env.stderr,
+                       "Subtest #%d: failed to copy subtest name!\n",
+                       test->subtest_num);
+               return false;
+       }
        env.test->old_error_cnt = env.test->error_cnt;
 
        return true;