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

TOMOYO Linux Cross Reference
Linux/lib/test_uuid.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Test cases for lib/uuid.c module.
  3  */
  4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  5 
  6 #include <linux/init.h>
  7 #include <linux/kernel.h>
  8 #include <linux/module.h>
  9 #include <linux/string.h>
 10 #include <linux/uuid.h>
 11 
 12 struct test_uuid_data {
 13         const char *uuid;
 14         guid_t le;
 15         uuid_t be;
 16 };
 17 
 18 static const struct test_uuid_data test_uuid_test_data[] = {
 19         {
 20                 .uuid = "c33f4995-3701-450e-9fbf-206a2e98e576",
 21                 .le = GUID_INIT(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76),
 22                 .be = UUID_INIT(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76),
 23         },
 24         {
 25                 .uuid = "64b4371c-77c1-48f9-8221-29f054fc023b",
 26                 .le = GUID_INIT(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b),
 27                 .be = UUID_INIT(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b),
 28         },
 29         {
 30                 .uuid = "0cb4ddff-a545-4401-9d06-688af53e7f84",
 31                 .le = GUID_INIT(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84),
 32                 .be = UUID_INIT(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84),
 33         },
 34 };
 35 
 36 static const char * const test_uuid_wrong_data[] = {
 37         "c33f4995-3701-450e-9fbf206a2e98e576 ", /* no hyphen(s) */
 38         "64b4371c-77c1-48f9-8221-29f054XX023b", /* invalid character(s) */
 39         "0cb4ddff-a545-4401-9d06-688af53e",     /* not enough data */
 40 };
 41 
 42 static unsigned total_tests __initdata;
 43 static unsigned failed_tests __initdata;
 44 
 45 static void __init test_uuid_failed(const char *prefix, bool wrong, bool be,
 46                                     const char *data, const char *actual)
 47 {
 48         pr_err("%s test #%u %s %s data: '%s'\n",
 49                prefix,
 50                total_tests,
 51                wrong ? "passed on wrong" : "failed on",
 52                be ? "BE" : "LE",
 53                data);
 54         if (actual && *actual)
 55                 pr_err("%s test #%u actual data: '%s'\n",
 56                        prefix,
 57                        total_tests,
 58                        actual);
 59         failed_tests++;
 60 }
 61 
 62 static void __init test_uuid_test(const struct test_uuid_data *data)
 63 {
 64         guid_t le;
 65         uuid_t be;
 66         char buf[48];
 67 
 68         /* LE */
 69         total_tests++;
 70         if (guid_parse(data->uuid, &le))
 71                 test_uuid_failed("conversion", false, false, data->uuid, NULL);
 72 
 73         total_tests++;
 74         if (!guid_equal(&data->le, &le)) {
 75                 sprintf(buf, "%pUl", &le);
 76                 test_uuid_failed("cmp", false, false, data->uuid, buf);
 77         }
 78 
 79         /* BE */
 80         total_tests++;
 81         if (uuid_parse(data->uuid, &be))
 82                 test_uuid_failed("conversion", false, true, data->uuid, NULL);
 83 
 84         total_tests++;
 85         if (!uuid_equal(&data->be, &be)) {
 86                 sprintf(buf, "%pUb", &be);
 87                 test_uuid_failed("cmp", false, true, data->uuid, buf);
 88         }
 89 }
 90 
 91 static void __init test_uuid_wrong(const char *data)
 92 {
 93         guid_t le;
 94         uuid_t be;
 95 
 96         /* LE */
 97         total_tests++;
 98         if (!guid_parse(data, &le))
 99                 test_uuid_failed("negative", true, false, data, NULL);
100 
101         /* BE */
102         total_tests++;
103         if (!uuid_parse(data, &be))
104                 test_uuid_failed("negative", true, true, data, NULL);
105 }
106 
107 static int __init test_uuid_init(void)
108 {
109         unsigned int i;
110 
111         for (i = 0; i < ARRAY_SIZE(test_uuid_test_data); i++)
112                 test_uuid_test(&test_uuid_test_data[i]);
113 
114         for (i = 0; i < ARRAY_SIZE(test_uuid_wrong_data); i++)
115                 test_uuid_wrong(test_uuid_wrong_data[i]);
116 
117         if (failed_tests == 0)
118                 pr_info("all %u tests passed\n", total_tests);
119         else
120                 pr_err("failed %u out of %u tests\n", failed_tests, total_tests);
121 
122         return failed_tests ? -EINVAL : 0;
123 }
124 module_init(test_uuid_init);
125 
126 static void __exit test_uuid_exit(void)
127 {
128         /* do nothing */
129 }
130 module_exit(test_uuid_exit);
131 
132 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
133 MODULE_DESCRIPTION("Test cases for lib/uuid.c module");
134 MODULE_LICENSE("Dual BSD/GPL");
135 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php