Lines Matching +full:stdout +full:- +full:path
1 // SPDX-License-Identifier: GPL-2.0-only
30 if (verbose() && env.worker_id == -1) { in stdio_hijack_init()
31 /* nothing to do, output to stdout by default */ in stdio_hijack_init()
35 fflush(stdout); in stdio_hijack_init()
38 stdout = open_memstream(log_buf, log_cnt); in stdio_hijack_init()
39 if (!stdout) { in stdio_hijack_init()
40 stdout = env.stdout; in stdio_hijack_init()
46 env.subtest_state->stdout = stdout; in stdio_hijack_init()
48 env.test_state->stdout = stdout; in stdio_hijack_init()
50 stderr = stdout; in stdio_hijack_init()
57 if (verbose() && env.worker_id == -1) { in stdio_hijack()
58 /* nothing to do, output to stdout by default */ in stdio_hijack()
62 env.stdout = stdout; in stdio_hijack()
72 if (verbose() && env.worker_id == -1) { in stdio_restore_cleanup()
73 /* nothing to do, output to stdout by default */ in stdio_restore_cleanup()
77 fflush(stdout); in stdio_restore_cleanup()
80 fclose(env.subtest_state->stdout); in stdio_restore_cleanup()
81 env.subtest_state->stdout = NULL; in stdio_restore_cleanup()
82 stdout = env.test_state->stdout; in stdio_restore_cleanup()
83 stderr = env.test_state->stdout; in stdio_restore_cleanup()
85 fclose(env.test_state->stdout); in stdio_restore_cleanup()
86 env.test_state->stdout = NULL; in stdio_restore_cleanup()
94 if (verbose() && env.worker_id == -1) { in stdio_restore()
95 /* nothing to do, output to stdout by default */ in stdio_restore()
99 if (stdout == env.stdout) in stdio_restore()
104 stdout = env.stdout; in stdio_restore()
164 for (i = 0; i < sel->blacklist.cnt; i++) { in should_run()
165 if (glob_match(name, sel->blacklist.tests[i].name) && in should_run()
166 !sel->blacklist.tests[i].subtest_cnt) in should_run()
170 for (i = 0; i < sel->whitelist.cnt; i++) { in should_run()
171 if (glob_match(name, sel->whitelist.tests[i].name)) in should_run()
175 if (!sel->whitelist.cnt && !sel->num_set) in should_run()
178 return num < sel->num_set_len && sel->num_set[num]; in should_run()
189 for (i = 0; i < sel->blacklist.cnt; i++) { in should_run_subtest()
190 if (glob_match(test_name, sel->blacklist.tests[i].name)) { in should_run_subtest()
191 if (!sel->blacklist.tests[i].subtest_cnt) in should_run_subtest()
194 for (j = 0; j < sel->blacklist.tests[i].subtest_cnt; j++) { in should_run_subtest()
196 sel->blacklist.tests[i].subtests[j])) in should_run_subtest()
202 for (i = 0; i < sel->whitelist.cnt; i++) { in should_run_subtest()
203 if (glob_match(test_name, sel->whitelist.tests[i].name)) { in should_run_subtest()
204 if (!sel->whitelist.tests[i].subtest_cnt) in should_run_subtest()
207 for (j = 0; j < sel->whitelist.tests[i].subtest_cnt; j++) { in should_run_subtest()
209 sel->whitelist.tests[i].subtests[j])) in should_run_subtest()
215 if (!sel->whitelist.cnt && !subtest_sel->num_set) in should_run_subtest()
218 return subtest_num < subtest_sel->num_set_len && subtest_sel->num_set[subtest_num]; in should_run_subtest()
230 int skipped_cnt = test_state->skip_cnt; in print_test_result()
231 int subtests_cnt = test_state->subtest_num; in print_test_result()
233 fprintf(env.stdout, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name); in print_test_result()
234 if (test_state->error_cnt) in print_test_result()
235 fprintf(env.stdout, "FAIL"); in print_test_result()
237 fprintf(env.stdout, "OK"); in print_test_result()
239 fprintf(env.stdout, "SKIP"); in print_test_result()
241 fprintf(env.stdout, "OK (SKIP: %d/%d)", skipped_cnt, subtests_cnt); in print_test_result()
243 fprintf(env.stdout, "\n"); in print_test_result()
249 fprintf(env.stdout, "%s", log_buf); in print_test_log()
250 if (log_buf[log_cnt - 1] != '\n') in print_test_log()
251 fprintf(env.stdout, "\n"); in print_test_log()
262 fprintf(env.stdout, "#%-*s %s/%s", in print_subtest_name()
267 fprintf(env.stdout, ":%s", result); in print_subtest_name()
269 fprintf(env.stdout, "\n"); in print_subtest_name()
290 bool test_failed = test_state->error_cnt > 0; in dump_test_log()
291 bool force_log = test_state->force_log; in dump_test_log()
300 if (env.worker_id != -1) in dump_test_log()
309 if (test_state->log_cnt && print_test) in dump_test_log()
310 print_test_log(test_state->log_buf, test_state->log_cnt); in dump_test_log()
314 jsonw_string_field(w, "name", test->test_name); in dump_test_log()
315 jsonw_uint_field(w, "number", test->test_num); in dump_test_log()
316 jsonw_write_log_message(w, test_state->log_buf, test_state->log_cnt); in dump_test_log()
322 for (i = 0; i < test_state->subtest_num; i++) { in dump_test_log()
323 subtest_state = &test_state->subtest_states[i]; in dump_test_log()
324 subtest_failed = subtest_state->error_cnt; in dump_test_log()
325 subtest_filtered = subtest_state->filtered; in dump_test_log()
331 if (subtest_state->log_cnt && print_subtest) { in dump_test_log()
332 print_test_log(subtest_state->log_buf, in dump_test_log()
333 subtest_state->log_cnt); in dump_test_log()
336 print_subtest_name(test->test_num, i + 1, in dump_test_log()
337 test->test_name, subtest_state->name, in dump_test_log()
338 test_result(subtest_state->error_cnt, in dump_test_log()
339 subtest_state->skipped)); in dump_test_log()
343 jsonw_string_field(w, "name", subtest_state->name); in dump_test_log()
345 jsonw_write_log_message(w, subtest_state->log_buf, subtest_state->log_cnt); in dump_test_log()
361 /* A bunch of tests set custom affinity per-thread and/or per-process. Reset
362 * it after each test/sub-test.
390 if (env.saved_netns_fd == -1) { in save_netns()
398 if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) { in restore_netns()
411 if (subtest_state->error_cnt) { in test__end_subtest()
412 test_state->error_cnt++; in test__end_subtest()
414 if (!subtest_state->skipped) in test__end_subtest()
415 test_state->sub_succ_cnt++; in test__end_subtest()
417 test_state->skip_cnt++; in test__end_subtest()
421 print_subtest_name(test->test_num, test_state->subtest_num, in test__end_subtest()
422 test->test_name, subtest_state->name, in test__end_subtest()
423 test_result(subtest_state->error_cnt, in test__end_subtest()
424 subtest_state->skipped)); in test__end_subtest()
440 state->subtest_num++; in test__start_subtest()
441 state->subtest_states = in test__start_subtest()
442 realloc(state->subtest_states, in test__start_subtest()
443 state->subtest_num * sub_state_size); in test__start_subtest()
444 if (!state->subtest_states) { in test__start_subtest()
449 subtest_state = &state->subtest_states[state->subtest_num - 1]; in test__start_subtest()
455 "Subtest #%d didn't provide sub-test name!\n", in test__start_subtest()
456 state->subtest_num); in test__start_subtest()
460 subtest_state->name = strdup(subtest_name); in test__start_subtest()
461 if (!subtest_state->name) { in test__start_subtest()
464 state->subtest_num); in test__start_subtest()
470 state->subtest_num, in test__start_subtest()
471 test->test_name, in test__start_subtest()
473 subtest_state->filtered = true; in test__start_subtest()
478 stdio_hijack_init(&subtest_state->log_buf, &subtest_state->log_cnt); in test__start_subtest()
485 env.test_state->force_log = true; in test__force_log()
491 env.subtest_state->skipped = true; in test__skip()
493 env.test_state->skip_cnt++; in test__skip()
499 env.subtest_state->error_cnt++; in test__fail()
501 env.test_state->error_cnt++; in test__fail()
504 int test__join_cgroup(const char *path) in test__join_cgroup() argument
508 if (!env.test->need_cgroup_cleanup) { in test__join_cgroup()
512 env.test->test_num, env.test->test_name); in test__join_cgroup()
513 return -1; in test__join_cgroup()
516 env.test->need_cgroup_cleanup = true; in test__join_cgroup()
519 fd = create_and_get_cgroup(path); in test__join_cgroup()
523 env.test->test_num, env.test->test_name, path, errno); in test__join_cgroup()
527 if (join_cgroup(path)) { in test__join_cgroup()
530 env.test->test_num, env.test->test_name, path, errno); in test__join_cgroup()
531 return -1; in test__join_cgroup()
543 fprintf(stdout, "%s:FAIL:map '%s' not found\n", test, name); in bpf_find_map()
545 return -1; in bpf_find_map()
557 if (sysctl_fd != -1) { in is_jit_enabled()
590 return -1; in compare_map_keys()
614 err = -1; in compare_stack_ips()
623 err = -1; in compare_stack_ips()
656 "Options accepting the NAMES parameter take either a comma-separated list\n"
673 ARG_DEBUG = -1,
682 { "name-blacklist", ARG_TEST_NAME_BLACKLIST, "NAMES", 0,
684 { "verifier-stats", ARG_VERIFIER_STATS, NULL, 0,
687 "Verbose output (use -vv or -vvv for progressively verbose output)" },
689 "Get number of selected top-level tests " },
700 { "json-summary", ARG_JSON_SUMMARY, "FILE", 0, "Write report in json format to this file."},
709 vfprintf(stdout, format, args); in libbpf_print_fn()
720 for (i = 0; i < set->cnt; i++) { in free_test_filter_set()
721 free((void *)set->tests[i].name); in free_test_filter_set()
722 for (j = 0; j < set->tests[i].subtest_cnt; j++) in free_test_filter_set()
723 free((void *)set->tests[i].subtests[j]); in free_test_filter_set()
725 free((void *)set->tests[i].subtests); in free_test_filter_set()
728 free((void *)set->tests); in free_test_filter_set()
733 free_test_filter_set(&test_selector->blacklist); in free_test_selector()
734 free_test_filter_set(&test_selector->whitelist); in free_test_selector()
735 free(test_selector->num_set); in free_test_selector()
742 struct test_env *env = state->input; in parse_arg()
752 &env->subtest_selector.num_set, in parse_arg()
753 &env->subtest_selector.num_set_len)) { in parse_arg()
756 return -EINVAL; in parse_arg()
759 if (parse_num_list(arg, &env->test_selector.num_set, in parse_arg()
760 &env->test_selector.num_set_len)) { in parse_arg()
762 return -EINVAL; in parse_arg()
770 &env->test_selector.whitelist, in parse_arg()
774 &env->test_selector.whitelist, in parse_arg()
783 &env->test_selector.blacklist, in parse_arg()
787 &env->test_selector.blacklist, in parse_arg()
793 env->verifier_stats = true; in parse_arg()
796 env->verbosity = VERBOSE_NORMAL; in parse_arg()
799 env->verbosity = VERBOSE_VERY; in parse_arg()
802 env->verbosity = VERBOSE_SUPER; in parse_arg()
806 "Unrecognized verbosity setting ('%s'), only -v and -vv are supported\n", in parse_arg()
808 return -EINVAL; in parse_arg()
813 if (setenv("SELFTESTS_VERBOSE", "1", 1) == -1) { in parse_arg()
817 return -EINVAL; in parse_arg()
823 env->get_test_cnt = true; in parse_arg()
826 env->list_test_names = true; in parse_arg()
830 env->workers = atoi(arg); in parse_arg()
831 if (!env->workers) { in parse_arg()
833 return -EINVAL; in parse_arg()
836 env->workers = get_nprocs(); in parse_arg()
840 env->debug = true; in parse_arg()
843 env->json = fopen(arg, "w"); in parse_arg()
844 if (env->json == NULL) { in parse_arg()
846 return -errno; in parse_arg()
862 * into corresponding sub-directory to load correct BPF objects.
864 * This is done by looking at executable name. If it contains "-flavor"
870 * some/path/to/test_progs[-flavor], where -flavor part is optional. in cd_flavor_subdir()
871 * First cut out "test_progs[-flavor]" part, then extract "flavor" in cd_flavor_subdir()
881 flavor = strrchr(flavor, '-'); in cd_flavor_subdir()
886 fprintf(stdout, "Switching to flavor '%s' subdirectory...\n", flavor); in cd_flavor_subdir()
896 err = -errno; in trigger_module_test_read()
912 return -ENOMEM; in trigger_module_test_write()
915 buf[write_sz-1] = '\0'; in trigger_module_test_write()
918 err = -errno; in trigger_module_test_write()
935 if (!ASSERT_NEQ(fd, -1, "open sysctl")) in write_sysctl()
936 return -1; in write_sysctl()
942 return -1; in write_sysctl()
957 if (!t || !btf_is_enum(t) || t->name_off) in get_bpf_max_tramp_links_from()
961 name = btf__str_by_offset(btf, e->name_off); in get_bpf_max_tramp_links_from()
963 return e->val; in get_bpf_max_tramp_links_from()
967 return -1; in get_bpf_max_tramp_links_from()
977 return -1; in get_bpf_max_tramp_links()
992 if (env.stdout) in crash_handler()
995 env.test_state->error_cnt++; in crash_handler()
998 if (env.worker_id != -1) in crash_handler()
1019 switch (msg->type) { in str_msg()
1021 sprintf(buf, "MSG_DO_TEST %d", msg->do_test.num); in str_msg()
1025 msg->test_done.num, in str_msg()
1026 msg->test_done.have_log); in str_msg()
1030 msg->subtest_done.num, in str_msg()
1031 msg->subtest_done.have_log); in str_msg()
1035 strlen(msg->test_log.log_buf), in str_msg()
1036 msg->test_log.is_last); in str_msg()
1080 stdio_hijack(&state->log_buf, &state->log_cnt); in run_one_test()
1082 if (test->run_test) in run_one_test()
1083 test->run_test(); in run_one_test()
1084 else if (test->run_serial_test) in run_one_test()
1085 test->run_serial_test(); in run_one_test()
1087 /* ensure last sub-test is finalized properly */ in run_one_test()
1091 state->tested = true; in run_one_test()
1093 if (verbose() && env.worker_id == -1) in run_one_test()
1098 if (test->need_cgroup_cleanup) in run_one_test()
1116 if (msg->type != type) { in read_prog_test_msg()
1117 printf("%s: unexpected message type %d. expected %d\n", __func__, msg->type, type); in read_prog_test_msg()
1156 int subtest_num = state->subtest_num; in dispatch_thread_send_subtests()
1158 state->subtest_states = malloc(subtest_num * sizeof(*subtest_state)); in dispatch_thread_send_subtests()
1161 subtest_state = &state->subtest_states[i]; in dispatch_thread_send_subtests()
1168 subtest_state->name = strdup(msg.subtest_done.name); in dispatch_thread_send_subtests()
1169 subtest_state->error_cnt = msg.subtest_done.error_cnt; in dispatch_thread_send_subtests()
1170 subtest_state->skipped = msg.subtest_done.skipped; in dispatch_thread_send_subtests()
1171 subtest_state->filtered = msg.subtest_done.filtered; in dispatch_thread_send_subtests()
1176 &subtest_state->log_buf, in dispatch_thread_send_subtests()
1177 &subtest_state->log_cnt)) in dispatch_thread_send_subtests()
1189 sock_fd = data->sock_fd; in dispatch_thread()
1192 int test_to_run = -1; in dispatch_thread()
1212 if (!test->should_run || test->run_serial_test) in dispatch_thread()
1226 env.worker_current_test[data->worker_id] = test_to_run; in dispatch_thread()
1239 state->tested = true; in dispatch_thread()
1240 state->error_cnt = msg.test_done.error_cnt; in dispatch_thread()
1241 state->skip_cnt = msg.test_done.skip_cnt; in dispatch_thread()
1242 state->sub_succ_cnt = msg.test_done.sub_succ_cnt; in dispatch_thread()
1243 state->subtest_num = msg.test_done.subtest_num; in dispatch_thread()
1248 &state->log_buf, in dispatch_thread()
1249 &state->log_cnt)) in dispatch_thread()
1254 if (!state->subtest_num) in dispatch_thread()
1267 fprintf(stderr, "[%d]: Protocol/IO error: %s.\n", data->worker_id, strerror(errno)); in dispatch_thread()
1277 data->worker_id, strerror(errno)); in dispatch_thread()
1292 if (!state->tested) in calculate_summary_and_print_errors()
1295 sub_succ_cnt += state->sub_succ_cnt; in calculate_summary_and_print_errors()
1296 skip_cnt += state->skip_cnt; in calculate_summary_and_print_errors()
1298 if (state->error_cnt) in calculate_summary_and_print_errors()
1304 if (env->json) { in calculate_summary_and_print_errors()
1305 w = jsonw_new(env->json); in calculate_summary_and_print_errors()
1307 fprintf(env->stderr, "Failed to create new JSON stream."); in calculate_summary_and_print_errors()
1333 if (!state->tested || !state->error_cnt) in calculate_summary_and_print_errors()
1346 if (env->json) in calculate_summary_and_print_errors()
1347 fclose(env->json); in calculate_summary_and_print_errors()
1352 env->succ_cnt = succ_cnt; in calculate_summary_and_print_errors()
1353 env->sub_succ_cnt = sub_succ_cnt; in calculate_summary_and_print_errors()
1354 env->fail_cnt = fail_cnt; in calculate_summary_and_print_errors()
1355 env->skip_cnt = skip_cnt; in calculate_summary_and_print_errors()
1415 if (!test->should_run || !test->run_serial_test) in server_main()
1423 fflush(stdout); in server_main()
1456 slen -= len; in worker_main_send_log()
1466 if (state->log_buf) { in free_subtest_state()
1467 free(state->log_buf); in free_subtest_state()
1468 state->log_buf = NULL; in free_subtest_state()
1469 state->log_cnt = 0; in free_subtest_state()
1471 free(state->name); in free_subtest_state()
1472 state->name = NULL; in free_subtest_state()
1484 for (i = 0; i < state->subtest_num; i++) { in worker_main_send_subtests()
1485 subtest_state = &state->subtest_states[i]; in worker_main_send_subtests()
1489 strncpy(msg.subtest_done.name, subtest_state->name, MAX_SUBTEST_NAME); in worker_main_send_subtests()
1491 msg.subtest_done.error_cnt = subtest_state->error_cnt; in worker_main_send_subtests()
1492 msg.subtest_done.skipped = subtest_state->skipped; in worker_main_send_subtests()
1493 msg.subtest_done.filtered = subtest_state->filtered; in worker_main_send_subtests()
1496 if (verbose() || state->force_log || subtest_state->error_cnt) { in worker_main_send_subtests()
1497 if (subtest_state->log_cnt) in worker_main_send_subtests()
1509 worker_main_send_log(sock, subtest_state->log_buf, subtest_state->log_cnt); in worker_main_send_subtests()
1512 free(subtest_state->name); in worker_main_send_subtests()
1516 for (; i < state->subtest_num; i++) in worker_main_send_subtests()
1517 free_subtest_state(&state->subtest_states[i]); in worker_main_send_subtests()
1518 free(state->subtest_states); in worker_main_send_subtests()
1549 test->test_name); in worker_main()
1556 msg.test_done.error_cnt = state->error_cnt; in worker_main()
1557 msg.test_done.skip_cnt = state->skip_cnt; in worker_main()
1558 msg.test_done.sub_succ_cnt = state->sub_succ_cnt; in worker_main()
1559 msg.test_done.subtest_num = state->subtest_num; in worker_main()
1562 if (verbose() || state->force_log || state->error_cnt) { in worker_main()
1563 if (state->log_cnt) in worker_main()
1573 worker_main_send_log(sock, state->log_buf, state->log_cnt); in worker_main()
1575 if (state->log_buf) { in worker_main()
1576 free(state->log_buf); in worker_main()
1577 state->log_buf = NULL; in worker_main()
1578 state->log_cnt = 0; in worker_main()
1581 if (state->subtest_num) in worker_main()
1589 test->test_name); in worker_main()
1595 return -1; in worker_main()
1609 for (j = 0; j < test_state->subtest_num; j++) in free_test_states()
1610 free_subtest_state(&test_state->subtest_states[j]); in free_test_states()
1612 free(test_state->subtest_states); in free_test_states()
1613 free(test_state->log_buf); in free_test_states()
1614 test_state->subtest_states = NULL; in free_test_states()
1615 test_state->log_buf = NULL; in free_test_states()
1653 return -1; in main()
1656 env.stdout = stdout; in main()
1674 test->test_num = i + 1; in main()
1675 test->should_run = should_run(&env.test_selector, in main()
1676 test->test_num, test->test_name); in main()
1678 if ((test->run_test == NULL && test->run_serial_test == NULL) || in main()
1679 (test->run_test != NULL && test->run_serial_test != NULL)) { in main()
1681 test->test_num, test->test_name, test->test_name, test->test_name); in main()
1691 env.worker_id = -1; /* main process */ in main()
1696 fprintf(stdout, "Launching %d workers.\n", env.workers); in main()
1703 return -1; in main()
1708 return -1; in main()
1720 if (env.worker_id == -1) { in main()
1734 if (!test->should_run) in main()
1743 fprintf(env.stdout, "%s\n", test->test_name); in main()