idr-test: Convert ida_check_nomem to new API
[linux-block.git] / lib / test_ida.c
CommitLineData
8ab8ba38
MW
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
9#include <linux/idr.h>
10#include <linux/module.h>
11
12static unsigned int tests_run;
13static unsigned int tests_passed;
14
15#ifdef __KERNEL__
16void ida_dump(struct ida *ida) { }
17#endif
18#define IDA_BUG_ON(ida, x) do { \
19 tests_run++; \
20 if (x) { \
21 ida_dump(ida); \
22 dump_stack(); \
23 } else { \
24 tests_passed++; \
25 } \
26} while (0)
27
28static int ida_checks(void)
29{
30 DEFINE_IDA(ida);
31
32 IDA_BUG_ON(&ida, !ida_is_empty(&ida));
33
34 printk("IDA: %u of %u tests passed\n", tests_passed, tests_run);
35 return (tests_run != tests_passed) ? 0 : -EINVAL;
36}
37
38static void ida_exit(void)
39{
40}
41
42module_init(ida_checks);
43module_exit(ida_exit);
44MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
45MODULE_LICENSE("GPL");