hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/lib/test-string_helpers.c
....@@ -238,6 +238,28 @@
238238 /* terminator */
239239 }};
240240
241
+static const struct test_string strings_upper[] __initconst = {
242
+ {
243
+ .in = "abcdefgh1234567890test",
244
+ .out = "ABCDEFGH1234567890TEST",
245
+ },
246
+ {
247
+ .in = "abCdeFgH1234567890TesT",
248
+ .out = "ABCDEFGH1234567890TEST",
249
+ },
250
+};
251
+
252
+static const struct test_string strings_lower[] __initconst = {
253
+ {
254
+ .in = "ABCDEFGH1234567890TEST",
255
+ .out = "abcdefgh1234567890test",
256
+ },
257
+ {
258
+ .in = "abCdeFgH1234567890TesT",
259
+ .out = "abcdefgh1234567890test",
260
+ },
261
+};
262
+
241263 static __init const char *test_string_find_match(const struct test_string_2 *s2,
242264 unsigned int flags)
243265 {
....@@ -390,6 +412,48 @@
390412 test_string_get_size_one(4096, U64_MAX, "75.6 ZB", "64.0 ZiB");
391413 }
392414
415
+static void __init test_string_upper_lower(void)
416
+{
417
+ char *dst;
418
+ int i;
419
+
420
+ for (i = 0; i < ARRAY_SIZE(strings_upper); i++) {
421
+ const char *s = strings_upper[i].in;
422
+ int len = strlen(strings_upper[i].in) + 1;
423
+
424
+ dst = kmalloc(len, GFP_KERNEL);
425
+ if (!dst)
426
+ return;
427
+
428
+ string_upper(dst, s);
429
+ if (memcmp(dst, strings_upper[i].out, len)) {
430
+ pr_warn("Test 'string_upper' failed : expected %s, got %s!\n",
431
+ strings_upper[i].out, dst);
432
+ kfree(dst);
433
+ return;
434
+ }
435
+ kfree(dst);
436
+ }
437
+
438
+ for (i = 0; i < ARRAY_SIZE(strings_lower); i++) {
439
+ const char *s = strings_lower[i].in;
440
+ int len = strlen(strings_lower[i].in) + 1;
441
+
442
+ dst = kmalloc(len, GFP_KERNEL);
443
+ if (!dst)
444
+ return;
445
+
446
+ string_lower(dst, s);
447
+ if (memcmp(dst, strings_lower[i].out, len)) {
448
+ pr_warn("Test 'string_lower failed : : expected %s, got %s!\n",
449
+ strings_lower[i].out, dst);
450
+ kfree(dst);
451
+ return;
452
+ }
453
+ kfree(dst);
454
+ }
455
+}
456
+
393457 static int __init test_string_helpers_init(void)
394458 {
395459 unsigned int i;
....@@ -411,6 +475,9 @@
411475 /* Test string_get_size() */
412476 test_string_get_size();
413477
478
+ /* Test string upper(), string_lower() */
479
+ test_string_upper_lower();
480
+
414481 return -EINVAL;
415482 }
416483 module_init(test_string_helpers_init);