Commit | Line | Data |
---|---|---|
89406ecd MD |
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> | |
3834b99f | 27 | #include <asm/byteorder.h> |
89406ecd | 28 | |
156a3977 MD |
29 | #include <lttng-events.h> |
30 | #include <lttng-tracer.h> | |
31 | #include <wrapper/tracepoint.h> | |
32 | #include <wrapper/kstrtox.h> | |
89406ecd MD |
33 | |
34 | #define TP_MODULE_NOAUTOLOAD | |
35 | #define LTTNG_PACKAGE_BUILD | |
36 | #define CREATE_TRACE_POINTS | |
156a3977 | 37 | #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module |
89406ecd MD |
38 | #define TRACE_INCLUDE_FILE lttng-test |
39 | #define LTTNG_INSTRUMENTATION | |
156a3977 | 40 | #include <instrumentation/events/lttng-module/lttng-test.h> |
89406ecd MD |
41 | |
42 | DEFINE_TRACE(lttng_test_filter_event); | |
43 | ||
44 | #define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event" | |
45 | ||
46 | #define LTTNG_WRITE_COUNT_MAX 64 | |
47 | ||
48 | static struct proc_dir_entry *lttng_test_filter_event_dentry; | |
49 | ||
50 | static | |
51 | void trace_test_event(unsigned int nr_iter) | |
52 | { | |
53 | int i, netint; | |
54 | long values[] = { 1, 2, 3 }; | |
3834b99f | 55 | uint32_t net_values[] = { 1, 2, 3 }; |
89406ecd MD |
56 | char text[10] = "test"; |
57 | char escape[10] = "\\*"; | |
58 | ||
3834b99f MD |
59 | for (i = 0; i < 3; i++) { |
60 | net_values[i] = htonl(net_values[i]); | |
61 | } | |
89406ecd MD |
62 | for (i = 0; i < nr_iter; i++) { |
63 | netint = htonl(i); | |
3834b99f | 64 | trace_lttng_test_filter_event(i, netint, values, text, strlen(text), escape, net_values); |
89406ecd MD |
65 | } |
66 | } | |
67 | ||
68 | /** | |
69 | * lttng_filter_event_write - trigger a lttng_test_filter_event | |
70 | * @file: file pointer | |
71 | * @user_buf: user string | |
72 | * @count: length to copy | |
73 | * | |
74 | * Return -1 on error, with EFAULT errno. Returns count on success. | |
75 | */ | |
76 | static | |
77 | ssize_t lttng_test_filter_event_write(struct file *file, const char __user *user_buf, | |
78 | size_t count, loff_t *ppos) | |
79 | { | |
80 | unsigned int nr_iter; | |
81 | ssize_t written; | |
82 | int ret; | |
83 | ||
84 | /* Get the number of iterations */ | |
5a18f28d | 85 | ret = lttng_kstrtouint_from_user(user_buf, count, 10, &nr_iter); |
89406ecd MD |
86 | if (ret) { |
87 | written = ret; | |
88 | goto end; | |
89 | } | |
90 | /* Trace the event */ | |
91 | trace_test_event(nr_iter); | |
92 | written = count; | |
93 | *ppos += written; | |
94 | end: | |
95 | return written; | |
96 | } | |
97 | ||
98 | static const struct file_operations lttng_test_filter_event_operations = { | |
99 | .write = lttng_test_filter_event_write, | |
100 | }; | |
101 | ||
102 | static | |
103 | int __init lttng_test_init(void) | |
104 | { | |
105 | int ret = 0; | |
106 | ||
107 | (void) wrapper_lttng_fixup_sig(THIS_MODULE); | |
108 | wrapper_vmalloc_sync_all(); | |
109 | lttng_test_filter_event_dentry = | |
110 | proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE, | |
111 | S_IRUGO | S_IWUGO, NULL, | |
112 | <tng_test_filter_event_operations, NULL); | |
113 | if (!lttng_test_filter_event_dentry) { | |
114 | printk(KERN_ERR "Error creating LTTng test filter file\n"); | |
115 | ret = -ENOMEM; | |
116 | goto error; | |
117 | } | |
118 | ret = __lttng_events_init__lttng_test(); | |
119 | if (ret) | |
120 | goto error_events; | |
121 | return ret; | |
122 | ||
123 | error_events: | |
124 | remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL); | |
125 | error: | |
126 | return ret; | |
127 | } | |
128 | ||
129 | module_init(lttng_test_init); | |
130 | ||
131 | static | |
132 | void __exit lttng_test_exit(void) | |
133 | { | |
134 | __lttng_events_exit__lttng_test(); | |
135 | if (lttng_test_filter_event_dentry) | |
136 | remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL); | |
137 | } | |
138 | ||
139 | module_exit(lttng_test_exit); | |
140 | ||
141 | MODULE_LICENSE("GPL and additional rights"); | |
142 | MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>"); | |
143 | MODULE_DESCRIPTION("LTTng Test"); | |
144 | MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." | |
145 | __stringify(LTTNG_MODULES_MINOR_VERSION) "." | |
146 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) | |
147 | LTTNG_MODULES_EXTRAVERSION); |