* [PATCH v2 1/2] lib/test_string.c: Make definition less dense
@ 2023-02-28 18:42 Björn Töpel
2023-02-28 18:42 ` [PATCH v2 2/2] lib/test_string.c: Add strncmp() tests Björn Töpel
2023-02-28 19:03 ` [PATCH v2 1/2] lib/test_string.c: Make definition less dense Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Björn Töpel @ 2023-02-28 18:42 UTC (permalink / raw)
To: Palmer Dabbelt, Andy Shevchenko, linux-kernel
Cc: Björn Töpel, Heiko Stuebner, linux-riscv
From: Björn Töpel <bjorn@rivosinc.com>
Checkpatch seems to have trouble making sense of the situation when
struct definitions, variable definitions, and __initconst marking is
done in one go.
Let's be nicer to checkpatch, and move the struct definition out,
which removes the error.
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
lib/test_string.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/lib/test_string.c b/lib/test_string.c
index c5cb92fb710e..550229084c41 100644
--- a/lib/test_string.c
+++ b/lib/test_string.c
@@ -179,15 +179,17 @@ static __init int strnchr_selftest(void)
return 0;
}
+struct strspn_test {
+ const char str[16];
+ const char accept[16];
+ const char reject[16];
+ unsigned int a;
+ unsigned int r;
+};
+
static __init int strspn_selftest(void)
{
- static const struct strspn_test {
- const char str[16];
- const char accept[16];
- const char reject[16];
- unsigned a;
- unsigned r;
- } tests[] __initconst = {
+ static const struct strspn_test tests[] __initconst = {
{ "foobar", "", "", 0, 6 },
{ "abba", "abc", "ABBA", 4, 4 },
{ "abba", "a", "b", 1, 1 },
base-commit: ae3419fbac845b4d3f3a9fae4cc80c68d82cdf6e
--
2.37.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] lib/test_string.c: Add strncmp() tests
2023-02-28 18:42 [PATCH v2 1/2] lib/test_string.c: Make definition less dense Björn Töpel
@ 2023-02-28 18:42 ` Björn Töpel
2023-02-28 19:03 ` [PATCH v2 1/2] lib/test_string.c: Make definition less dense Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Björn Töpel @ 2023-02-28 18:42 UTC (permalink / raw)
To: Palmer Dabbelt, Andy Shevchenko, linux-kernel
Cc: Palmer Dabbelt, Heiko Stuebner, linux-riscv,
Björn Töpel
From: Palmer Dabbelt <palmer@rivosinc.com>
The RISC-V strncmp() fails on some inputs, see the linked thread for
more details. It turns out there were no strncmp() calls in the self
tests, this adds one.
Link: https://lore.kernel.org/all/2801162.88bMQJbFj6@diego/
Reported-by: Heiko Stübner <heiko@sntech.de>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
---
v1->v2: Added two more tests (pos/neg). (Andy)
Minor code style issues. (Andy)
Fixed checkpatch errors.
---
lib/test_string.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/lib/test_string.c b/lib/test_string.c
index 550229084c41..b95037eb138b 100644
--- a/lib/test_string.c
+++ b/lib/test_string.c
@@ -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:
--
2.37.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] lib/test_string.c: Make definition less dense
2023-02-28 18:42 [PATCH v2 1/2] lib/test_string.c: Make definition less dense Björn Töpel
2023-02-28 18:42 ` [PATCH v2 2/2] lib/test_string.c: Add strncmp() tests Björn Töpel
@ 2023-02-28 19:03 ` Andy Shevchenko
2023-02-28 19:41 ` Björn Töpel
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2023-02-28 19:03 UTC (permalink / raw)
To: Björn Töpel
Cc: Palmer Dabbelt, Andy Shevchenko, linux-kernel,
Björn Töpel, Heiko Stuebner, linux-riscv
On Tue, Feb 28, 2023 at 8:42 PM Björn Töpel <bjorn@kernel.org> wrote:
>
> From: Björn Töpel <bjorn@rivosinc.com>
>
> Checkpatch seems to have trouble making sense of the situation when
> struct definitions, variable definitions, and __initconst marking is
> done in one go.
>
> Let's be nicer to checkpatch, and move the struct definition out,
> which removes the error.
Not that I'm against the patch, but how hard is it to fix the checkpatch?
In case you go this way with a patch, it probably makes sense to move
test data out of the function as well with something like
strspn_test_data name.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] lib/test_string.c: Make definition less dense
2023-02-28 19:03 ` [PATCH v2 1/2] lib/test_string.c: Make definition less dense Andy Shevchenko
@ 2023-02-28 19:41 ` Björn Töpel
0 siblings, 0 replies; 4+ messages in thread
From: Björn Töpel @ 2023-02-28 19:41 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Palmer Dabbelt, Andy Shevchenko, linux-kernel,
Björn Töpel, Heiko Stuebner, linux-riscv
Andy Shevchenko <andy.shevchenko@gmail.com> writes:
> On Tue, Feb 28, 2023 at 8:42 PM Björn Töpel <bjorn@kernel.org> wrote:
>>
>> From: Björn Töpel <bjorn@rivosinc.com>
>>
>> Checkpatch seems to have trouble making sense of the situation when
>> struct definitions, variable definitions, and __initconst marking is
>> done in one go.
>>
>> Let's be nicer to checkpatch, and move the struct definition out,
>> which removes the error.
>
> Not that I'm against the patch, but how hard is it to fix the checkpatch?
Uhm, good one. I'll have a look (the .pl scared me off).
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-28 19:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-28 18:42 [PATCH v2 1/2] lib/test_string.c: Make definition less dense Björn Töpel
2023-02-28 18:42 ` [PATCH v2 2/2] lib/test_string.c: Add strncmp() tests Björn Töpel
2023-02-28 19:03 ` [PATCH v2 1/2] lib/test_string.c: Make definition less dense Andy Shevchenko
2023-02-28 19:41 ` Björn Töpel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox