Commit | Line | Data |
---|---|---|
ab95d85d JD |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com> |
ab95d85d | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
ab95d85d | 6 | # |
ab95d85d JD |
7 | |
8 | TEST_DESC="Kernel tracer - lttng-logger" | |
9 | ||
10 | CURDIR=$(dirname $0)/ | |
11 | TESTDIR=$CURDIR/../.. | |
12 | NUM_TESTS=30 | |
13 | PAYLOAD="test_logger" | |
14 | SESSION_NAME="kernel_event_basic" | |
15 | ||
16 | source $TESTDIR/utils/utils.sh | |
17 | ||
18 | function test_proc_logger() | |
19 | { | |
20 | diag "Test /proc/lttng-logger" | |
21 | ||
22 | TRACE_PATH=$(mktemp -d) | |
23 | ||
24 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
25 | ||
26 | lttng_enable_kernel_event $SESSION_NAME "lttng_logger" | |
27 | ||
28 | start_lttng_tracing_ok | |
29 | ||
30 | test -e /proc/lttng-logger | |
31 | if test $? = 0; then | |
32 | pass "/proc/lttng-logger exists" | |
33 | echo -n "$PAYLOAD proc" > /proc/lttng-logger | |
34 | ok $? "Write in /proc/lttng-logger" | |
35 | else | |
36 | fail "No /proc/lttng-logger" | |
37 | fi | |
38 | ||
39 | stop_lttng_tracing_ok | |
40 | ||
41 | validate_trace_count "lttng_logger" $TRACE_PATH 1 | |
42 | validate_trace_only_exp "$PAYLOAD" $TRACE_PATH | |
43 | ||
44 | destroy_lttng_session_ok $SESSION_NAME | |
45 | ||
46 | rm -rf $TRACE_PATH | |
47 | } | |
48 | ||
49 | function test_dev_logger() | |
50 | { | |
51 | diag "Test /dev/lttng-logger" | |
52 | ||
53 | TRACE_PATH=$(mktemp -d) | |
54 | ||
55 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
56 | ||
57 | lttng_enable_kernel_event $SESSION_NAME "lttng_logger" | |
58 | ||
59 | start_lttng_tracing_ok | |
60 | ||
61 | test -c /dev/lttng-logger | |
62 | if test $? = 0; then | |
63 | pass "/dev/lttng-logger is a character device" | |
64 | echo -n "$PAYLOAD dev" > /dev/lttng-logger | |
65 | ok $? "Write in /dev/lttng-logger" | |
66 | else | |
67 | fail "No /dev/lttng-logger" | |
68 | fi | |
69 | ||
70 | stop_lttng_tracing_ok | |
71 | ||
72 | validate_trace_count "lttng_logger" $TRACE_PATH 1 | |
73 | validate_trace_only_exp "$PAYLOAD" $TRACE_PATH | |
74 | ||
75 | destroy_lttng_session_ok $SESSION_NAME | |
76 | ||
77 | rm -rf $TRACE_PATH | |
78 | } | |
79 | ||
80 | function test_payload_limit() | |
81 | { | |
82 | diag "Test lttng-logger payload limit" | |
83 | ||
84 | TRACE_PATH=$(mktemp -d) | |
85 | ||
86 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
87 | ||
88 | lttng_enable_kernel_event $SESSION_NAME "lttng_logger" | |
89 | ||
90 | start_lttng_tracing_ok | |
91 | ||
92 | # Write 100 times "test_logger", which generates 1200 characters, we expect | |
93 | # the tracer to write 2 events from that string because it limits the | |
94 | # input to 1024 strings. | |
95 | printf "%.s $PAYLOAD" {1..100} > /proc/lttng-logger | |
96 | printf "%.s $PAYLOAD" {1..100} > /dev/lttng-logger | |
97 | ||
98 | stop_lttng_tracing_ok | |
99 | ||
100 | validate_trace_count "lttng_logger" $TRACE_PATH 4 | |
101 | validate_trace_only_exp "$PAYLOAD" $TRACE_PATH | |
102 | ||
103 | destroy_lttng_session_ok $SESSION_NAME | |
104 | ||
105 | rm -rf $TRACE_PATH | |
106 | } | |
107 | ||
108 | # MUST set TESTDIR before calling those functions | |
109 | plan_tests $NUM_TESTS | |
110 | ||
111 | print_test_banner "$TEST_DESC" | |
112 | ||
113 | if [ "$(id -u)" == "0" ]; then | |
114 | isroot=1 | |
115 | else | |
116 | isroot=0 | |
117 | fi | |
118 | ||
119 | skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || | |
120 | { | |
121 | start_lttng_sessiond | |
122 | ||
123 | test_proc_logger | |
124 | test_dev_logger | |
125 | test_payload_limit | |
126 | ||
127 | stop_lttng_sessiond | |
128 | } |