From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
kernel-team@fb.com, yonghong.song@linux.dev,
jose.marchesi@oracle.com, Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH bpf-next v4 06/10] selftests/bpf: no need to track next_match_pos in struct test_loader
Date: Mon, 22 Jul 2024 16:38:40 -0700 [thread overview]
Message-ID: <20240722233844.1406874-7-eddyz87@gmail.com> (raw)
In-Reply-To: <20240722233844.1406874-1-eddyz87@gmail.com>
The call stack for validate_case() function looks as follows:
- test_loader__run_subtests()
- process_subtest()
- run_subtest()
- prepare_case(), which does 'tester->next_match_pos = 0';
- validate_case(), which increments tester->next_match_pos.
Hence, each subtest is run with next_match_pos freshly set to zero.
Meaning that there is no need to persist this variable in the
struct test_loader, use local variable instead.
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
tools/testing/selftests/bpf/test_loader.c | 19 ++++++++-----------
tools/testing/selftests/bpf/test_progs.h | 1 -
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
index f14e10b0de96..47508cf66e89 100644
--- a/tools/testing/selftests/bpf/test_loader.c
+++ b/tools/testing/selftests/bpf/test_loader.c
@@ -434,7 +434,6 @@ static void prepare_case(struct test_loader *tester,
bpf_program__set_flags(prog, prog_flags | spec->prog_flags);
tester->log_buf[0] = '\0';
- tester->next_match_pos = 0;
}
static void emit_verifier_log(const char *log_buf, bool force)
@@ -450,25 +449,23 @@ static void validate_case(struct test_loader *tester,
struct bpf_program *prog,
int load_err)
{
- int i, j, err;
- char *match;
regmatch_t reg_match[1];
+ const char *log = tester->log_buf;
+ int i, j, err;
for (i = 0; i < subspec->expect_msg_cnt; i++) {
struct expect_msg *msg = &subspec->expect_msgs[i];
+ const char *match = NULL;
if (msg->substr) {
- match = strstr(tester->log_buf + tester->next_match_pos, msg->substr);
+ match = strstr(log, msg->substr);
if (match)
- tester->next_match_pos = match - tester->log_buf + strlen(msg->substr);
+ log += strlen(msg->substr);
} else {
- err = regexec(&msg->regex,
- tester->log_buf + tester->next_match_pos, 1, reg_match, 0);
+ err = regexec(&msg->regex, log, 1, reg_match, 0);
if (err == 0) {
- match = tester->log_buf + tester->next_match_pos + reg_match[0].rm_so;
- tester->next_match_pos += reg_match[0].rm_eo;
- } else {
- match = NULL;
+ match = log + reg_match[0].rm_so;
+ log += reg_match[0].rm_eo;
}
}
diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
index 51341d50213b..b1e949fb16cf 100644
--- a/tools/testing/selftests/bpf/test_progs.h
+++ b/tools/testing/selftests/bpf/test_progs.h
@@ -447,7 +447,6 @@ typedef int (*pre_execution_cb)(struct bpf_object *obj);
struct test_loader {
char *log_buf;
size_t log_buf_sz;
- size_t next_match_pos;
pre_execution_cb pre_execution_cb;
struct bpf_object *obj;
--
2.45.2
next prev parent reply other threads:[~2024-07-22 23:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-22 23:38 [PATCH bpf-next v4 00/10] no_caller_saved_registers attribute for helper calls Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 01/10] bpf: add a get_helper_proto() utility function Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 02/10] bpf: no_caller_saved_registers attribute for helper calls Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 03/10] bpf, x86, riscv, arm: no_caller_saved_registers for bpf_get_smp_processor_id() Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 04/10] selftests/bpf: extract utility function for BPF disassembly Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 05/10] selftests/bpf: print correct offset for pseudo calls in disasm_insn() Eduard Zingerman
2024-07-22 23:38 ` Eduard Zingerman [this message]
2024-07-22 23:38 ` [PATCH bpf-next v4 07/10] selftests/bpf: extract test_loader->expect_msgs as a data structure Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 08/10] selftests/bpf: allow checking xlated programs in verifier_* tests Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 09/10] selftests/bpf: __arch_* macro to limit test cases to specific archs Eduard Zingerman
2024-07-22 23:38 ` [PATCH bpf-next v4 10/10] selftests/bpf: test no_caller_saved_registers spill/fill removal Eduard Zingerman
2024-07-23 0:36 ` [PATCH bpf-next v4 00/10] no_caller_saved_registers attribute for helper calls bot+bpf-ci
2024-07-23 1:18 ` bot+bpf-ci
2024-07-23 2:42 ` bot+bpf-ci
2024-07-24 3:52 ` Alexei Starovoitov
2024-07-24 4:00 ` patchwork-bot+netdevbpf
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=20240722233844.1406874-7-eddyz87@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jose.marchesi@oracle.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--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 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.