add tests
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 28 Mar 2009 23:49:48 +0000 (23:49 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 28 Mar 2009 23:49:48 +0000 (23:49 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@3359 04897980-b3bd-0310-b5e0-8ef037075253

trunk/tests/kernel/genkprobe.c [new file with mode: 0644]
trunk/tests/kernel/test-lttng-tp.c [new file with mode: 0644]
trunk/tests/kernel/test-trace.c [new file with mode: 0644]
trunk/tests/kernel/tp-test.h [new file with mode: 0644]

diff --git a/trunk/tests/kernel/genkprobe.c b/trunk/tests/kernel/genkprobe.c
new file mode 100644 (file)
index 0000000..5a9a167
--- /dev/null
@@ -0,0 +1,53 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/kprobes.h>
+
+MODULE_LICENSE("GPL");
+
+static int kph(struct kprobe *kp, struct pt_regs *regs)
+{
+       return 0;
+}
+static int kpfh(struct kprobe *kp, struct pt_regs *regs, int nr)
+{
+  printk("fault occurred on kprobes at %p(@%lx:%d)\n", kp->addr, regs->ip, nr);
+       return 0;
+}
+static struct kprobe kp[] = {
+[0]={.pre_handler=kph, .fault_handler=kpfh, .symbol_name="sys_accept"},
+[1]={.pre_handler=kph, .fault_handler=kpfh, .symbol_name="sys_access"},
+[2]={.pre_handler=kph, .fault_handler=kpfh, .symbol_name="sys_acct"},
+[3]={.pre_handler=kph, .fault_handler=kpfh, .symbol_name="sys_add_key"},
+[4]={.pre_handler=kph, .fault_handler=kpfh, .symbol_name="sys_adjtimex"},
+[5]={.pre_handler=kph, .fault_handler=kpfh, .symbol_name="sys_alarm"},
+[6]={.pre_handler=kph, .fault_handler=kpfh, .symbol_name="sys_bdflush"},
+};
+#define NRPB 7
+
+static struct kprobe *kps[NRPB];
+
+int __gen_init(void)
+{
+       int ret, i;
+       for (i=0;i<NRPB;i++)
+               kps[i]=&kp[i];
+       printk("registering...");
+       ret = register_kprobes(kps, NRPB);
+       if (ret) {
+               printk("failed to register kprobes\n");
+               return ret;
+       }
+       printk("registered\n");
+       return 0;
+}
+
+void __gen_exit(void)
+{
+       printk("unregistering...");
+       unregister_kprobes(kps, NRPB);
+       printk("unregistered\n");
+}
+
+module_init(__gen_init);
+module_exit(__gen_exit);
diff --git a/trunk/tests/kernel/test-lttng-tp.c b/trunk/tests/kernel/test-lttng-tp.c
new file mode 100644 (file)
index 0000000..c7c8baf
--- /dev/null
@@ -0,0 +1,108 @@
+/* test-lttng-tp.c
+ *
+ * Test lttng event write.
+ */
+
+#include <linux/jiffies.h>
+#include <linux/compiler.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/math64.h>
+#include <linux/proc_fs.h>
+#include "tp-test.h"
+#include <asm/timex.h>
+#include <asm/system.h>
+
+#define NR_LOOPS 20000
+
+DEFINE_TRACE(kernel_test);
+
+struct proc_dir_entry *pentry = NULL;
+
+int test_val;
+
+static void do_testbaseline(void)
+{
+       unsigned long flags;
+       unsigned int i;
+       cycles_t time1, time2, time;
+       u32 rem;
+
+       local_irq_save(flags);
+       preempt_disable();
+       time1 = get_cycles();
+       for (i = 0; i < NR_LOOPS; i++) {
+               asm volatile ("");
+       }
+       time2 = get_cycles();
+       local_irq_restore(flags);
+       preempt_enable();
+       time = time2 - time1;
+
+       printk(KERN_ALERT "test results: time for baseline\n");
+       printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
+       printk(KERN_ALERT "total time: %llu\n", time);
+       time = div_u64_rem(time, NR_LOOPS, &rem);
+       printk(KERN_ALERT "-> baseline takes %llu cycles\n", time);
+       printk(KERN_ALERT "test end\n");
+}
+
+static void do_test_tp(void)
+{
+       unsigned long flags;
+       unsigned int i;
+       cycles_t time1, time2, time;
+       u32 rem;
+
+       local_irq_save(flags);
+       preempt_disable();
+       time1 = get_cycles();
+       for (i = 0; i < NR_LOOPS; i++) {
+               trace_kernel_test((void *)999, (void *)10);
+       }
+       time2 = get_cycles();
+       local_irq_restore(flags);
+       preempt_enable();
+       time = time2 - time1;
+
+       printk(KERN_ALERT "test results: time for one probe\n");
+       printk(KERN_ALERT "number of loops: %d\n", NR_LOOPS);
+       printk(KERN_ALERT "total time: %llu\n", time);
+       time = div_u64_rem(time, NR_LOOPS, &rem);
+       printk(KERN_ALERT "-> one probe takes %llu cycles\n", time);
+       printk(KERN_ALERT "test end\n");
+}
+
+static int my_open(struct inode *inode, struct file *file)
+{
+       do_testbaseline();
+       do_test_tp();
+
+       return -EPERM;
+}
+
+static const struct file_operations my_operations = {
+       .open = my_open,
+};
+
+static int ltt_test_init(void)
+{
+       printk(KERN_ALERT "test init\n");
+       pentry = create_proc_entry("testltt", 0444, NULL);
+       if (pentry)
+               pentry->proc_fops = &my_operations;
+       return 0;
+}
+
+static void ltt_test_exit(void)
+{
+       printk(KERN_ALERT "test exit\n");
+       remove_proc_entry("testltt", NULL);
+}
+
+module_init(ltt_test_init)
+module_exit(ltt_test_exit)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("TP test");
diff --git a/trunk/tests/kernel/test-trace.c b/trunk/tests/kernel/test-trace.c
new file mode 100644 (file)
index 0000000..3b3c26e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * test-trace.c
+ *
+ * Test tracepoint probes.
+ */
+
+#include <linux/module.h>
+#include "tp-test.h"
+#include <linux/ltt-type-serializer.h>
+
+/* kernel_trap_entry specialized tracepoint probe */
+
+struct serialize_long_long {
+       unsigned long f1;
+       unsigned long f2;
+       unsigned char end_field[0];
+} LTT_ALIGN;
+
+void probe_test(void *a, void *b);
+
+DEFINE_MARKER_TP(kernel, test, kernel_test,
+       probe_test, "f1 %p f2 %p");
+
+notrace void probe_test(void *a, void *b)
+{
+       struct marker *marker;
+       struct serialize_long_long data;
+
+       data.f1 = (long)a;
+       data.f2 = (long)b;
+
+       marker = &GET_MARKER(kernel, test);
+       ltt_specialized_trace(marker, marker->single.probe_private,
+               &data, serialize_sizeof(data), sizeof(long));
+}
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Test Tracepoint Probes");
diff --git a/trunk/tests/kernel/tp-test.h b/trunk/tests/kernel/tp-test.h
new file mode 100644 (file)
index 0000000..16b6729
--- /dev/null
@@ -0,0 +1,5 @@
+#include <linux/tracepoint.h>
+
+DECLARE_TRACE(kernel_test,
+       TPPROTO(void *a, void *b),
+               TPARGS(a, b));
This page took 0.027748 seconds and 4 git commands to generate.