xref: /linux/tools/testing/selftests/sched_ext/enq_select_cpu_fails.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
4  * Copyright (c) 2023 David Vernet <dvernet@meta.com>
5  * Copyright (c) 2023 Tejun Heo <tj@kernel.org>
6  */
7 #include <bpf/bpf.h>
8 #include <scx/common.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
11 #include "enq_select_cpu_fails.bpf.skel.h"
12 #include "scx_test.h"
13 
setup(void ** ctx)14 static enum scx_test_status setup(void **ctx)
15 {
16 	struct enq_select_cpu_fails *skel;
17 
18 	skel = enq_select_cpu_fails__open_and_load();
19 	if (!skel) {
20 		SCX_ERR("Failed to open and load skel");
21 		return SCX_TEST_FAIL;
22 	}
23 	*ctx = skel;
24 
25 	return SCX_TEST_PASS;
26 }
27 
run(void * ctx)28 static enum scx_test_status run(void *ctx)
29 {
30 	struct enq_select_cpu_fails *skel = ctx;
31 	struct bpf_link *link;
32 
33 	link = bpf_map__attach_struct_ops(skel->maps.enq_select_cpu_fails_ops);
34 	if (!link) {
35 		SCX_ERR("Failed to attach scheduler");
36 		return SCX_TEST_FAIL;
37 	}
38 
39 	sleep(1);
40 
41 	bpf_link__destroy(link);
42 
43 	return SCX_TEST_PASS;
44 }
45 
cleanup(void * ctx)46 static void cleanup(void *ctx)
47 {
48 	struct enq_select_cpu_fails *skel = ctx;
49 
50 	enq_select_cpu_fails__destroy(skel);
51 }
52 
53 struct scx_test enq_select_cpu_fails = {
54 	.name = "enq_select_cpu_fails",
55 	.description = "Verify we fail to call scx_bpf_select_cpu_dfl() "
56 		       "from ops.enqueue()",
57 	.setup = setup,
58 	.run = run,
59 	.cleanup = cleanup,
60 };
61 REGISTER_SCX_TEST(&enq_select_cpu_fails)
62