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