test_ida.c 953 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * test_ida.c: Test the IDA API
  4. * Copyright (c) 2016-2018 Microsoft Corporation
  5. * Copyright (c) 2018 Oracle Corporation
  6. * Author: Matthew Wilcox <willy@infradead.org>
  7. */
  8. #include <linux/idr.h>
  9. #include <linux/module.h>
  10. static unsigned int tests_run;
  11. static unsigned int tests_passed;
  12. #ifdef __KERNEL__
  13. void ida_dump(struct ida *ida) { }
  14. #endif
  15. #define IDA_BUG_ON(ida, x) do { \
  16. tests_run++; \
  17. if (x) { \
  18. ida_dump(ida); \
  19. dump_stack(); \
  20. } else { \
  21. tests_passed++; \
  22. } \
  23. } while (0)
  24. static int ida_checks(void)
  25. {
  26. DEFINE_IDA(ida);
  27. IDA_BUG_ON(&ida, !ida_is_empty(&ida));
  28. printk("IDA: %u of %u tests passed\n", tests_passed, tests_run);
  29. return (tests_run != tests_passed) ? 0 : -EINVAL;
  30. }
  31. static void ida_exit(void)
  32. {
  33. }
  34. module_init(ida_checks);
  35. module_exit(ida_exit);
  36. MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
  37. MODULE_LICENSE("GPL");