Lines Matching +full:library +full:- +full:sel

1 // SPDX-License-Identifier: GPL-2.0-only
44 if (verbose() && env.worker_id == -1) { in stdio_hijack_init()
60 env.subtest_state->stdout = stdout; in stdio_hijack_init()
62 env.test_state->stdout = stdout; in stdio_hijack_init()
71 if (verbose() && env.worker_id == -1) { in stdio_hijack()
86 if (verbose() && env.worker_id == -1) { in stdio_restore_cleanup()
94 fclose(env.subtest_state->stdout); in stdio_restore_cleanup()
95 env.subtest_state->stdout = NULL; in stdio_restore_cleanup()
96 stdout = env.test_state->stdout; in stdio_restore_cleanup()
97 stderr = env.test_state->stdout; in stdio_restore_cleanup()
99 fclose(env.test_state->stdout); in stdio_restore_cleanup()
100 env.test_state->stdout = NULL; in stdio_restore_cleanup()
108 if (verbose() && env.worker_id == -1) { in stdio_restore()
160 /* Override C runtime library's usleep() implementation to ensure nanosleep()
174 static bool should_run(struct test_selector *sel, int num, const char *name) in should_run() argument
178 for (i = 0; i < sel->blacklist.cnt; i++) { in should_run()
179 if (glob_match(name, sel->blacklist.tests[i].name) && in should_run()
180 !sel->blacklist.tests[i].subtest_cnt) in should_run()
184 for (i = 0; i < sel->whitelist.cnt; i++) { in should_run()
185 if (glob_match(name, sel->whitelist.tests[i].name)) in should_run()
189 if (!sel->whitelist.cnt && !sel->num_set) in should_run()
192 return num < sel->num_set_len && sel->num_set[num]; in should_run()
195 static bool should_run_subtest(struct test_selector *sel, in should_run_subtest() argument
203 for (i = 0; i < sel->blacklist.cnt; i++) { in should_run_subtest()
204 if (glob_match(test_name, sel->blacklist.tests[i].name)) { in should_run_subtest()
205 if (!sel->blacklist.tests[i].subtest_cnt) in should_run_subtest()
208 for (j = 0; j < sel->blacklist.tests[i].subtest_cnt; j++) { in should_run_subtest()
210 sel->blacklist.tests[i].subtests[j])) in should_run_subtest()
216 for (i = 0; i < sel->whitelist.cnt; i++) { in should_run_subtest()
217 if (glob_match(test_name, sel->whitelist.tests[i].name)) { in should_run_subtest()
218 if (!sel->whitelist.tests[i].subtest_cnt) in should_run_subtest()
221 for (j = 0; j < sel->whitelist.tests[i].subtest_cnt; j++) { in should_run_subtest()
223 sel->whitelist.tests[i].subtests[j])) in should_run_subtest()
229 if (!sel->whitelist.cnt && !subtest_sel->num_set) in should_run_subtest()
232 return subtest_num < subtest_sel->num_set_len && subtest_sel->num_set[subtest_num]; in should_run_subtest()
244 int skipped_cnt = test_state->skip_cnt; in print_test_result()
245 int subtests_cnt = test_state->subtest_num; in print_test_result()
247 fprintf(env.stdout, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name); in print_test_result()
248 if (test_state->error_cnt) in print_test_result()
264 if (log_buf[log_cnt - 1] != '\n') in print_test_log()
276 fprintf(env.stdout, "#%-*s %s/%s", in print_subtest_name()
304 bool test_failed = test_state->error_cnt > 0; in dump_test_log()
305 bool force_log = test_state->force_log; in dump_test_log()
314 if (env.worker_id != -1) in dump_test_log()
323 if (test_state->log_cnt && print_test) in dump_test_log()
324 print_test_log(test_state->log_buf, test_state->log_cnt); in dump_test_log()
328 jsonw_string_field(w, "name", test->test_name); in dump_test_log()
329 jsonw_uint_field(w, "number", test->test_num); in dump_test_log()
330 jsonw_write_log_message(w, test_state->log_buf, test_state->log_cnt); in dump_test_log()
336 for (i = 0; i < test_state->subtest_num; i++) { in dump_test_log()
337 subtest_state = &test_state->subtest_states[i]; in dump_test_log()
338 subtest_failed = subtest_state->error_cnt; in dump_test_log()
339 subtest_filtered = subtest_state->filtered; in dump_test_log()
345 if (subtest_state->log_cnt && print_subtest) { in dump_test_log()
346 print_test_log(subtest_state->log_buf, in dump_test_log()
347 subtest_state->log_cnt); in dump_test_log()
350 print_subtest_name(test->test_num, i + 1, in dump_test_log()
351 test->test_name, subtest_state->name, in dump_test_log()
352 test_result(subtest_state->error_cnt, in dump_test_log()
353 subtest_state->skipped)); in dump_test_log()
357 jsonw_string_field(w, "name", subtest_state->name); in dump_test_log()
359 jsonw_write_log_message(w, subtest_state->log_buf, subtest_state->log_cnt); in dump_test_log()
375 /* A bunch of tests set custom affinity per-thread and/or per-process. Reset
376 * it after each test/sub-test.
404 if (env.saved_netns_fd == -1) { in save_netns()
412 if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) { in restore_netns()
425 if (subtest_state->error_cnt) { in test__end_subtest()
426 test_state->error_cnt++; in test__end_subtest()
428 if (!subtest_state->skipped) in test__end_subtest()
429 test_state->sub_succ_cnt++; in test__end_subtest()
431 test_state->skip_cnt++; in test__end_subtest()
435 print_subtest_name(test->test_num, test_state->subtest_num, in test__end_subtest()
436 test->test_name, subtest_state->name, in test__end_subtest()
437 test_result(subtest_state->error_cnt, in test__end_subtest()
438 subtest_state->skipped)); in test__end_subtest()
454 state->subtest_num++; in test__start_subtest()
455 state->subtest_states = in test__start_subtest()
456 realloc(state->subtest_states, in test__start_subtest()
457 state->subtest_num * sub_state_size); in test__start_subtest()
458 if (!state->subtest_states) { in test__start_subtest()
463 subtest_state = &state->subtest_states[state->subtest_num - 1]; in test__start_subtest()
469 "Subtest #%d didn't provide sub-test name!\n", in test__start_subtest()
470 state->subtest_num); in test__start_subtest()
474 subtest_state->name = strdup(subtest_name); in test__start_subtest()
475 if (!subtest_state->name) { in test__start_subtest()
478 state->subtest_num); in test__start_subtest()
484 state->subtest_num, in test__start_subtest()
485 test->test_name, in test__start_subtest()
487 subtest_state->filtered = true; in test__start_subtest()
492 stdio_hijack_init(&subtest_state->log_buf, &subtest_state->log_cnt); in test__start_subtest()
499 env.test_state->force_log = true; in test__force_log()
505 env.subtest_state->skipped = true; in test__skip()
507 env.test_state->skip_cnt++; in test__skip()
513 env.subtest_state->error_cnt++; in test__fail()
515 env.test_state->error_cnt++; in test__fail()
522 if (!env.test->need_cgroup_cleanup) { in test__join_cgroup()
526 env.test->test_num, env.test->test_name); in test__join_cgroup()
527 return -1; in test__join_cgroup()
530 env.test->need_cgroup_cleanup = true; in test__join_cgroup()
537 env.test->test_num, env.test->test_name, path, errno); in test__join_cgroup()
544 env.test->test_num, env.test->test_name, path, errno); in test__join_cgroup()
545 return -1; in test__join_cgroup()
559 return -1; in bpf_find_map()
571 if (sysctl_fd != -1) { in is_jit_enabled()
604 return -1; in compare_map_keys()
628 err = -1; in compare_stack_ips()
637 err = -1; in compare_stack_ips()
670 "Options accepting the NAMES parameter take either a comma-separated list\n"
687 ARG_DEBUG = -1,
696 { "name-blacklist", ARG_TEST_NAME_BLACKLIST, "NAMES", 0,
698 { "verifier-stats", ARG_VERIFIER_STATS, NULL, 0,
701 "Verbose output (use -vv or -vvv for progressively verbose output)" },
703 "Get number of selected top-level tests " },
714 { "json-summary", ARG_JSON_SUMMARY, "FILE", 0, "Write report in json format to this file."},
734 for (i = 0; i < set->cnt; i++) { in free_test_filter_set()
735 free((void *)set->tests[i].name); in free_test_filter_set()
736 for (j = 0; j < set->tests[i].subtest_cnt; j++) in free_test_filter_set()
737 free((void *)set->tests[i].subtests[j]); in free_test_filter_set()
739 free((void *)set->tests[i].subtests); in free_test_filter_set()
742 free((void *)set->tests); in free_test_filter_set()
747 free_test_filter_set(&test_selector->blacklist); in free_test_selector()
748 free_test_filter_set(&test_selector->whitelist); in free_test_selector()
749 free(test_selector->num_set); in free_test_selector()
756 struct test_env *env = state->input; in parse_arg()
766 &env->subtest_selector.num_set, in parse_arg()
767 &env->subtest_selector.num_set_len)) { in parse_arg()
770 return -EINVAL; in parse_arg()
773 if (parse_num_list(arg, &env->test_selector.num_set, in parse_arg()
774 &env->test_selector.num_set_len)) { in parse_arg()
776 return -EINVAL; in parse_arg()
784 &env->test_selector.whitelist, in parse_arg()
788 &env->test_selector.whitelist, in parse_arg()
797 &env->test_selector.blacklist, in parse_arg()
801 &env->test_selector.blacklist, in parse_arg()
807 env->verifier_stats = true; in parse_arg()
810 env->verbosity = VERBOSE_NORMAL; in parse_arg()
813 env->verbosity = VERBOSE_VERY; in parse_arg()
816 env->verbosity = VERBOSE_SUPER; in parse_arg()
820 "Unrecognized verbosity setting ('%s'), only -v and -vv are supported\n", in parse_arg()
822 return -EINVAL; in parse_arg()
827 if (setenv("SELFTESTS_VERBOSE", "1", 1) == -1) { in parse_arg()
831 return -EINVAL; in parse_arg()
837 env->get_test_cnt = true; in parse_arg()
840 env->list_test_names = true; in parse_arg()
844 env->workers = atoi(arg); in parse_arg()
845 if (!env->workers) { in parse_arg()
847 return -EINVAL; in parse_arg()
850 env->workers = get_nprocs(); in parse_arg()
854 env->debug = true; in parse_arg()
857 env->json = fopen(arg, "w"); in parse_arg()
858 if (env->json == NULL) { in parse_arg()
860 return -errno; in parse_arg()
876 * into corresponding sub-directory to load correct BPF objects.
878 * This is done by looking at executable name. If it contains "-flavor"
884 * some/path/to/test_progs[-flavor], where -flavor part is optional. in cd_flavor_subdir()
885 * First cut out "test_progs[-flavor]" part, then extract "flavor" in cd_flavor_subdir()
895 flavor = strrchr(flavor, '-'); in cd_flavor_subdir()
910 err = -errno; in trigger_module_test_read()
926 return -ENOMEM; in trigger_module_test_write()
929 buf[write_sz-1] = '\0'; in trigger_module_test_write()
932 err = -errno; in trigger_module_test_write()
949 if (!ASSERT_NEQ(fd, -1, "open sysctl")) in write_sysctl()
950 return -1; in write_sysctl()
956 return -1; in write_sysctl()
971 if (!t || !btf_is_enum(t) || t->name_off) in get_bpf_max_tramp_links_from()
975 name = btf__str_by_offset(btf, e->name_off); in get_bpf_max_tramp_links_from()
977 return e->val; in get_bpf_max_tramp_links_from()
981 return -1; in get_bpf_max_tramp_links_from()
991 return -1; in get_bpf_max_tramp_links()
1009 env.test_state->error_cnt++; in crash_handler()
1012 if (env.worker_id != -1) in crash_handler()
1033 switch (msg->type) { in str_msg()
1035 sprintf(buf, "MSG_DO_TEST %d", msg->do_test.num); in str_msg()
1039 msg->test_done.num, in str_msg()
1040 msg->test_done.have_log); in str_msg()
1044 msg->subtest_done.num, in str_msg()
1045 msg->subtest_done.have_log); in str_msg()
1049 strlen(msg->test_log.log_buf), in str_msg()
1050 msg->test_log.is_last); in str_msg()
1094 stdio_hijack(&state->log_buf, &state->log_cnt); in run_one_test()
1096 if (test->run_test) in run_one_test()
1097 test->run_test(); in run_one_test()
1098 else if (test->run_serial_test) in run_one_test()
1099 test->run_serial_test(); in run_one_test()
1101 /* ensure last sub-test is finalized properly */ in run_one_test()
1105 state->tested = true; in run_one_test()
1107 if (verbose() && env.worker_id == -1) in run_one_test()
1112 if (test->need_cgroup_cleanup) in run_one_test()
1130 if (msg->type != type) { in read_prog_test_msg()
1131 printf("%s: unexpected message type %d. expected %d\n", __func__, msg->type, type); in read_prog_test_msg()
1170 int subtest_num = state->subtest_num; in dispatch_thread_send_subtests()
1172 state->subtest_states = malloc(subtest_num * sizeof(*subtest_state)); in dispatch_thread_send_subtests()
1175 subtest_state = &state->subtest_states[i]; in dispatch_thread_send_subtests()
1182 subtest_state->name = strdup(msg.subtest_done.name); in dispatch_thread_send_subtests()
1183 subtest_state->error_cnt = msg.subtest_done.error_cnt; in dispatch_thread_send_subtests()
1184 subtest_state->skipped = msg.subtest_done.skipped; in dispatch_thread_send_subtests()
1185 subtest_state->filtered = msg.subtest_done.filtered; in dispatch_thread_send_subtests()
1190 &subtest_state->log_buf, in dispatch_thread_send_subtests()
1191 &subtest_state->log_cnt)) in dispatch_thread_send_subtests()
1203 sock_fd = data->sock_fd; in dispatch_thread()
1206 int test_to_run = -1; in dispatch_thread()
1226 if (!test->should_run || test->run_serial_test) in dispatch_thread()
1240 env.worker_current_test[data->worker_id] = test_to_run; in dispatch_thread()
1253 state->tested = true; in dispatch_thread()
1254 state->error_cnt = msg.test_done.error_cnt; in dispatch_thread()
1255 state->skip_cnt = msg.test_done.skip_cnt; in dispatch_thread()
1256 state->sub_succ_cnt = msg.test_done.sub_succ_cnt; in dispatch_thread()
1257 state->subtest_num = msg.test_done.subtest_num; in dispatch_thread()
1262 &state->log_buf, in dispatch_thread()
1263 &state->log_cnt)) in dispatch_thread()
1268 if (!state->subtest_num) in dispatch_thread()
1281 fprintf(stderr, "[%d]: Protocol/IO error: %s.\n", data->worker_id, strerror(errno)); in dispatch_thread()
1291 data->worker_id, strerror(errno)); in dispatch_thread()
1306 if (!state->tested) in calculate_summary_and_print_errors()
1309 sub_succ_cnt += state->sub_succ_cnt; in calculate_summary_and_print_errors()
1310 skip_cnt += state->skip_cnt; in calculate_summary_and_print_errors()
1312 if (state->error_cnt) in calculate_summary_and_print_errors()
1318 if (env->json) { in calculate_summary_and_print_errors()
1319 w = jsonw_new(env->json); in calculate_summary_and_print_errors()
1321 fprintf(env->stderr, "Failed to create new JSON stream."); in calculate_summary_and_print_errors()
1347 if (!state->tested || !state->error_cnt) in calculate_summary_and_print_errors()
1360 if (env->json) in calculate_summary_and_print_errors()
1361 fclose(env->json); in calculate_summary_and_print_errors()
1366 env->succ_cnt = succ_cnt; in calculate_summary_and_print_errors()
1367 env->sub_succ_cnt = sub_succ_cnt; in calculate_summary_and_print_errors()
1368 env->fail_cnt = fail_cnt; in calculate_summary_and_print_errors()
1369 env->skip_cnt = skip_cnt; in calculate_summary_and_print_errors()
1429 if (!test->should_run || !test->run_serial_test) in server_main()
1470 slen -= len; in worker_main_send_log()
1480 if (state->log_buf) { in free_subtest_state()
1481 free(state->log_buf); in free_subtest_state()
1482 state->log_buf = NULL; in free_subtest_state()
1483 state->log_cnt = 0; in free_subtest_state()
1485 free(state->name); in free_subtest_state()
1486 state->name = NULL; in free_subtest_state()
1498 for (i = 0; i < state->subtest_num; i++) { in worker_main_send_subtests()
1499 subtest_state = &state->subtest_states[i]; in worker_main_send_subtests()
1503 strncpy(msg.subtest_done.name, subtest_state->name, MAX_SUBTEST_NAME); in worker_main_send_subtests()
1505 msg.subtest_done.error_cnt = subtest_state->error_cnt; in worker_main_send_subtests()
1506 msg.subtest_done.skipped = subtest_state->skipped; in worker_main_send_subtests()
1507 msg.subtest_done.filtered = subtest_state->filtered; in worker_main_send_subtests()
1510 if (verbose() || state->force_log || subtest_state->error_cnt) { in worker_main_send_subtests()
1511 if (subtest_state->log_cnt) in worker_main_send_subtests()
1523 worker_main_send_log(sock, subtest_state->log_buf, subtest_state->log_cnt); in worker_main_send_subtests()
1526 free(subtest_state->name); in worker_main_send_subtests()
1530 for (; i < state->subtest_num; i++) in worker_main_send_subtests()
1531 free_subtest_state(&state->subtest_states[i]); in worker_main_send_subtests()
1532 free(state->subtest_states); in worker_main_send_subtests()
1563 test->test_name); in worker_main()
1570 msg.test_done.error_cnt = state->error_cnt; in worker_main()
1571 msg.test_done.skip_cnt = state->skip_cnt; in worker_main()
1572 msg.test_done.sub_succ_cnt = state->sub_succ_cnt; in worker_main()
1573 msg.test_done.subtest_num = state->subtest_num; in worker_main()
1576 if (verbose() || state->force_log || state->error_cnt) { in worker_main()
1577 if (state->log_cnt) in worker_main()
1587 worker_main_send_log(sock, state->log_buf, state->log_cnt); in worker_main()
1589 if (state->log_buf) { in worker_main()
1590 free(state->log_buf); in worker_main()
1591 state->log_buf = NULL; in worker_main()
1592 state->log_cnt = 0; in worker_main()
1595 if (state->subtest_num) in worker_main()
1603 test->test_name); in worker_main()
1609 return -1; in worker_main()
1623 for (j = 0; j < test_state->subtest_num; j++) in free_test_states()
1624 free_subtest_state(&test_state->subtest_states[j]); in free_test_states()
1626 free(test_state->subtest_states); in free_test_states()
1627 free(test_state->log_buf); in free_test_states()
1628 test_state->subtest_states = NULL; in free_test_states()
1629 test_state->log_buf = NULL; in free_test_states()
1667 return -1; in main()
1688 test->test_num = i + 1; in main()
1689 test->should_run = should_run(&env.test_selector, in main()
1690 test->test_num, test->test_name); in main()
1692 if ((test->run_test == NULL && test->run_serial_test == NULL) || in main()
1693 (test->run_test != NULL && test->run_serial_test != NULL)) { in main()
1695 test->test_num, test->test_name, test->test_name, test->test_name); in main()
1705 env.worker_id = -1; /* main process */ in main()
1717 return -1; in main()
1722 return -1; in main()
1734 if (env.worker_id == -1) { in main()
1748 if (!test->should_run) in main()
1757 fprintf(env.stdout, "%s\n", test->test_name); in main()