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>
20 #define TP_MODULE_NOAUTOLOAD
21 #define LTTNG_PACKAGE_BUILD
22 #define CREATE_TRACE_POINTS
23 #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module
24 #define TRACE_INCLUDE_FILE lttng-test
25 #define LTTNG_INSTRUMENTATION
26 #include <instrumentation/events/lttng-module/lttng-test.h>
28 DEFINE_TRACE(lttng_test_filter_event
);
30 #define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
32 #define LTTNG_WRITE_COUNT_MAX 64
34 static struct proc_dir_entry
*lttng_test_filter_event_dentry
;
37 void trace_test_event(unsigned int nr_iter
)
40 long values
[] = { 1, 2, 3 };
41 uint32_t net_values
[] = { 1, 2, 3 };
42 char text
[10] = "test";
43 char escape
[10] = "\\*";
45 for (i
= 0; i
< 3; i
++) {
46 net_values
[i
] = htonl(net_values
[i
]);
48 for (i
= 0; i
< nr_iter
; i
++) {
50 trace_lttng_test_filter_event(i
, netint
, values
, text
, strlen(text
), escape
, net_values
);
55 * lttng_filter_event_write - trigger a lttng_test_filter_event
57 * @user_buf: user string
58 * @count: length to copy
60 * Return -1 on error, with EFAULT errno. Returns count on success.
63 ssize_t
lttng_test_filter_event_write(struct file
*file
, const char __user
*user_buf
,
64 size_t count
, loff_t
*ppos
)
70 /* Get the number of iterations */
71 ret
= kstrtouint_from_user(user_buf
, count
, 10, &nr_iter
);
77 trace_test_event(nr_iter
);
84 static const struct file_operations lttng_test_filter_event_operations
= {
85 .write
= lttng_test_filter_event_write
,
89 int __init
lttng_test_init(void)
93 (void) wrapper_lttng_fixup_sig(THIS_MODULE
);
94 wrapper_vmalloc_sync_all();
95 lttng_test_filter_event_dentry
=
96 proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE
,
97 S_IRUGO
| S_IWUGO
, NULL
,
98 <tng_test_filter_event_operations
, NULL
);
99 if (!lttng_test_filter_event_dentry
) {
100 printk(KERN_ERR
"Error creating LTTng test filter file\n");
104 ret
= __lttng_events_init__lttng_test();
110 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE
, NULL
);
115 module_init(lttng_test_init
);
118 void __exit
lttng_test_exit(void)
120 __lttng_events_exit__lttng_test();
121 if (lttng_test_filter_event_dentry
)
122 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE
, NULL
);
125 module_exit(lttng_test_exit
);
127 MODULE_LICENSE("GPL and additional rights");
128 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
129 MODULE_DESCRIPTION("LTTng Test");
130 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
131 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
132 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
133 LTTNG_MODULES_EXTRAVERSION
);