File Index
Files and directories
Sign in
FILE

cpumask.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/prog_tests/cpumask.c C
 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
 8static 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_firstand_nocpu",
14	"test_test_and_set_clear",
15	"test_and_or_xor",
16	"test_intersects_subset",
17	"test_copy_any_anyand",
18	"test_insert_leave",
19	"test_insert_remove_release",
20	"test_global_mask_rcu",
21	"test_global_mask_array_one_rcu",
22	"test_global_mask_array_rcu",
23	"test_global_mask_array_l2_rcu",
24	"test_global_mask_nested_rcu",
25	"test_global_mask_nested_deep_rcu",
26	"test_global_mask_nested_deep_array_rcu",
27	"test_cpumask_weight",
28	"test_refcount_null_tracking",
29	"test_populate_reject_small_mask",
30	"test_populate_reject_unaligned",
31	"test_populate",
32};
33
34static void verify_success(const char *prog_name)
35{
36	struct cpumask_success *skel;
37	struct bpf_program *prog;
38	struct bpf_link *link = NULL;
39	pid_t child_pid;
40	int status, err;
41
42	skel = cpumask_success__open();
43	if (!ASSERT_OK_PTR(skel, "cpumask_success__open"))
44		return;
45
46	skel->bss->pid = getpid();
47	skel->bss->nr_cpus = libbpf_num_possible_cpus();
48
49	err = cpumask_success__load(skel);
50	if (!ASSERT_OK(err, "cpumask_success__load"))
51		goto cleanup;
52
53	prog = bpf_object__find_program_by_name(skel->obj, prog_name);
54	if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
55		goto cleanup;
56
57	link = bpf_program__attach(prog);
58	if (!ASSERT_OK_PTR(link, "bpf_program__attach"))
59		goto cleanup;
60
61	child_pid = fork();
62	if (!ASSERT_GT(child_pid, -1, "child_pid"))
63		goto cleanup;
64	if (child_pid == 0)
65		_exit(0);
66	waitpid(child_pid, &status, 0);
67	ASSERT_OK(skel->bss->err, "post_wait_err");
68
69cleanup:
70	bpf_link__destroy(link);
71	cpumask_success__destroy(skel);
72}
73
74void test_cpumask(void)
75{
76	int i;
77
78	for (i = 0; i < ARRAY_SIZE(cpumask_success_testcases); i++) {
79		if (!test__start_subtest(cpumask_success_testcases[i]))
80			continue;
81
82		verify_success(cpumask_success_testcases[i]);
83	}
84
85	RUN_TESTS(cpumask_failure);
86}
~/ Read-only file preview.