3 # Copyright (C) - 2017 Julien Desfossez <jdesfossez@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 TEST_DESC
="Kernel tracer - lttng-logger"
24 SESSION_NAME
="kernel_event_basic"
26 source $TESTDIR/utils
/utils.sh
28 function test_proc_logger
()
30 diag
"Test /proc/lttng-logger"
32 TRACE_PATH
=$
(mktemp
-d)
34 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
36 lttng_enable_kernel_event
$SESSION_NAME "lttng_logger"
38 start_lttng_tracing_ok
40 test -e /proc
/lttng-logger
42 pass
"/proc/lttng-logger exists"
43 echo -n "$PAYLOAD proc" > /proc
/lttng-logger
44 ok $?
"Write in /proc/lttng-logger"
46 fail
"No /proc/lttng-logger"
51 validate_trace_count
"lttng_logger" $TRACE_PATH 1
52 validate_trace_only_exp
"$PAYLOAD" $TRACE_PATH
54 destroy_lttng_session_ok
$SESSION_NAME
59 function test_dev_logger
()
61 diag
"Test /dev/lttng-logger"
63 TRACE_PATH
=$
(mktemp
-d)
65 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
67 lttng_enable_kernel_event
$SESSION_NAME "lttng_logger"
69 start_lttng_tracing_ok
71 test -c /dev
/lttng-logger
73 pass
"/dev/lttng-logger is a character device"
74 echo -n "$PAYLOAD dev" > /dev
/lttng-logger
75 ok $?
"Write in /dev/lttng-logger"
77 fail
"No /dev/lttng-logger"
82 validate_trace_count
"lttng_logger" $TRACE_PATH 1
83 validate_trace_only_exp
"$PAYLOAD" $TRACE_PATH
85 destroy_lttng_session_ok
$SESSION_NAME
90 function test_payload_limit
()
92 diag
"Test lttng-logger payload limit"
94 TRACE_PATH
=$
(mktemp
-d)
96 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
98 lttng_enable_kernel_event
$SESSION_NAME "lttng_logger"
100 start_lttng_tracing_ok
102 # Write 100 times "test_logger", which generates 1200 characters, we expect
103 # the tracer to write 2 events from that string because it limits the
104 # input to 1024 strings.
105 printf "%.s $PAYLOAD" {1.
.100} > /proc
/lttng-logger
106 printf "%.s $PAYLOAD" {1.
.100} > /dev
/lttng-logger
108 stop_lttng_tracing_ok
110 validate_trace_count
"lttng_logger" $TRACE_PATH 4
111 validate_trace_only_exp
"$PAYLOAD" $TRACE_PATH
113 destroy_lttng_session_ok
$SESSION_NAME
118 # MUST set TESTDIR before calling those functions
119 plan_tests
$NUM_TESTS
121 print_test_banner
"$TEST_DESC"
123 if [ "$(id -u)" == "0" ]; then
129 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||