3 # We use the something && ok || fail pattern quite a lot; it is not correct in general,
4 # which makes shellcheck complain about it, but in our case it's ok to use it since
5 # the ok function will never fail.
6 # shellcheck disable=SC2015
8 source dlog_test_header
12 USAGE_MESSAGE="usage: $0 [--verbose] [--quick] pipe|logger|zero-copy"
14 OPTS=$(getopt --shell sh --options "" --long verbose,quick --quiet -- "$@")
15 if [ "$?" -eq 1 ]; then
36 echo "This should never happen :)"
42 if [ "$1" = "pipe" ]; then
44 elif [ "$1" = "logger" ]; then
46 elif [ "$1" = "zero-copy" ]; then
48 # We still accept the legacy {pipe,logger}_quick syntax because there's no reason not to.
49 elif [ "$1" = "pipe_quick" ]; then
52 elif [ "$1" = "logger_quick" ]; then
60 # supress stderr messages from subcommands
61 if [ "$verbose" -eq 0 ]; then
66 capsh --print | grep Current | grep cap_syslog > /dev/null || { echo "*** ERROR: cap_syslog missing"; NEEDS_TO_QUIT=1; }
67 mount | grep ' / ' | grep rw > /dev/null || { echo "*** ERROR: root not mounted read-write"; NEEDS_TO_QUIT=1; }
68 [ "$NEEDS_TO_QUIT" -eq 0 ] || exit 1
70 if [ "$type" = "pipe" ] || [ -f /lib/modules/"$(uname -r)"/extra/logger.ko ]; then
76 if [ -z "$DLOG_CONFIG_PATH" ]; then
77 ORIGINAL_CONFIG_PATH="/etc/dlog.conf"
79 ORIGINAL_CONFIG_PATH="$DLOG_CONFIG_PATH"
82 export DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.test"
83 PATH=$PATH:@libexecdir@/libdlog/
85 if [ "$type" != "zero-copy" ]; then # These tests are inherently dynamic.
86 #create dir for runtime filters
87 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
88 mkdir -m 777 -p "$RUNTIME_FILTERS_DIR"
90 if [ "$quick" -ne 1 ]; then
91 dlog_test_daemon_early_quit $type
99 if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
102 dlogutil -c -b radio -b system -b main
103 LOG_DETAILS="dlogctl --disable (no args, limiter_apply_to_all_buffers=0)"
106 # without 'limiter_apply_to_all_buffers=1' this
107 # only applies to the three platform buffers:
108 # main, radio, and system
109 PREPLOG_CONFIG_PATH="$DLOG_CONFIG_PATH"
110 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.plog"
111 [ "$(dlogctl -g | grep regular | grep -c DISABLED)" -eq 3 ] && ok || fail
112 DLOG_CONFIG_PATH="$PREPLOG_CONFIG_PATH"
114 LOG_DETAILS="dlogctl --disable (no args, limiter_apply_to_all_buffers=1)"
116 [ "$(dlogctl -g | grep regular | grep -c ENABLED)" -eq 0 ] && ok || fail
118 LOG_DETAILS="testing if filters were applied"
119 dlogsend -b system -t TEST test
120 dlogsend -b main -t TEST test
121 dlogsend -b radio -t TEST test
122 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
124 LOG_DETAILS="dlogctl --enable (no args)"
126 [ "$(dlogctl -g | grep regular | grep -c DISABLED)" -eq 0 ] && ok || fail
127 LOG_DETAILS="testing if filters were applied"
128 dlogutil -c -b radio -b system -b main
129 dlogsend -b system -t TEST test
130 dlogsend -b main -t TEST test
131 dlogsend -b radio -t TEST test
132 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
134 LOG_DETAILS="dlogctl --disable (1 arg)"
135 dlogctl --disable -b system
136 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c system)" -eq 1 ] &&
137 [ "$(dlogctl -g | grep regular | grep -c DISABLED )" -eq 1 ] && ok || fail
138 LOG_DETAILS="testing if filters were applied"
139 dlogutil -c -b radio -b system -b main
140 dlogsend -b system -t TEST test
141 dlogsend -b main -t TEST test
142 dlogsend -b radio -t TEST test
143 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
145 LOG_DETAILS="dlogctl --disable (multiple args)"
146 dlogctl --disable -b main -b radio
147 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -cv system)" -eq 2 ] &&
148 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c radio)" -eq 1 ] &&
149 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c main)" -eq 1 ] && ok || fail
150 LOG_DETAILS="testing if filters were applied"
151 dlogutil -c -b radio -b system -b main
152 dlogsend -b system -t TEST test
153 dlogsend -b main -t TEST test
154 dlogsend -b radio -t TEST test
155 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
157 LOG_DETAILS="dlogctl --enable (multiple args)"
158 dlogctl --enable -b radio -b system
159 [ "$(dlogctl -g | grep regular | grep -c DISABLED )" -eq 1 ] &&
160 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c main)" -eq 1 ] &&
161 [ "$(dlogctl -g | grep regular | grep ENABLED | grep -c system)" -eq 1 ] &&
162 [ "$(dlogctl -g | grep regular | grep ENABLED | grep -c radio)" -eq 1 ] && ok || fail
163 LOG_DETAILS="testing if filters were applied"
164 dlogutil -c -b radio -b system -b main
165 dlogsend -b system -t TEST test
166 dlogsend -b main -t TEST test
167 dlogsend -b radio -t TEST test
168 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
170 LOG_DETAILS="dlogctl --enable (1 arg)"
171 dlogctl --enable -b main
172 [ "$(dlogctl -g | grep regular | grep -c DISABLED)" -eq 0 ] && ok || fail
173 LOG_DETAILS="testing if filters were applied"
174 dlogutil -c -b radio -b system -b main
175 dlogsend -b system -t TEST test
176 dlogsend -b main -t TEST test
177 dlogsend -b radio -t TEST test
178 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
180 LOG_DETAILS="dlogctl -s allow"
181 dlogutil -c -b radio -b system -b main
184 dlogctl -t TEST_TAG -s allow
185 dlogsend -b main -t TEST_TAG test
186 dlogsend -b main -t TEST test
187 [ "$(dlogutil -d -b main | wc -l)" -eq 1 ] && ok || fail
189 LOG_DETAILS="dlogctl -s [N]"
190 dlogutil -c -b radio -b system -b main
193 dlogctl -t TEST_TAG -s 3
194 dlogsend -b main -c 10 -t TEST_TAG test
195 dlogsend -b main -c 10 -t TEST test
196 [ "$(dlogutil -d -b main | wc -l)" -eq 4 ] && ok || fail
198 LOG_DETAILS="testing invalid parameters for dlogctl (1/13)"
199 dlogctl -s invalid > /dev/null && fail || ok
201 LOG_DETAILS="testing invalid parameters for dlogctl (2/13)"
202 dlogctl -p X -g > /dev/null && fail || ok
204 LOG_DETAILS="testing invalid parameters for dlogctl (3/13)"
205 dlogctl -b invalid --disable > /dev/null && fail || ok
207 LOG_DETAILS="testing invalid parameters for dlogctl (4/13)"
208 dlogctl -s allow -g -t xyz -p E > /dev/null && fail || ok
210 LOG_DETAILS="testing invalid parameters for dlogctl (5/13)"
211 dlogctl -s allow -c > /dev/null && fail || ok
213 LOG_DETAILS="testing invalid parameters for dlogctl (6/13)"
214 dlogctl -c -g -t xyz -p E > /dev/null && fail || ok
217 LOG_DETAILS="testing invalid parameters for dlogctl (7/13)"
218 dlogctl -s -10 > /dev/null && fail || ok
220 LOG_DETAILS="testing invalid parameters for dlogctl (8/13)"
221 dlogctl -s 999999 > /dev/null && fail || ok
224 LOG_DETAILS="testing invalid parameters for dlogctl (9/13)"
225 dlogctl -s 100 && ok || fail
227 LOG_DETAILS="testing invalid parameters for dlogctl (10/13)"
228 [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 1 ] && ok || fail
231 LOG_DETAILS="testing invalid parameters for dlogctl (11/13)"
232 [ "$(dlogctl -g | grep -F '*:*' | grep -c 100)" -eq 1 ] && ok || fail
235 LOG_DETAILS="testing invalid parameters for dlogctl (12/13)"
236 dlogctl -c -t '*' -p '*' && ok || fail
238 LOG_DETAILS="testing invalid parameters for dlogctl (13/13)"
239 [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 0 ] && ok || fail
242 LOG_DETAILS="testing if the whole dynamic config directory is respected"
244 cp $RUNTIME_FILTERS_DIR/05-logctl.conf $RUNTIME_FILTERS_DIR/10-other.conf
246 dlogutil -c -b radio -b system -b main
247 dlogsend -b system -t TEST test
248 dlogsend -b main -t TEST test
249 dlogsend -b radio -t TEST test
250 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
251 rm $RUNTIME_FILTERS_DIR/10-other.conf
255 SEED=$(head -c 6 /dev/urandom | base64)
256 dlogsend -b main -k "$SEED"
257 # -k is async, unlike normal mode; therefore we have to wait until the logging process actually finishes.
258 while pgrep "dlogsend" > /dev/null || pgrep "dlog-log-critical" > /dev/null; do :; done
259 CRIT_PATH="@DLOG_CRITICAL_LOGFILE_PATH@"
260 LOG_DETAILS="testing if critical logging works"
261 cat "$CRIT_PATH".a "$CRIT_PATH".b | grep -F "$SEED" > /dev/null && ok || fail
263 if [ "$type" = "pipe" ] && [ "$quick" -ne 1 ]; then
264 dlogsend -c 2 -d 2 -t DLOGSEND_SIGPIPE_TEST test &
267 kill -s PIPE $DLOGSEND_PID
269 LOG_DETAILS="testing if dlogsend logs even after SIGPIPE"
270 [ "$(dlogutil -d DLOGSEND_SIGPIPE_TEST | wc -l)" -eq 2 ] && ok || fail
275 LOG_DETAILS="testing if dlogutil rejects dotnet"
276 dlogutil -db dotnet_api && fail || ok
278 LOG_DETAILS="testing if dlogutil rejects native"
279 dlogutil -db native_api && fail || ok
281 LOG_DETAILS="testing if dotnet redirects to regular apps (1/2)"
282 dlogsend -b dotnet_api "TEST"
284 [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
286 LOG_DETAILS="testing if dotnet redirects to regular apps (2/2)"
287 dlogsend -c 6 -b dotnet_api "TEST"
289 [ "$(dlogutil -d -b apps | wc -l)" -eq 7 ] && ok || fail
291 LOG_DETAILS="testing if native redirects to regular apps (1/2)"
292 dlogsend -b native_api "TEST"
294 [ "$(dlogutil -d -b apps | wc -l)" -eq 8 ] && ok || fail
296 LOG_DETAILS="testing if native redirects to regular apps (2/2)"
297 dlogsend -c 6 -b native_api "TEST"
299 [ "$(dlogutil -d -b apps | wc -l)" -eq 14 ] && ok || fail
301 if [ "$type" != "zero-copy" ]; then # These tests are inherently dynamic.
303 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (1/4)"
304 dlogctl -b apps --enable
305 dlogctl -b dotnet_api --disable
306 dlogsend -b dotnet_api "TEST"
307 [ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
308 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (2/4)"
309 dlogsend -b apps "TEST"
310 [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
311 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (3/4)"
312 dlogctl -b apps --disable
313 dlogctl -b dotnet_api --enable
314 dlogsend -b dotnet_api "TEST"
315 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
316 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (4/4)"
317 dlogsend -b apps "TEST"
318 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
322 LOG_DETAILS="testing if blocking native and regular apps is separate (1/4)"
323 dlogctl -b apps --enable
324 dlogctl -b native_api --disable
325 dlogsend -b native_api "TEST"
326 [ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
327 LOG_DETAILS="testing if blocking native and regular apps is separate (2/4)"
328 dlogsend -b apps "TEST"
329 [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
330 LOG_DETAILS="testing if blocking native and regular apps is separate (3/4)"
331 dlogctl -b apps --disable
332 dlogctl -b native_api --enable
333 dlogsend -b native_api "TEST"
334 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
335 LOG_DETAILS="testing if blocking native and regular apps is separate (4/4)"
336 dlogsend -b apps "TEST"
337 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
340 # put 100 log entries in the "main" buffer
346 LOG_DETAILS="testing if dlogutil -d exits with success after printing logs"
347 dlogutil -d > /dev/null && ok || fail
349 LOG_DETAILS="testing if -t argument is parsed properly"
350 dlogutil -t dummy > /dev/null && fail || ok
352 LOG_DETAILS="testing if -u argument is parsed properly"
353 dlogutil -du dummy > /dev/null && fail || ok
355 LOG_DETAILS="testing if limiting printed log entries to less than exists in the buffer returns proper value"
356 [ "$(dlogutil -b main -t 20 | wc -l)" -eq 20 ] && ok || fail # less logs than currently in buffer
358 LOG_DETAILS="testing if limiting printed log entries to more than exists in the buffer returns proper value"
359 [ "$(dlogutil -b main -t 200 | wc -l)" -eq 100 ] && ok || fail # more
361 LOG_DETAILS="testing if dlogutil returns exact amount of entries as there is in the buffer"
362 [ "$(dlogutil -b main -d | wc -l)" -eq 100 ] && ok || fail # exactly
364 LOG_DETAILS="testing if reading from dummy buffer returns an error as expected"
365 dlogutil -b nonexistent_buffer > /dev/null && fail || ok
367 if [ "$type" != "zero-copy" ]; then # No buffer split in zero-copy
368 LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)"
369 [ "$(dlogutil -d -b system | wc -l)" -eq 0 ] && ok || fail
372 LOG_DETAILS="testing if dlogutil -c empties all buffers"
373 dlogutil -cb main && ok || fail
375 LOG_DETAILS="testing if writing entries to empty buffer and reading them returns proper amount of entries"
377 [ "$(dlogutil -b main -d | wc -l)" -eq 10 ] && ok || fail # should be 10, not 110
379 LOG_DETAILS="testing if filters work (1/3)"
380 [ "$(dlogutil -b main -d '*:E' | wc -l)" -eq 5 ] && ok || fail # half of current logs (test_libdlog alternates between error and info log levels)
382 LOG_DETAILS="testing if filters work (2/3)"
383 [ "$(dlogutil -b main -d '*:W' | wc -l)" -eq 5 ] && ok || fail
385 LOG_DETAILS="testing if filters work (3/3)"
386 [ "$(dlogutil -b main -d '*:I' | wc -l)" -eq 10 ] && ok || fail
388 LOG_DETAILS="testing if exact filters work (1/3)"
389 [ "$(dlogutil -b main -d '*:=E' | wc -l)" -eq 5 ] && ok || fail
391 LOG_DETAILS="testing if exact filters work (2/3)"
392 [ "$(dlogutil -b main -d '*:=W' | wc -l)" -eq 0 ] && ok || fail
394 LOG_DETAILS="testing if exact filters work (3/3)"
395 [ "$(dlogutil -b main -d '*:=I' | wc -l)" -eq 5 ] && ok || fail
397 LOG_DETAILS="testing if adding \"silent\" filter works"
398 [ "$(dlogutil -b main -s -d | wc -l)" -eq 0 ] && ok || fail
400 if [ "$type" != "zero-copy" ]; then # No buffer size access in zero-copy
401 LOG_DETAILS="testing if reading buffer size returns proper exit code"
402 dlogutil -gb main > /dev/null && ok || fail
405 LOG_DETAILS="testing if writing all entries to single file works (-f)"
406 dlogutil -f $TESTDIR/dlog_test_file -d > /dev/null && ok || fail
408 if [ "$quick" -ne 1 ]; then
409 LOG_DETAILS="testing if the continuous mode works as expected (1/2)"
410 dlogutil -b main -f $TESTDIR/dlog_continuous1_file &
413 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
415 [ "$WAS_ALIVE" -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous1_file)" -eq 10 ] && ok || fail
417 LOG_DETAILS="testing if the continuous mode works as expected (2/2)"
418 dlogutil -b main -f $TESTDIR/dlog_continuous2_file &
421 dlogsend -b main "Hi!"
423 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
425 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous2_file)" -eq 11 ] && ok || fail
427 LOG_DETAILS="testing if the monitor mode works as expected (1/2)"
428 dlogutil --monitor -b main -f $TESTDIR/dlog_monitor1_file &
431 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
433 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor1_file)" -eq 0 ] && ok || fail
435 LOG_DETAILS="testing if the monitor mode works as expected (2/2)"
436 dlogutil --monitor -b main -f $TESTDIR/dlog_monitor2_file &
439 dlogsend -b main "Hi!"
441 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
443 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor2_file)" -eq 1 ] && ok || fail
447 test_libdlog 100000 &
448 LIBDLOGUTIL_CORRECT_PID=$!
449 wait $LIBDLOGUTIL_CORRECT_PID
451 # NB: rotation only really makes sense in the continuous mode
452 # from a user PoV, but the logic doesn't care about dumping
453 # so we do it to simplify things
454 dlogutil -df $TESTDIR/dlog_rotating_file -r 12 -n 3 # 3 files at 12 KB each
456 LOG_DETAILS="testing if single file is properly created"
457 if [ -e $TESTDIR/dlog_test_file ]; then ok; else fail; fi
459 LOG_DETAILS="testing if rotating file is properly created (1/4)"
460 if [ -e $TESTDIR/dlog_rotating_file.1 ]; then ok; else fail; fi
462 LOG_DETAILS="testing if rotating file is properly created (2/4)"
463 if [ -e $TESTDIR/dlog_rotating_file.2 ]; then ok; else fail; fi
465 LOG_DETAILS="testing if rotating file is properly created (3/4)"
466 if [ -e $TESTDIR/dlog_rotating_file.3 ]; then ok; else fail; fi
468 LOG_DETAILS="testing if rotating file is properly created (4/4)"
469 if [ -e $TESTDIR/dlog_rotating_file.4 ]; then fail; else ok; fi
471 LOG_DETAILS="testing the size of log files"
472 if [ "$(du "$TESTDIR"/dlog_rotating_file.3 | sed "s#$TESTDIR/dlog_rotating_file.3##g")" -eq 16 ]; then ok; else fail; fi # the actual size is one sector more (so 12 -> 16) because the limit is checked after reaching it, not before
474 LOG_DETAILS="testing if libdlogutil works correctly in the dump mode"
475 test_libdlogutil dump $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
476 if [ "$quick" -ne 1 ]; then
477 LOG_DETAILS="testing if libdlogutil works correctly if processing the logs takes some time"
478 test_libdlogutil timer $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
480 LOG_DETAILS="testing if libdlogutil works correctly in the continuous mode"
481 test_libdlogutil continuous $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
482 LOG_DETAILS="testing if libdlogutil skips all the logs in the monitor mode correctly"
483 test_libdlogutil monitor $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
484 LOG_DETAILS="testing if libdlogutil priority filter works correctly"
485 test_libdlogutil priority $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
486 LOG_DETAILS="testing if libdlogutil exact priority filter works correctly"
487 test_libdlogutil priority_exact $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
488 LOG_DETAILS="testing if libdlogutil limits the log amount correctly"
489 test_libdlogutil limit $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
490 LOG_DETAILS="testing if libdlogutil PID filter works correctly (1/2)"
491 test_libdlogutil pid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
492 LOG_DETAILS="testing if libdlogutil PID filter works correctly (2/2)"
493 test_libdlogutil pid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
494 LOG_DETAILS="testing if libdlogutil TID filter works correctly (1/2)"
495 test_libdlogutil tid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
496 LOG_DETAILS="testing if libdlogutil TID filter works correctly (2/2)"
497 test_libdlogutil tid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
498 LOG_DETAILS="testing if libdlogutil tag filter works correctly (1/2)"
499 test_libdlogutil tag_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
500 LOG_DETAILS="testing if libdlogutil tag filter works correctly (2/2)"
501 test_libdlogutil tag_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
502 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (1/2)"
503 test_libdlogutil prefix_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
504 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (2/2)"
505 test_libdlogutil prefix_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
506 if [ "$type" != "zero-copy" ]; then # These rely on things not available in zero-copy
507 LOG_DETAILS="testing if libdlogutil returns the correct buffer traits"
508 test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
509 LOG_DETAILS="testing if libdlogutil aliasing works"
510 if [ "$type" = "pipe" ]; then
511 test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
513 DLOG_CONFIG_PATH="@datadir@/dlog-logger.conf.alias" test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
516 LOG_DETAILS="testing if libdlogutil errors out correctly if used improperly"
517 test_libdlogutil negative $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
519 cmd_prefix_no_v="dlogutil -t 1 -u 0"
520 cmd_prefix="$cmd_prefix_no_v -v"
523 regex_prio="[VDIWEFS]{1}"
524 regex_pidtid="P[0-9[:space:]]{5,},\s{1}T[0-9[:space:]]{5,}"
525 regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
526 regex_timezone="[\+-]{1}[0-9]{4}"
528 for PARAM in always auto none never; do
529 for PRIO in info error; do
530 for OUTPUT in pipe tty; do
531 if [ "$PARAM" = "always" ]; then
533 elif [ "$PARAM" = "never" ]; then
535 elif [ "$OUTPUT" = "tty" ]; then
541 if [ "$PRIO" = "info" ]; then
542 REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
543 elif [ "$COLOR_EXPECTED" -eq 0 ]; then
544 REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
546 REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m \([[:print:]]*\)@~\[0m$/1/g"
549 # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
550 COMMAND="$cmd_prefix $format"
552 if [ "$PARAM" = "none" ]; then
553 LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
555 COMMAND="$COMMAND --color=$PARAM"
556 LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
559 if [ "$PRIO" = "info" ]; then
560 COMMAND="$COMMAND '*:=I'"
562 COMMAND="$COMMAND '*:=E'"
565 if [ "$OUTPUT" = "tty" ]; then
566 # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
567 COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
570 # $(eval) is needed since `$COMMAND` may contain `"`
571 line="$(eval "$COMMAND" | tr '\033\n' '~@')"
572 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
576 # TODO: It would be cool to also test warning messages (which have a different color),
577 # but this would require deeper changes to this script, which is already janky enough.
579 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
580 LOG_DETAILS="testing if \"$format\" print format works"
581 line=$($cmd_prefix $format)
582 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
585 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[:print:]]*$/1/g"
586 LOG_DETAILS="testing if \"$format\" print format works"
587 line=$($cmd_prefix $format)
588 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
591 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
592 LOG_DETAILS="testing if \"$format\" print format works"
593 line=$($cmd_prefix $format)
594 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
597 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
598 LOG_DETAILS="testing if \"$format\" print format works"
599 line=$($cmd_prefix $format)
600 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
603 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
604 LOG_DETAILS="testing if \"$format\" print format works"
605 line=$($cmd_prefix $format)
606 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
609 REGEX="s/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
610 LOG_DETAILS="testing if \"$format\" print format works"
611 line=$($cmd_prefix $format)
612 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
614 format="recv_realtime"
615 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
616 LOG_DETAILS="testing if \"$format\" print format works"
617 line=$($cmd_prefix $format)
618 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
621 REGEX="s/^$regex_time\s{1}\[[0-9[:space:]]{3,}.[0-9[:space:]]{3,}\]\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
622 LOG_DETAILS="testing if \"$format\" print format works"
623 line=$($cmd_prefix $format)
624 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
627 REGEX="s/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]@[[:print:]]+@$/1/g"
628 LOG_DETAILS="testing if \"$format\" print format works"
629 line=$($cmd_prefix $format)
630 [ "$(echo "$line" | tr '\n' '@' | sed -re "$REGEX")" = "1" ] && ok || fail
633 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
634 LOG_DETAILS="testing if \"$format\" print format works"
635 line=$($cmd_prefix $format)
636 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
639 if [ "$type" = "pipe" ]; then
640 REGEX="s/^\{\"priority\":\"(verbose|debug|info|warning|error|fatal|silent)\",\"pid\":[1-9][0-9]*,\"tid\":[1-9][0-9]*,\"recv_real\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$regex_timezone\",\"recv_real_ns\":[1-9][0-9]*,\"recv_mono\":[1-9][0-9]+\.[0-9]{9},\"sent_real\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$regex_timezone\",\"sent_real_ns\":[1-9][0-9]*,\"sent_mono\":[1-9][0-9]+\.[0-9]{9},\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
641 elif [ "$type" = "logger" ]; then
642 REGEX="s/^\{\"priority\":\"(verbose|debug|info|warning|error|fatal|silent)\",\"pid\":[1-9][0-9]*,\"tid\":[1-9][0-9]*,\"sent_real\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$regex_timezone\",\"sent_real_ns\":[1-9][0-9]*,\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
644 REGEX="s/^\{\"priority\":\"(verbose|debug|info|warning|error|fatal|silent)\",\"pid\":[1-9][0-9]*,\"tid\":[1-9][0-9]*,\"sent_mono\":[1-9][0-9]+\.[0-9]{9},\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
646 LOG_DETAILS="testing if \"$format\" print format works"
647 line=$($cmd_prefix $format)
648 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
650 SOURCE="$DLOG_CONFIG_PATH"
651 DLOG_CONFIG_PATH="$TESTDIR/defaultprintformat.conf"
652 cp "$SOURCE" "$DLOG_CONFIG_PATH"
654 # TODO: It would be good to also test the daemon side of things.
655 LOG_DETAILS="testing default log format selection (none -> brief)"
656 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
657 line=$($cmd_prefix_no_v)
658 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
660 echo "util_default_format=rwtime" >> $DLOG_CONFIG_PATH
661 LOG_DETAILS="testing default log format selection (rwtime)"
662 REGEX="s/^$regex_time\s{1}\[[0-9[:space:]]{3,}.[0-9[:space:]]{3,}\]\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
663 line=$($cmd_prefix_no_v)
664 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
666 DLOG_CONFIG_PATH="$SOURCE"
669 LOG_DETAILS="testing if \"$format\" print format works"
671 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
672 line=$($cmd_prefix $format)
673 [ "$line" = "rawformatTEST" ] && ok || fail
675 if [ "$quick" -ne 1 ]; then
676 LOG_DETAILS="testing if dlogsend -d works"
678 dlogsend -b main -c 9999 -d 4 -f 7 -t DLOG_TESTSUITE "hi" &
682 # In 10 seconds, 3 cycles 7 logs each should have happened.
683 [ "$(dlogutil -d DLOG_TESTSUITE | wc -l)" -eq 21 ] && ok || fail
686 if [ "$type" = "pipe" ]; then
687 for format in raw brief long; do
688 for i in 1 2 3 4 5 6 7 8 10 15 20 25 513 514 515 516 517 518 519 520; do
689 LOG_DETAILS="testing if padding works correctly (format $format/count $i)"
690 log=$(printf '%0.s&' $(seq 1 $i)) # Print the '&' character $i times
693 dlogsend -b main "$log"
694 line=$($cmd_prefix $format | tr '\n' '@')
701 REGEX="s/I\/DLOG_SEND\([0-9[:space:]]{5,}\):\s{1}$log@$/1/g"
704 REGEX="s/\[\s{1}$regex_time.[0-9]{3,}\s{1}I\/DLOG_SEND\s{1}$regex_pidtid\]@$log@@/1/g"
708 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
713 if [ "$type" != "zero-copy" ]; then # No KMSG in zero-copy
714 LOG_DETAILS="testing if KMSG works in the default format"
715 # We check if the command returns at least 100 logs. This seems to be a safe value.
716 # Feel free to change it to a reasonable yet lower value if the test happens to fail otherwise.
717 [ "$(dlogutil -db kmsg | wc -l)" -gt 100 ] && ok || fail
720 if [ "$quick" -ne 1 ]; then
721 if [ "$type" != "zero-copy" ]; then # No KMSG in zero-copy
722 LOG_DETAILS="testing if KMSG works in the raw format"
723 last_dmesg=$(dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g")
724 sleep 1 # To make sure dlog has already parsed the log
725 dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail
728 dlog_test_tid_filtering_secure_logging $type
735 dlogsend -b main -t DLOG_TESTSUITE_TAG0 -pI tagTEST0
736 dlogsend -b main -t DLOG_TESTSUITE_TAG1 -pI tagTEST1
737 dlogsend -b main -t DLOG_TESTSUITE_TAG2 -pF tagTEST2
739 LOG_DETAILS="testing if tag filtering works (1/8)"
740 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG0' | wc -l)" -eq 1 ] && ok || fail
741 LOG_DETAILS="testing if tag filtering works (2/8)"
742 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG1' | wc -l)" -eq 1 ] && ok || fail
743 LOG_DETAILS="testing if tag filtering works (3/8)"
744 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG' | wc -l)" -eq 0 ] && ok || fail
745 LOG_DETAILS="testing if tag filtering works (4/8)"
746 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*' | wc -l)" -eq 3 ] && ok || fail
747 LOG_DETAILS="testing if tag filtering works (5/8)"
748 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:I' | wc -l)" -eq 3 ] && ok || fail
749 LOG_DETAILS="testing if tag filtering works (6/8)"
750 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:W' | wc -l)" -eq 1 ] && ok || fail
751 LOG_DETAILS="testing if tag filtering works (7/8)"
752 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG' | wc -l)" -eq 0 ] && ok || fail
753 LOG_DETAILS="testing if tag filtering works (8/8)"
754 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l)" -eq 0 ] && ok || fail
756 if [ "$type" != "zero-copy" ]; then # No dynamic filters in zero-copy
757 LOG_DETAILS="testing if limiter and runtime filtering works"
760 [ "$(dlogutil -d -b radio | wc -l)" -eq 12 ] && ok || fail
763 LOG_DETAILS="testing proper SMACK label for dynamic config file location"
764 ORIG_FILTERS_DIR=$(grep dynamic_config_path "$ORIGINAL_CONFIG_PATH" | awk -F "=" '{print $2}')
765 # Running ls on an arbitrary directory and trying to make sense of results is problematic.
766 # However, this is not a problem in our usecase, as we only care about the first field, the security context.
767 # We don't even care about the filename, which isn't arbitrary anyway (-d on fixed path).
768 # shellcheck disable=SC2012
769 [ "$(ls -dZ "$ORIG_FILTERS_DIR" | awk -F ' ' '{print $1}')" = "System::Shared" ] && ok || fail
771 if [ "$quick" -ne 1 ]; then
772 # This creates a process which will wait for SIGCONT and then spam logs. We know its PID, so we can add
773 # PID-based limits and see what happens.
774 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
776 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
777 dlogctl --pid $DLOGSEND_PID -s deny
778 kill -s CONT $DLOGSEND_PID
780 LOG_DETAILS="testing if PID limiting works (1/14)"
781 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 0 ] && ok || fail
782 LOG_DETAILS="testing if PID limiting works (2/14)"
783 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 1 ] && ok || fail
784 LOG_DETAILS="testing if PID limiting works (3/14)"
785 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = "Denied" ] && ok || fail
786 LOG_DETAILS="testing if PID limiting works (4/14)"
787 dlogctl -g | grep -q "Denied for $DLOGSEND_PID" && ok || fail
789 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
791 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
792 dlogctl --pid $DLOGSEND_PID -s 25
793 kill -s CONT $DLOGSEND_PID
795 LOG_DETAILS="testing if PID limiting works (5/14)"
796 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 25 ] && ok || fail
797 LOG_DETAILS="testing if PID limiting works (6/14)"
798 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 1 ] && ok || fail
799 LOG_DETAILS="testing if PID limiting works (7/14)"
800 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = '25 logs/min' ] && ok || fail
801 LOG_DETAILS="testing if PID limiting works (8/14)"
802 dlogctl -g | grep -q "25 logs/min for $DLOGSEND_PID" && ok || fail
804 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
806 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
807 dlogctl --pid $DLOGSEND_PID -s allow
808 kill -s CONT $DLOGSEND_PID
810 LOG_DETAILS="testing if PID limiting works (9/14)"
811 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 100 ] && ok || fail
812 LOG_DETAILS="testing if PID limiting works (10/14)"
813 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 0 ] && ok || fail
814 LOG_DETAILS="testing if PID limiting works (11/14)"
815 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = 'Unlimited' ] && ok || fail
816 LOG_DETAILS="testing if PID limiting works (12/14)"
817 dlogctl -g | grep -q "Unlimited for $DLOGSEND_PID" && ok || fail
819 echo "qos_refresh_rate_s=5" > "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
820 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 15 -d 1 "Pid test"' &
822 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
823 dlogctl --pid $DLOGSEND_PID -s 2
824 kill -s CONT $DLOGSEND_PID
826 rm "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
827 LOG_DETAILS="testing if PID limiting works (13/14)"
828 # In each 5 second period, 5 logs are sent, so there are 3 periods.
829 # 2 logs from each period are allowed.
830 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 6 ] && ok || fail
831 LOG_DETAILS="testing if PID limiting works (14/14)"
832 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 3 ] && ok || fail
834 PREQOS_CONFIG_PATH=$DLOG_CONFIG_PATH
835 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.qos"
836 kill $LOGGER > /dev/null
838 if [ "$type" = "logger" ]; then
845 dlogsend -b main -t DLOG_QOS_TEST0 -c 30 -d 1 -f 2 "A normal app that just wants to log"
846 LOG_DETAILS="testing if QoS works (1/4)"
847 [ "$(dlogutil -d DLOG_QOS_TEST0 | grep -cv blocked)" -eq 30 ] && ok || fail
848 kill $LOGGER > /dev/null
850 if [ "$type" = "logger" ]; then
857 dlogsend -b main -t DLOG_QOS_TEST1 -c 300 -d 1 -f 20 "Some log spam"
858 LOG_DETAILS="testing if QoS works (2/4)"
859 [ "$(dlogutil -d DLOG_QOS_TEST1 | grep -cv blocked)" -le 210 ] && ok || fail
860 kill $LOGGER > /dev/null
862 if [ "$type" = "logger" ]; then
869 dlogsend -b main -t DLOG_QOS_TEST2 -c 30 -d 1 -f 2 "A normal app that just wants to log" &
871 dlogsend -b main -t DLOG_QOS_TEST3 -c 270 -d 1 -f 18 "Some log spam"
873 LOG_DETAILS="testing if QoS works (3/4)"
874 [ "$(dlogutil -d DLOG_QOS_TEST2 DLOG_QOS_TEST3 | grep -cv blocked)" -le 210 ] && ok || fail
875 LOG_DETAILS="testing if QoS works (4/4)"
876 [ "$(dlogutil -d DLOG_QOS_TEST2 | grep -cv blocked)" -gt 24 ] && ok || fail
878 DLOG_CONFIG_PATH=$PREQOS_CONFIG_PATH
879 kill $LOGGER > /dev/null
885 # limiter test (the feature allows to enable/disable particular log type)
886 dlogsend -c 11 -d 1 -t QWE blabla &
889 dlogctl -t QWE -s deny
890 LOG_DETAILS="testing if log limiter works (deny) (1/3)"
891 [ "$(dlogutil -d QWE | wc -l)" -eq 1 ] && ok || fail
893 LOG_DETAILS="testing if log limiter works (deny) (2/3)"
894 [ "$(dlogutil -d QWE | wc -l)" -eq 1 ] && ok || fail
896 dlogctl -t QWE -s allow
898 LOG_DETAILS="testing if log limiter works (allow) (3/3)"
899 [ "$(dlogutil -d QWE | wc -l)" -eq 5 ] && ok || fail
905 if [ "$LEGACY_LOGGER" -ne 1 ] && [ "$quick" -ne 1 ]; then
908 LOG_DETAILS="testing if basic stdout redirection works correctly (1/2)"
909 [ "$(dlog_redirect_stdout --outtag FOO -- /usr/bin/echo Hi)" = "" ] && ok || fail
911 LOG_DETAILS="testing if basic stdout redirection works correctly (2/2)"
912 [ "$(dlogutil -db main -v tag)" = "I/FOO : Hi" ] && ok || fail
915 # No need to check output in this case, as nothing is written to stdout anyway
916 dlog_redirect_stdout --errtag BAR -- /usr/bin/sh -c "echo Hi >&2"
918 LOG_DETAILS="testing if basic stderr redirection works correctly"
919 [ "$(dlogutil -db main -v tag)" = "E/BAR : Hi" ] && ok || fail
922 LOG_DETAILS="testing if redirector doesn't redirect anything by default (1/2)"
923 [ "$(dlog_redirect_stdout -- /usr/bin/echo Hi)" = "Hi" ] && ok || fail
925 LOG_DETAILS="testing if redirector doesn't redirect anything by default (2/2)"
926 [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
929 if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy
930 dlog_redirect_stdout --outbuffer radio --outtag AN_INTERESTING_TAG --outprio W -- /usr/bin/echo Hi
932 LOG_DETAILS="testing if redirector settings work correctly on stdout (1/2)"
933 [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
934 LOG_DETAILS="testing if redirector settings work correctly on stdout (2/2)"
935 [ "$(dlogutil -db radio -v tag)" = "W/AN_INTERESTING_TAG: Hi" ] && ok || fail
938 dlog_redirect_stdout --errbuffer radio --errtag ANOTHER_INTERESTING_TAG --errprio I -- /usr/bin/sh -c "echo Hi >&2"
940 LOG_DETAILS="testing if redirector settings work correctly on stderr (1/2)"
941 [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
942 LOG_DETAILS="testing if redirector settings work correctly on stderr (2/2)"
943 [ "$(dlogutil -db radio -v tag)" = "I/ANOTHER_INTERESTING_TAG: Hi" ] && ok || fail
947 echo "Testing" | dlog_redirect_stdout --outtag BAZ -- /usr/bin/cat
949 LOG_DETAILS="testing if redirector passes stdin correctly"
950 [ "$(dlogutil -db main -v tag)" = "I/BAZ : Testing" ] && ok || fail
953 dlog_redirect_stdout --outtag QUUX -- /usr/bin/cat << EOF
961 LOG_DETAILS="testing if multiline logs are handled correctly"
962 [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
965 dlog_redirect_stdout --outtag QUUX -- /usr/bin/sh -c "printf \"line 1\0line 2\0line 3\0line 4\0line 5\""
967 LOG_DETAILS="testing if logs with the '\\0' character are handled correctly"
968 [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
971 dlog_redirect_stdout --outtag QUUX -- /usr/bin/sh -c "printf \"line 1\0line 2\nline 3\0line 4\nline 5\""
973 LOG_DETAILS="testing if logs with mixed delimiters are handled correctly"
974 [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
977 rm -f "$TESTDIR"/input
978 rm -f "$TESTDIR"/output
979 base64 -w 0 < /dev/urandom 2> /dev/null | head -c 250000 > "$TESTDIR"/input
980 dlog_redirect_stdout --outtag XYZZY -- /usr/bin/cat "$TESTDIR"/input
982 dlogutil -db main -v raw | tr -d '\n' > "$TESTDIR"/output
983 LOG_DETAILS="testing if long lines are handled correctly"
984 # Usually we would just diff or cmp the files. Unfortunately, as of writing, Tizen doesn't have such luxuries.
985 [ "$(sha256sum < "$TESTDIR"/input)" = "$(sha256sum < "$TESTDIR"/output)" ] && ok || fail
988 if [ "$type" = "pipe" ]; then
989 # TODO: Actually implement and enable this in the logger backend
990 dlogctl -b main --disable-stdout
991 LOG_DETAILS="testing if redirection can be disabled (1/3)"
992 [ "$(dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test)" = "" ] && ok || fail
994 LOG_DETAILS="testing if redirection can be disabled (2/3)"
995 [ "$(dlogutil -db main -v raw)" = "" ] && ok || fail
996 LOG_DETAILS="testing if redirection can be disabled (3/3)"
997 [ "$(dlogctl --get | grep 'main (regular)')" = "* main (regular): ENABLED" ] && ok || fail
999 dlogctl -b main --enable-stdout
1000 LOG_DETAILS="testing if redirection can be reenabled (1/3)"
1001 [ "$(dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test)" = "" ] && ok || fail
1003 LOG_DETAILS="testing if redirection can be reenabled (2/3)"
1004 [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail
1005 LOG_DETAILS="testing if redirection can be reenabled (3/3)"
1006 [ "$(dlogctl --get | grep 'main (regular)')" = "* main (regular): ENABLED" ] && ok || fail
1010 if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy
1011 dlogctl -b radio --disable-stdout
1012 dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test
1014 LOG_DETAILS="testing if dlogctl --disable-stdout respects buffer choice"
1015 [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail
1019 LOG_DETAILS="testing if redirection check works (1/5)"
1020 test_libredirect 0 0 && ok || fail
1021 LOG_DETAILS="testing if redirection check works (2/5)"
1022 dlog_redirect_stdout -- /usr/libexec/libdlog/test_libredirect 0 0 && ok || fail
1023 LOG_DETAILS="testing if redirection check works (3/5)"
1024 dlog_redirect_stdout --outtag X -- /usr/libexec/libdlog/test_libredirect 1 0 && ok || fail
1025 LOG_DETAILS="testing if redirection check works (4/5)"
1026 dlog_redirect_stdout --errtag X -- /usr/libexec/libdlog/test_libredirect 0 1 && ok || fail
1027 LOG_DETAILS="testing if redirection check works (5/5)"
1028 dlog_redirect_stdout --outtag X --errtag Y -- /usr/libexec/libdlog/test_libredirect 1 1 && ok || fail
1030 if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy
1031 LOG_DETAILS="testing if multiple redirections work (1/4)"
1032 test_libredirect_multi && ok || fail
1033 LOG_DETAILS="testing if multiple redirections work (2/4)"
1034 [ "$(dlogutil -db main -v tag | grep "Message 1")" = "W/TAG1 : Message 1" ] && ok || fail
1035 LOG_DETAILS="testing if multiple redirections work (3/4)"
1036 [ "$(dlogutil -db main -v tag | grep "Message 2")" = "E/TAG2 : Message 2" ] && ok || fail
1037 LOG_DETAILS="testing if multiple redirections work (4/4)"
1038 [ "$(dlogutil -db system -v tag)" = "I/TAG3 : Message 3" ] && ok || fail
1039 dlogutil -cb main -b system
1043 if [ "$type" != "zero-copy" ]; then # No dynamic filters in zero-copy
1045 echo "deduplicate_method=only_identical_neighbours" > "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1046 echo "deduplicate_interval_ms=10" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1048 dlogsend -p Info -b main -c 9 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
1049 LOG_DETAILS="testing if deduplication with warnings works properly (1/12)"
1050 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 1 ] && ok || fail
1051 LOG_DETAILS="testing if deduplication with warnings works properly (2/12)"
1052 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 0 ] && ok || fail
1054 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
1055 LOG_DETAILS="testing if deduplication with warnings works properly (3/12)"
1056 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 3 ] && ok || fail
1057 LOG_DETAILS="testing if deduplication with warnings works properly (4/12)"
1058 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 1 ] && ok || fail
1060 echo "deduplicate_warn_quantity=8" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1062 dlogsend -p Info -b main -c 24 -t DLOG_DEDUP_TEST Message
1063 LOG_DETAILS="testing if deduplication with warnings works properly (5/12)"
1064 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 4 ] && ok || fail
1065 LOG_DETAILS="testing if deduplication with warnings works properly (6/12)"
1066 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Message LOG DUPLICATED')" -eq 3 ] && ok || fail
1068 dlogsend -p Info -b main -c 8 -t DLOG_DEDUP_TEST longerMessage
1069 LOG_DETAILS="testing if deduplication with warnings works properly (7/12)"
1070 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c longerMessage)" -eq 2 ] && ok || fail
1071 LOG_DETAILS="testing if deduplication with warnings works properly (8/12)"
1072 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 6 ] && ok || fail
1073 LOG_DETAILS="testing if deduplication with warnings works properly (9/12)"
1074 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'longerMessage LOG DUPLICATED')" -eq 1 ] && ok || fail
1076 echo "deduplicate_warn_quantity=-1" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1078 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, no warning"
1079 LOG_DETAILS="testing if deduplication with warnings works properly (10/12)"
1080 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning')" -eq 1 ] && ok || fail
1081 LOG_DETAILS="testing if deduplication with warnings works properly (11/12)"
1082 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication')" -eq 4 ] && ok || fail
1083 LOG_DETAILS="testing if deduplication with warnings works properly (12/12)"
1084 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning LOG DUPLICATED')" -eq 0 ] && ok || fail
1086 rm "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1089 LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
1090 sleep 1 # make sure the earlier logs are handled so that they don't end up handled after the clear
1091 test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
1093 if [ "$(date +%Y)" -le 2000 ]; then
1094 # This implies that the date isn't set. Let's set it to some date to better test timestamps.
1095 date -s "@2121212121" > /dev/null
1097 dlogsend -b main -t DLOG_TS_TEST "The future is now, old man"
1098 LOG_DETAILS="testing if the timestamps are correct"
1099 test_verifytime && ok || fail
1101 DLOG_PREV_PATH=$DLOG_CONFIG_PATH
1103 dlog_test_stdout_redirect $type
1105 DLOG_CONFIG_PATH=$DLOG_PREV_PATH
1107 if [ "$quick" -ne 1 ]; then
1108 if [ "$type" != "zero-copy" ]; then # Backend autodection and logger daemon stuff don't really work on zero-copy
1109 kill $LOGGER > /dev/null
1112 dlog_test_backend_autodetection $type
1113 dlog_test_logger_buffering_logging $type
1120 LOG_DETAILS="testing if the library works with multithreaded app"
1121 dlogutil -f $TESTDIR/dlog_mt_test &
1123 test_libdlog && ok || fail
1132 # Spawn logging scripts and wait for them to finish.
1133 # We launch all the $SPAWN_CNT scripts in a subshell, and then use the wait command in order to
1134 # wait for all the jobs of the subshell, which means all the logging scripts.
1135 # Each of the logging scripts is a new subsubshell which waits a random amount of seconds and then logs
1136 # a single message. This gets us 5 groups of logs separated by a second; there are about 200 logs in each
1137 # group, sent about at the same time.
1139 for i in $(seq 1 $SPAWN_CNT); do
1140 delay=$(shuf -i 1-5 -n 1)
1141 ( sleep "$delay" && dlogsend -b main -t DLOG_TESTSUITE "$delay" ) &
1146 LOG_DETAILS="testing if libdlogutil sorts by the timestamp correctly"
1148 test_libdlogutil sorting $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
1150 if [ "$type" = "pipe" ]; then
1151 for P in recv sent; do
1152 for Q in mono real; do
1153 LOG_DETAILS="testing if dlogutil --sort-by works correctly (${P}_${Q})"
1154 [ "$(dlogutil -db main --sort-by "${P}_${Q}" | wc -l)" -eq "$SPAWN_CNT" ] && ok || fail
1157 for P in recv sent; do
1158 LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_mono)"
1159 dlogutil -db main --sort-by "${P}_mono" -v json | sed -Ee "s/^.*\"${P}_mono\":([^,}]*).*\$/\\1/" | sort -c && ok || fail
1160 LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_real)"
1161 dlogutil -db main --sort-by "${P}_real" -v json | sed -Ee "s/^.*\"${P}_real\":\"([^\"]*)\",\"${P}_real_ns\":([^,}]*).*\$/\\1 \2/" | sort -c -k1,1 -k2,2g && ok || fail
1165 sort_formats="kerneltime time recv_realtime rwtime threadtime long"
1167 for format in $sort_formats; do
1168 LOG_DETAILS="testing if sorting by timestamp from random sources on heavy load works ($format format)"
1170 # collect data and analyze timestamps
1171 dlogutil -b main -d -v "$format" | (
1175 while read -r line; do
1176 # filter out empty lines in "long" format
1177 [ -z "$line" ] && continue
1178 # filter out non-timestamp lines in "long" format
1179 if [ "$format" = "long" ] && [ "$(echo "$line" | sed -re 's/^\[[:print:]*\]$/line_ok/g')" != "line_ok" ]; then
1183 ts=$(extract_timestamp "$format" "$line")
1185 if [ "$ts" -ge "$prev_ts" ]; then
1188 printf "%s\n%s\n\n" "$prev_line" "$line" || break
1192 ) | grep -q ^ && fail || ok
1197 if [ "$type" = "pipe" ]; then
1198 kill $LOGGER > /dev/null
1201 PRERESIZE_CONFIG_PATH="$DLOG_CONFIG_PATH"
1202 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.compress"
1204 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
1205 mkdir -m 777 -p "$RUNTIME_FILTERS_DIR"
1211 dlogsend -b main -c 9999 resizetestblalbl &
1213 LOG_DETAILS="testing if compression-resize works (1/3)"
1214 [ "$(dlogutil -d -m xyz123 | wc -l)" -ge 1 ] && ok || fail
1216 dlogctl --compression-name xyz123 --compression-resize 1
1218 LOG_DETAILS="testing if compression-resize works (2/3)"
1219 [ "$(dlogutil -d -m xyz123 | wc -l)" -eq 0 ] && ok || fail
1221 dlogctl --compression-name xyz123 --compression-resize 200000
1222 dlogsend -b main -c 9999 resizetestblalbl &
1224 LOG_DETAILS="testing if compression-resize works (3/3)"
1225 [ "$(dlogutil -d -m xyz123 | wc -l)" -ge 1 ] && ok || fail
1228 kill $LOGGER > /dev/null
1229 DLOG_CONFIG_PATH=$PRERESIZE_CONFIG_PATH
1230 rm -rf $RUNTIME_FILTERS_DIR
1233 # show results, clean up and return an exit code
1235 echo "$OKS / $TOTAL tests passed"
1236 echo "$FAILS / $TOTAL tests failed"
1238 if [ "$quick" -eq 1 ]; then
1239 echo "WARNING: quick mode!"
1240 echo "About 20% slowest running tests are disabled. Some functionality might be untested."
1241 echo "Rerun without '--quick' to run all tests."
1242 elif [ "$LEGACY_LOGGER" -eq 1 ]; then
1243 echo "WARNING: legacy logger module!"
1244 echo "Some functionality is untested."
1245 echo "Rerun on a device with the out-of-tree logger module to run all tests."
1249 # THE LINE ABOVE MUST STAY THE LAST COMMAND IN THE FILE!
1250 # This is because it is used to pass the exit code. If another command
1251 # is executed after it, its exit code will be propagated instead.