Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/test_fprobe: Add a test case for nr_maxactive

Add a test case for nr_maxactive. If the number of active
functions is more than nr_maxactive, it must be skipped.

Link: https://lkml.kernel.org/r/167526698856.433354.4430007340787176666.stgit@mhiramat.roam.corp.google.com

Cc: Florent Revest <revest@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Masami Hiramatsu (Google) and committed by
Steven Rostedt (Google)
7e7ef1bf 59a7a298

+42
+42
lib/test_fprobe.c
··· 17 17 /* Use indirect calls to avoid inlining the target functions */ 18 18 static u32 (*target)(u32 value); 19 19 static u32 (*target2)(u32 value); 20 + static u32 (*target_nest)(u32 value, u32 (*nest)(u32)); 20 21 static unsigned long target_ip; 21 22 static unsigned long target2_ip; 23 + static unsigned long target_nest_ip; 22 24 23 25 static noinline u32 fprobe_selftest_target(u32 value) 24 26 { ··· 30 28 static noinline u32 fprobe_selftest_target2(u32 value) 31 29 { 32 30 return (value / div_factor) + 1; 31 + } 32 + 33 + static noinline u32 fprobe_selftest_nest_target(u32 value, u32 (*nest)(u32)) 34 + { 35 + return nest(value + 2); 33 36 } 34 37 35 38 static notrace void fp_entry_handler(struct fprobe *fp, unsigned long ip, ··· 72 65 KUNIT_EXPECT_EQ(current_test, *(u32 *)data, entry_val); 73 66 } else 74 67 KUNIT_EXPECT_NULL(current_test, data); 68 + } 69 + 70 + static notrace void nest_entry_handler(struct fprobe *fp, unsigned long ip, 71 + struct pt_regs *regs, void *data) 72 + { 73 + KUNIT_EXPECT_FALSE(current_test, preemptible()); 74 + } 75 + 76 + static notrace void nest_exit_handler(struct fprobe *fp, unsigned long ip, 77 + struct pt_regs *regs, void *data) 78 + { 79 + KUNIT_EXPECT_FALSE(current_test, preemptible()); 80 + KUNIT_EXPECT_EQ(current_test, ip, target_nest_ip); 75 81 } 76 82 77 83 /* Test entry only (no rethook) */ ··· 183 163 KUNIT_EXPECT_EQ(test, 0, unregister_fprobe(&fp)); 184 164 } 185 165 166 + /* Test nr_maxactive */ 167 + static void test_fprobe_nest(struct kunit *test) 168 + { 169 + static const char *syms[] = {"fprobe_selftest_target", "fprobe_selftest_nest_target"}; 170 + struct fprobe fp = { 171 + .entry_handler = nest_entry_handler, 172 + .exit_handler = nest_exit_handler, 173 + .nr_maxactive = 1, 174 + }; 175 + 176 + current_test = test; 177 + KUNIT_EXPECT_EQ(test, 0, register_fprobe_syms(&fp, syms, 2)); 178 + 179 + target_nest(rand1, target); 180 + KUNIT_EXPECT_EQ(test, 1, fp.nmissed); 181 + 182 + KUNIT_EXPECT_EQ(test, 0, unregister_fprobe(&fp)); 183 + } 184 + 186 185 static unsigned long get_ftrace_location(void *func) 187 186 { 188 187 unsigned long size, addr = (unsigned long)func; ··· 217 178 rand1 = get_random_u32_above(div_factor); 218 179 target = fprobe_selftest_target; 219 180 target2 = fprobe_selftest_target2; 181 + target_nest = fprobe_selftest_nest_target; 220 182 target_ip = get_ftrace_location(target); 221 183 target2_ip = get_ftrace_location(target2); 184 + target_nest_ip = get_ftrace_location(target_nest); 222 185 223 186 return 0; 224 187 } ··· 230 189 KUNIT_CASE(test_fprobe), 231 190 KUNIT_CASE(test_fprobe_syms), 232 191 KUNIT_CASE(test_fprobe_data), 192 + KUNIT_CASE(test_fprobe_nest), 233 193 {} 234 194 }; 235 195