test_example.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
  4. * Copyright (c) 2024 Tejun Heo <tj@kernel.org>
  5. * Copyright (c) 2024 David Vernet <dvernet@meta.com>
  6. */
  7. #include <bpf/bpf.h>
  8. #include <scx/common.h>
  9. #include "scx_test.h"
  10. static bool setup_called = false;
  11. static bool run_called = false;
  12. static bool cleanup_called = false;
  13. static int context = 10;
  14. static enum scx_test_status setup(void **ctx)
  15. {
  16. setup_called = true;
  17. *ctx = &context;
  18. return SCX_TEST_PASS;
  19. }
  20. static enum scx_test_status run(void *ctx)
  21. {
  22. int *arg = ctx;
  23. SCX_ASSERT(setup_called);
  24. SCX_ASSERT(!run_called && !cleanup_called);
  25. SCX_EQ(*arg, context);
  26. run_called = true;
  27. return SCX_TEST_PASS;
  28. }
  29. static void cleanup (void *ctx)
  30. {
  31. SCX_BUG_ON(!run_called || cleanup_called, "Wrong callbacks invoked");
  32. }
  33. struct scx_test example = {
  34. .name = "example",
  35. .description = "Validate the basic function of the test suite itself",
  36. .setup = setup,
  37. .run = run,
  38. .cleanup = cleanup,
  39. };
  40. REGISTER_SCX_TEST(&example)