fix: Adjust ranges for Ubuntu 5.4.0-67 kernel
[lttng-modules.git] / tests / probes / lttng-test.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
89406ecd
MD
3 * lttng-test.c
4 *
5 * Linux Trace Toolkit Next Generation Test Module
6 *
7 * Copyright 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
89406ecd
MD
8 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/proc_fs.h>
13#include <linux/byteorder/generic.h>
3834b99f 14#include <asm/byteorder.h>
89406ecd 15
2df37e95
MD
16#include <lttng/events.h>
17#include <lttng/tracer.h>
156a3977 18#include <wrapper/tracepoint.h>
89406ecd
MD
19
20#define TP_MODULE_NOAUTOLOAD
21#define LTTNG_PACKAGE_BUILD
22#define CREATE_TRACE_POINTS
4f47ccf0 23#define TRACE_INCLUDE_PATH instrumentation/events
89406ecd
MD
24#define TRACE_INCLUDE_FILE lttng-test
25#define LTTNG_INSTRUMENTATION
4f47ccf0 26#include <instrumentation/events/lttng-test.h>
89406ecd 27
0116245f
MJ
28LTTNG_DEFINE_TRACE(lttng_test_filter_event,
29 PARAMS(int anint, int netint, long *values,
30 char *text, size_t textlen,
31 char *etext, uint32_t * net_values),
32 PARAMS(anint, netint, values, text, textlen, etext, net_values)
33);
89406ecd
MD
34
35#define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
36
37#define LTTNG_WRITE_COUNT_MAX 64
38
39static struct proc_dir_entry *lttng_test_filter_event_dentry;
40
41static
42void trace_test_event(unsigned int nr_iter)
43{
44 int i, netint;
45 long values[] = { 1, 2, 3 };
3834b99f 46 uint32_t net_values[] = { 1, 2, 3 };
89406ecd
MD
47 char text[10] = "test";
48 char escape[10] = "\\*";
49
3834b99f
MD
50 for (i = 0; i < 3; i++) {
51 net_values[i] = htonl(net_values[i]);
52 }
89406ecd
MD
53 for (i = 0; i < nr_iter; i++) {
54 netint = htonl(i);
3834b99f 55 trace_lttng_test_filter_event(i, netint, values, text, strlen(text), escape, net_values);
89406ecd
MD
56 }
57}
58
59/**
60 * lttng_filter_event_write - trigger a lttng_test_filter_event
61 * @file: file pointer
62 * @user_buf: user string
63 * @count: length to copy
64 *
65 * Return -1 on error, with EFAULT errno. Returns count on success.
66 */
67static
68ssize_t lttng_test_filter_event_write(struct file *file, const char __user *user_buf,
69 size_t count, loff_t *ppos)
70{
71 unsigned int nr_iter;
72 ssize_t written;
73 int ret;
74
75 /* Get the number of iterations */
1a9417ef 76 ret = kstrtouint_from_user(user_buf, count, 10, &nr_iter);
89406ecd
MD
77 if (ret) {
78 written = ret;
79 goto end;
80 }
81 /* Trace the event */
82 trace_test_event(nr_iter);
83 written = count;
84 *ppos += written;
85end:
86 return written;
87}
88
5f4c791e 89#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
059de147
MJ
90static const struct proc_ops lttng_test_filter_event_proc_ops = {
91 .proc_write = lttng_test_filter_event_write,
92};
93#else
94static const struct file_operations lttng_test_filter_event_proc_ops = {
89406ecd
MD
95 .write = lttng_test_filter_event_write,
96};
059de147 97#endif
89406ecd
MD
98
99static
100int __init lttng_test_init(void)
101{
102 int ret = 0;
103
104 (void) wrapper_lttng_fixup_sig(THIS_MODULE);
263b6c88 105 wrapper_vmalloc_sync_mappings();
89406ecd
MD
106 lttng_test_filter_event_dentry =
107 proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE,
108 S_IRUGO | S_IWUGO, NULL,
059de147 109 &lttng_test_filter_event_proc_ops, NULL);
89406ecd
MD
110 if (!lttng_test_filter_event_dentry) {
111 printk(KERN_ERR "Error creating LTTng test filter file\n");
112 ret = -ENOMEM;
113 goto error;
114 }
115 ret = __lttng_events_init__lttng_test();
116 if (ret)
117 goto error_events;
118 return ret;
119
120error_events:
121 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
122error:
123 return ret;
124}
125
126module_init(lttng_test_init);
127
128static
129void __exit lttng_test_exit(void)
130{
131 __lttng_events_exit__lttng_test();
132 if (lttng_test_filter_event_dentry)
133 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
134}
135
136module_exit(lttng_test_exit);
137
138MODULE_LICENSE("GPL and additional rights");
139MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
140MODULE_DESCRIPTION("LTTng Test");
141MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
142 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
143 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
144 LTTNG_MODULES_EXTRAVERSION);
This page took 0.041868 seconds and 4 git commands to generate.