1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 3 #include "test_progs.h" 4 #include "testing_helpers.h" 5 6 static void init_test_filter_set(struct test_filter_set *set) 7 { 8 set->cnt = 0; 9 set->tests = NULL; 10 } 11 12 static void free_test_filter_set(struct test_filter_set *set) 13 { 14 int i, j; 15 16 for (i = 0; i < set->cnt; i++) { 17 for (j = 0; j < set->tests[i].subtest_cnt; j++) 18 free((void *)set->tests[i].subtests[j]); 19 free(set->tests[i].subtests); 20 free(set->tests[i].name); 21 } 22 23 free(set->tests); 24 init_test_filter_set(set); 25 } 26 27 static void test_parse_test_list(void) 28 { 29 struct test_filter_set set; 30 31 init_test_filter_set(&set); 32 33 ASSERT_OK(parse_test_list("arg_parsing", &set, true), "parsing"); 34 if (!ASSERT_EQ(set.cnt, 1, "test filters count")) 35 goto error; 36 if (!ASSERT_OK_PTR(set.tests, "test filters initialized")) 37 goto error; 38 ASSERT_EQ(set.tests[0].subtest_cnt, 0, "subtest filters count"); 39 ASSERT_OK(strcmp("arg_parsing", set.tests[0].name), "subtest name"); 40 free_test_filter_set(&set); 41 42 ASSERT_OK(parse_test_list("arg_parsing,bpf_cookie", &set, true), 43 "parsing"); 44 if (!ASSERT_EQ(set.cnt, 2, "count of test filters")) 45 goto error; 46 if (!ASSERT_OK_PTR(set.tests, "test filters initialized")) 47 goto error; 48 ASSERT_EQ(set.tests[0].subtest_cnt, 0, "subtest filters count"); 49 ASSERT_EQ(set.tests[1].subtest_cnt, 0, "subtest filters count"); 50 ASSERT_OK(strcmp("arg_parsing", set.tests[0].name), "test name"); 51 ASSERT_OK(strcmp("bpf_cookie", set.tests[1].name), "test name"); 52 free_test_filter_set(&set); 53 54 ASSERT_OK(parse_test_list("arg_parsing/arg_parsing,bpf_cookie", 55 &set, 56 true), 57 "parsing"); 58 if (!ASSERT_EQ(set.cnt, 2, "count of test filters")) 59 goto error; 60 if (!ASSERT_OK_PTR(set.tests, "test filters initialized")) 61 goto error; 62 if (!ASSERT_EQ(set.tests[0].subtest_cnt, 1, "subtest filters count")) 63 goto error; 64 ASSERT_EQ(set.tests[1].subtest_cnt, 0, "subtest filters count"); 65 ASSERT_OK(strcmp("arg_parsing", set.tests[0].name), "test name"); 66 ASSERT_OK(strcmp("arg_parsing", set.tests[0].subtests[0]), 67 "subtest name"); 68 ASSERT_OK(strcmp("bpf_cookie", set.tests[1].name), "test name"); 69 free_test_filter_set(&set); 70 71 ASSERT_OK(parse_test_list("arg_parsing/arg_parsing", &set, true), 72 "parsing"); 73 ASSERT_OK(parse_test_list("bpf_cookie", &set, true), "parsing"); 74 ASSERT_OK(parse_test_list("send_signal", &set, true), "parsing"); 75 if (!ASSERT_EQ(set.cnt, 3, "count of test filters")) 76 goto error; 77 if (!ASSERT_OK_PTR(set.tests, "test filters initialized")) 78 goto error; 79 if (!ASSERT_EQ(set.tests[0].subtest_cnt, 1, "subtest filters count")) 80 goto error; 81 ASSERT_EQ(set.tests[1].subtest_cnt, 0, "subtest filters count"); 82 ASSERT_EQ(set.tests[2].subtest_cnt, 0, "subtest filters count"); 83 ASSERT_OK(strcmp("arg_parsing", set.tests[0].name), "test name"); 84 ASSERT_OK(strcmp("arg_parsing", set.tests[0].subtests[0]), 85 "subtest name"); 86 ASSERT_OK(strcmp("bpf_cookie", set.tests[1].name), "test name"); 87 ASSERT_OK(strcmp("send_signal", set.tests[2].name), "test name"); 88 free_test_filter_set(&set); 89 90 ASSERT_OK(parse_test_list("bpf_cookie/trace", &set, false), "parsing"); 91 if (!ASSERT_EQ(set.cnt, 1, "count of test filters")) 92 goto error; 93 if (!ASSERT_OK_PTR(set.tests, "test filters initialized")) 94 goto error; 95 if (!ASSERT_EQ(set.tests[0].subtest_cnt, 1, "subtest filters count")) 96 goto error; 97 ASSERT_OK(strcmp("*bpf_cookie*", set.tests[0].name), "test name"); 98 ASSERT_OK(strcmp("*trace*", set.tests[0].subtests[0]), "subtest name"); 99 error: 100 free_test_filter_set(&set); 101 } 102 103 void test_arg_parsing(void) 104 { 105 if (test__start_subtest("test_parse_test_list")) 106 test_parse_test_list(); 107 } 108