1*a5db7817SDavid Vernet /* SPDX-License-Identifier: GPL-2.0 */
2*a5db7817SDavid Vernet /*
3*a5db7817SDavid Vernet * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
4*a5db7817SDavid Vernet * Copyright (c) 2024 David Vernet <dvernet@meta.com>
5*a5db7817SDavid Vernet */
6*a5db7817SDavid Vernet #include <bpf/bpf.h>
7*a5db7817SDavid Vernet #include <scx/common.h>
8*a5db7817SDavid Vernet #include <unistd.h>
9*a5db7817SDavid Vernet #include "dsp_local_on.bpf.skel.h"
10*a5db7817SDavid Vernet #include "scx_test.h"
11*a5db7817SDavid Vernet
setup(void ** ctx)12*a5db7817SDavid Vernet static enum scx_test_status setup(void **ctx)
13*a5db7817SDavid Vernet {
14*a5db7817SDavid Vernet struct dsp_local_on *skel;
15*a5db7817SDavid Vernet
16*a5db7817SDavid Vernet skel = dsp_local_on__open();
17*a5db7817SDavid Vernet SCX_FAIL_IF(!skel, "Failed to open");
18*a5db7817SDavid Vernet
19*a5db7817SDavid Vernet skel->rodata->nr_cpus = libbpf_num_possible_cpus();
20*a5db7817SDavid Vernet SCX_FAIL_IF(dsp_local_on__load(skel), "Failed to load skel");
21*a5db7817SDavid Vernet *ctx = skel;
22*a5db7817SDavid Vernet
23*a5db7817SDavid Vernet return SCX_TEST_PASS;
24*a5db7817SDavid Vernet }
25*a5db7817SDavid Vernet
run(void * ctx)26*a5db7817SDavid Vernet static enum scx_test_status run(void *ctx)
27*a5db7817SDavid Vernet {
28*a5db7817SDavid Vernet struct dsp_local_on *skel = ctx;
29*a5db7817SDavid Vernet struct bpf_link *link;
30*a5db7817SDavid Vernet
31*a5db7817SDavid Vernet link = bpf_map__attach_struct_ops(skel->maps.dsp_local_on_ops);
32*a5db7817SDavid Vernet SCX_FAIL_IF(!link, "Failed to attach struct_ops");
33*a5db7817SDavid Vernet
34*a5db7817SDavid Vernet /* Just sleeping is fine, plenty of scheduling events happening */
35*a5db7817SDavid Vernet sleep(1);
36*a5db7817SDavid Vernet
37*a5db7817SDavid Vernet SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR));
38*a5db7817SDavid Vernet bpf_link__destroy(link);
39*a5db7817SDavid Vernet
40*a5db7817SDavid Vernet return SCX_TEST_PASS;
41*a5db7817SDavid Vernet }
42*a5db7817SDavid Vernet
cleanup(void * ctx)43*a5db7817SDavid Vernet static void cleanup(void *ctx)
44*a5db7817SDavid Vernet {
45*a5db7817SDavid Vernet struct dsp_local_on *skel = ctx;
46*a5db7817SDavid Vernet
47*a5db7817SDavid Vernet dsp_local_on__destroy(skel);
48*a5db7817SDavid Vernet }
49*a5db7817SDavid Vernet
50*a5db7817SDavid Vernet struct scx_test dsp_local_on = {
51*a5db7817SDavid Vernet .name = "dsp_local_on",
52*a5db7817SDavid Vernet .description = "Verify we can directly dispatch tasks to a local DSQs "
53*a5db7817SDavid Vernet "from osp.dispatch()",
54*a5db7817SDavid Vernet .setup = setup,
55*a5db7817SDavid Vernet .run = run,
56*a5db7817SDavid Vernet .cleanup = cleanup,
57*a5db7817SDavid Vernet };
58*a5db7817SDavid Vernet REGISTER_SCX_TEST(&dsp_local_on)
59