1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
4 * Copyright (c) 2024 David Vernet <dvernet@meta.com>
5 * Copyright (c) 2024 Tejun Heo <tj@kernel.org>
6 */
7 #include <bpf/bpf.h>
8 #include <scx/common.h>
9 #include <unistd.h>
10 #include "ddsp_vtimelocal_fail.bpf.skel.h"
11 #include "scx_test.h"
12
setup(void ** ctx)13 static enum scx_test_status setup(void **ctx)
14 {
15 struct ddsp_vtimelocal_fail *skel;
16
17 skel = ddsp_vtimelocal_fail__open_and_load();
18 SCX_FAIL_IF(!skel, "Failed to open and load skel");
19 *ctx = skel;
20
21 return SCX_TEST_PASS;
22 }
23
run(void * ctx)24 static enum scx_test_status run(void *ctx)
25 {
26 struct ddsp_vtimelocal_fail *skel = ctx;
27 struct bpf_link *link;
28
29 link = bpf_map__attach_struct_ops(skel->maps.ddsp_vtimelocal_fail_ops);
30 SCX_FAIL_IF(!link, "Failed to attach struct_ops");
31
32 sleep(1);
33
34 SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR));
35 bpf_link__destroy(link);
36
37 return SCX_TEST_PASS;
38 }
39
cleanup(void * ctx)40 static void cleanup(void *ctx)
41 {
42 struct ddsp_vtimelocal_fail *skel = ctx;
43
44 ddsp_vtimelocal_fail__destroy(skel);
45 }
46
47 struct scx_test ddsp_vtimelocal_fail = {
48 .name = "ddsp_vtimelocal_fail",
49 .description = "Verify we gracefully fail, and fall back to using a "
50 "built-in DSQ, if we do a direct vtime dispatch to a "
51 "built-in DSQ from DSQ in ops.select_cpu()",
52 .setup = setup,
53 .run = run,
54 .cleanup = cleanup,
55 };
56 REGISTER_SCX_TEST(&ddsp_vtimelocal_fail)
57