[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzabCuTcA4jPsp+hYboCnr74PptL7hjZtm3HX1j0SJ2YSw@mail.gmail.com>
Date: Tue, 6 Jul 2021 20:32:49 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alan Maguire <alan.maguire@...cle.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, Martin Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
john fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Bill Wendling <morbo@...gle.com>,
Shuah Khan <shuah@...nel.org>, bpf <bpf@...r.kernel.org>,
Networking <netdev@...r.kernel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v5 bpf-next 2/3] selftests/bpf: add ASSERT_STRNEQ()
variant for test_progs
On Sat, Jun 19, 2021 at 1:56 AM Alan Maguire <alan.maguire@...cle.com> wrote:
>
> It will support strncmp()-style string comparisons.
>
> Suggested-by: Andrii Nakryiko <andrii.nakryiko@...il.com>
> Signed-off-by: Alan Maguire <alan.maguire@...cle.com>
> ---
> tools/testing/selftests/bpf/test_progs.h | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
> index 8ef7f33..d2944da 100644
> --- a/tools/testing/selftests/bpf/test_progs.h
> +++ b/tools/testing/selftests/bpf/test_progs.h
> @@ -221,6 +221,18 @@ struct test_env {
> ___ok; \
> })
>
> +#define ASSERT_STRNEQ(actual, expected, len, name) ({ \
> + static int duration = 0; \
> + const char *___act = actual; \
> + const char *___exp = expected; \
> + size_t ___len = len; \
> + bool ___ok = strncmp(___act, ___exp, ___len) == 0; \
> + CHECK(!___ok, (name), \
> + "unexpected %s: actual '%s' != expected '%s'\n", \
> + (name), ___act, ___exp); \
it would be nice to only emit what we are actually comparing - first n
characters of each string. Luckily, printf is cool enough to support
this:
printf("actual '%.*s' != expected '%.*s'\n", ___len, ___act, ___len, ___exp);
> + ___ok; \
> +})
> +
> #define ASSERT_OK(res, name) ({ \
> static int duration = 0; \
> long long ___res = (res); \
> --
> 1.8.3.1
>
Powered by blists - more mailing lists