Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 2 | #include <stdbool.h> |
Arnaldo Carvalho de Melo | e5e6312 | 2016-07-22 12:12:49 -0300 | [diff] [blame] | 3 | #include <stdlib.h> |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 4 | #include "tests.h" |
| 5 | #include "dso.h" |
| 6 | #include "debug.h" |
| 7 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 8 | static int test(const char *path, bool alloc_name, bool kmod, |
| 9 | int comp, const char *name) |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 10 | { |
| 11 | struct kmod_path m; |
| 12 | |
| 13 | memset(&m, 0x0, sizeof(m)); |
| 14 | |
| 15 | TEST_ASSERT_VAL("kmod_path__parse", |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 16 | !__kmod_path__parse(&m, path, alloc_name)); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 17 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 18 | pr_debug("%s - alloc name %d, kmod %d, comp %d, name '%s'\n", |
| 19 | path, alloc_name, m.kmod, m.comp, m.name); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 20 | |
| 21 | TEST_ASSERT_VAL("wrong kmod", m.kmod == kmod); |
| 22 | TEST_ASSERT_VAL("wrong comp", m.comp == comp); |
| 23 | |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 24 | if (name) |
| 25 | TEST_ASSERT_VAL("wrong name", m.name && !strcmp(name, m.name)); |
| 26 | else |
| 27 | TEST_ASSERT_VAL("wrong name", !m.name); |
| 28 | |
| 29 | free(m.name); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 30 | return 0; |
| 31 | } |
| 32 | |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 33 | static int test_is_kernel_module(const char *path, int cpumode, bool expect) |
| 34 | { |
| 35 | TEST_ASSERT_VAL("is_kernel_module", |
| 36 | (!!is_kernel_module(path, cpumode)) == (!!expect)); |
| 37 | pr_debug("%s (cpumode: %d) - is_kernel_module: %s\n", |
| 38 | path, cpumode, expect ? "true" : "false"); |
| 39 | return 0; |
| 40 | } |
| 41 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 42 | #define T(path, an, k, c, n) \ |
| 43 | TEST_ASSERT_VAL("failed", !test(path, an, k, c, n)) |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 44 | |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 45 | #define M(path, c, e) \ |
| 46 | TEST_ASSERT_VAL("failed", !test_is_kernel_module(path, c, e)) |
| 47 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 48 | int test__kmod_path__parse(struct test *t __maybe_unused, int subtest __maybe_unused) |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 49 | { |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 50 | /* path alloc_name kmod comp name */ |
| 51 | T("/xxxx/xxxx/x-x.ko", true , true, 0 , "[x_x]"); |
| 52 | T("/xxxx/xxxx/x-x.ko", false , true, 0 , NULL ); |
| 53 | T("/xxxx/xxxx/x-x.ko", true , true, 0 , "[x_x]"); |
| 54 | T("/xxxx/xxxx/x-x.ko", false , true, 0 , NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 55 | M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); |
| 56 | M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_KERNEL, true); |
| 57 | M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_USER, false); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 58 | |
Kim Phillips | 805b151 | 2017-05-03 13:14:02 +0100 | [diff] [blame] | 59 | #ifdef HAVE_ZLIB_SUPPORT |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 60 | /* path alloc_name kmod comp name */ |
| 61 | T("/xxxx/xxxx/x.ko.gz", true , true, 1 , "[x]"); |
| 62 | T("/xxxx/xxxx/x.ko.gz", false , true, 1 , NULL ); |
| 63 | T("/xxxx/xxxx/x.ko.gz", true , true, 1 , "[x]"); |
| 64 | T("/xxxx/xxxx/x.ko.gz", false , true, 1 , NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 65 | M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); |
| 66 | M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_KERNEL, true); |
| 67 | M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_USER, false); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 68 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 69 | /* path alloc_name kmod comp name */ |
| 70 | T("/xxxx/xxxx/x.gz", true , false, 1 , "x.gz"); |
| 71 | T("/xxxx/xxxx/x.gz", false , false, 1 , NULL ); |
| 72 | T("/xxxx/xxxx/x.gz", true , false, 1 , "x.gz"); |
| 73 | T("/xxxx/xxxx/x.gz", false , false, 1 , NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 74 | M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); |
| 75 | M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_KERNEL, false); |
| 76 | M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_USER, false); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 77 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 78 | /* path alloc_name kmod comp name */ |
| 79 | T("x.gz", true , false, 1 , "x.gz"); |
| 80 | T("x.gz", false , false, 1 , NULL ); |
| 81 | T("x.gz", true , false, 1 , "x.gz"); |
| 82 | T("x.gz", false , false, 1 , NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 83 | M("x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); |
| 84 | M("x.gz", PERF_RECORD_MISC_KERNEL, false); |
| 85 | M("x.gz", PERF_RECORD_MISC_USER, false); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 86 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 87 | /* path alloc_name kmod comp name */ |
| 88 | T("x.ko.gz", true , true, 1 , "[x]"); |
| 89 | T("x.ko.gz", false , true, 1 , NULL ); |
| 90 | T("x.ko.gz", true , true, 1 , "[x]"); |
| 91 | T("x.ko.gz", false , true, 1 , NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 92 | M("x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); |
| 93 | M("x.ko.gz", PERF_RECORD_MISC_KERNEL, true); |
| 94 | M("x.ko.gz", PERF_RECORD_MISC_USER, false); |
Kim Phillips | 805b151 | 2017-05-03 13:14:02 +0100 | [diff] [blame] | 95 | #endif |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 96 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 97 | /* path alloc_name kmod comp name */ |
| 98 | T("[test_module]", true , true, false, "[test_module]"); |
| 99 | T("[test_module]", false , true, false, NULL ); |
| 100 | T("[test_module]", true , true, false, "[test_module]"); |
| 101 | T("[test_module]", false , true, false, NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 102 | M("[test_module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); |
| 103 | M("[test_module]", PERF_RECORD_MISC_KERNEL, true); |
| 104 | M("[test_module]", PERF_RECORD_MISC_USER, false); |
| 105 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 106 | /* path alloc_name kmod comp name */ |
| 107 | T("[test.module]", true , true, false, "[test.module]"); |
| 108 | T("[test.module]", false , true, false, NULL ); |
| 109 | T("[test.module]", true , true, false, "[test.module]"); |
| 110 | T("[test.module]", false , true, false, NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 111 | M("[test.module]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true); |
| 112 | M("[test.module]", PERF_RECORD_MISC_KERNEL, true); |
| 113 | M("[test.module]", PERF_RECORD_MISC_USER, false); |
| 114 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 115 | /* path alloc_name kmod comp name */ |
| 116 | T("[vdso]", true , false, false, "[vdso]"); |
| 117 | T("[vdso]", false , false, false, NULL ); |
| 118 | T("[vdso]", true , false, false, "[vdso]"); |
| 119 | T("[vdso]", false , false, false, NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 120 | M("[vdso]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); |
| 121 | M("[vdso]", PERF_RECORD_MISC_KERNEL, false); |
| 122 | M("[vdso]", PERF_RECORD_MISC_USER, false); |
| 123 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 124 | T("[vdso32]", true , false, false, "[vdso32]"); |
| 125 | T("[vdso32]", false , false, false, NULL ); |
| 126 | T("[vdso32]", true , false, false, "[vdso32]"); |
| 127 | T("[vdso32]", false , false, false, NULL ); |
Adrian Hunter | dcaeae4 | 2018-06-04 15:56:53 +0300 | [diff] [blame] | 128 | M("[vdso32]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); |
| 129 | M("[vdso32]", PERF_RECORD_MISC_KERNEL, false); |
| 130 | M("[vdso32]", PERF_RECORD_MISC_USER, false); |
| 131 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 132 | T("[vdsox32]", true , false, false, "[vdsox32]"); |
| 133 | T("[vdsox32]", false , false, false, NULL ); |
| 134 | T("[vdsox32]", true , false, false, "[vdsox32]"); |
| 135 | T("[vdsox32]", false , false, false, NULL ); |
Adrian Hunter | dcaeae4 | 2018-06-04 15:56:53 +0300 | [diff] [blame] | 136 | M("[vdsox32]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); |
| 137 | M("[vdsox32]", PERF_RECORD_MISC_KERNEL, false); |
| 138 | M("[vdsox32]", PERF_RECORD_MISC_USER, false); |
| 139 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 140 | /* path alloc_name kmod comp name */ |
| 141 | T("[vsyscall]", true , false, false, "[vsyscall]"); |
| 142 | T("[vsyscall]", false , false, false, NULL ); |
| 143 | T("[vsyscall]", true , false, false, "[vsyscall]"); |
| 144 | T("[vsyscall]", false , false, false, NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 145 | M("[vsyscall]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); |
| 146 | M("[vsyscall]", PERF_RECORD_MISC_KERNEL, false); |
| 147 | M("[vsyscall]", PERF_RECORD_MISC_USER, false); |
| 148 | |
Jiri Olsa | b946cd3 | 2018-08-17 11:48:13 +0200 | [diff] [blame] | 149 | /* path alloc_name kmod comp name */ |
| 150 | T("[kernel.kallsyms]", true , false, false, "[kernel.kallsyms]"); |
| 151 | T("[kernel.kallsyms]", false , false, false, NULL ); |
| 152 | T("[kernel.kallsyms]", true , false, false, "[kernel.kallsyms]"); |
| 153 | T("[kernel.kallsyms]", false , false, false, NULL ); |
Wang Nan | 1f121b0 | 2015-06-03 08:52:21 +0000 | [diff] [blame] | 154 | M("[kernel.kallsyms]", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false); |
| 155 | M("[kernel.kallsyms]", PERF_RECORD_MISC_KERNEL, false); |
| 156 | M("[kernel.kallsyms]", PERF_RECORD_MISC_USER, false); |
Jiri Olsa | 3c8a67f | 2015-02-05 15:40:25 +0100 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |