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