diff options
Diffstat (limited to 'tools/perf/tests/kmod-path.c')
-rw-r--r-- | tools/perf/tests/kmod-path.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tools/perf/tests/kmod-path.c b/tools/perf/tests/kmod-path.c new file mode 100644 index 000000000000..e8d7cbb9320c --- /dev/null +++ b/tools/perf/tests/kmod-path.c | |||
@@ -0,0 +1,73 @@ | |||
1 | #include <stdbool.h> | ||
2 | #include "tests.h" | ||
3 | #include "dso.h" | ||
4 | #include "debug.h" | ||
5 | |||
6 | static int test(const char *path, bool alloc_name, bool alloc_ext, | ||
7 | bool kmod, bool comp, const char *name, const char *ext) | ||
8 | { | ||
9 | struct kmod_path m; | ||
10 | |||
11 | memset(&m, 0x0, sizeof(m)); | ||
12 | |||
13 | TEST_ASSERT_VAL("kmod_path__parse", | ||
14 | !__kmod_path__parse(&m, path, alloc_name, alloc_ext)); | ||
15 | |||
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); | ||
18 | |||
19 | TEST_ASSERT_VAL("wrong kmod", m.kmod == kmod); | ||
20 | TEST_ASSERT_VAL("wrong comp", m.comp == comp); | ||
21 | |||
22 | if (ext) | ||
23 | TEST_ASSERT_VAL("wrong ext", m.ext && !strcmp(ext, m.ext)); | ||
24 | else | ||
25 | TEST_ASSERT_VAL("wrong ext", !m.ext); | ||
26 | |||
27 | if (name) | ||
28 | TEST_ASSERT_VAL("wrong name", m.name && !strcmp(name, m.name)); | ||
29 | else | ||
30 | TEST_ASSERT_VAL("wrong name", !m.name); | ||
31 | |||
32 | free(m.name); | ||
33 | free(m.ext); | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | #define T(path, an, ae, k, c, n, e) \ | ||
38 | TEST_ASSERT_VAL("failed", !test(path, an, ae, k, c, n, e)) | ||
39 | |||
40 | int test__kmod_path__parse(void) | ||
41 | { | ||
42 | /* path alloc_name alloc_ext kmod comp name ext */ | ||
43 | T("/xxxx/xxxx/x-x.ko", true , true , true, false, "[x_x]", NULL); | ||
44 | T("/xxxx/xxxx/x-x.ko", false , true , true, false, NULL , NULL); | ||
45 | T("/xxxx/xxxx/x-x.ko", true , false , true, false, "[x_x]", NULL); | ||
46 | T("/xxxx/xxxx/x-x.ko", false , false , true, false, NULL , NULL); | ||
47 | |||
48 | /* path alloc_name alloc_ext kmod comp name ext */ | ||
49 | T("/xxxx/xxxx/x.ko.gz", true , true , true, true, "[x]", "gz"); | ||
50 | T("/xxxx/xxxx/x.ko.gz", false , true , true, true, NULL , "gz"); | ||
51 | T("/xxxx/xxxx/x.ko.gz", true , false , true, true, "[x]", NULL); | ||
52 | T("/xxxx/xxxx/x.ko.gz", false , false , true, true, NULL , NULL); | ||
53 | |||
54 | /* path alloc_name alloc_ext kmod comp name ext */ | ||
55 | T("/xxxx/xxxx/x.gz", true , true , false, true, "x.gz" ,"gz"); | ||
56 | T("/xxxx/xxxx/x.gz", false , true , false, true, NULL ,"gz"); | ||
57 | T("/xxxx/xxxx/x.gz", true , false , false, true, "x.gz" , NULL); | ||
58 | T("/xxxx/xxxx/x.gz", false , false , false, true, NULL , NULL); | ||
59 | |||
60 | /* path alloc_name alloc_ext kmod comp name ext */ | ||
61 | T("x.gz", true , true , false, true, "x.gz", "gz"); | ||
62 | T("x.gz", false , true , false, true, NULL , "gz"); | ||
63 | T("x.gz", true , false , false, true, "x.gz", NULL); | ||
64 | T("x.gz", false , false , false, true, NULL , NULL); | ||
65 | |||
66 | /* path alloc_name alloc_ext kmod comp name ext */ | ||
67 | T("x.ko.gz", true , true , true, true, "[x]", "gz"); | ||
68 | T("x.ko.gz", false , true , true, true, NULL , "gz"); | ||
69 | T("x.ko.gz", true , false , true, true, "[x]", NULL); | ||
70 | T("x.ko.gz", false , false , true, true, NULL , NULL); | ||
71 | |||
72 | return 0; | ||
73 | } | ||