Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 <sys/wait.h>
10#include <unistd.h>
11#include "select_cpu_vtime.bpf.skel.h"
12#include "scx_test.h"
13
14static enum scx_test_status setup(void **ctx)
15{
16 struct select_cpu_vtime *skel;
17
18 skel = select_cpu_vtime__open();
19 SCX_FAIL_IF(!skel, "Failed to open");
20 SCX_ENUM_INIT(skel);
21 SCX_FAIL_IF(select_cpu_vtime__load(skel), "Failed to load skel");
22
23 *ctx = skel;
24
25 return SCX_TEST_PASS;
26}
27
28static enum scx_test_status run(void *ctx)
29{
30 struct select_cpu_vtime *skel = ctx;
31 struct bpf_link *link;
32
33 SCX_ASSERT(!skel->bss->consumed);
34
35 link = bpf_map__attach_struct_ops(skel->maps.select_cpu_vtime_ops);
36 SCX_FAIL_IF(!link, "Failed to attach scheduler");
37
38 sleep(1);
39
40 SCX_ASSERT(skel->bss->consumed);
41
42 bpf_link__destroy(link);
43
44 return SCX_TEST_PASS;
45}
46
47static void cleanup(void *ctx)
48{
49 struct select_cpu_vtime *skel = ctx;
50
51 select_cpu_vtime__destroy(skel);
52}
53
54struct scx_test select_cpu_vtime = {
55 .name = "select_cpu_vtime",
56 .description = "Test doing direct vtime-dispatching from "
57 "ops.select_cpu(), to a non-built-in DSQ",
58 .setup = setup,
59 .run = run,
60 .cleanup = cleanup,
61};
62REGISTER_SCX_TEST(&select_cpu_vtime)