update tests
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 16 Sep 2006 17:54:33 +0000 (17:54 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 16 Sep 2006 17:54:33 +0000 (17:54 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@2117 04897980-b3bd-0310-b5e0-8ef037075253

tests/kernel/Makefile
tests/kernel/test-kprobes.c [new file with mode: 0644]

index c3b79bce0b9cd94337445a4d2ce40eb1cafc31e1..bd2ddc49f9c8d76a8fd2c81632969bc052e0c41c 100644 (file)
@@ -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 (file)
index 0000000..d1b00ef
--- /dev/null
@@ -0,0 +1,73 @@
+/* test-kprobes.c
+ *
+ * kprobe timing test.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/kprobes.h>
+#include <linux/kallsyms.h>
+#include <linux/sched.h>
+
+
+/*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");
+
This page took 0.026872 seconds and 4 git commands to generate.