Skip to content

Commit 4ef5d6a

Browse files
eddyz87anakryiko
authored andcommitted
selftests/bpf: no need to track next_match_pos in struct test_loader
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 <[email protected]> Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]>
1 parent 203e6ab commit 4ef5d6a

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

tools/testing/selftests/bpf/test_loader.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ static void prepare_case(struct test_loader *tester,
434434
bpf_program__set_flags(prog, prog_flags | spec->prog_flags);
435435

436436
tester->log_buf[0] = '\0';
437-
tester->next_match_pos = 0;
438437
}
439438

440439
static void emit_verifier_log(const char *log_buf, bool force)
@@ -450,25 +449,23 @@ static void validate_case(struct test_loader *tester,
450449
struct bpf_program *prog,
451450
int load_err)
452451
{
453-
int i, j, err;
454-
char *match;
455452
regmatch_t reg_match[1];
453+
const char *log = tester->log_buf;
454+
int i, j, err;
456455

457456
for (i = 0; i < subspec->expect_msg_cnt; i++) {
458457
struct expect_msg *msg = &subspec->expect_msgs[i];
458+
const char *match = NULL;
459459

460460
if (msg->substr) {
461-
match = strstr(tester->log_buf + tester->next_match_pos, msg->substr);
461+
match = strstr(log, msg->substr);
462462
if (match)
463-
tester->next_match_pos = match - tester->log_buf + strlen(msg->substr);
463+
log += strlen(msg->substr);
464464
} else {
465-
err = regexec(&msg->regex,
466-
tester->log_buf + tester->next_match_pos, 1, reg_match, 0);
465+
err = regexec(&msg->regex, log, 1, reg_match, 0);
467466
if (err == 0) {
468-
match = tester->log_buf + tester->next_match_pos + reg_match[0].rm_so;
469-
tester->next_match_pos += reg_match[0].rm_eo;
470-
} else {
471-
match = NULL;
467+
match = log + reg_match[0].rm_so;
468+
log += reg_match[0].rm_eo;
472469
}
473470
}
474471

tools/testing/selftests/bpf/test_progs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ typedef int (*pre_execution_cb)(struct bpf_object *obj);
447447
struct test_loader {
448448
char *log_buf;
449449
size_t log_buf_sz;
450-
size_t next_match_pos;
451450
pre_execution_cb pre_execution_cb;
452451

453452
struct bpf_object *obj;

0 commit comments

Comments
 (0)