Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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