From: compudj Date: Sat, 28 Mar 2009 23:49:48 +0000 (+0000) Subject: add tests X-Git-Tag: v0.12.20~130 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2200bbb06e512818a11eeff019677da516154c77;p=lttv.git add tests git-svn-id: http://ltt.polymtl.ca/svn@3359 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/trunk/tests/kernel/genkprobe.c b/trunk/tests/kernel/genkprobe.c new file mode 100644 index 00000000..5a9a167d --- /dev/null +++ b/trunk/tests/kernel/genkprobe.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +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 +#include +#include +#include +#include +#include +#include "tp-test.h" +#include +#include + +#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 index 00000000..3b3c26e2 --- /dev/null +++ b/trunk/tests/kernel/test-trace.c @@ -0,0 +1,39 @@ +/* + * test-trace.c + * + * Test tracepoint probes. + */ + +#include +#include "tp-test.h" +#include + +/* 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 index 00000000..16b6729e --- /dev/null +++ b/trunk/tests/kernel/tp-test.h @@ -0,0 +1,5 @@ +#include + +DECLARE_TRACE(kernel_test, + TPPROTO(void *a, void *b), + TPARGS(a, b));