All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Bill Wendling <morbo@google.com>,
	Shuah Khan <shuah@kernel.org>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 bpf-next 2/3] selftests/bpf: add ASSERT_STRNEQ() variant for test_progs
Date: Tue, 6 Jul 2021 20:32:49 -0700	[thread overview]
Message-ID: <CAEf4BzabCuTcA4jPsp+hYboCnr74PptL7hjZtm3HX1j0SJ2YSw@mail.gmail.com> (raw)
In-Reply-To: <1624092968-5598-3-git-send-email-alan.maguire@oracle.com>

On Sat, Jun 19, 2021 at 1:56 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> It will support strncmp()-style string comparisons.
>
> Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.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
>

  reply	other threads:[~2021-07-07  3:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-19  8:56 [PATCH v5 bpf-next 0/3] libbpf: BTF dumper support for typed data Alan Maguire
2021-06-19  8:56 ` [PATCH v5 bpf-next 1/3] " Alan Maguire
2021-06-19 13:41   ` kernel test robot
2021-07-07  1:58   ` Andrii Nakryiko
2021-06-19  8:56 ` [PATCH v5 bpf-next 2/3] selftests/bpf: add ASSERT_STRNEQ() variant for test_progs Alan Maguire
2021-07-07  3:32   ` Andrii Nakryiko [this message]
2021-06-19  8:56 ` [PATCH v5 bpf-next 3/3] selftests/bpf: add dump type data tests to btf dump tests Alan Maguire
2021-07-07  3:51   ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEf4BzabCuTcA4jPsp+hYboCnr74PptL7hjZtm3HX1j0SJ2YSw@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=morbo@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.