Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Fix up some selftests #173

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/testing/selftests/sched_ext/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ CONFIG_SCHED_CLASS_EXT=y
CONFIG_CGROUPS=y
CONFIG_CGROUP_SCHED=y
CONFIG_EXT_GROUP_SCHED=y
CONFIG_BPF=y
CONFIG_BPF_SYSCALL=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_BTF=y
2 changes: 1 addition & 1 deletion tools/testing/selftests/sched_ext/ddsp_bogus_dsq_fail.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static enum scx_test_status run(void *ctx)

sleep(1);

SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR);
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR));
bpf_link__destroy(link);

return SCX_TEST_PASS;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/sched_ext/ddsp_vtimelocal_fail.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static enum scx_test_status run(void *ctx)

sleep(1);

SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR);
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR));
bpf_link__destroy(link);

return SCX_TEST_PASS;
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/sched_ext/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ static enum scx_test_status run(void *ctx)
}

/* Assumes uei.kind is written last */
while (skel->data->uei.kind == SCX_EXIT_NONE)
while (skel->data->uei.kind == EXIT_KIND(SCX_EXIT_NONE))
sched_yield();

SCX_EQ(skel->data->uei.kind, SCX_EXIT_UNREG_BPF);
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG_BPF));
SCX_EQ(skel->data->uei.exit_code, tc);
sprintf(buf, "%d", tc);
SCX_ASSERT(!strcmp(skel->data->uei.msg, buf));
Expand Down
15 changes: 2 additions & 13 deletions tools/testing/selftests/sched_ext/minimal.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* A completely minimal scheduler.
*
* This scheduler defines the absolute minimal set of struct sched_ext_ops
* fields: its name (and until a bug is fixed in libbpf, also an ops.running()
* callback). It should _not_ fail to be loaded, and can be used to exercise
* the default scheduling paths in ext.c.
* fields: its name. It should _not_ fail to be loaded, and can be used to
* exercise the default scheduling paths in ext.c.
*
* Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
* Copyright (c) 2023 David Vernet <[email protected]>
Expand All @@ -16,17 +15,7 @@

char _license[] SEC("license") = "GPL";

void BPF_STRUCT_OPS(minimal_running, struct task_struct *p)
{}

SEC(".struct_ops.link")
struct sched_ext_ops minimal_ops = {
/*
* It shouldn't be necessary to define this minimal_running op, but
* libbpf currently expects that a struct_ops map will always have at
* least one struct_ops prog when loading. Until that issue is fixed,
* let's also define a minimal prog so that we can load and test.
*/
.enable = minimal_running,
.name = "minimal",
};
6 changes: 3 additions & 3 deletions tools/testing/selftests/sched_ext/prog_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ static enum scx_test_status run(void *ctx)
return SCX_TEST_FAIL;
}

//err = bpf_prog_test_run_opts(prog_fd, &topts);
err = bpf_prog_test_run_opts(prog_fd, &topts);
SCX_EQ(err, 0);

/* Assumes uei.kind is written last */
while (skel->data->uei.kind == SCX_EXIT_NONE)
while (skel->data->uei.kind == EXIT_KIND(SCX_EXIT_NONE))
sched_yield();

SCX_EQ(skel->data->uei.kind, SCX_EXIT_UNREG_BPF);
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG_BPF));
SCX_EQ(skel->data->uei.exit_code, 0xdeadbeef);
close(prog_fd);
bpf_link__destroy(link);
Expand Down
15 changes: 2 additions & 13 deletions tools/testing/selftests/sched_ext/scx_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,15 @@

#include <errno.h>
#include <scx/common.h>
#include <scx/compat.h>

enum scx_test_status {
SCX_TEST_PASS = 0,
SCX_TEST_SKIP,
SCX_TEST_FAIL,
};

/* Copied from include/linux/sched/ext.h */
enum scx_test_exit_kind {
SCX_EXIT_NONE,
SCX_EXIT_DONE,

SCX_EXIT_UNREG = 64, /* User-space initiated unregistration */
SCX_EXIT_UNREG_BPF, /* BPF-initiated unregistration */
SCX_EXIT_SYSRQ, /* requested by 'S' sysrq */

SCX_EXIT_ERROR = 1024, /* runtime error, error msg contains details */
SCX_EXIT_ERROR_BPF, /* ERROR but triggered through scx_bpf_error() */
SCX_EXIT_ERROR_STALL, /* watchdog detected stalled runnable tasks */
};
#define EXIT_KIND(__ent) __COMPAT_ENUM_OR_ZERO("scx_exit_kind", #__ent)

struct scx_test {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static enum scx_test_status run(void *ctx)

sleep(1);

SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR);
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR));
bpf_link__destroy(link);

return SCX_TEST_PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static enum scx_test_status run(void *ctx)

sleep(1);

SCX_EQ(skel->data->uei.kind, SCX_EXIT_ERROR);
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR));
bpf_link__destroy(link);

return SCX_TEST_PASS;
Expand Down