create_dsq.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. */
  6. #include <bpf/bpf.h>
  7. #include <scx/common.h>
  8. #include <sys/wait.h>
  9. #include <unistd.h>
  10. #include "create_dsq.bpf.skel.h"
  11. #include "scx_test.h"
  12. static enum scx_test_status setup(void **ctx)
  13. {
  14. struct create_dsq *skel;
  15. skel = create_dsq__open();
  16. SCX_FAIL_IF(!skel, "Failed to open");
  17. SCX_ENUM_INIT(skel);
  18. SCX_FAIL_IF(create_dsq__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 create_dsq *skel = ctx;
  25. struct bpf_link *link;
  26. link = bpf_map__attach_struct_ops(skel->maps.create_dsq_ops);
  27. if (!link) {
  28. SCX_ERR("Failed to attach scheduler");
  29. return SCX_TEST_FAIL;
  30. }
  31. bpf_link__destroy(link);
  32. return SCX_TEST_PASS;
  33. }
  34. static void cleanup(void *ctx)
  35. {
  36. struct create_dsq *skel = ctx;
  37. create_dsq__destroy(skel);
  38. }
  39. struct scx_test create_dsq = {
  40. .name = "create_dsq",
  41. .description = "Create and destroy a dsq in a loop",
  42. .setup = setup,
  43. .run = run,
  44. .cleanup = cleanup,
  45. };
  46. REGISTER_SCX_TEST(&create_dsq)