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 LTTNG_DEFINE_TRACE(lttng_test_filter_event
,
30 PARAMS(int anint
, int netint
, long *values
,
31 char *text
, size_t textlen
,
32 char *etext
, uint32_t * net_values
),
33 PARAMS(anint
, netint
, values
, text
, textlen
, etext
, net_values
)
36 #define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
38 #define LTTNG_WRITE_COUNT_MAX 64
40 static struct proc_dir_entry
*lttng_test_filter_event_dentry
;
43 void trace_test_event(unsigned int nr_iter
)
46 long values
[] = { 1, 2, 3 };
47 uint32_t net_values
[] = { 1, 2, 3 };
48 char text
[10] = "test";
49 char escape
[10] = "\\*";
51 for (i
= 0; i
< 3; i
++) {
52 net_values
[i
] = htonl(net_values
[i
]);
54 for (i
= 0; i
< nr_iter
; i
++) {
56 trace_lttng_test_filter_event(i
, netint
, values
, text
, strlen(text
), escape
, net_values
);
61 * lttng_filter_event_write - trigger a lttng_test_filter_event
63 * @user_buf: user string
64 * @count: length to copy
66 * Return -1 on error, with EFAULT errno. Returns count on success.
69 ssize_t
lttng_test_filter_event_write(struct file
*file
, const char __user
*user_buf
,
70 size_t count
, loff_t
*ppos
)
76 /* Get the number of iterations */
77 ret
= lttng_kstrtouint_from_user(user_buf
, count
, 10, &nr_iter
);
83 trace_test_event(nr_iter
);
90 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
91 static const struct proc_ops lttng_test_filter_event_proc_ops
= {
92 .proc_write
= lttng_test_filter_event_write
,
95 static const struct file_operations lttng_test_filter_event_proc_ops
= {
96 .write
= lttng_test_filter_event_write
,
101 int __init
lttng_test_init(void)
105 (void) wrapper_lttng_fixup_sig(THIS_MODULE
);
106 wrapper_vmalloc_sync_mappings();
107 lttng_test_filter_event_dentry
=
108 proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE
,
109 S_IRUGO
| S_IWUGO
, NULL
,
110 <tng_test_filter_event_proc_ops
, NULL
);
111 if (!lttng_test_filter_event_dentry
) {
112 printk(KERN_ERR
"Error creating LTTng test filter file\n");
116 ret
= __lttng_events_init__lttng_test();
122 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE
, NULL
);
127 module_init(lttng_test_init
);
130 void __exit
lttng_test_exit(void)
132 __lttng_events_exit__lttng_test();
133 if (lttng_test_filter_event_dentry
)
134 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE
, NULL
);
137 module_exit(lttng_test_exit
);
139 MODULE_LICENSE("GPL and additional rights");
140 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
141 MODULE_DESCRIPTION("LTTng Test");
142 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
143 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
144 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
145 LTTNG_MODULES_EXTRAVERSION
);