1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
4  * Copyright (c) 2023 David Vernet <[email protected]>
5  * Copyright (c) 2023 Tejun Heo <[email protected]>
6  */
7 #include <bpf/bpf.h>
8 #include <scx/common.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
11 #include "minimal.bpf.skel.h"
12 #include "scx_test.h"
13 
setup(void ** ctx)14 static enum scx_test_status setup(void **ctx)
15 {
16 	struct minimal *skel;
17 
18 	skel = minimal__open();
19 	SCX_FAIL_IF(!skel, "Failed to open");
20 	SCX_ENUM_INIT(skel);
21 	SCX_FAIL_IF(minimal__load(skel), "Failed to load skel");
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 minimal *skel = ctx;
31 	struct bpf_link *link;
32 
33 	link = bpf_map__attach_struct_ops(skel->maps.minimal_ops);
34 	if (!link) {
35 		SCX_ERR("Failed to attach scheduler");
36 		return SCX_TEST_FAIL;
37 	}
38 
39 	bpf_link__destroy(link);
40 
41 	return SCX_TEST_PASS;
42 }
43 
cleanup(void * ctx)44 static void cleanup(void *ctx)
45 {
46 	struct minimal *skel = ctx;
47 
48 	minimal__destroy(skel);
49 }
50 
51 struct scx_test minimal = {
52 	.name = "minimal",
53 	.description = "Verify we can load a fully minimal scheduler",
54 	.setup = setup,
55 	.run = run,
56 	.cleanup = cleanup,
57 };
58 REGISTER_SCX_TEST(&minimal)
59