1 // SPDX-License-Identifier: GPL-2.0-only
3 * Kernel module for testing dynamic_debug
6 * Jim Cromie <jim.cromie@gmail.com>
9 #define pr_fmt(fmt) "test_dd: " fmt
11 #include <linux/module.h>
13 /* run tests by reading or writing sysfs node: do_prints */
15 static void do_prints(void); /* device under test */
16 static int param_set_do_prints(const char *instr
, const struct kernel_param
*kp
)
21 static int param_get_do_prints(char *buffer
, const struct kernel_param
*kp
)
24 return scnprintf(buffer
, PAGE_SIZE
, "did do_prints\n");
26 static const struct kernel_param_ops param_ops_do_prints
= {
27 .set
= param_set_do_prints
,
28 .get
= param_get_do_prints
,
30 module_param_cb(do_prints
, ¶m_ops_do_prints
, NULL
, 0600);
33 * Using the CLASSMAP api:
34 * - classmaps must have corresponding enum
35 * - enum symbols must match/correlate with class-name strings in the map.
36 * - base must equal enum's 1st value
37 * - multiple maps must set their base to share the 0-30 class_id space !!
38 * (build-bug-on tips welcome)
40 * - tie together sysname, mapname, bitsname, flagsname
42 #define DD_SYS_WRAP(_model, _flags) \
43 static unsigned long bits_##_model; \
44 static struct ddebug_class_param _flags##_model = { \
45 .bits = &bits_##_model, \
47 .map = &map_##_model, \
49 module_param_cb(_flags##_##_model, ¶m_ops_dyndbg_classes, &_flags##_model, 0600)
51 /* numeric input, independent bits */
52 enum cat_disjoint_bits
{
63 DECLARE_DYNDBG_CLASSMAP(map_disjoint_bits
, DD_CLASS_TYPE_DISJOINT_BITS
, 0,
74 DD_SYS_WRAP(disjoint_bits
, p
);
75 DD_SYS_WRAP(disjoint_bits
, T
);
77 /* symbolic input, independent bits */
78 enum cat_disjoint_names
{ LOW
= 11, MID
, HI
};
79 DECLARE_DYNDBG_CLASSMAP(map_disjoint_names
, DD_CLASS_TYPE_DISJOINT_NAMES
, 10,
81 DD_SYS_WRAP(disjoint_names
, p
);
82 DD_SYS_WRAP(disjoint_names
, T
);
84 /* numeric verbosity, V2 > V1 related */
85 enum cat_level_num
{ V0
= 14, V1
, V2
, V3
, V4
, V5
, V6
, V7
};
86 DECLARE_DYNDBG_CLASSMAP(map_level_num
, DD_CLASS_TYPE_LEVEL_NUM
, 14,
87 "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
88 DD_SYS_WRAP(level_num
, p
);
89 DD_SYS_WRAP(level_num
, T
);
91 /* symbolic verbosity */
92 enum cat_level_names
{ L0
= 22, L1
, L2
, L3
, L4
, L5
, L6
, L7
};
93 DECLARE_DYNDBG_CLASSMAP(map_level_names
, DD_CLASS_TYPE_LEVEL_NAMES
, 22,
94 "L0", "L1", "L2", "L3", "L4", "L5", "L6", "L7");
95 DD_SYS_WRAP(level_names
, p
);
96 DD_SYS_WRAP(level_names
, T
);
98 /* stand-in for all pr_debug etc */
99 #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
101 static void do_cats(void)
103 pr_debug("doing categories\n");
121 static void do_levels(void)
123 pr_debug("doing levels\n");
142 static void do_prints(void)
148 static int __init
test_dynamic_debug_init(void)
150 pr_debug("init start\n");
152 pr_debug("init done\n");
156 static void __exit
test_dynamic_debug_exit(void)
158 pr_debug("exited\n");
161 module_init(test_dynamic_debug_init
);
162 module_exit(test_dynamic_debug_exit
);
164 MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
165 MODULE_DESCRIPTION("Kernel module for testing dynamic_debug");
166 MODULE_LICENSE("GPL");