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