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 <unistd.h> 10 #include "ddsp_vtimelocal_fail.bpf.skel.h" 11 #include "scx_test.h" 12 13 static enum scx_test_status setup(void **ctx) 14 { 15 struct ddsp_vtimelocal_fail *skel; 16 17 skel = ddsp_vtimelocal_fail__open(); 18 SCX_FAIL_IF(!skel, "Failed to open"); 19 SCX_ENUM_INIT(skel); 20 SCX_FAIL_IF(ddsp_vtimelocal_fail__load(skel), "Failed to load skel"); 21 22 *ctx = skel; 23 24 return SCX_TEST_PASS; 25 } 26 27 static enum scx_test_status run(void *ctx) 28 { 29 struct ddsp_vtimelocal_fail *skel = ctx; 30 struct bpf_link *link; 31 32 link = bpf_map__attach_struct_ops(skel->maps.ddsp_vtimelocal_fail_ops); 33 SCX_FAIL_IF(!link, "Failed to attach struct_ops"); 34 35 sleep(1); 36 37 SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR)); 38 bpf_link__destroy(link); 39 40 return SCX_TEST_PASS; 41 } 42 43 static void cleanup(void *ctx) 44 { 45 struct ddsp_vtimelocal_fail *skel = ctx; 46 47 ddsp_vtimelocal_fail__destroy(skel); 48 } 49 50 struct scx_test ddsp_vtimelocal_fail = { 51 .name = "ddsp_vtimelocal_fail", 52 .description = "Verify we gracefully fail, and fall back to using a " 53 "built-in DSQ, if we do a direct vtime dispatch to a " 54 "built-in DSQ from DSQ in ops.select_cpu()", 55 .setup = setup, 56 .run = run, 57 .cleanup = cleanup, 58 }; 59 REGISTER_SCX_TEST(&ddsp_vtimelocal_fail) 60