From ad32d9aa2904b1d6a04303e39fb755b4cfb620c9 Mon Sep 17 00:00:00 2001 From: compudj Date: Sat, 16 Sep 2006 17:54:33 +0000 Subject: [PATCH] update tests git-svn-id: http://ltt.polymtl.ca/svn@2117 04897980-b3bd-0310-b5e0-8ef037075253 --- tests/kernel/Makefile | 16 ++++---- tests/kernel/test-kprobes.c | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 tests/kernel/test-kprobes.c diff --git a/tests/kernel/Makefile b/tests/kernel/Makefile index c3b79bce..bd2ddc49 100644 --- a/tests/kernel/Makefile +++ b/tests/kernel/Makefile @@ -8,13 +8,15 @@ ifneq ($(CONFIG_LTT),) # obj-m += test-instrument-size-big.o # obj-m += test-printk-effect.o endif - obj-m += test-cmpxchg.o - obj-m += test-cmpxchg-nolock.o - obj-m += test-spinlock.o - obj-m += test-inc.o - obj-m += test-inc-nolock.o - obj-m += test-kmalloc.o - obj-m += test-irqdis.o +# obj-m += test-cmpxchg.o +# obj-m += test-cmpxchg-nolock.o +# obj-m += test-spinlock.o +# obj-m += test-inc.o +# obj-m += test-inc-nolock.o +# obj-m += test-kmalloc.o +# obj-m += test-irqdis.o +# obj-m += test-int3.o + obj-m += test-kprobes.o else KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) diff --git a/tests/kernel/test-kprobes.c b/tests/kernel/test-kprobes.c new file mode 100644 index 00000000..d1b00ef1 --- /dev/null +++ b/tests/kernel/test-kprobes.c @@ -0,0 +1,73 @@ +/* test-kprobes.c + * + * kprobe timing test. + */ + +#include +#include +#include +#include +#include + + +/*For each probe you need to allocate a kprobe structure*/ +static struct kprobe kp; + +/*kprobe pre_handler: called just before the probed instruction is executed*/ +int handler_pre(struct kprobe *p, struct pt_regs *regs) +{ + //printk("pre_handler: p->addr=0x%p, eip=%lx, eflags=0x%lx\n", + // p->addr, regs->eip, regs->eflags); + //dump_stack(); + return 0; +} + +/*kprobe post_handler: called after the probed instruction is executed*/ +void handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags) +{ + //printk("post_handler: p->addr=0x%p, eflags=0x%lx\n", + // p->addr, regs->eflags); +} + +/* fault_handler: this is called if an exception is generated for any + * instruction within the pre- or post-handler, or when Kprobes + * single-steps the probed instruction. + */ +int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr) +{ + //printk("fault_handler: p->addr=0x%p, trap #%dn", + // p->addr, trapnr); + /* Return 0 because we don't handle the fault. */ + return 0; +} + +int init_module(void) +{ + int ret; + kp.pre_handler = handler_pre; + kp.post_handler = handler_post; + kp.fault_handler = handler_fault; + kp.addr = (kprobe_opcode_t*) kallsyms_lookup_name("ltt_relay_reserve_slot"); + /* register the kprobe now */ + if (!kp.addr) { + printk("Couldn't find %s to plant kprobe\n", "ltt_relay_reserve_slot"); + return -1; + } + if ((ret = register_kprobe(&kp) < 0)) { + printk("register_kprobe failed, returned %d\n", ret); + return -1; + } + printk("kprobe registered\n"); + return 0; +} + +void cleanup_module(void) +{ + unregister_kprobe(&kp); + printk("kprobe unregistered\n"); +} + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Mathieu Desnoyers"); +MODULE_DESCRIPTION("Linux Trace Toolkit Test"); + -- 2.34.1