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

Commit

Permalink
Merge pull request #210 from sched-ext/create_dsq_test
Browse files Browse the repository at this point in the history
scx: Add a selftest for creating and destroying a DSQ
  • Loading branch information
Byte-Lab authored May 22, 2024
2 parents dda9ab3 + 67841ae commit 98ece8c
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/sched_ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ endef
all_test_bpfprogs := $(foreach prog,$(wildcard *.bpf.c),$(INCLUDE_DIR)/$(patsubst %.c,%.skel.h,$(prog)))

auto-test-targets := \
create_dsq \
enq_last_no_enq_fails \
enq_select_cpu_fails \
ddsp_bogus_dsq_fail \
Expand Down
58 changes: 58 additions & 0 deletions tools/testing/selftests/sched_ext/create_dsq.bpf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Create and destroy DSQs in a loop.
*
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
* Copyright (c) 2024 David Vernet <[email protected]>
*/

#include <scx/common.bpf.h>

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

void BPF_STRUCT_OPS(create_dsq_exit_task, struct task_struct *p,
struct scx_exit_task_args *args)
{
scx_bpf_destroy_dsq(p->pid);
}

s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init_task, struct task_struct *p,
struct scx_init_task_args *args)
{
s32 err;

err = scx_bpf_create_dsq(p->pid, -1);
if (err)
scx_bpf_error("Failed to create DSQ for %s[%d]",
p->comm, p->pid);

return err;
}

s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init)
{
u32 i;
s32 err;

bpf_for(i, 0, 1024) {
err = scx_bpf_create_dsq(i, -1);
if (err) {
scx_bpf_error("Failed to create DSQ %d", i);
return 0;
}
}

bpf_for(i, 0, 1024) {
scx_bpf_destroy_dsq(i);
}

return 0;
}

SEC(".struct_ops.link")
struct sched_ext_ops create_dsq_ops = {
.init_task = create_dsq_init_task,
.exit_task = create_dsq_exit_task,
.init = create_dsq_init,
.name = "create_dsq",
};
57 changes: 57 additions & 0 deletions tools/testing/selftests/sched_ext/create_dsq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
* Copyright (c) 2024 David Vernet <[email protected]>
*/
#include <bpf/bpf.h>
#include <scx/common.h>
#include <sys/wait.h>
#include <unistd.h>
#include "create_dsq.bpf.skel.h"
#include "scx_test.h"

static enum scx_test_status setup(void **ctx)
{
struct create_dsq *skel;

skel = create_dsq__open_and_load();
if (!skel) {
SCX_ERR("Failed to open and load skel");
return SCX_TEST_FAIL;
}
*ctx = skel;

return SCX_TEST_PASS;
}

static enum scx_test_status run(void *ctx)
{
struct create_dsq *skel = ctx;
struct bpf_link *link;

link = bpf_map__attach_struct_ops(skel->maps.create_dsq_ops);
if (!link) {
SCX_ERR("Failed to attach scheduler");
return SCX_TEST_FAIL;
}

bpf_link__destroy(link);

return SCX_TEST_PASS;
}

static void cleanup(void *ctx)
{
struct create_dsq *skel = ctx;

create_dsq__destroy(skel);
}

struct scx_test create_dsq = {
.name = "create_dsq",
.description = "Create and destroy a dsq in a loop",
.setup = setup,
.run = run,
.cleanup = cleanup,
};
REGISTER_SCX_TEST(&create_dsq)

0 comments on commit 98ece8c

Please sign in to comment.