Lines Matching +full:library +full:- +full:sel
1 // SPDX-License-Identifier: GPL-2.0-only
48 if (verbose() && env.worker_id == -1) { in stdio_hijack_init()
64 env.subtest_state->stdout_saved = stdout; in stdio_hijack_init()
66 env.test_state->stdout_saved = stdout; in stdio_hijack_init()
75 if (verbose() && env.worker_id == -1) { in stdio_hijack()
90 if (verbose() && env.worker_id == -1) { in stdio_restore_cleanup()
98 fclose(env.subtest_state->stdout_saved); in stdio_restore_cleanup()
99 env.subtest_state->stdout_saved = NULL; in stdio_restore_cleanup()
100 stdout = env.test_state->stdout_saved; in stdio_restore_cleanup()
101 stderr = env.test_state->stdout_saved; in stdio_restore_cleanup()
103 fclose(env.test_state->stdout_saved); in stdio_restore_cleanup()
104 env.test_state->stdout_saved = NULL; in stdio_restore_cleanup()
112 if (verbose() && env.worker_id == -1) { in stdio_restore()
165 /* Override C runtime library's usleep() implementation to ensure nanosleep()
179 static bool should_run(struct test_selector *sel, int num, const char *name) in should_run() argument
183 for (i = 0; i < sel->blacklist.cnt; i++) { in should_run()
184 if (glob_match(name, sel->blacklist.tests[i].name) && in should_run()
185 !sel->blacklist.tests[i].subtest_cnt) in should_run()
189 for (i = 0; i < sel->whitelist.cnt; i++) { in should_run()
190 if (glob_match(name, sel->whitelist.tests[i].name)) in should_run()
194 if (!sel->whitelist.cnt && !sel->num_set) in should_run()
197 return num < sel->num_set_len && sel->num_set[num]; in should_run()
206 for (i = 0; i < filter->cnt; i++) { in match_subtest()
207 if (glob_match(test_name, filter->tests[i].name)) { in match_subtest()
208 if (!filter->tests[i].subtest_cnt) in match_subtest()
211 for (j = 0; j < filter->tests[i].subtest_cnt; j++) { in match_subtest()
213 filter->tests[i].subtests[j])) in match_subtest()
222 static bool should_run_subtest(struct test_selector *sel, in should_run_subtest() argument
228 if (match_subtest(&sel->blacklist, test_name, subtest_name)) in should_run_subtest()
231 if (match_subtest(&sel->whitelist, test_name, subtest_name)) in should_run_subtest()
234 if (!sel->whitelist.cnt && !subtest_sel->num_set) in should_run_subtest()
237 return subtest_num < subtest_sel->num_set_len && subtest_sel->num_set[subtest_num]; in should_run_subtest()
240 static bool should_tmon(struct test_selector *sel, const char *name) in should_tmon() argument
244 for (i = 0; i < sel->whitelist.cnt; i++) { in should_tmon()
245 if (glob_match(name, sel->whitelist.tests[i].name) && in should_tmon()
246 !sel->whitelist.tests[i].subtest_cnt) in should_tmon()
262 int skipped_cnt = test_state->skip_cnt; in print_test_result()
263 int subtests_cnt = test_state->subtest_num; in print_test_result()
265 fprintf(env.stdout_saved, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name); in print_test_result()
266 if (test_state->error_cnt) in print_test_result()
282 if (log_buf[log_cnt - 1] != '\n') in print_test_log()
294 fprintf(env.stdout_saved, "#%-*s %s/%s", in print_subtest_name()
322 bool test_failed = test_state->error_cnt > 0; in dump_test_log()
323 bool force_log = test_state->force_log; in dump_test_log()
332 if (env.worker_id != -1) in dump_test_log()
341 if (test_state->log_cnt && print_test) in dump_test_log()
342 print_test_log(test_state->log_buf, test_state->log_cnt); in dump_test_log()
346 jsonw_string_field(w, "name", test->test_name); in dump_test_log()
347 jsonw_uint_field(w, "number", test->test_num); in dump_test_log()
348 jsonw_write_log_message(w, test_state->log_buf, test_state->log_cnt); in dump_test_log()
354 for (i = 0; i < test_state->subtest_num; i++) { in dump_test_log()
355 subtest_state = &test_state->subtest_states[i]; in dump_test_log()
356 subtest_failed = subtest_state->error_cnt; in dump_test_log()
357 subtest_filtered = subtest_state->filtered; in dump_test_log()
363 if (subtest_state->log_cnt && print_subtest) { in dump_test_log()
364 print_test_log(subtest_state->log_buf, in dump_test_log()
365 subtest_state->log_cnt); in dump_test_log()
368 print_subtest_name(test->test_num, i + 1, in dump_test_log()
369 test->test_name, subtest_state->name, in dump_test_log()
370 test_result(subtest_state->error_cnt, in dump_test_log()
371 subtest_state->skipped)); in dump_test_log()
375 jsonw_string_field(w, "name", subtest_state->name); in dump_test_log()
377 jsonw_write_log_message(w, subtest_state->log_buf, subtest_state->log_cnt); in dump_test_log()
393 /* A bunch of tests set custom affinity per-thread and/or per-process. Reset
394 * it after each test/sub-test.
422 if (env.saved_netns_fd == -1) { in save_netns()
430 if (setns(env.saved_netns_fd, CLONE_NEWNET) == -1) { in restore_netns()
443 if (subtest_state->error_cnt) { in test__end_subtest()
444 test_state->error_cnt++; in test__end_subtest()
446 if (!subtest_state->skipped) in test__end_subtest()
447 test_state->sub_succ_cnt++; in test__end_subtest()
449 test_state->skip_cnt++; in test__end_subtest()
453 print_subtest_name(test->test_num, test_state->subtest_num, in test__end_subtest()
454 test->test_name, subtest_state->name, in test__end_subtest()
455 test_result(subtest_state->error_cnt, in test__end_subtest()
456 subtest_state->skipped)); in test__end_subtest()
472 state->subtest_num++; in test__start_subtest()
473 state->subtest_states = in test__start_subtest()
474 realloc(state->subtest_states, in test__start_subtest()
475 state->subtest_num * sub_state_size); in test__start_subtest()
476 if (!state->subtest_states) { in test__start_subtest()
481 subtest_state = &state->subtest_states[state->subtest_num - 1]; in test__start_subtest()
487 "Subtest #%d didn't provide sub-test name!\n", in test__start_subtest()
488 state->subtest_num); in test__start_subtest()
492 subtest_state->name = strdup(subtest_name); in test__start_subtest()
493 if (!subtest_state->name) { in test__start_subtest()
496 state->subtest_num); in test__start_subtest()
502 state->subtest_num, in test__start_subtest()
503 test->test_name, in test__start_subtest()
505 subtest_state->filtered = true; in test__start_subtest()
509 subtest_state->should_tmon = match_subtest(&env.tmon_selector.whitelist, in test__start_subtest()
510 test->test_name, in test__start_subtest()
514 stdio_hijack_init(&subtest_state->log_buf, &subtest_state->log_cnt); in test__start_subtest()
521 env.test_state->force_log = true; in test__force_log()
527 env.subtest_state->skipped = true; in test__skip()
529 env.test_state->skip_cnt++; in test__skip()
535 env.subtest_state->error_cnt++; in test__fail()
537 env.test_state->error_cnt++; in test__fail()
544 if (!env.test->need_cgroup_cleanup) { in test__join_cgroup()
548 env.test->test_num, env.test->test_name); in test__join_cgroup()
549 return -1; in test__join_cgroup()
552 env.test->need_cgroup_cleanup = true; in test__join_cgroup()
559 env.test->test_num, env.test->test_name, path, errno); in test__join_cgroup()
566 env.test->test_num, env.test->test_name, path, errno); in test__join_cgroup()
567 return -1; in test__join_cgroup()
581 return -1; in bpf_find_map()
608 return -1; in compare_map_keys()
632 err = -1; in compare_stack_ips()
641 err = -1; in compare_stack_ips()
662 * It also implements the functionality of the option "-m" by starting
681 netns_obj->nsname = strdup(nsname); in netns_new()
682 if (!netns_obj->nsname) in netns_new()
691 if (env.test->should_tmon || in netns_new()
692 (env.subtest_state && env.subtest_state->should_tmon)) { in netns_new()
693 test_name = env.test->test_name; in netns_new()
694 subtest_name = env.subtest_state ? env.subtest_state->name : NULL; in netns_new()
695 netns_obj->tmon = traffic_monitor_start(nsname, test_name, subtest_name); in netns_new()
696 if (!netns_obj->tmon) { in netns_new()
701 netns_obj->tmon = NULL; in netns_new()
705 netns_obj->nstoken = open_netns(nsname); in netns_new()
706 if (!netns_obj->nstoken) in netns_new()
712 traffic_monitor_stop(netns_obj->tmon); in netns_new()
714 free(netns_obj->nsname); in netns_new()
728 traffic_monitor_stop(netns_obj->tmon); in netns_free()
729 close_netns(netns_obj->nstoken); in netns_free()
730 remove_netns(netns_obj->nsname); in netns_free()
731 free(netns_obj->nsname); in netns_free()
760 "Options accepting the NAMES parameter take either a comma-separated list\n"
777 ARG_DEBUG = -1,
787 { "name-blacklist", ARG_TEST_NAME_BLACKLIST, "NAMES", 0,
789 { "verifier-stats", ARG_VERIFIER_STATS, NULL, 0,
792 "Verbose output (use -vv or -vvv for progressively verbose output)" },
794 "Get number of selected top-level tests " },
805 { "json-summary", ARG_JSON_SUMMARY, "FILE", 0, "Write report in json format to this file."},
807 { "traffic-monitor", ARG_TRAFFIC_MONITOR, "NAMES", 0,
830 return -EINVAL; in start_libbpf_log_capture()
837 return -EINVAL; in start_libbpf_log_capture()
887 for (i = 0; i < set->cnt; i++) { in free_test_filter_set()
888 free((void *)set->tests[i].name); in free_test_filter_set()
889 for (j = 0; j < set->tests[i].subtest_cnt; j++) in free_test_filter_set()
890 free((void *)set->tests[i].subtests[j]); in free_test_filter_set()
892 free((void *)set->tests[i].subtests); in free_test_filter_set()
895 free((void *)set->tests); in free_test_filter_set()
900 free_test_filter_set(&test_selector->blacklist); in free_test_selector()
901 free_test_filter_set(&test_selector->whitelist); in free_test_selector()
902 free(test_selector->num_set); in free_test_selector()
909 struct test_env *env = state->input; in parse_arg()
919 &env->subtest_selector.num_set, in parse_arg()
920 &env->subtest_selector.num_set_len)) { in parse_arg()
923 return -EINVAL; in parse_arg()
926 if (parse_num_list(arg, &env->test_selector.num_set, in parse_arg()
927 &env->test_selector.num_set_len)) { in parse_arg()
929 return -EINVAL; in parse_arg()
937 &env->test_selector.whitelist, in parse_arg()
941 &env->test_selector.whitelist, in parse_arg()
950 &env->test_selector.blacklist, in parse_arg()
954 &env->test_selector.blacklist, in parse_arg()
960 env->verifier_stats = true; in parse_arg()
963 env->verbosity = VERBOSE_NORMAL; in parse_arg()
966 env->verbosity = VERBOSE_VERY; in parse_arg()
969 env->verbosity = VERBOSE_SUPER; in parse_arg()
973 "Unrecognized verbosity setting ('%s'), only -v and -vv are supported\n", in parse_arg()
975 return -EINVAL; in parse_arg()
978 env_verbosity = env->verbosity; in parse_arg()
981 if (setenv("SELFTESTS_VERBOSE", "1", 1) == -1) { in parse_arg()
985 return -EINVAL; in parse_arg()
991 env->get_test_cnt = true; in parse_arg()
994 env->list_test_names = true; in parse_arg()
998 env->workers = atoi(arg); in parse_arg()
999 if (!env->workers) { in parse_arg()
1001 return -EINVAL; in parse_arg()
1004 env->workers = get_nprocs(); in parse_arg()
1008 env->debug = true; in parse_arg()
1011 env->json = fopen(arg, "w"); in parse_arg()
1012 if (env->json == NULL) { in parse_arg()
1014 return -errno; in parse_arg()
1026 &env->tmon_selector.whitelist, in parse_arg()
1030 &env->tmon_selector.whitelist, in parse_arg()
1042 * into corresponding sub-directory to load correct BPF objects.
1044 * This is done by looking at executable name. If it contains "-flavor"
1050 * some/path/to/test_progs[-flavor], where -flavor part is optional. in cd_flavor_subdir()
1051 * First cut out "test_progs[-flavor]" part, then extract "flavor" in cd_flavor_subdir()
1061 flavor = strrchr(flavor, '-'); in cd_flavor_subdir()
1076 err = -errno; in trigger_module_test_read()
1092 return -ENOMEM; in trigger_module_test_write()
1095 buf[write_sz-1] = '\0'; in trigger_module_test_write()
1098 err = -errno; in trigger_module_test_write()
1115 if (!ASSERT_NEQ(fd, -1, "open sysctl")) in write_sysctl()
1116 return -1; in write_sysctl()
1122 return -1; in write_sysctl()
1137 if (!t || !btf_is_enum(t) || t->name_off) in get_bpf_max_tramp_links_from()
1141 name = btf__str_by_offset(btf, e->name_off); in get_bpf_max_tramp_links_from()
1143 return e->val; in get_bpf_max_tramp_links_from()
1147 return -1; in get_bpf_max_tramp_links_from()
1157 return -1; in get_bpf_max_tramp_links()
1175 env.test_state->error_cnt++; in crash_handler()
1178 if (env.worker_id != -1) in crash_handler()
1199 switch (msg->type) { in str_msg()
1201 sprintf(buf, "MSG_DO_TEST %d", msg->do_test.num); in str_msg()
1205 msg->test_done.num, in str_msg()
1206 msg->test_done.have_log); in str_msg()
1210 msg->subtest_done.num, in str_msg()
1211 msg->subtest_done.have_log); in str_msg()
1215 strlen(msg->test_log.log_buf), in str_msg()
1216 msg->test_log.is_last); in str_msg()
1260 stdio_hijack(&state->log_buf, &state->log_cnt); in run_one_test()
1262 if (test->run_test) in run_one_test()
1263 test->run_test(); in run_one_test()
1264 else if (test->run_serial_test) in run_one_test()
1265 test->run_serial_test(); in run_one_test()
1267 /* ensure last sub-test is finalized properly */ in run_one_test()
1271 state->tested = true; in run_one_test()
1273 if (verbose() && env.worker_id == -1) in run_one_test()
1278 if (test->need_cgroup_cleanup) in run_one_test()
1297 if (msg->type != type) { in read_prog_test_msg()
1298 printf("%s: unexpected message type %d. expected %d\n", __func__, msg->type, type); in read_prog_test_msg()
1337 int subtest_num = state->subtest_num; in dispatch_thread_send_subtests()
1339 state->subtest_states = malloc(subtest_num * sizeof(*subtest_state)); in dispatch_thread_send_subtests()
1342 subtest_state = &state->subtest_states[i]; in dispatch_thread_send_subtests()
1349 subtest_state->name = strdup(msg.subtest_done.name); in dispatch_thread_send_subtests()
1350 subtest_state->error_cnt = msg.subtest_done.error_cnt; in dispatch_thread_send_subtests()
1351 subtest_state->skipped = msg.subtest_done.skipped; in dispatch_thread_send_subtests()
1352 subtest_state->filtered = msg.subtest_done.filtered; in dispatch_thread_send_subtests()
1357 &subtest_state->log_buf, in dispatch_thread_send_subtests()
1358 &subtest_state->log_cnt)) in dispatch_thread_send_subtests()
1370 sock_fd = data->sock_fd; in dispatch_thread()
1373 int test_to_run = -1; in dispatch_thread()
1393 if (!test->should_run || test->run_serial_test) in dispatch_thread()
1407 env.worker_current_test[data->worker_id] = test_to_run; in dispatch_thread()
1420 state->tested = true; in dispatch_thread()
1421 state->error_cnt = msg.test_done.error_cnt; in dispatch_thread()
1422 state->skip_cnt = msg.test_done.skip_cnt; in dispatch_thread()
1423 state->sub_succ_cnt = msg.test_done.sub_succ_cnt; in dispatch_thread()
1424 state->subtest_num = msg.test_done.subtest_num; in dispatch_thread()
1429 &state->log_buf, in dispatch_thread()
1430 &state->log_cnt)) in dispatch_thread()
1435 if (!state->subtest_num) in dispatch_thread()
1448 fprintf(stderr, "[%d]: Protocol/IO error: %s.\n", data->worker_id, strerror(errno)); in dispatch_thread()
1458 data->worker_id, strerror(errno)); in dispatch_thread()
1473 if (!state->tested) in calculate_summary_and_print_errors()
1476 sub_succ_cnt += state->sub_succ_cnt; in calculate_summary_and_print_errors()
1477 skip_cnt += state->skip_cnt; in calculate_summary_and_print_errors()
1479 if (state->error_cnt) in calculate_summary_and_print_errors()
1485 if (env->json) { in calculate_summary_and_print_errors()
1486 w = jsonw_new(env->json); in calculate_summary_and_print_errors()
1488 fprintf(env->stderr_saved, "Failed to create new JSON stream."); in calculate_summary_and_print_errors()
1514 if (!state->tested || !state->error_cnt) in calculate_summary_and_print_errors()
1527 if (env->json) in calculate_summary_and_print_errors()
1528 fclose(env->json); in calculate_summary_and_print_errors()
1533 env->succ_cnt = succ_cnt; in calculate_summary_and_print_errors()
1534 env->sub_succ_cnt = sub_succ_cnt; in calculate_summary_and_print_errors()
1535 env->fail_cnt = fail_cnt; in calculate_summary_and_print_errors()
1536 env->skip_cnt = skip_cnt; in calculate_summary_and_print_errors()
1596 if (!test->should_run || !test->run_serial_test) in server_main()
1637 slen -= len; in worker_main_send_log()
1647 if (state->log_buf) { in free_subtest_state()
1648 free(state->log_buf); in free_subtest_state()
1649 state->log_buf = NULL; in free_subtest_state()
1650 state->log_cnt = 0; in free_subtest_state()
1652 free(state->name); in free_subtest_state()
1653 state->name = NULL; in free_subtest_state()
1665 for (i = 0; i < state->subtest_num; i++) { in worker_main_send_subtests()
1666 subtest_state = &state->subtest_states[i]; in worker_main_send_subtests()
1670 strncpy(msg.subtest_done.name, subtest_state->name, MAX_SUBTEST_NAME); in worker_main_send_subtests()
1672 msg.subtest_done.error_cnt = subtest_state->error_cnt; in worker_main_send_subtests()
1673 msg.subtest_done.skipped = subtest_state->skipped; in worker_main_send_subtests()
1674 msg.subtest_done.filtered = subtest_state->filtered; in worker_main_send_subtests()
1677 if (verbose() || state->force_log || subtest_state->error_cnt) { in worker_main_send_subtests()
1678 if (subtest_state->log_cnt) in worker_main_send_subtests()
1690 worker_main_send_log(sock, subtest_state->log_buf, subtest_state->log_cnt); in worker_main_send_subtests()
1693 free(subtest_state->name); in worker_main_send_subtests()
1697 for (; i < state->subtest_num; i++) in worker_main_send_subtests()
1698 free_subtest_state(&state->subtest_states[i]); in worker_main_send_subtests()
1699 free(state->subtest_states); in worker_main_send_subtests()
1730 test->test_name); in worker_main()
1737 msg.test_done.error_cnt = state->error_cnt; in worker_main()
1738 msg.test_done.skip_cnt = state->skip_cnt; in worker_main()
1739 msg.test_done.sub_succ_cnt = state->sub_succ_cnt; in worker_main()
1740 msg.test_done.subtest_num = state->subtest_num; in worker_main()
1743 if (verbose() || state->force_log || state->error_cnt) { in worker_main()
1744 if (state->log_cnt) in worker_main()
1754 worker_main_send_log(sock, state->log_buf, state->log_cnt); in worker_main()
1756 if (state->log_buf) { in worker_main()
1757 free(state->log_buf); in worker_main()
1758 state->log_buf = NULL; in worker_main()
1759 state->log_cnt = 0; in worker_main()
1762 if (state->subtest_num) in worker_main()
1770 test->test_name); in worker_main()
1776 return -1; in worker_main()
1790 for (j = 0; j < test_state->subtest_num; j++) in free_test_states()
1791 free_subtest_state(&test_state->subtest_states[j]); in free_test_states()
1793 free(test_state->subtest_states); in free_test_states()
1794 free(test_state->log_buf); in free_test_states()
1795 test_state->subtest_states = NULL; in free_test_states()
1796 test_state->log_buf = NULL; in free_test_states()
1834 return -1; in main()
1855 test->test_num = i + 1; in main()
1856 test->should_run = should_run(&env.test_selector, in main()
1857 test->test_num, test->test_name); in main()
1859 if ((test->run_test == NULL && test->run_serial_test == NULL) || in main()
1860 (test->run_test != NULL && test->run_serial_test != NULL)) { in main()
1862 test->test_num, test->test_name, test->test_name, test->test_name); in main()
1865 if (test->should_run) in main()
1866 test->should_tmon = should_tmon(&env.tmon_selector, test->test_name); in main()
1874 env.worker_id = -1; /* main process */ in main()
1886 return -1; in main()
1891 return -1; in main()
1903 if (env.worker_id == -1) { in main()
1917 if (!test->should_run) in main()
1926 fprintf(env.stdout_saved, "%s\n", test->test_name); in main()