42e48cf2be41ade450d2e2a3a989bfbe924f35a7
[lttng-modules.git] / tests / probes / lttng-test.c
1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
3 * lttng-test.c
4 *
5 * Linux Trace Toolkit Next Generation Test Module
6 *
7 * Copyright 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/proc_fs.h>
13 #include <linux/byteorder/generic.h>
14 #include <asm/byteorder.h>
15
16 #include <lttng-events.h>
17 #include <lttng-tracer.h>
18 #include <wrapper/tracepoint.h>
19 #include <wrapper/kstrtox.h>
20
21 #define TP_MODULE_NOAUTOLOAD
22 #define LTTNG_PACKAGE_BUILD
23 #define CREATE_TRACE_POINTS
24 #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module
25 #define TRACE_INCLUDE_FILE lttng-test
26 #define LTTNG_INSTRUMENTATION
27 #include <instrumentation/events/lttng-module/lttng-test.h>
28
29 DEFINE_TRACE(lttng_test_filter_event);
30
31 #define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
32
33 #define LTTNG_WRITE_COUNT_MAX 64
34
35 static struct proc_dir_entry *lttng_test_filter_event_dentry;
36
37 static
38 void trace_test_event(unsigned int nr_iter)
39 {
40 int i, netint;
41 long values[] = { 1, 2, 3 };
42 uint32_t net_values[] = { 1, 2, 3 };
43 char text[10] = "test";
44 char escape[10] = "\\*";
45
46 for (i = 0; i < 3; i++) {
47 net_values[i] = htonl(net_values[i]);
48 }
49 for (i = 0; i < nr_iter; i++) {
50 netint = htonl(i);
51 trace_lttng_test_filter_event(i, netint, values, text, strlen(text), escape, net_values);
52 }
53 }
54
55 /**
56 * lttng_filter_event_write - trigger a lttng_test_filter_event
57 * @file: file pointer
58 * @user_buf: user string
59 * @count: length to copy
60 *
61 * Return -1 on error, with EFAULT errno. Returns count on success.
62 */
63 static
64 ssize_t lttng_test_filter_event_write(struct file *file, const char __user *user_buf,
65 size_t count, loff_t *ppos)
66 {
67 unsigned int nr_iter;
68 ssize_t written;
69 int ret;
70
71 /* Get the number of iterations */
72 ret = lttng_kstrtouint_from_user(user_buf, count, 10, &nr_iter);
73 if (ret) {
74 written = ret;
75 goto end;
76 }
77 /* Trace the event */
78 trace_test_event(nr_iter);
79 written = count;
80 *ppos += written;
81 end:
82 return written;
83 }
84
85 static const struct file_operations lttng_test_filter_event_operations = {
86 .write = lttng_test_filter_event_write,
87 };
88
89 static
90 int __init lttng_test_init(void)
91 {
92 int ret = 0;
93
94 (void) wrapper_lttng_fixup_sig(THIS_MODULE);
95 wrapper_vmalloc_sync_all();
96 lttng_test_filter_event_dentry =
97 proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE,
98 S_IRUGO | S_IWUGO, NULL,
99 &lttng_test_filter_event_operations, NULL);
100 if (!lttng_test_filter_event_dentry) {
101 printk(KERN_ERR "Error creating LTTng test filter file\n");
102 ret = -ENOMEM;
103 goto error;
104 }
105 ret = __lttng_events_init__lttng_test();
106 if (ret)
107 goto error_events;
108 return ret;
109
110 error_events:
111 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
112 error:
113 return ret;
114 }
115
116 module_init(lttng_test_init);
117
118 static
119 void __exit lttng_test_exit(void)
120 {
121 __lttng_events_exit__lttng_test();
122 if (lttng_test_filter_event_dentry)
123 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
124 }
125
126 module_exit(lttng_test_exit);
127
128 MODULE_LICENSE("GPL and additional rights");
129 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
130 MODULE_DESCRIPTION("LTTng Test");
131 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
132 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
133 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
134 LTTNG_MODULES_EXTRAVERSION);
This page took 0.031721 seconds and 3 git commands to generate.