6 static int test(const char *path
, bool alloc_name
, bool alloc_ext
,
7 bool kmod
, bool comp
, const char *name
, const char *ext
)
11 memset(&m
, 0x0, sizeof(m
));
13 TEST_ASSERT_VAL("kmod_path__parse",
14 !__kmod_path__parse(&m
, path
, alloc_name
, alloc_ext
));
16 pr_debug("%s - alloc name %d, alloc ext %d, kmod %d, comp %d, name '%s', ext '%s'\n",
17 path
, alloc_name
, alloc_ext
, m
.kmod
, m
.comp
, m
.name
, m
.ext
);
19 TEST_ASSERT_VAL("wrong kmod", m
.kmod
== kmod
);
20 TEST_ASSERT_VAL("wrong comp", m
.comp
== comp
);
23 TEST_ASSERT_VAL("wrong ext", m
.ext
&& !strcmp(ext
, m
.ext
));
25 TEST_ASSERT_VAL("wrong ext", !m
.ext
);
28 TEST_ASSERT_VAL("wrong name", m
.name
&& !strcmp(name
, m
.name
));
30 TEST_ASSERT_VAL("wrong name", !m
.name
);
37 static int test_is_kernel_module(const char *path
, int cpumode
, bool expect
)
39 TEST_ASSERT_VAL("is_kernel_module",
40 (!!is_kernel_module(path
, cpumode
)) == (!!expect
));
41 pr_debug("%s (cpumode: %d) - is_kernel_module: %s\n",
42 path
, cpumode
, expect
? "true" : "false");
46 #define T(path, an, ae, k, c, n, e) \
47 TEST_ASSERT_VAL("failed", !test(path, an, ae, k, c, n, e))
49 #define M(path, c, e) \
50 TEST_ASSERT_VAL("failed", !test_is_kernel_module(path, c, e))
52 int test__kmod_path__parse(int subtest __maybe_unused
)
54 /* path alloc_name alloc_ext kmod comp name ext */
55 T("/xxxx/xxxx/x-x.ko", true , true , true, false, "[x_x]", NULL
);
56 T("/xxxx/xxxx/x-x.ko", false , true , true, false, NULL
, NULL
);
57 T("/xxxx/xxxx/x-x.ko", true , false , true, false, "[x_x]", NULL
);
58 T("/xxxx/xxxx/x-x.ko", false , false , true, false, NULL
, NULL
);
59 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, true);
60 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_KERNEL
, true);
61 M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_USER
, false);
63 /* path alloc_name alloc_ext kmod comp name ext */
64 T("/xxxx/xxxx/x.ko.gz", true , true , true, true, "[x]", "gz");
65 T("/xxxx/xxxx/x.ko.gz", false , true , true, true, NULL
, "gz");
66 T("/xxxx/xxxx/x.ko.gz", true , false , true, true, "[x]", NULL
);
67 T("/xxxx/xxxx/x.ko.gz", false , false , true, true, NULL
, NULL
);
68 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, true);
69 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_KERNEL
, true);
70 M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_USER
, false);
72 /* path alloc_name alloc_ext kmod comp name ext */
73 T("/xxxx/xxxx/x.gz", true , true , false, true, "x.gz" ,"gz");
74 T("/xxxx/xxxx/x.gz", false , true , false, true, NULL
,"gz");
75 T("/xxxx/xxxx/x.gz", true , false , false, true, "x.gz" , NULL
);
76 T("/xxxx/xxxx/x.gz", false , false , false, true, NULL
, NULL
);
77 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, false);
78 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_KERNEL
, false);
79 M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_USER
, false);
81 /* path alloc_name alloc_ext kmod comp name ext */
82 T("x.gz", true , true , false, true, "x.gz", "gz");
83 T("x.gz", false , true , false, true, NULL
, "gz");
84 T("x.gz", true , false , false, true, "x.gz", NULL
);
85 T("x.gz", false , false , false, true, NULL
, NULL
);
86 M("x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, false);
87 M("x.gz", PERF_RECORD_MISC_KERNEL
, false);
88 M("x.gz", PERF_RECORD_MISC_USER
, false);
90 /* path alloc_name alloc_ext kmod comp name ext */
91 T("x.ko.gz", true , true , true, true, "[x]", "gz");
92 T("x.ko.gz", false , true , true, true, NULL
, "gz");
93 T("x.ko.gz", true , false , true, true, "[x]", NULL
);
94 T("x.ko.gz", false , false , true, true, NULL
, NULL
);
95 M("x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, true);
96 M("x.ko.gz", PERF_RECORD_MISC_KERNEL
, true);
97 M("x.ko.gz", PERF_RECORD_MISC_USER
, false);
99 /* path alloc_name alloc_ext kmod comp name ext */
100 T("[test_module]", true , true , true, false, "[test_module]", NULL
);
101 T("[test_module]", false , true , true, false, NULL
, NULL
);
102 T("[test_module]", true , false , true, false, "[test_module]", NULL
);
103 T("[test_module]", false , false , true, false, NULL
, NULL
);
104 M("[test_module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, true);
105 M("[test_module]", PERF_RECORD_MISC_KERNEL
, true);
106 M("[test_module]", PERF_RECORD_MISC_USER
, false);
108 /* path alloc_name alloc_ext kmod comp name ext */
109 T("[test.module]", true , true , true, false, "[test.module]", NULL
);
110 T("[test.module]", false , true , true, false, NULL
, NULL
);
111 T("[test.module]", true , false , true, false, "[test.module]", NULL
);
112 T("[test.module]", false , false , true, false, NULL
, NULL
);
113 M("[test.module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, true);
114 M("[test.module]", PERF_RECORD_MISC_KERNEL
, true);
115 M("[test.module]", PERF_RECORD_MISC_USER
, false);
117 /* path alloc_name alloc_ext kmod comp name ext */
118 T("[vdso]", true , true , false, false, "[vdso]", NULL
);
119 T("[vdso]", false , true , false, false, NULL
, NULL
);
120 T("[vdso]", true , false , false, false, "[vdso]", NULL
);
121 T("[vdso]", false , false , false, false, NULL
, NULL
);
122 M("[vdso]", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, false);
123 M("[vdso]", PERF_RECORD_MISC_KERNEL
, false);
124 M("[vdso]", PERF_RECORD_MISC_USER
, false);
126 /* path alloc_name alloc_ext kmod comp name ext */
127 T("[vsyscall]", true , true , false, false, "[vsyscall]", NULL
);
128 T("[vsyscall]", false , true , false, false, NULL
, NULL
);
129 T("[vsyscall]", true , false , false, false, "[vsyscall]", NULL
);
130 T("[vsyscall]", false , false , false, false, NULL
, NULL
);
131 M("[vsyscall]", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, false);
132 M("[vsyscall]", PERF_RECORD_MISC_KERNEL
, false);
133 M("[vsyscall]", PERF_RECORD_MISC_USER
, false);
135 /* path alloc_name alloc_ext kmod comp name ext */
136 T("[kernel.kallsyms]", true , true , false, false, "[kernel.kallsyms]", NULL
);
137 T("[kernel.kallsyms]", false , true , false, false, NULL
, NULL
);
138 T("[kernel.kallsyms]", true , false , false, false, "[kernel.kallsyms]", NULL
);
139 T("[kernel.kallsyms]", false , false , false, false, NULL
, NULL
);
140 M("[kernel.kallsyms]", PERF_RECORD_MISC_CPUMODE_UNKNOWN
, false);
141 M("[kernel.kallsyms]", PERF_RECORD_MISC_KERNEL
, false);
142 M("[kernel.kallsyms]", PERF_RECORD_MISC_USER
, false);