@@ -209,6 +209,44 @@ static __init int strspn_selftest(void)
return 0;
}
+struct strncmp_test {
+ const char *str_a;
+ const char *str_b;
+ unsigned long count;
+ unsigned long max_off;
+ int retval;
+};
+
+static __init int strncmp_selftest(void)
+{
+ size_t i;
+ static const struct strncmp_test tests[] __initconst = {
+ { "/dev/vda", "/dev/", 5, 4, 0 },
+ { "/dev/vda", "/dev/vdb", 5, 4, 0 },
+ { "00000000---11111", "00000000---11112", 12, 4, 0 },
+ { "ABC", "AB", 3, 0, 67 },
+ { "ABA", "ABZ", 3, 0, -25 },
+ { "ABC", "ABC", 3, 0, 0 },
+ };
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i) {
+ const struct strncmp_test *s = tests + i;
+ size_t off;
+
+ for (off = 0; off <= s->max_off; off++) {
+ int res = strncmp(s->str_a + off, s->str_b + off, s->count - off);
+
+ if (res == 0 && s->retval != 0)
+ return 0x1000 + 0x100*off + 0x10*i + 0x0;
+ if (res > 0 && s->retval <= 0)
+ return 0x1000 + 0x100*off + 0x10*i + 0x1;
+ if (res < 0 && s->retval >= 0)
+ return 0x1000 + 0x100*off + 0x10*i + 0x2;
+ }
+ }
+ return 0;
+}
+
static __exit void string_selftest_remove(void)
{
}
@@ -247,6 +285,11 @@ static __init int string_selftest_init(void)
if (subtest)
goto fail;
+ test = 7;
+ subtest = strncmp_selftest();
+ if (subtest)
+ goto fail;
+
pr_info("String selftests succeeded\n");
return 0;
fail: