ddsp_vtimelocal_fail.c 1.4 KB

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