3 # Copyright (C) 2016 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
8 TEST_DESC
="Kernel tracer - select, poll and epoll payload extraction"
12 VALIDATE_SCRIPT
="$CURDIR/validate_select_poll_epoll.py"
16 # Babeltrace python bindings are required for the validation, but
17 # it is not a mandatory dependancy of the project, so fail run the
18 # without the content validation, at least we test that we are not
19 # crashing the kernel.
20 $VALIDATE_SCRIPT --help >/dev
/null
2>&1
22 echo "# Failed to run the validation script, Babeltrace Python bindings might be missing"
26 LAST_WARNING
=$
(dmesg |
grep " WARNING:" | cut
-d' ' -f1 |
tail -1)
27 LAST_OOPS
=$
(dmesg |
grep " OOPS:" | cut
-d' ' -f1 |
tail -1)
28 LAST_BUG
=$
(dmesg |
grep " BUG:" | cut
-d' ' -f1 |
tail -1)
30 source $TESTDIR/utils
/utils.sh
32 function check_trace_content
()
34 if test $DISABLE_VALIDATE == 1; then
35 ok
0 "Validation skipped"
41 ok
0 "Validation success"
47 function test_working_cases
()
49 TRACE_PATH
=$
(mktemp
-d)
50 SESSION_NAME
="syscall_payload"
52 # arm64 does not have epoll_wait
53 uname
-m |
grep -E "aarch64" >/dev
/null
2>&1
55 SYSCALL_LIST
="select,pselect6,poll,ppoll,epoll_ctl,epoll_pwait"
57 SYSCALL_LIST
="select,pselect6,poll,ppoll,epoll_ctl,epoll_wait,epoll_pwait"
60 diag
"Working cases for select, pselect6, poll, ppoll and epoll, waiting for input"
62 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
64 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
65 add_context_kernel_ok
$SESSION_NAME channel0 pid
67 start_lttng_tracing_ok
68 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 1); } 2>/dev
/null
70 pid
=$
(echo $out | cut
-d' ' -f1)
72 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
73 check_trace_content
-t 1 -p $pid $TRACE_PATH
75 destroy_lttng_session_ok
$SESSION_NAME
80 function test_timeout_cases
()
82 TRACE_PATH
=$
(mktemp
-d)
83 SESSION_NAME
="syscall_payload"
85 # arm64 does not have epoll_wait
86 uname
-m |
grep -E "aarch64" >/dev
/null
2>&1
88 SYSCALL_LIST
="select,pselect6,poll,ppoll,epoll_ctl,epoll_pwait"
90 SYSCALL_LIST
="select,pselect6,poll,ppoll,epoll_ctl,epoll_wait,epoll_pwait"
93 diag
"Timeout cases (1ms) for select, pselect6, poll, ppoll and epoll"
95 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
97 lttng_enable_kernel_syscall_ok
$SESSION_NAME "$SYSCALL_LIST"
98 add_context_kernel_ok
$SESSION_NAME channel0 pid
100 start_lttng_tracing_ok
101 { out
=$
($CURDIR/select_poll_epoll
-t 2); } 2>/dev
/null
102 stop_lttng_tracing_ok
103 pid
=$
(echo $out | cut
-d' ' -f1)
105 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
106 check_trace_content
-t 2 -p $pid $TRACE_PATH 2>/dev
/null
108 destroy_lttng_session_ok
$SESSION_NAME
113 function test_pselect_invalid_fd
()
115 TRACE_PATH
=$
(mktemp
-d)
116 SESSION_NAME
="syscall_payload"
117 SYSCALL_LIST
="pselect6"
119 diag
"pselect with invalid FD"
121 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
123 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
124 add_context_kernel_ok
$SESSION_NAME channel0 pid
126 start_lttng_tracing_ok
127 { out
=$
($CURDIR/select_poll_epoll
-t 3); } 2>/dev
/null
128 stop_lttng_tracing_ok
129 pid
=$
(echo $out | cut
-d' ' -f1)
131 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
132 check_trace_content
-t 3 -p $pid $TRACE_PATH 2>/dev
/null
134 destroy_lttng_session_ok
$SESSION_NAME
139 function test_big_ppoll
()
141 TRACE_PATH
=$
(mktemp
-d)
142 SESSION_NAME
="syscall_payload"
145 diag
"ppoll with 2047 FDs"
147 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
149 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
150 add_context_kernel_ok
$SESSION_NAME channel0 pid
152 start_lttng_tracing_ok
153 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 4); } 2>/dev
/null
154 stop_lttng_tracing_ok
155 pid
=$
(echo $out | cut
-d' ' -f1)
157 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
158 check_trace_content
-t 4 -p $pid $TRACE_PATH 2>/dev
/null
160 destroy_lttng_session_ok
$SESSION_NAME
165 function test_ppoll_overflow
()
167 TRACE_PATH
=$
(mktemp
-d)
168 SESSION_NAME
="syscall_payload"
171 diag
"ppoll buffer overflow, should segfault, waits for input"
173 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
175 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
176 add_context_kernel_ok
$SESSION_NAME channel0 pid
178 start_lttng_tracing_ok
179 diag
"Expect segfaults"
180 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 5); } 2>/dev
/null
181 stop_lttng_tracing_ok
183 pid
=$
(echo $out | cut
-d' ' -f1)
185 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
187 check_trace_content
-t 5 -p $pid $TRACE_PATH 2>/dev
/null
189 destroy_lttng_session_ok
$SESSION_NAME
194 function test_pselect_invalid_ptr
()
196 TRACE_PATH
=$
(mktemp
-d)
197 SESSION_NAME
="syscall_payload"
198 SYSCALL_LIST
="pselect6"
200 diag
"pselect with invalid pointer, waits for input"
202 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
204 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
205 add_context_kernel_ok
$SESSION_NAME channel0 pid
207 start_lttng_tracing_ok
208 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 6); } 2>/dev
/null
209 stop_lttng_tracing_ok
210 pid
=$
(echo $out | cut
-d' ' -f1)
212 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
213 check_trace_content
-t 6 -p $pid $TRACE_PATH 2>/dev
/null
215 destroy_lttng_session_ok
$SESSION_NAME
220 function test_ppoll_ulong_max
()
222 TRACE_PATH
=$
(mktemp
-d)
223 SESSION_NAME
="syscall_payload"
226 diag
"ppoll with ulong_max fds, waits for input"
228 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
230 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
231 add_context_kernel_ok
$SESSION_NAME channel0 pid
233 start_lttng_tracing_ok
234 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 7); } 2>/dev
/null
235 stop_lttng_tracing_ok
236 pid
=$
(echo $out | cut
-d' ' -f1)
238 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
239 check_trace_content
-t 7 -p $pid $TRACE_PATH 2>/dev
/null
241 destroy_lttng_session_ok
$SESSION_NAME
246 function test_epoll_pwait_invalid_ptr
()
248 TRACE_PATH
=$
(mktemp
-d)
249 SESSION_NAME
="syscall_payload"
250 SYSCALL_LIST
="epoll_pwait"
252 diag
"epoll_pwait with invalid pointer, waits for input"
254 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
256 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
257 add_context_kernel_ok
$SESSION_NAME channel0 pid
259 start_lttng_tracing_ok
260 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 8); } 2>/dev
/null
261 stop_lttng_tracing_ok
262 pid
=$
(echo $out | cut
-d' ' -f1)
264 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
265 check_trace_content
-t 8 -p $pid $TRACE_PATH 2>/dev
/null
267 destroy_lttng_session_ok
$SESSION_NAME
272 function test_epoll_pwait_int_max
()
274 TRACE_PATH
=$
(mktemp
-d)
275 SESSION_NAME
="syscall_payload"
276 SYSCALL_LIST
="epoll_pwait"
278 diag
"epoll_pwait with maxevents set to INT_MAX, waits for input"
280 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
282 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
283 add_context_kernel_ok
$SESSION_NAME channel0 pid
285 start_lttng_tracing_ok
286 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 9); } 2>/dev
/null
287 stop_lttng_tracing_ok
288 pid
=$
(echo $out | cut
-d' ' -f1)
290 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
291 check_trace_content
-t 9 -p $pid $TRACE_PATH 2>/dev
/null
293 destroy_lttng_session_ok
$SESSION_NAME
298 function test_ppoll_concurrent
()
300 TRACE_PATH
=$
(mktemp
-d)
301 SESSION_NAME
="syscall_payload"
304 diag
"ppoll with concurrent updates of the structure from user-space, stress test (3000 iterations), waits for input + timeout 1ms"
306 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
308 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
309 add_context_kernel_ok
$SESSION_NAME channel0 pid
311 start_lttng_tracing_ok
312 { out
=$
(yes |
$CURDIR/select_poll_epoll
-t 10); } 2>/dev
/null
313 stop_lttng_tracing_ok
314 pid
=$
(echo $out | cut
-d' ' -f1)
316 validate_trace
"$SYSCALL_LIST" $TRACE_PATH
317 check_trace_content
-t 10 -p $pid $TRACE_PATH 2>/dev
/null
319 destroy_lttng_session_ok
$SESSION_NAME
324 function test_epoll_pwait_concurrent
()
326 TRACE_PATH
=$
(mktemp
-d)
327 SESSION_NAME
="syscall_payload"
328 SYSCALL_LIST
="epoll_ctl,epoll_pwait"
330 diag
"epoll_pwait with concurrent munmap of the buffer from user-space, should randomly segfault, run multiple times, waits for input + timeout 1ms"
332 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
334 lttng_enable_kernel_syscall_ok
$SESSION_NAME $SYSCALL_LIST
335 add_context_kernel_ok
$SESSION_NAME channel0 pid
337 start_lttng_tracing_ok
338 diag
"Expect segfaults"
339 for i
in $
(seq 1 100); do
340 { out
=$
($CURDIR/select_poll_epoll
-t 11); } 2>/dev
/null
342 pid
=$
(echo $out | cut
-d' ' -f1)
343 stop_lttng_tracing_ok
345 # epoll_wait is not always generated in the trace (stress test)
346 validate_trace
"epoll_ctl" $TRACE_PATH
347 check_trace_content
-t 11 -p $pid $TRACE_PATH 2>/dev
/null
349 destroy_lttng_session_ok
$SESSION_NAME
354 # MUST set TESTDIR before calling those functions
355 plan_tests
$NUM_TESTS
357 print_test_banner
"$TEST_DESC"
359 # Only run this test on x86 and arm
360 uname
-m |
grep -E "x86|i686|arm|aarch64" >/dev
/null
2>&1
361 if test $?
!= 0; then
362 skip
0 "Run only on x86 and arm. Skipping all tests." $NUM_TESTS
366 if [ "$(id -u)" == "0" ]; then
372 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
374 validate_lttng_modules_present
380 test_pselect_invalid_fd
383 test_pselect_invalid_ptr
385 test_epoll_pwait_invalid_ptr
386 test_epoll_pwait_int_max
387 test_ppoll_concurrent
388 test_epoll_pwait_concurrent
392 NEW_WARNING
=$
(dmesg |
grep " WARNING:" | cut
-d' ' -f1 |
tail -1)
393 NEW_OOPS
=$
(dmesg |
grep " OOPS:" | cut
-d' ' -f1 |
tail -1)
394 NEW_BUG
=$
(dmesg |
grep " BUG:" | cut
-d' ' -f1 |
tail -1)
396 if test "$LAST_WARNING" != "$NEW_WARNING"; then
397 fail
"New WARNING generated"
399 if test "$LAST_OOPS" != "$NEW_OOPS"; then
400 fail
"New OOPS generated"
402 if test "$LAST_BUG" != "$NEW_BUG"; then
403 fail
"New BUG generated"