Merge tag 'afs-fixes-20200609' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowe...
[linux-block.git] / lib / test_bitops.c
CommitLineData
c348c163
JB
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 2020 Intel Corporation
4 */
5
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7
8#include <linux/init.h>
9#include <linux/module.h>
10#include <linux/printk.h>
11
12/* a tiny module only meant to test set/clear_bit */
13
14/* use an enum because thats the most common BITMAP usage */
15enum bitops_fun {
16 BITOPS_4 = 4,
17 BITOPS_7 = 7,
18 BITOPS_11 = 11,
19 BITOPS_31 = 31,
20 BITOPS_88 = 88,
21 BITOPS_LAST = 255,
22 BITOPS_LENGTH = 256
23};
24
25static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
26
27static int __init test_bitops_startup(void)
28{
29 pr_warn("Loaded test module\n");
30 set_bit(BITOPS_4, g_bitmap);
31 set_bit(BITOPS_7, g_bitmap);
32 set_bit(BITOPS_11, g_bitmap);
33 set_bit(BITOPS_31, g_bitmap);
34 set_bit(BITOPS_88, g_bitmap);
35 return 0;
36}
37
38static void __exit test_bitops_unstartup(void)
39{
40 int bit_set;
41
42 clear_bit(BITOPS_4, g_bitmap);
43 clear_bit(BITOPS_7, g_bitmap);
44 clear_bit(BITOPS_11, g_bitmap);
45 clear_bit(BITOPS_31, g_bitmap);
46 clear_bit(BITOPS_88, g_bitmap);
47
48 bit_set = find_first_bit(g_bitmap, BITOPS_LAST);
49 if (bit_set != BITOPS_LAST)
50 pr_err("ERROR: FOUND SET BIT %d\n", bit_set);
51
52 pr_warn("Unloaded test module\n");
53}
54
55module_init(test_bitops_startup);
56module_exit(test_bitops_unstartup);
57
58MODULE_AUTHOR("Jesse Brandeburg <jesse.brandeburg@intel.com>");
59MODULE_LICENSE("GPL");
60MODULE_DESCRIPTION("Bit testing module");