Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / sched_ext / exit.c
blob31bcd06e21cd3d1d12a255be31c510e9db358f60
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 */
6 #include <bpf/bpf.h>
7 #include <sched.h>
8 #include <scx/common.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
11 #include "exit.bpf.skel.h"
12 #include "scx_test.h"
14 #include "exit_test.h"
16 static enum scx_test_status run(void *ctx)
18 enum exit_test_case tc;
20 for (tc = 0; tc < NUM_EXITS; tc++) {
21 struct exit *skel;
22 struct bpf_link *link;
23 char buf[16];
25 skel = exit__open();
26 skel->rodata->exit_point = tc;
27 exit__load(skel);
28 link = bpf_map__attach_struct_ops(skel->maps.exit_ops);
29 if (!link) {
30 SCX_ERR("Failed to attach scheduler");
31 exit__destroy(skel);
32 return SCX_TEST_FAIL;
35 /* Assumes uei.kind is written last */
36 while (skel->data->uei.kind == EXIT_KIND(SCX_EXIT_NONE))
37 sched_yield();
39 SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG_BPF));
40 SCX_EQ(skel->data->uei.exit_code, tc);
41 sprintf(buf, "%d", tc);
42 SCX_ASSERT(!strcmp(skel->data->uei.msg, buf));
43 bpf_link__destroy(link);
44 exit__destroy(skel);
47 return SCX_TEST_PASS;
50 struct scx_test exit_test = {
51 .name = "exit",
52 .description = "Verify we can cleanly exit a scheduler in multiple places",
53 .run = run,
55 REGISTER_SCX_TEST(&exit_test)