1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
5 * Linux Trace Toolkit Next Generation Test Module
7 * Copyright 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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>
16 #include <lttng-events.h>
17 #include <lttng-tracer.h>
18 #include <wrapper/tracepoint.h>
19 #include <wrapper/kstrtox.h>
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>
29 DEFINE_TRACE(lttng_test_filter_event
);
31 #define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
33 #define LTTNG_WRITE_COUNT_MAX 64
35 static struct proc_dir_entry
*lttng_test_filter_event_dentry
;
38 void trace_test_event(unsigned int nr_iter
)
41 long values
[] = { 1, 2, 3 };
42 uint32_t net_values
[] = { 1, 2, 3 };
43 char text
[10] = "test";
44 char escape
[10] = "\\*";
46 for (i
= 0; i
< 3; i
++) {
47 net_values
[i
] = htonl(net_values
[i
]);
49 for (i
= 0; i
< nr_iter
; i
++) {
51 trace_lttng_test_filter_event(i
, netint
, values
, text
, strlen(text
), escape
, net_values
);
56 * lttng_filter_event_write - trigger a lttng_test_filter_event
58 * @user_buf: user string
59 * @count: length to copy
61 * Return -1 on error, with EFAULT errno. Returns count on success.
64 ssize_t
lttng_test_filter_event_write(struct file
*file
, const char __user
*user_buf
,
65 size_t count
, loff_t
*ppos
)
71 /* Get the number of iterations */
72 ret
= lttng_kstrtouint_from_user(user_buf
, count
, 10, &nr_iter
);
78 trace_test_event(nr_iter
);
85 static const struct file_operations lttng_test_filter_event_operations
= {
86 .write
= lttng_test_filter_event_write
,
90 int __init
lttng_test_init(void)
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 <tng_test_filter_event_operations
, NULL
);
100 if (!lttng_test_filter_event_dentry
) {
101 printk(KERN_ERR
"Error creating LTTng test filter file\n");
105 ret
= __lttng_events_init__lttng_test();
111 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE
, NULL
);
116 module_init(lttng_test_init
);
119 void __exit
lttng_test_exit(void)
121 __lttng_events_exit__lttng_test();
122 if (lttng_test_filter_event_dentry
)
123 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE
, NULL
);
126 module_exit(lttng_test_exit
);
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
);