1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ 3 4 #include <test_progs.h> 5 #include "cpumask_failure.skel.h" 6 #include "cpumask_success.skel.h" 7 8 static const char * const cpumask_success_testcases[] = { 9 "test_alloc_free_cpumask", 10 "test_set_clear_cpu", 11 "test_setall_clear_cpu", 12 "test_first_firstzero_cpu", 13 "test_test_and_set_clear", 14 "test_and_or_xor", 15 "test_intersects_subset", 16 "test_copy_any_anyand", 17 "test_insert_leave", 18 "test_insert_remove_release", 19 "test_global_mask_rcu", 20 }; 21 22 static void verify_success(const char *prog_name) 23 { 24 struct cpumask_success *skel; 25 struct bpf_program *prog; 26 struct bpf_link *link = NULL; 27 pid_t child_pid; 28 int status; 29 30 skel = cpumask_success__open(); 31 if (!ASSERT_OK_PTR(skel, "cpumask_success__open")) 32 return; 33 34 skel->bss->pid = getpid(); 35 skel->bss->nr_cpus = libbpf_num_possible_cpus(); 36 37 cpumask_success__load(skel); 38 if (!ASSERT_OK_PTR(skel, "cpumask_success__load")) 39 goto cleanup; 40 41 prog = bpf_object__find_program_by_name(skel->obj, prog_name); 42 if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name")) 43 goto cleanup; 44 45 link = bpf_program__attach(prog); 46 if (!ASSERT_OK_PTR(link, "bpf_program__attach")) 47 goto cleanup; 48 49 child_pid = fork(); 50 if (!ASSERT_GT(child_pid, -1, "child_pid")) 51 goto cleanup; 52 if (child_pid == 0) 53 _exit(0); 54 waitpid(child_pid, &status, 0); 55 ASSERT_OK(skel->bss->err, "post_wait_err"); 56 57 cleanup: 58 bpf_link__destroy(link); 59 cpumask_success__destroy(skel); 60 } 61 62 void test_cpumask(void) 63 { 64 int i; 65 66 for (i = 0; i < ARRAY_SIZE(cpumask_success_testcases); i++) { 67 if (!test__start_subtest(cpumask_success_testcases[i])) 68 continue; 69 70 verify_success(cpumask_success_testcases[i]); 71 } 72 73 RUN_TESTS(cpumask_failure); 74 } 75