BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Cupertino Miranda <cupertino.miranda@oracle.com>, bpf@vger.kernel.org
Cc: jose.marchesi@oracle.com, david.faust@oracle.com,
	Yonghong Song <yonghong.song@linux.dev>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>
Subject: Re: [PATCH bpf-next 1/2] selftests/bpf: Support checks against a regular expression.
Date: Tue, 04 Jun 2024 14:35:23 -0700	[thread overview]
Message-ID: <592e19d427d20c2046eaf1478addb484419711f7.camel@gmail.com> (raw)
In-Reply-To: <20240603155308.199254-2-cupertino.miranda@oracle.com>

On Mon, 2024-06-03 at 16:53 +0100, Cupertino Miranda wrote:

I think this macro is a long overdue, thank you for working on this.
A few notes below.

[...]

> +static int push_regex(const char *regex_str, struct test_subspec *subspec)
> +{
> +	void *tmp;
> +	int regcomp_res;
> +
> +	tmp = realloc(subspec->expect,
> +		      (1 + subspec->expect_msg_cnt) * sizeof(struct expect_msg));
> +	if (!tmp) {
> +		ASSERT_FAIL("failed to realloc memory for messages\n");
> +		return -ENOMEM;
> +	}
> +	subspec->expect = tmp;
> +
> +	subspec->expect[subspec->expect_msg_cnt].regex = (regex_t *) malloc(sizeof(regex_t));
> +	regcomp_res = regcomp (subspec->expect[subspec->expect_msg_cnt].regex,
> +			       regex_str, REG_EXTENDED|REG_NEWLINE);
> +	if (regcomp_res != 0) {
> +		fprintf(stderr, "Regexp: '%s'\n", regex_str);
> +		ASSERT_FAIL("failed to compile regex\n");
> +		return -EINVAL;
> +	}

Maybe also use a regerror() function that could be used to print
what's wrong with the regex.
Also, there is a ctx_rewrite.c:compile_regex, it might be interesting
to extract in from ctx_rewrite.c to testing_helpers.c and use it here.

> +
> +	subspec->expect[subspec->expect_msg_cnt].msg = regex_str;
> +	subspec->expect_msg_cnt += 1;
>  	return 0;
>  }

[...]

> @@ -403,26 +453,44 @@ static void validate_case(struct test_loader *tester,
>  			  int load_err)
>  {
>  	int i, j;
> +	const char *match;
>  
>  	for (i = 0; i < subspec->expect_msg_cnt; i++) {
> -		char *match;
>  		const char *expect_msg;
> +		regex_t *regex;
> +		regmatch_t reg_match[1];
> +
> +		expect_msg = subspec->expect[i].msg;
> +		regex = subspec->expect[i].regex;
> +
> +		if (regex == NULL) {
> +			match = strstr(tester->log_buf + tester->next_match_pos, expect_msg);
> +			if (!ASSERT_OK_PTR (match, "expect_msg")) {
> +				/* if we are in verbose mode, we've already emitted log */
> +				if (env.verbosity == VERBOSE_NONE)
> +					emit_verifier_log(tester->log_buf, true /*force*/);
> +				for (j = 0; j < i; j++)
> +					fprintf(stderr,
> +						"MATCHED  MSG: '%s'\n", subspec->expect[j].msg);
> +				fprintf(stderr, "EXPECTED MSG: '%s'\n", expect_msg);
> +				return;
> +			}
> +			tester->next_match_pos = match - tester->log_buf + strlen(expect_msg);
> +		} else {
> +			int match_size = regexec (regex, tester->log_buf + tester->next_match_pos, 1, reg_match, 0);
                                                ^
Nit:                                            |
        I think scripts/checkpatch.pl complains about such spaces

[...]

There is no regfree() call in the patch-set,
could you please extend free_test_spec()?



  parent reply	other threads:[~2024-06-04 21:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-03 15:53 [PATCH bpf-next 0/2] Regular expression support for test output matching Cupertino Miranda
2024-06-03 15:53 ` [PATCH bpf-next 1/2] selftests/bpf: Support checks against a regular expression Cupertino Miranda
2024-06-04 18:16   ` Andrii Nakryiko
2024-06-04 21:35   ` Eduard Zingerman [this message]
2024-06-03 15:53 ` [PATCH bpf-next 2/2] selftests/bpf: Match tests against " Cupertino Miranda
2024-06-04 18:16   ` Andrii Nakryiko
2024-06-06 10:50     ` Cupertino Miranda
2024-06-06 15:50       ` Alexei Starovoitov
2024-06-06 18:07         ` Cupertino Miranda
2024-06-06 17:19       ` Andrii Nakryiko
2024-06-06 17:47         ` Eduard Zingerman
2024-06-06 19:27           ` Jose E. Marchesi
2024-06-06 18:35         ` Cupertino Miranda

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=592e19d427d20c2046eaf1478addb484419711f7.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=cupertino.miranda@oracle.com \
    --cc=david.faust@oracle.com \
    --cc=jose.marchesi@oracle.com \
    --cc=yonghong.song@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox