54be4c7c90a4c89cdfab81fa38c873b451057e80
[lttng-modules.git] / tests / probes / lttng-test.c
1 /*
2 * lttng-test.c
3 *
4 * Linux Trace Toolkit Next Generation Test Module
5 *
6 * Copyright 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/proc_fs.h>
26 #include <linux/byteorder/generic.h>
27
28 #include <lttng-events.h>
29 #include <lttng-tracer.h>
30 #include <wrapper/tracepoint.h>
31 #include <wrapper/kstrtox.h>
32
33 #define TP_MODULE_NOAUTOLOAD
34 #define LTTNG_PACKAGE_BUILD
35 #define CREATE_TRACE_POINTS
36 #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module
37 #define TRACE_INCLUDE_FILE lttng-test
38 #define LTTNG_INSTRUMENTATION
39 #include <instrumentation/events/lttng-module/lttng-test.h>
40
41 DEFINE_TRACE(lttng_test_filter_event);
42
43 #define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
44
45 #define LTTNG_WRITE_COUNT_MAX 64
46
47 static struct proc_dir_entry *lttng_test_filter_event_dentry;
48
49 static
50 void trace_test_event(unsigned int nr_iter)
51 {
52 int i, netint;
53 long values[] = { 1, 2, 3 };
54 char text[10] = "test";
55 char escape[10] = "\\*";
56
57 for (i = 0; i < nr_iter; i++) {
58 netint = htonl(i);
59 trace_lttng_test_filter_event(i, netint, values, text, strlen(text), escape);
60 }
61 }
62
63 /**
64 * lttng_filter_event_write - trigger a lttng_test_filter_event
65 * @file: file pointer
66 * @user_buf: user string
67 * @count: length to copy
68 *
69 * Return -1 on error, with EFAULT errno. Returns count on success.
70 */
71 static
72 ssize_t lttng_test_filter_event_write(struct file *file, const char __user *user_buf,
73 size_t count, loff_t *ppos)
74 {
75 unsigned int nr_iter;
76 ssize_t written;
77 int ret;
78
79 /* Get the number of iterations */
80 ret = lttng_kstrtouint_from_user(user_buf, count, 10, &nr_iter);
81 if (ret) {
82 written = ret;
83 goto end;
84 }
85 /* Trace the event */
86 trace_test_event(nr_iter);
87 written = count;
88 *ppos += written;
89 end:
90 return written;
91 }
92
93 static const struct file_operations lttng_test_filter_event_operations = {
94 .write = lttng_test_filter_event_write,
95 };
96
97 static
98 int __init lttng_test_init(void)
99 {
100 int ret = 0;
101
102 (void) wrapper_lttng_fixup_sig(THIS_MODULE);
103 wrapper_vmalloc_sync_all();
104 lttng_test_filter_event_dentry =
105 proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE,
106 S_IRUGO | S_IWUGO, NULL,
107 &lttng_test_filter_event_operations, NULL);
108 if (!lttng_test_filter_event_dentry) {
109 printk(KERN_ERR "Error creating LTTng test filter file\n");
110 ret = -ENOMEM;
111 goto error;
112 }
113 ret = __lttng_events_init__lttng_test();
114 if (ret)
115 goto error_events;
116 return ret;
117
118 error_events:
119 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
120 error:
121 return ret;
122 }
123
124 module_init(lttng_test_init);
125
126 static
127 void __exit lttng_test_exit(void)
128 {
129 __lttng_events_exit__lttng_test();
130 if (lttng_test_filter_event_dentry)
131 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
132 }
133
134 module_exit(lttng_test_exit);
135
136 MODULE_LICENSE("GPL and additional rights");
137 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
138 MODULE_DESCRIPTION("LTTng Test");
139 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
140 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
141 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
142 LTTNG_MODULES_EXTRAVERSION);
This page took 0.031195 seconds and 3 git commands to generate.