~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/kmod-path.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp