minimal.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
  4. * Copyright (c) 2023 David Vernet <dvernet@meta.com>
  5. * Copyright (c) 2023 Tejun Heo <tj@kernel.org>
  6. */
  7. #include <bpf/bpf.h>
  8. #include <scx/common.h>
  9. #include <sys/wait.h>
  10. #include <unistd.h>
  11. #include "minimal.bpf.skel.h"
  12. #include "scx_test.h"
  13. static enum scx_test_status setup(void **ctx)
  14. {
  15. struct minimal *skel;
  16. skel = minimal__open();
  17. SCX_FAIL_IF(!skel, "Failed to open");
  18. SCX_ENUM_INIT(skel);
  19. SCX_FAIL_IF(minimal__load(skel), "Failed to load skel");
  20. *ctx = skel;
  21. return SCX_TEST_PASS;
  22. }
  23. static enum scx_test_status run(void *ctx)
  24. {
  25. struct minimal *skel = ctx;
  26. struct bpf_link *link;
  27. link = bpf_map__attach_struct_ops(skel->maps.minimal_ops);
  28. if (!link) {
  29. SCX_ERR("Failed to attach scheduler");
  30. return SCX_TEST_FAIL;
  31. }
  32. bpf_link__destroy(link);
  33. return SCX_TEST_PASS;
  34. }
  35. static void cleanup(void *ctx)
  36. {
  37. struct minimal *skel = ctx;
  38. minimal__destroy(skel);
  39. }
  40. struct scx_test minimal = {
  41. .name = "minimal",
  42. .description = "Verify we can load a fully minimal scheduler",
  43. .setup = setup,
  44. .run = run,
  45. .cleanup = cleanup,
  46. };
  47. REGISTER_SCX_TEST(&minimal)