Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/tests: convert test_uuid module to KUnit

Move lib/test_uuid.c to lib/tests/uuid_kunit.c and convert it to use KUnit.

This change switches the ad-hoc test code to standard KUnit test cases.
The test data remains the same, but the verification logic is updated to
use KUNIT_EXPECT_* macros.

Also remove CONFIG_TEST_UUID from arch/*/configs/* because it is no longer
used. The new CONFIG_UUID_KUNIT_TEST will be automatically enabled by
CONFIG_KUNIT_ALL_TESTS.

[lukas.bulwahn@redhat.com: MAINTAINERS: adjust file entry in UUID HELPERS]
Link: https://lkml.kernel.org/r/20251217053907.2778515-1-lukas.bulwahn@redhat.com
Link: https://lkml.kernel.org/r/20251215134322.12949-1-sakamo.ryota@gmail.com
Signed-off-by: Ryota Sakamoto <sakamo.ryota@gmail.com>
Signed-off-by: Lukas Bulwahn <lukas.bulwahn@redhat.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: David Gow <davidgow@google.com>
Cc: Andriy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: Lukas Bulwahn <lukas.bulwahn@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ryota Sakamoto and committed by
Andrew Morton
6dcd539f 29300f92

+119 -152
+1 -1
MAINTAINERS
··· 27260 27260 L: linux-kernel@vger.kernel.org 27261 27261 S: Maintained 27262 27262 F: include/linux/uuid.h 27263 - F: lib/test_uuid.c 27263 + F: lib/tests/uuid_kunit.c 27264 27264 F: lib/uuid.c 27265 27265 27266 27266 UV SYSFS DRIVER
-1
arch/m68k/configs/amiga_defconfig
··· 618 618 CONFIG_TEST_HEXDUMP=m 619 619 CONFIG_TEST_KSTRTOX=m 620 620 CONFIG_TEST_BITMAP=m 621 - CONFIG_TEST_UUID=m 622 621 CONFIG_TEST_XARRAY=m 623 622 CONFIG_TEST_MAPLE_TREE=m 624 623 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/apollo_defconfig
··· 575 575 CONFIG_TEST_HEXDUMP=m 576 576 CONFIG_TEST_KSTRTOX=m 577 577 CONFIG_TEST_BITMAP=m 578 - CONFIG_TEST_UUID=m 579 578 CONFIG_TEST_XARRAY=m 580 579 CONFIG_TEST_MAPLE_TREE=m 581 580 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/atari_defconfig
··· 595 595 CONFIG_TEST_HEXDUMP=m 596 596 CONFIG_TEST_KSTRTOX=m 597 597 CONFIG_TEST_BITMAP=m 598 - CONFIG_TEST_UUID=m 599 598 CONFIG_TEST_XARRAY=m 600 599 CONFIG_TEST_MAPLE_TREE=m 601 600 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/bvme6000_defconfig
··· 567 567 CONFIG_TEST_HEXDUMP=m 568 568 CONFIG_TEST_KSTRTOX=m 569 569 CONFIG_TEST_BITMAP=m 570 - CONFIG_TEST_UUID=m 571 570 CONFIG_TEST_XARRAY=m 572 571 CONFIG_TEST_MAPLE_TREE=m 573 572 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/hp300_defconfig
··· 577 577 CONFIG_TEST_HEXDUMP=m 578 578 CONFIG_TEST_KSTRTOX=m 579 579 CONFIG_TEST_BITMAP=m 580 - CONFIG_TEST_UUID=m 581 580 CONFIG_TEST_XARRAY=m 582 581 CONFIG_TEST_MAPLE_TREE=m 583 582 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/mac_defconfig
··· 594 594 CONFIG_TEST_HEXDUMP=m 595 595 CONFIG_TEST_KSTRTOX=m 596 596 CONFIG_TEST_BITMAP=m 597 - CONFIG_TEST_UUID=m 598 597 CONFIG_TEST_XARRAY=m 599 598 CONFIG_TEST_MAPLE_TREE=m 600 599 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/multi_defconfig
··· 681 681 CONFIG_TEST_HEXDUMP=m 682 682 CONFIG_TEST_KSTRTOX=m 683 683 CONFIG_TEST_BITMAP=m 684 - CONFIG_TEST_UUID=m 685 684 CONFIG_TEST_XARRAY=m 686 685 CONFIG_TEST_MAPLE_TREE=m 687 686 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/mvme147_defconfig
··· 567 567 CONFIG_TEST_HEXDUMP=m 568 568 CONFIG_TEST_KSTRTOX=m 569 569 CONFIG_TEST_BITMAP=m 570 - CONFIG_TEST_UUID=m 571 570 CONFIG_TEST_XARRAY=m 572 571 CONFIG_TEST_MAPLE_TREE=m 573 572 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/mvme16x_defconfig
··· 568 568 CONFIG_TEST_HEXDUMP=m 569 569 CONFIG_TEST_KSTRTOX=m 570 570 CONFIG_TEST_BITMAP=m 571 - CONFIG_TEST_UUID=m 572 571 CONFIG_TEST_XARRAY=m 573 572 CONFIG_TEST_MAPLE_TREE=m 574 573 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/q40_defconfig
··· 584 584 CONFIG_TEST_HEXDUMP=m 585 585 CONFIG_TEST_KSTRTOX=m 586 586 CONFIG_TEST_BITMAP=m 587 - CONFIG_TEST_UUID=m 588 587 CONFIG_TEST_XARRAY=m 589 588 CONFIG_TEST_MAPLE_TREE=m 590 589 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/sun3_defconfig
··· 564 564 CONFIG_TEST_HEXDUMP=m 565 565 CONFIG_TEST_KSTRTOX=m 566 566 CONFIG_TEST_BITMAP=m 567 - CONFIG_TEST_UUID=m 568 567 CONFIG_TEST_XARRAY=m 569 568 CONFIG_TEST_MAPLE_TREE=m 570 569 CONFIG_TEST_RHASHTABLE=m
-1
arch/m68k/configs/sun3x_defconfig
··· 565 565 CONFIG_TEST_HEXDUMP=m 566 566 CONFIG_TEST_KSTRTOX=m 567 567 CONFIG_TEST_BITMAP=m 568 - CONFIG_TEST_UUID=m 569 568 CONFIG_TEST_XARRAY=m 570 569 CONFIG_TEST_MAPLE_TREE=m 571 570 CONFIG_TEST_RHASHTABLE=m
-1
arch/powerpc/configs/ppc64_defconfig
··· 443 443 CONFIG_TEST_PRINTF=m 444 444 CONFIG_TEST_SCANF=m 445 445 CONFIG_TEST_BITMAP=m 446 - CONFIG_TEST_UUID=m 447 446 CONFIG_TEST_XARRAY=m 448 447 CONFIG_TEST_MAPLE_TREE=m 449 448 CONFIG_TEST_RHASHTABLE=m
+11 -3
lib/Kconfig.debug
··· 2499 2499 2500 2500 If unsure, say N. 2501 2501 2502 - config TEST_UUID 2503 - tristate "Test functions located in the uuid module at runtime" 2504 - 2505 2502 config TEST_XARRAY 2506 2503 tristate "Test the XArray code at runtime" 2507 2504 ··· 3279 3282 This builds the "test_ratelimit" module that should be used 3280 3283 for correctness verification and concurrent testings of rate 3281 3284 limiting. 3285 + 3286 + If unsure, say N. 3287 + 3288 + config UUID_KUNIT_TEST 3289 + tristate "KUnit test for UUID" if !KUNIT_ALL_TESTS 3290 + depends on KUNIT 3291 + default KUNIT_ALL_TESTS 3292 + help 3293 + This option enables the KUnit test suite for the uuid library, 3294 + which provides functions for generating and parsing UUID and GUID. 3295 + The test suite checks parsing of UUID and GUID strings. 3282 3296 3283 3297 If unsure, say N. 3284 3298
-1
lib/Makefile
··· 89 89 GCOV_PROFILE_test_bitmap.o := n 90 90 endif 91 91 92 - obj-$(CONFIG_TEST_UUID) += test_uuid.o 93 92 obj-$(CONFIG_TEST_XARRAY) += test_xarray.o 94 93 obj-$(CONFIG_TEST_MAPLE_TREE) += test_maple_tree.o 95 94 obj-$(CONFIG_TEST_PARMAN) += test_parman.o
-134
lib/test_uuid.c
··· 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");
+1
lib/tests/Makefile
··· 49 49 obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o 50 50 obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o 51 51 obj-$(CONFIG_RATELIMIT_KUNIT_TEST) += test_ratelimit.o 52 + obj-$(CONFIG_UUID_KUNIT_TEST) += uuid_kunit.o 52 53 53 54 obj-$(CONFIG_TEST_RUNTIME_MODULE) += module/
+106
lib/tests/uuid_kunit.c
··· 1 + // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 2 + /* 3 + * Test cases for lib/uuid.c module. 4 + */ 5 + 6 + #include <kunit/test.h> 7 + #include <linux/uuid.h> 8 + 9 + struct test_uuid_data { 10 + const char *uuid; 11 + guid_t le; 12 + uuid_t be; 13 + }; 14 + 15 + static const struct test_uuid_data test_uuid_test_data[] = { 16 + { 17 + .uuid = "c33f4995-3701-450e-9fbf-206a2e98e576", 18 + .le = GUID_INIT(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76), 19 + .be = UUID_INIT(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76), 20 + }, 21 + { 22 + .uuid = "64b4371c-77c1-48f9-8221-29f054fc023b", 23 + .le = GUID_INIT(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b), 24 + .be = UUID_INIT(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b), 25 + }, 26 + { 27 + .uuid = "0cb4ddff-a545-4401-9d06-688af53e7f84", 28 + .le = GUID_INIT(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84), 29 + .be = UUID_INIT(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84), 30 + }, 31 + }; 32 + 33 + static const char * const test_uuid_wrong_data[] = { 34 + "c33f4995-3701-450e-9fbf206a2e98e576 ", /* no hyphen(s) */ 35 + "64b4371c-77c1-48f9-8221-29f054XX023b", /* invalid character(s) */ 36 + "0cb4ddff-a545-4401-9d06-688af53e", /* not enough data */ 37 + }; 38 + 39 + static void uuid_test_guid_valid(struct kunit *test) 40 + { 41 + unsigned int i; 42 + const struct test_uuid_data *data; 43 + guid_t le; 44 + 45 + for (i = 0; i < ARRAY_SIZE(test_uuid_test_data); i++) { 46 + data = &test_uuid_test_data[i]; 47 + KUNIT_EXPECT_EQ(test, guid_parse(data->uuid, &le), 0); 48 + KUNIT_EXPECT_TRUE(test, guid_equal(&data->le, &le)); 49 + } 50 + } 51 + 52 + static void uuid_test_uuid_valid(struct kunit *test) 53 + { 54 + unsigned int i; 55 + const struct test_uuid_data *data; 56 + uuid_t be; 57 + 58 + for (i = 0; i < ARRAY_SIZE(test_uuid_test_data); i++) { 59 + data = &test_uuid_test_data[i]; 60 + KUNIT_EXPECT_EQ(test, uuid_parse(data->uuid, &be), 0); 61 + KUNIT_EXPECT_TRUE(test, uuid_equal(&data->be, &be)); 62 + } 63 + } 64 + 65 + static void uuid_test_guid_invalid(struct kunit *test) 66 + { 67 + unsigned int i; 68 + const char *uuid; 69 + guid_t le; 70 + 71 + for (i = 0; i < ARRAY_SIZE(test_uuid_wrong_data); i++) { 72 + uuid = test_uuid_wrong_data[i]; 73 + KUNIT_EXPECT_EQ(test, guid_parse(uuid, &le), -EINVAL); 74 + } 75 + } 76 + 77 + static void uuid_test_uuid_invalid(struct kunit *test) 78 + { 79 + unsigned int i; 80 + const char *uuid; 81 + uuid_t be; 82 + 83 + for (i = 0; i < ARRAY_SIZE(test_uuid_wrong_data); i++) { 84 + uuid = test_uuid_wrong_data[i]; 85 + KUNIT_EXPECT_EQ(test, uuid_parse(uuid, &be), -EINVAL); 86 + } 87 + } 88 + 89 + static struct kunit_case uuid_test_cases[] = { 90 + KUNIT_CASE(uuid_test_guid_valid), 91 + KUNIT_CASE(uuid_test_uuid_valid), 92 + KUNIT_CASE(uuid_test_guid_invalid), 93 + KUNIT_CASE(uuid_test_uuid_invalid), 94 + {}, 95 + }; 96 + 97 + static struct kunit_suite uuid_test_suite = { 98 + .name = "uuid", 99 + .test_cases = uuid_test_cases, 100 + }; 101 + 102 + kunit_test_suite(uuid_test_suite); 103 + 104 + MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>"); 105 + MODULE_DESCRIPTION("Test cases for lib/uuid.c module"); 106 + MODULE_LICENSE("Dual BSD/GPL");