File Index
Files and directories
Sign in
FILE

wq.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/prog_tests/wq.c C
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2024 Benjamin Tissoires */
 3#include <test_progs.h>
 4#include "wq.skel.h"
 5#include "wq_failures.skel.h"
 6
 7void serial_test_wq(void)
 8{
 9	struct wq *wq_skel = NULL;
10	int err, prog_fd;
11
12	LIBBPF_OPTS(bpf_test_run_opts, topts);
13
14	RUN_TESTS(wq);
15
16	/* re-run the success test to check if the timer was actually executed */
17
18	wq_skel = wq__open_and_load();
19	if (!ASSERT_OK_PTR(wq_skel, "wq__open_and_load"))
20		return;
21
22	err = wq__attach(wq_skel);
23	if (!ASSERT_OK(err, "wq_attach"))
24		goto clean_up;
25
26	prog_fd = bpf_program__fd(wq_skel->progs.test_syscall_array_sleepable);
27	err = bpf_prog_test_run_opts(prog_fd, &topts);
28	ASSERT_OK(err, "test_run");
29	ASSERT_EQ(topts.retval, 0, "test_run");
30
31	usleep(50); /* 10 usecs should be enough, but give it extra */
32
33	ASSERT_EQ(wq_skel->bss->ok_sleepable, (1 << 1), "ok_sleepable");
34clean_up:
35	wq__destroy(wq_skel);
36}
37
38void serial_test_failures_wq(void)
39{
40	RUN_TESTS(wq_failures);
41}
42
43static void test_failure_map_no_btf(void)
44{
45	struct wq *skel = NULL;
46	char log[8192];
47	const struct bpf_insn *insns;
48	size_t insn_cnt;
49	int ret, err, map_fd;
50	LIBBPF_OPTS(bpf_prog_load_opts, opts, .log_size = sizeof(log), .log_buf = log,
51		    .log_level = 2);
52
53	skel = wq__open();
54	if (!ASSERT_OK_PTR(skel, "skel_open"))
55		return;
56
57	err = bpf_object__prepare(skel->obj);
58	if (!ASSERT_OK(err, "skel__prepare"))
59		goto out;
60
61	map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "map_no_btf", sizeof(__u32), sizeof(__u64), 100,
62				NULL);
63	if (!ASSERT_GT(map_fd, -1, "map create"))
64		goto out;
65
66	err = bpf_map__reuse_fd(skel->maps.array, map_fd);
67	if (!ASSERT_OK(err, "map reuse fd")) {
68		close(map_fd);
69		goto out;
70	}
71
72	insns = bpf_program__insns(skel->progs.test_map_no_btf);
73	if (!ASSERT_OK_PTR(insns, "insns ptr"))
74		goto out;
75
76	insn_cnt = bpf_program__insn_cnt(skel->progs.test_map_no_btf);
77	if (!ASSERT_GT(insn_cnt, 0u, "insn cnt"))
78		goto out;
79
80	ret = bpf_prog_load(BPF_PROG_TYPE_TRACEPOINT, NULL, "GPL", insns, insn_cnt, &opts);
81	if (!ASSERT_LT(ret, 0, "prog load failed")) {
82		if (ret > 0)
83			close(ret);
84		goto out;
85	}
86
87	ASSERT_HAS_SUBSTR(log, "map 'map_no_btf' has to have BTF in order to use bpf_wq",
88			  "log complains no map BTF");
89out:
90	wq__destroy(skel);
91}
92
93void test_wq_custom(void)
94{
95	if (test__start_subtest("test_failure_map_no_btf"))
96		test_failure_map_no_btf();
97}
~/ Read-only file preview.