Skip to content

Commit aeb5bbb

Browse files
ameryhungAlexei Starovoitov
authored andcommitted
selftests/bpf: Clean up call sites of stdio_restore()
reset_affinity() and save_ns() are only called in run_one_test(). There is no need to call stdio_restore() in reset_affinity() and save_ns() if stdio_restore() is moved right after a test finishes in run_one_test(). Also remove an unnecessary check of env.stdout_saved in crash_handler() by moving env.stdout_saved assignment to the beginning of main(). Signed-off-by: Amery Hung <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent f5e2889 commit aeb5bbb

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

tools/testing/selftests/bpf/test_progs.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,6 @@ static void dump_test_log(const struct prog_test_def *test,
474474
print_test_result(test, test_state);
475475
}
476476

477-
static void stdio_restore(void);
478-
479477
/* A bunch of tests set custom affinity per-thread and/or per-process. Reset
480478
* it after each test/sub-test.
481479
*/
@@ -490,13 +488,11 @@ static void reset_affinity(void)
490488

491489
err = sched_setaffinity(0, sizeof(cpuset), &cpuset);
492490
if (err < 0) {
493-
stdio_restore();
494491
fprintf(stderr, "Failed to reset process affinity: %d!\n", err);
495492
exit(EXIT_ERR_SETUP_INFRA);
496493
}
497494
err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
498495
if (err < 0) {
499-
stdio_restore();
500496
fprintf(stderr, "Failed to reset thread affinity: %d!\n", err);
501497
exit(EXIT_ERR_SETUP_INFRA);
502498
}
@@ -514,7 +510,6 @@ static void save_netns(void)
514510
static void restore_netns(void)
515511
{
516512
if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) {
517-
stdio_restore();
518513
perror("setns(CLONE_NEWNS)");
519514
exit(EXIT_ERR_SETUP_INFRA);
520515
}
@@ -1270,8 +1265,7 @@ void crash_handler(int signum)
12701265

12711266
sz = backtrace(bt, ARRAY_SIZE(bt));
12721267

1273-
if (env.stdout_saved)
1274-
stdio_restore();
1268+
stdio_restore();
12751269
if (env.test) {
12761270
env.test_state->error_cnt++;
12771271
dump_test_log(env.test, env.test_state, true, false, NULL);
@@ -1400,6 +1394,8 @@ static void run_one_test(int test_num)
14001394

14011395
state->tested = true;
14021396

1397+
stdio_restore();
1398+
14031399
if (verbose() && env.worker_id == -1)
14041400
print_test_result(test, state);
14051401

@@ -1408,7 +1404,6 @@ static void run_one_test(int test_num)
14081404
if (test->need_cgroup_cleanup)
14091405
cleanup_cgroup_environment();
14101406

1411-
stdio_restore();
14121407
free(stop_libbpf_log_capture());
14131408

14141409
dump_test_log(test, state, false, false, NULL);
@@ -1943,6 +1938,9 @@ int main(int argc, char **argv)
19431938

19441939
sigaction(SIGSEGV, &sigact, NULL);
19451940

1941+
env.stdout_saved = stdout;
1942+
env.stderr_saved = stderr;
1943+
19461944
env.secs_till_notify = 10;
19471945
env.secs_till_kill = 120;
19481946
err = argp_parse(&argp, argc, argv, 0, NULL, &env);
@@ -1969,9 +1967,6 @@ int main(int argc, char **argv)
19691967
return -1;
19701968
}
19711969

1972-
env.stdout_saved = stdout;
1973-
env.stderr_saved = stderr;
1974-
19751970
env.has_testmod = true;
19761971
if (!env.list_test_names) {
19771972
/* ensure previous instance of the module is unloaded */

0 commit comments

Comments
 (0)