1*a5db7817SDavid Vernet /* SPDX-License-Identifier: GPL-2.0 */ 2*a5db7817SDavid Vernet /* 3*a5db7817SDavid Vernet * Copyright (c) 2023 Meta Platforms, Inc. and affiliates. 4*a5db7817SDavid Vernet * Copyright (c) 2023 David Vernet <dvernet@meta.com> 5*a5db7817SDavid Vernet * Copyright (c) 2023 Tejun Heo <tj@kernel.org> 6*a5db7817SDavid Vernet */ 7*a5db7817SDavid Vernet #include <bpf/bpf.h> 8*a5db7817SDavid Vernet #include <scx/common.h> 9*a5db7817SDavid Vernet #include <sys/wait.h> 10*a5db7817SDavid Vernet #include <unistd.h> 11*a5db7817SDavid Vernet #include "enq_select_cpu_fails.bpf.skel.h" 12*a5db7817SDavid Vernet #include "scx_test.h" 13*a5db7817SDavid Vernet setup(void ** ctx)14*a5db7817SDavid Vernetstatic enum scx_test_status setup(void **ctx) 15*a5db7817SDavid Vernet { 16*a5db7817SDavid Vernet struct enq_select_cpu_fails *skel; 17*a5db7817SDavid Vernet 18*a5db7817SDavid Vernet skel = enq_select_cpu_fails__open_and_load(); 19*a5db7817SDavid Vernet if (!skel) { 20*a5db7817SDavid Vernet SCX_ERR("Failed to open and load skel"); 21*a5db7817SDavid Vernet return SCX_TEST_FAIL; 22*a5db7817SDavid Vernet } 23*a5db7817SDavid Vernet *ctx = skel; 24*a5db7817SDavid Vernet 25*a5db7817SDavid Vernet return SCX_TEST_PASS; 26*a5db7817SDavid Vernet } 27*a5db7817SDavid Vernet run(void * ctx)28*a5db7817SDavid Vernetstatic enum scx_test_status run(void *ctx) 29*a5db7817SDavid Vernet { 30*a5db7817SDavid Vernet struct enq_select_cpu_fails *skel = ctx; 31*a5db7817SDavid Vernet struct bpf_link *link; 32*a5db7817SDavid Vernet 33*a5db7817SDavid Vernet link = bpf_map__attach_struct_ops(skel->maps.enq_select_cpu_fails_ops); 34*a5db7817SDavid Vernet if (!link) { 35*a5db7817SDavid Vernet SCX_ERR("Failed to attach scheduler"); 36*a5db7817SDavid Vernet return SCX_TEST_FAIL; 37*a5db7817SDavid Vernet } 38*a5db7817SDavid Vernet 39*a5db7817SDavid Vernet sleep(1); 40*a5db7817SDavid Vernet 41*a5db7817SDavid Vernet bpf_link__destroy(link); 42*a5db7817SDavid Vernet 43*a5db7817SDavid Vernet return SCX_TEST_PASS; 44*a5db7817SDavid Vernet } 45*a5db7817SDavid Vernet cleanup(void * ctx)46*a5db7817SDavid Vernetstatic void cleanup(void *ctx) 47*a5db7817SDavid Vernet { 48*a5db7817SDavid Vernet struct enq_select_cpu_fails *skel = ctx; 49*a5db7817SDavid Vernet 50*a5db7817SDavid Vernet enq_select_cpu_fails__destroy(skel); 51*a5db7817SDavid Vernet } 52*a5db7817SDavid Vernet 53*a5db7817SDavid Vernet struct scx_test enq_select_cpu_fails = { 54*a5db7817SDavid Vernet .name = "enq_select_cpu_fails", 55*a5db7817SDavid Vernet .description = "Verify we fail to call scx_bpf_select_cpu_dfl() " 56*a5db7817SDavid Vernet "from ops.enqueue()", 57*a5db7817SDavid Vernet .setup = setup, 58*a5db7817SDavid Vernet .run = run, 59*a5db7817SDavid Vernet .cleanup = cleanup, 60*a5db7817SDavid Vernet }; 61*a5db7817SDavid Vernet REGISTER_SCX_TEST(&enq_select_cpu_fails) 62