lkml.org 
[lkml]   [2024]   [Apr]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v3 4/4] selftests/nolibc: Add tests for strlcat() and strlcpy()
+ Shuah and Paul, please see below.

So I picked this up and it got picked up by Shuah, but...

On 2024-02-18 16:51:06+0000, Rodrigo Campos wrote:
> I've verified that the tests matches libbsd's strlcat()/strlcpy()
> implementation.
>
> Please note that as strlcat()/strlcpy() are not part of the libc, the
> tests are only compiled when using nolibc.
>
> Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>
> ---
> tools/testing/selftests/nolibc/nolibc-test.c | 40 ++++++++++++++++++++
> 1 file changed, 40 insertions(+)
>
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 6ba4f8275ac4..d373fc14706c 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -600,6 +600,25 @@ int expect_strne(const char *expr, int llen, const char *cmp)
> return ret;
> }
>
> +#define EXPECT_STRBUFEQ(cond, expr, buf, val, cmp) \
> + do { if (!(cond)) result(llen, SKIPPED); else ret += expect_str_buf_eq(expr, buf, val, llen, cmp); } while (0)
> +
> +static __attribute__((unused))
> +int expect_str_buf_eq(size_t expr, const char *buf, size_t val, int llen, const char *cmp)
> +{
> + llen += printf(" = %lu <%s> ", expr, buf);

This introduces a compiler warning on 32bit:

i386-linux-gcc -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra -fno-stack-protector -m32 -mstack-protector-guard=global -fstack-protector-all -o nolibc-test \
-nostdlib -nostdinc -static -Isysroot/i386/include nolibc-test.c nolibc-test-linkage.c -lgcc
nolibc-test.c: In function 'expect_str_buf_eq':
nolibc-test.c:610:30: error: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
610 | llen += printf(" = %lu <%s> ", expr, buf);
| ~~^ ~~~~
| | |
| | size_t {aka unsigned int}
| long unsigned int
| %u

It is easy enough to fix through a cast to "unsigned long".

The original patch was already sent to Shuah and included in -next.

Shuah, Paul:

I'd like to rewrite the offending commit instead of having a fixup commit.
As it seems to me the original patch would only go into 6.10 anyways.

Any objections?

Notes to self:

* Add flag to run-tests.sh to use -Werror
* Implement "%zu" in nolibc printf()

> + if (strcmp(buf, cmp) != 0) {
> + result(llen, FAIL);
> + return 1;
> + }
> + if (expr != val) {
> + result(llen, FAIL);
> + return 1;
> + }
> +
> + result(llen, OK);
> + return 0;
> +}

> [..]

\
 
 \ /
  Last update: 2024-05-27 17:57    [W:0.077 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site