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
10 #relevant pids default vals
15 TEST_DYNAMIC_FILTERS=true
19 [ "$UTIL_PID" -ne -1 ] && kill "$UTIL_PID" > /dev/null 2>&1
20 [ "$MT_TEST" -ne -1 ] && kill "$MT_TEST" > /dev/null 2>&1
21 [ "$LOGGER" -ne -1 ] && kill "$LOGGER" > /dev/null 2>&1
22 # Shellcheck doesn't like this because the rm call is bad if $TESTDIR is empty.
23 # However, such cases would be caught by the conditional.
24 # shellcheck disable=SC2115
25 [ -d "$TESTDIR" ] && rm -rf "$TESTDIR"/*
26 [ -d "$RUNTIME_FILTERS_DIR" ] && rm -rf "$RUNTIME_FILTERS_DIR"
31 USAGE_MESSAGE="usage: $0 [--verbose] [--quick] pipe|logger|zero-copy"
33 OPTS=$(getopt --shell sh --options "" --long verbose,quick --quiet -- "$@")
34 if [ "$?" -eq 1 ]; then
55 echo "This should never happen :)"
61 if [ "$1" = "pipe" ]; then
63 elif [ "$1" = "logger" ]; then
65 elif [ "$1" = "zero-copy" ]; then
67 # We still accept the legacy {pipe,logger}_quick syntax because there's no reason not to.
68 elif [ "$1" = "pipe_quick" ]; then
71 elif [ "$1" = "logger_quick" ]; then
79 # supress stderr messages from subcommands
80 if [ "$verbose" -eq 0 ]; then
85 capsh --print | grep Current | grep cap_syslog > /dev/null || { echo "*** ERROR: cap_syslog missing"; NEEDS_TO_QUIT=1; }
86 mount | grep ' / ' | grep rw > /dev/null || { echo "*** ERROR: root not mounted read-write"; NEEDS_TO_QUIT=1; }
87 [ "$NEEDS_TO_QUIT" -eq 0 ] || exit 1
89 if [ "$type" = "pipe" ] || [ -f /lib/modules/"$(uname -r)"/extra/logger.ko ]; then
95 if [ -z "$DLOG_CONFIG_PATH" ]; then
96 ORIGINAL_CONFIG_PATH="/etc/dlog.conf"
98 ORIGINAL_CONFIG_PATH="$DLOG_CONFIG_PATH"
101 export DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.test"
102 PATH=$PATH:@libexecdir@/libdlog/
104 if [ "$type" != "zero-copy" ]; then # These tests are inherently dynamic.
105 #create dir for runtime filters
106 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
107 mkdir -m 777 -p "$RUNTIME_FILTERS_DIR"
109 PREEARLYQUIT_CONFIG_PATH="$DLOG_CONFIG_PATH"
110 DLOG_CONFIG_PATH="$TESTDIR/earlyquit.conf"
111 if [ "$quick" -ne 1 ]; then
112 for PERSISTENT in 1 0; do
114 for SYSLOG in 1 0; do
116 # TODO: Does syslog even work? Disabling for now.
117 [ "$SYSLOG" -eq 1 ] && continue
119 if [ "$QOS" -eq 1 ]; then
120 SOURCE="@datadir@/dlog-$type.conf.qos"
122 SOURCE="@datadir@/dlog-$type.conf.test"
125 if [ "$PERSISTENT" -eq 1 ]; then
126 cp "$SOURCE" "$DLOG_CONFIG_PATH"
128 sed 's/^dlog_logger_conf.*$/#\0/' <"$SOURCE" >"$DLOG_CONFIG_PATH"
131 echo "handle_kmsg=$KMSG" >> "$DLOG_CONFIG_PATH"
132 echo "syslog_force=$SYSLOG" >> "$DLOG_CONFIG_PATH"
138 kill $LOGGER > /dev/null
142 if [ "$PERSISTENT" -eq 0 ] && [ "$KMSG" -eq 0 ] && [ "$SYSLOG" -eq 0 ] && [ "$QOS" -eq 0 ] && [ "$type" = "logger" ]; then
148 LOG_DETAILS="testing if daemon stops when not needed (persistent=$PERSISTENT, kmsg=$KMSG, syslog=$SYSLOG, qos=$QOS)"
149 [ "$STOPPED" -eq "$EXPECTED" ] && ok || fail
150 done; done; done; done
152 DLOG_CONFIG_PATH="$PREEARLYQUIT_CONFIG_PATH"
159 if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
162 dlogutil -c -b radio -b system -b main
163 LOG_DETAILS="dlogctl --disable (no args, limiter_apply_to_all_buffers=0)"
166 # without 'limiter_apply_to_all_buffers=1' this
167 # only applies to the three platform buffers:
168 # main, radio, and system
169 PREPLOG_CONFIG_PATH="$DLOG_CONFIG_PATH"
170 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.plog"
171 [ "$(dlogctl -g | grep regular | grep -c DISABLED)" -eq 3 ] && ok || fail
172 DLOG_CONFIG_PATH="$PREPLOG_CONFIG_PATH"
174 LOG_DETAILS="dlogctl --disable (no args, limiter_apply_to_all_buffers=1)"
176 [ "$(dlogctl -g | grep regular | grep -c ENABLED)" -eq 0 ] && ok || fail
178 LOG_DETAILS="testing if filters were applied"
179 dlogsend -b system -t TEST test
180 dlogsend -b main -t TEST test
181 dlogsend -b radio -t TEST test
182 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
184 LOG_DETAILS="dlogctl --enable (no args)"
186 [ "$(dlogctl -g | grep regular | grep -c DISABLED)" -eq 0 ] && ok || fail
187 LOG_DETAILS="testing if filters were applied"
188 dlogutil -c -b radio -b system -b main
189 dlogsend -b system -t TEST test
190 dlogsend -b main -t TEST test
191 dlogsend -b radio -t TEST test
192 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
194 LOG_DETAILS="dlogctl --disable (1 arg)"
195 dlogctl --disable -b system
196 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c system)" -eq 1 ] &&
197 [ "$(dlogctl -g | grep regular | grep -c DISABLED )" -eq 1 ] && ok || fail
198 LOG_DETAILS="testing if filters were applied"
199 dlogutil -c -b radio -b system -b main
200 dlogsend -b system -t TEST test
201 dlogsend -b main -t TEST test
202 dlogsend -b radio -t TEST test
203 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
205 LOG_DETAILS="dlogctl --disable (multiple args)"
206 dlogctl --disable -b main -b radio
207 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -cv system)" -eq 2 ] &&
208 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c radio)" -eq 1 ] &&
209 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c main)" -eq 1 ] && ok || fail
210 LOG_DETAILS="testing if filters were applied"
211 dlogutil -c -b radio -b system -b main
212 dlogsend -b system -t TEST test
213 dlogsend -b main -t TEST test
214 dlogsend -b radio -t TEST test
215 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
217 LOG_DETAILS="dlogctl --enable (multiple args)"
218 dlogctl --enable -b radio -b system
219 [ "$(dlogctl -g | grep regular | grep -c DISABLED )" -eq 1 ] &&
220 [ "$(dlogctl -g | grep regular | grep DISABLED | grep -c main)" -eq 1 ] &&
221 [ "$(dlogctl -g | grep regular | grep ENABLED | grep -c system)" -eq 1 ] &&
222 [ "$(dlogctl -g | grep regular | grep ENABLED | grep -c radio)" -eq 1 ] && ok || fail
223 LOG_DETAILS="testing if filters were applied"
224 dlogutil -c -b radio -b system -b main
225 dlogsend -b system -t TEST test
226 dlogsend -b main -t TEST test
227 dlogsend -b radio -t TEST test
228 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
230 LOG_DETAILS="dlogctl --enable (1 arg)"
231 dlogctl --enable -b main
232 [ "$(dlogctl -g | grep regular | grep -c DISABLED)" -eq 0 ] && ok || fail
233 LOG_DETAILS="testing if filters were applied"
234 dlogutil -c -b radio -b system -b main
235 dlogsend -b system -t TEST test
236 dlogsend -b main -t TEST test
237 dlogsend -b radio -t TEST test
238 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
240 LOG_DETAILS="dlogctl -s allow"
241 dlogutil -c -b radio -b system -b main
244 dlogctl -t TEST_TAG -s allow
245 dlogsend -b main -t TEST_TAG test
246 dlogsend -b main -t TEST test
247 [ "$(dlogutil -d -b main | wc -l)" -eq 1 ] && ok || fail
249 LOG_DETAILS="dlogctl -s [N]"
250 dlogutil -c -b radio -b system -b main
253 dlogctl -t TEST_TAG -s 3
254 dlogsend -b main -c 10 -t TEST_TAG test
255 dlogsend -b main -c 10 -t TEST test
256 [ "$(dlogutil -d -b main | wc -l)" -eq 4 ] && ok || fail
258 LOG_DETAILS="testing invalid parameters for dlogctl (1/13)"
259 dlogctl -s invalid > /dev/null && fail || ok
261 LOG_DETAILS="testing invalid parameters for dlogctl (2/13)"
262 dlogctl -p X -g > /dev/null && fail || ok
264 LOG_DETAILS="testing invalid parameters for dlogctl (3/13)"
265 dlogctl -b invalid --disable > /dev/null && fail || ok
267 LOG_DETAILS="testing invalid parameters for dlogctl (4/13)"
268 dlogctl -s allow -g -t xyz -p E > /dev/null && fail || ok
270 LOG_DETAILS="testing invalid parameters for dlogctl (5/13)"
271 dlogctl -s allow -c > /dev/null && fail || ok
273 LOG_DETAILS="testing invalid parameters for dlogctl (6/13)"
274 dlogctl -c -g -t xyz -p E > /dev/null && fail || ok
277 LOG_DETAILS="testing invalid parameters for dlogctl (7/13)"
278 dlogctl -s -10 > /dev/null && fail || ok
280 LOG_DETAILS="testing invalid parameters for dlogctl (8/13)"
281 dlogctl -s 999999 > /dev/null && fail || ok
284 LOG_DETAILS="testing invalid parameters for dlogctl (9/13)"
285 dlogctl -s 100 && ok || fail
287 LOG_DETAILS="testing invalid parameters for dlogctl (10/13)"
288 [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 1 ] && ok || fail
291 LOG_DETAILS="testing invalid parameters for dlogctl (11/13)"
292 [ "$(dlogctl -g | grep -F '*:*' | grep -c 100)" -eq 1 ] && ok || fail
295 LOG_DETAILS="testing invalid parameters for dlogctl (12/13)"
296 dlogctl -c -t '*' -p '*' && ok || fail
298 LOG_DETAILS="testing invalid parameters for dlogctl (13/13)"
299 [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 0 ] && ok || fail
302 LOG_DETAILS="testing if the whole dynamic config directory is respected"
304 cp $RUNTIME_FILTERS_DIR/05-logctl.conf $RUNTIME_FILTERS_DIR/10-other.conf
306 dlogutil -c -b radio -b system -b main
307 dlogsend -b system -t TEST test
308 dlogsend -b main -t TEST test
309 dlogsend -b radio -t TEST test
310 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
311 rm $RUNTIME_FILTERS_DIR/10-other.conf
315 SEED=$(head -c 6 /dev/urandom | base64)
316 dlogsend -b main -k "$SEED"
317 # -k is async, unlike normal mode; therefore we have to wait until the logging process actually finishes.
318 while pgrep "dlogsend" > /dev/null || pgrep "dlog-log-critical" > /dev/null; do :; done
319 CRIT_PATH="@DLOG_CRITICAL_LOGFILE_PATH@"
320 LOG_DETAILS="testing if critical logging works"
321 cat "$CRIT_PATH".a "$CRIT_PATH".b | grep -F "$SEED" > /dev/null && ok || fail
323 if [ "$type" = "pipe" ] && [ "$quick" -ne 1 ]; then
324 dlogsend -c 2 -d 2 -t DLOGSEND_SIGPIPE_TEST test &
327 kill -s PIPE $DLOGSEND_PID
329 LOG_DETAILS="testing if dlogsend logs even after SIGPIPE"
330 [ "$(dlogutil -d DLOGSEND_SIGPIPE_TEST | wc -l)" -eq 2 ] && ok || fail
335 LOG_DETAILS="testing if dlogutil rejects dotnet"
336 dlogutil -db dotnet_api && fail || ok
338 LOG_DETAILS="testing if dlogutil rejects native"
339 dlogutil -db native_api && fail || ok
341 LOG_DETAILS="testing if dotnet redirects to regular apps (1/2)"
342 dlogsend -b dotnet_api "TEST"
344 [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
346 LOG_DETAILS="testing if dotnet redirects to regular apps (2/2)"
347 dlogsend -c 6 -b dotnet_api "TEST"
349 [ "$(dlogutil -d -b apps | wc -l)" -eq 7 ] && ok || fail
351 LOG_DETAILS="testing if native redirects to regular apps (1/2)"
352 dlogsend -b native_api "TEST"
354 [ "$(dlogutil -d -b apps | wc -l)" -eq 8 ] && ok || fail
356 LOG_DETAILS="testing if native redirects to regular apps (2/2)"
357 dlogsend -c 6 -b native_api "TEST"
359 [ "$(dlogutil -d -b apps | wc -l)" -eq 14 ] && ok || fail
361 if [ "$type" != "zero-copy" ]; then # These tests are inherently dynamic.
363 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (1/4)"
364 dlogctl -b apps --enable
365 dlogctl -b dotnet_api --disable
366 dlogsend -b dotnet_api "TEST"
367 [ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
368 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (2/4)"
369 dlogsend -b apps "TEST"
370 [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
371 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (3/4)"
372 dlogctl -b apps --disable
373 dlogctl -b dotnet_api --enable
374 dlogsend -b dotnet_api "TEST"
375 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
376 LOG_DETAILS="testing if blocking dotnet and regular apps is separate (4/4)"
377 dlogsend -b apps "TEST"
378 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
382 LOG_DETAILS="testing if blocking native and regular apps is separate (1/4)"
383 dlogctl -b apps --enable
384 dlogctl -b native_api --disable
385 dlogsend -b native_api "TEST"
386 [ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
387 LOG_DETAILS="testing if blocking native and regular apps is separate (2/4)"
388 dlogsend -b apps "TEST"
389 [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
390 LOG_DETAILS="testing if blocking native and regular apps is separate (3/4)"
391 dlogctl -b apps --disable
392 dlogctl -b native_api --enable
393 dlogsend -b native_api "TEST"
394 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
395 LOG_DETAILS="testing if blocking native and regular apps is separate (4/4)"
396 dlogsend -b apps "TEST"
397 [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
400 # put 100 log entries in the "main" buffer
406 LOG_DETAILS="testing if dlogutil -d exits with success after printing logs"
407 dlogutil -d > /dev/null && ok || fail
409 LOG_DETAILS="testing if -t argument is parsed properly"
410 dlogutil -t dummy > /dev/null && fail || ok
412 LOG_DETAILS="testing if -u argument is parsed properly"
413 dlogutil -du dummy > /dev/null && fail || ok
415 LOG_DETAILS="testing if limiting printed log entries to less than exists in the buffer returns proper value"
416 [ "$(dlogutil -b main -t 20 | wc -l)" -eq 20 ] && ok || fail # less logs than currently in buffer
418 LOG_DETAILS="testing if limiting printed log entries to more than exists in the buffer returns proper value"
419 [ "$(dlogutil -b main -t 200 | wc -l)" -eq 100 ] && ok || fail # more
421 LOG_DETAILS="testing if dlogutil returns exact amount of entries as there is in the buffer"
422 [ "$(dlogutil -b main -d | wc -l)" -eq 100 ] && ok || fail # exactly
424 LOG_DETAILS="testing if reading from dummy buffer returns an error as expected"
425 dlogutil -b nonexistent_buffer > /dev/null && fail || ok
427 if [ "$type" != "zero-copy" ]; then # No buffer split in zero-copy
428 LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)"
429 [ "$(dlogutil -d -b system | wc -l)" -eq 0 ] && ok || fail
432 LOG_DETAILS="testing if dlogutil -c empties all buffers"
433 dlogutil -cb main && ok || fail
435 LOG_DETAILS="testing if writing entries to empty buffer and reading them returns proper amount of entries"
437 [ "$(dlogutil -b main -d | wc -l)" -eq 10 ] && ok || fail # should be 10, not 110
439 LOG_DETAILS="testing if filters work (1/3)"
440 [ "$(dlogutil -b main -d '*:E' | wc -l)" -eq 5 ] && ok || fail # half of current logs (test_libdlog alternates between error and info log levels)
442 LOG_DETAILS="testing if filters work (2/3)"
443 [ "$(dlogutil -b main -d '*:W' | wc -l)" -eq 5 ] && ok || fail
445 LOG_DETAILS="testing if filters work (3/3)"
446 [ "$(dlogutil -b main -d '*:I' | wc -l)" -eq 10 ] && ok || fail
448 LOG_DETAILS="testing if exact filters work (1/3)"
449 [ "$(dlogutil -b main -d '*:=E' | wc -l)" -eq 5 ] && ok || fail
451 LOG_DETAILS="testing if exact filters work (2/3)"
452 [ "$(dlogutil -b main -d '*:=W' | wc -l)" -eq 0 ] && ok || fail
454 LOG_DETAILS="testing if exact filters work (3/3)"
455 [ "$(dlogutil -b main -d '*:=I' | wc -l)" -eq 5 ] && ok || fail
457 LOG_DETAILS="testing if adding \"silent\" filter works"
458 [ "$(dlogutil -b main -s -d | wc -l)" -eq 0 ] && ok || fail
460 if [ "$type" != "zero-copy" ]; then # No buffer size access in zero-copy
461 LOG_DETAILS="testing if reading buffer size returns proper exit code"
462 dlogutil -gb main > /dev/null && ok || fail
465 LOG_DETAILS="testing if writing all entries to single file works (-f)"
466 dlogutil -f $TESTDIR/dlog_test_file -d > /dev/null && ok || fail
468 if [ "$quick" -ne 1 ]; then
469 LOG_DETAILS="testing if the continuous mode works as expected (1/2)"
470 dlogutil -b main -f $TESTDIR/dlog_continuous1_file &
473 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
475 [ "$WAS_ALIVE" -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous1_file)" -eq 10 ] && ok || fail
477 LOG_DETAILS="testing if the continuous mode works as expected (2/2)"
478 dlogutil -b main -f $TESTDIR/dlog_continuous2_file &
481 dlogsend -b main "Hi!"
483 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
485 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous2_file)" -eq 11 ] && ok || fail
487 LOG_DETAILS="testing if the monitor mode works as expected (1/2)"
488 dlogutil --monitor -b main -f $TESTDIR/dlog_monitor1_file &
491 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
493 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor1_file)" -eq 0 ] && ok || fail
495 LOG_DETAILS="testing if the monitor mode works as expected (2/2)"
496 dlogutil --monitor -b main -f $TESTDIR/dlog_monitor2_file &
499 dlogsend -b main "Hi!"
501 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
503 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor2_file)" -eq 1 ] && ok || fail
507 test_libdlog 100000 &
508 LIBDLOGUTIL_CORRECT_PID=$!
509 wait $LIBDLOGUTIL_CORRECT_PID
511 # NB: rotation only really makes sense in the continuous mode
512 # from a user PoV, but the logic doesn't care about dumping
513 # so we do it to simplify things
514 dlogutil -df $TESTDIR/dlog_rotating_file -r 12 -n 3 # 3 files at 12 KB each
516 LOG_DETAILS="testing if single file is properly created"
517 if [ -e $TESTDIR/dlog_test_file ]; then ok; else fail; fi
519 LOG_DETAILS="testing if rotating file is properly created (1/4)"
520 if [ -e $TESTDIR/dlog_rotating_file.1 ]; then ok; else fail; fi
522 LOG_DETAILS="testing if rotating file is properly created (2/4)"
523 if [ -e $TESTDIR/dlog_rotating_file.2 ]; then ok; else fail; fi
525 LOG_DETAILS="testing if rotating file is properly created (3/4)"
526 if [ -e $TESTDIR/dlog_rotating_file.3 ]; then ok; else fail; fi
528 LOG_DETAILS="testing if rotating file is properly created (4/4)"
529 if [ -e $TESTDIR/dlog_rotating_file.4 ]; then fail; else ok; fi
531 LOG_DETAILS="testing the size of log files"
532 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
534 LOG_DETAILS="testing if libdlogutil works correctly in the dump mode"
535 test_libdlogutil dump $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
536 if [ "$quick" -ne 1 ]; then
537 LOG_DETAILS="testing if libdlogutil works correctly if processing the logs takes some time"
538 test_libdlogutil timer $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
540 LOG_DETAILS="testing if libdlogutil works correctly in the continuous mode"
541 test_libdlogutil continuous $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
542 LOG_DETAILS="testing if libdlogutil skips all the logs in the monitor mode correctly"
543 test_libdlogutil monitor $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
544 LOG_DETAILS="testing if libdlogutil priority filter works correctly"
545 test_libdlogutil priority $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
546 LOG_DETAILS="testing if libdlogutil exact priority filter works correctly"
547 test_libdlogutil priority_exact $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
548 LOG_DETAILS="testing if libdlogutil limits the log amount correctly"
549 test_libdlogutil limit $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
550 LOG_DETAILS="testing if libdlogutil PID filter works correctly (1/2)"
551 test_libdlogutil pid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
552 LOG_DETAILS="testing if libdlogutil PID filter works correctly (2/2)"
553 test_libdlogutil pid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
554 LOG_DETAILS="testing if libdlogutil TID filter works correctly (1/2)"
555 test_libdlogutil tid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
556 LOG_DETAILS="testing if libdlogutil TID filter works correctly (2/2)"
557 test_libdlogutil tid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
558 LOG_DETAILS="testing if libdlogutil tag filter works correctly (1/2)"
559 test_libdlogutil tag_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
560 LOG_DETAILS="testing if libdlogutil tag filter works correctly (2/2)"
561 test_libdlogutil tag_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
562 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (1/2)"
563 test_libdlogutil prefix_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
564 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (2/2)"
565 test_libdlogutil prefix_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
566 if [ "$type" != "zero-copy" ]; then # These rely on things not available in zero-copy
567 LOG_DETAILS="testing if libdlogutil returns the correct buffer traits"
568 test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
569 LOG_DETAILS="testing if libdlogutil aliasing works"
570 if [ "$type" = "pipe" ]; then
571 test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
573 DLOG_CONFIG_PATH="@datadir@/dlog-logger.conf.alias" test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
576 LOG_DETAILS="testing if libdlogutil errors out correctly if used improperly"
577 test_libdlogutil negative $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
579 cmd_prefix_no_v="dlogutil -t 1 -u 0"
580 cmd_prefix="$cmd_prefix_no_v -v"
583 regex_prio="[VDIWEFS]{1}"
584 regex_pidtid="P[0-9[:space:]]{5,},\s{1}T[0-9[:space:]]{5,}"
585 regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
586 regex_timezone="[\+-]{1}[0-9]{4}"
588 for PARAM in always auto none never; do
589 for PRIO in info error; do
590 for OUTPUT in pipe tty; do
591 if [ "$PARAM" = "always" ]; then
593 elif [ "$PARAM" = "never" ]; then
595 elif [ "$OUTPUT" = "tty" ]; then
601 if [ "$PRIO" = "info" ]; then
602 REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
603 elif [ "$COLOR_EXPECTED" -eq 0 ]; then
604 REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
606 REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m \([[:print:]]*\)@~\[0m$/1/g"
609 # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
610 COMMAND="$cmd_prefix $format"
612 if [ "$PARAM" = "none" ]; then
613 LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
615 COMMAND="$COMMAND --color=$PARAM"
616 LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
619 if [ "$PRIO" = "info" ]; then
620 COMMAND="$COMMAND '*:=I'"
622 COMMAND="$COMMAND '*:=E'"
625 if [ "$OUTPUT" = "tty" ]; then
626 # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
627 COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
630 # $(eval) is needed since `$COMMAND` may contain `"`
631 line="$(eval "$COMMAND" | tr '\033\n' '~@')"
632 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
636 # TODO: It would be cool to also test warning messages (which have a different color),
637 # but this would require deeper changes to this script, which is already janky enough.
639 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
640 LOG_DETAILS="testing if \"$format\" print format works"
641 line=$($cmd_prefix $format)
642 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
645 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[: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
651 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
652 LOG_DETAILS="testing if \"$format\" print format works"
653 line=$($cmd_prefix $format)
654 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
657 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
658 LOG_DETAILS="testing if \"$format\" print format works"
659 line=$($cmd_prefix $format)
660 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
663 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
664 LOG_DETAILS="testing if \"$format\" print format works"
665 line=$($cmd_prefix $format)
666 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
669 REGEX="s/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
670 LOG_DETAILS="testing if \"$format\" print format works"
671 line=$($cmd_prefix $format)
672 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
674 format="recv_realtime"
675 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
676 LOG_DETAILS="testing if \"$format\" print format works"
677 line=$($cmd_prefix $format)
678 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
681 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"
682 LOG_DETAILS="testing if \"$format\" print format works"
683 line=$($cmd_prefix $format)
684 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
687 REGEX="s/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]@[[:print:]]+@$/1/g"
688 LOG_DETAILS="testing if \"$format\" print format works"
689 line=$($cmd_prefix $format)
690 [ "$(echo "$line" | tr '\n' '@' | sed -re "$REGEX")" = "1" ] && ok || fail
693 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
694 LOG_DETAILS="testing if \"$format\" print format works"
695 line=$($cmd_prefix $format)
696 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
699 if [ "$type" = "pipe" ]; then
700 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_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_mono\":[1-9][0-9]+\.[0-9]{9},\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
701 elif [ "$type" = "logger" ]; then
702 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\",\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
704 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"
706 LOG_DETAILS="testing if \"$format\" print format works"
707 line=$($cmd_prefix $format)
708 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
710 SOURCE="$DLOG_CONFIG_PATH"
711 DLOG_CONFIG_PATH="$TESTDIR/defaultprintformat.conf"
712 cp "$SOURCE" "$DLOG_CONFIG_PATH"
714 # TODO: It would be good to also test the daemon side of things.
715 LOG_DETAILS="testing default log format selection (none -> brief)"
716 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
717 line=$($cmd_prefix_no_v)
718 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
720 echo "util_default_format=rwtime" >> $DLOG_CONFIG_PATH
721 LOG_DETAILS="testing default log format selection (rwtime)"
722 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"
723 line=$($cmd_prefix_no_v)
724 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
726 DLOG_CONFIG_PATH="$SOURCE"
729 LOG_DETAILS="testing if \"$format\" print format works"
731 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
732 line=$($cmd_prefix $format)
733 [ "$line" = "rawformatTEST" ] && ok || fail
735 if [ "$quick" -ne 1 ]; then
736 LOG_DETAILS="testing if dlogsend -d works"
738 dlogsend -b main -c 9999 -d 4 -f 7 -t DLOG_TESTSUITE "hi" &
742 # In 10 seconds, 3 cycles 7 logs each should have happened.
743 [ "$(dlogutil -d DLOG_TESTSUITE | wc -l)" -eq 21 ] && ok || fail
746 if [ "$type" = "pipe" ]; then
747 for format in raw brief long; do
748 for i in 1 2 3 4 5 6 7 8 10 15 20 25 513 514 515 516 517 518 519 520; do
749 LOG_DETAILS="testing if padding works correctly (format $format/count $i)"
750 log=$(printf '%0.s&' $(seq 1 $i)) # Print the '&' character $i times
753 dlogsend -b main "$log"
754 line=$($cmd_prefix $format | tr '\n' '@')
761 REGEX="s/I\/DLOG_SEND\([0-9[:space:]]{5,}\):\s{1}$log@$/1/g"
764 REGEX="s/\[\s{1}$regex_time.[0-9]{3,}\s{1}I\/DLOG_SEND\s{1}$regex_pidtid\]@$log@@/1/g"
768 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
773 if [ "$type" != "zero-copy" ]; then # No KMSG in zero-copy
774 LOG_DETAILS="testing if KMSG works in the default format"
775 # We check if the command returns at least 100 logs. This seems to be a safe value.
776 # Feel free to change it to a reasonable yet lower value if the test happens to fail otherwise.
777 [ "$(dlogutil -db kmsg | wc -l)" -gt 100 ] && ok || fail
780 if [ "$quick" -ne 1 ]; then
781 if [ "$type" != "zero-copy" ]; then # No KMSG in zero-copy
782 LOG_DETAILS="testing if KMSG works in the raw format"
783 last_dmesg=$(dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g")
784 sleep 1 # To make sure dlog has already parsed the log
785 dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail
788 LOG_DETAILS="testing if pid filtering works"
789 dlogsend -b main -t DLOG_TESTSUITE pidTEST &
791 line=$(dlogutil -v raw -d --pid $!)
792 [ "$line" = "pidTEST" ] && ok || fail
794 LOG_DETAILS="testing if tid filtering works"
795 dlogsend -b main -t DLOG_TESTSUITE tidTEST &
797 line=$(dlogutil -v raw -d --tid $!) #dlogsend is a single threaded app so tid is the same as pid
798 [ "$line" = "tidTEST" ] && ok || fail
800 mv $DLOG_CONFIG_PATH $DLOG_CONFIG_PATH.1
801 LOG_DETAILS="testing if secure logging works (1/2)"
802 grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
803 echo "enable_secure_logs=1" >> $DLOG_CONFIG_PATH
805 dlogsend -zb main -t DLOG_TESTSUITE secure &
807 dlogsend -b main -t DLOG_TESTSUITE insecure &
809 line=$(dlogutil -v raw -d | head -n1)
810 [ "$line" = "secure" ] && ok || fail
811 LOG_DETAILS="testing if secure logging works (2/2)"
812 grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
813 echo "enable_secure_logs=0" >> $DLOG_CONFIG_PATH
815 dlogsend -zb main -t DLOG_TESTSUITE secure &
817 dlogsend -b main -t DLOG_TESTSUITE insecure &
819 line=$(dlogutil -v raw -d | head -n1)
820 [ "$line" = "insecure" ] && ok || fail
821 mv $DLOG_CONFIG_PATH.1 $DLOG_CONFIG_PATH
824 dlogsend -b main -t DLOG_TESTSUITE_TAG0 -pI tagTEST0
825 dlogsend -b main -t DLOG_TESTSUITE_TAG1 -pI tagTEST1
826 dlogsend -b main -t DLOG_TESTSUITE_TAG2 -pF tagTEST2
828 LOG_DETAILS="testing if tag filtering works (1/8)"
829 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG0' | wc -l)" -eq 1 ] && ok || fail
830 LOG_DETAILS="testing if tag filtering works (2/8)"
831 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG1' | wc -l)" -eq 1 ] && ok || fail
832 LOG_DETAILS="testing if tag filtering works (3/8)"
833 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG' | wc -l)" -eq 0 ] && ok || fail
834 LOG_DETAILS="testing if tag filtering works (4/8)"
835 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*' | wc -l)" -eq 3 ] && ok || fail
836 LOG_DETAILS="testing if tag filtering works (5/8)"
837 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:I' | wc -l)" -eq 3 ] && ok || fail
838 LOG_DETAILS="testing if tag filtering works (6/8)"
839 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:W' | wc -l)" -eq 1 ] && ok || fail
840 LOG_DETAILS="testing if tag filtering works (7/8)"
841 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG' | wc -l)" -eq 0 ] && ok || fail
842 LOG_DETAILS="testing if tag filtering works (8/8)"
843 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l)" -eq 0 ] && ok || fail
845 if [ "$type" != "zero-copy" ]; then # No dynamic filters in zero-copy
846 LOG_DETAILS="testing if limiter and runtime filtering works"
849 [ "$(dlogutil -d -b radio | wc -l)" -eq 12 ] && ok || fail
852 LOG_DETAILS="testing proper SMACK label for dynamic config file location"
853 ORIG_FILTERS_DIR=$(grep dynamic_config_path "$ORIGINAL_CONFIG_PATH" | awk -F "=" '{print $2}')
854 # Running ls on an arbitrary directory and trying to make sense of results is problematic.
855 # However, this is not a problem in our usecase, as we only care about the first field, the security context.
856 # We don't even care about the filename, which isn't arbitrary anyway (-d on fixed path).
857 # shellcheck disable=SC2012
858 [ "$(ls -dZ "$ORIG_FILTERS_DIR" | awk -F ' ' '{print $1}')" = "System::Shared" ] && ok || fail
860 if [ "$quick" -ne 1 ]; then
861 # This creates a process which will wait for SIGCONT and then spam logs. We know its PID, so we can add
862 # PID-based limits and see what happens.
863 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
865 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
866 dlogctl --pid $DLOGSEND_PID -s deny
867 kill -s CONT $DLOGSEND_PID
869 LOG_DETAILS="testing if PID limiting works (1/14)"
870 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 0 ] && ok || fail
871 LOG_DETAILS="testing if PID limiting works (2/14)"
872 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 1 ] && ok || fail
873 LOG_DETAILS="testing if PID limiting works (3/14)"
874 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = "Denied" ] && ok || fail
875 LOG_DETAILS="testing if PID limiting works (4/14)"
876 dlogctl -g | grep -q "Denied for $DLOGSEND_PID" && ok || fail
878 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
880 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
881 dlogctl --pid $DLOGSEND_PID -s 25
882 kill -s CONT $DLOGSEND_PID
884 LOG_DETAILS="testing if PID limiting works (5/14)"
885 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 25 ] && ok || fail
886 LOG_DETAILS="testing if PID limiting works (6/14)"
887 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 1 ] && ok || fail
888 LOG_DETAILS="testing if PID limiting works (7/14)"
889 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = '25 logs/min' ] && ok || fail
890 LOG_DETAILS="testing if PID limiting works (8/14)"
891 dlogctl -g | grep -q "25 logs/min for $DLOGSEND_PID" && ok || fail
893 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
895 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
896 dlogctl --pid $DLOGSEND_PID -s allow
897 kill -s CONT $DLOGSEND_PID
899 LOG_DETAILS="testing if PID limiting works (9/14)"
900 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 100 ] && ok || fail
901 LOG_DETAILS="testing if PID limiting works (10/14)"
902 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 0 ] && ok || fail
903 LOG_DETAILS="testing if PID limiting works (11/14)"
904 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = 'Unlimited' ] && ok || fail
905 LOG_DETAILS="testing if PID limiting works (12/14)"
906 dlogctl -g | grep -q "Unlimited for $DLOGSEND_PID" && ok || fail
908 echo "qos_refresh_rate_s=5" > "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
909 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 15 -d 1 "Pid test"' &
911 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
912 dlogctl --pid $DLOGSEND_PID -s 2
913 kill -s CONT $DLOGSEND_PID
915 rm "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
916 LOG_DETAILS="testing if PID limiting works (13/14)"
917 # In each 5 second period, 5 logs are sent, so there are 3 periods.
918 # 2 logs from each period are allowed.
919 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 6 ] && ok || fail
920 LOG_DETAILS="testing if PID limiting works (14/14)"
921 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 3 ] && ok || fail
923 PREQOS_CONFIG_PATH=$DLOG_CONFIG_PATH
924 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.qos"
925 kill $LOGGER > /dev/null
927 if [ "$type" = "logger" ]; then
934 dlogsend -b main -t DLOG_QOS_TEST0 -c 30 -d 1 -f 2 "A normal app that just wants to log"
935 LOG_DETAILS="testing if QoS works (1/4)"
936 [ "$(dlogutil -d DLOG_QOS_TEST0 | grep -cv blocked)" -eq 30 ] && ok || fail
937 kill $LOGGER > /dev/null
939 if [ "$type" = "logger" ]; then
946 dlogsend -b main -t DLOG_QOS_TEST1 -c 300 -d 1 -f 20 "Some log spam"
947 LOG_DETAILS="testing if QoS works (2/4)"
948 [ "$(dlogutil -d DLOG_QOS_TEST1 | grep -cv blocked)" -le 210 ] && ok || fail
949 kill $LOGGER > /dev/null
951 if [ "$type" = "logger" ]; then
958 dlogsend -b main -t DLOG_QOS_TEST2 -c 30 -d 1 -f 2 "A normal app that just wants to log" &
960 dlogsend -b main -t DLOG_QOS_TEST3 -c 270 -d 1 -f 18 "Some log spam"
962 LOG_DETAILS="testing if QoS works (3/4)"
963 [ "$(dlogutil -d DLOG_QOS_TEST2 DLOG_QOS_TEST3 | grep -cv blocked)" -le 210 ] && ok || fail
964 LOG_DETAILS="testing if QoS works (4/4)"
965 [ "$(dlogutil -d DLOG_QOS_TEST2 | grep -cv blocked)" -gt 24 ] && ok || fail
967 DLOG_CONFIG_PATH=$PREQOS_CONFIG_PATH
968 kill $LOGGER > /dev/null
974 # limiter test (the feature allows to enable/disable particular log type)
975 dlogsend -c 11 -d 1 -t QWE blabla &
978 dlogctl -t QWE -s deny
979 LOG_DETAILS="testing if log limiter works (deny) (1/3)"
980 [ "$(dlogutil -d QWE | wc -l)" -eq 1 ] && ok || fail
982 LOG_DETAILS="testing if log limiter works (deny) (2/3)"
983 [ "$(dlogutil -d QWE | wc -l)" -eq 1 ] && ok || fail
985 dlogctl -t QWE -s allow
987 LOG_DETAILS="testing if log limiter works (allow) (3/3)"
988 [ "$(dlogutil -d QWE | wc -l)" -eq 5 ] && ok || fail
994 if [ "$LEGACY_LOGGER" -ne 1 ] && [ "$quick" -ne 1 ]; then
997 LOG_DETAILS="testing if basic stdout redirection works correctly (1/2)"
998 [ "$(dlog_redirect_stdout --outtag FOO -- /usr/bin/echo Hi)" = "" ] && ok || fail
1000 LOG_DETAILS="testing if basic stdout redirection works correctly (2/2)"
1001 [ "$(dlogutil -db main -v tag)" = "I/FOO : Hi" ] && ok || fail
1004 # No need to check output in this case, as nothing is written to stdout anyway
1005 dlog_redirect_stdout --errtag BAR -- /usr/bin/sh -c "echo Hi >&2"
1007 LOG_DETAILS="testing if basic stderr redirection works correctly"
1008 [ "$(dlogutil -db main -v tag)" = "E/BAR : Hi" ] && ok || fail
1011 LOG_DETAILS="testing if redirector doesn't redirect anything by default (1/2)"
1012 [ "$(dlog_redirect_stdout -- /usr/bin/echo Hi)" = "Hi" ] && ok || fail
1014 LOG_DETAILS="testing if redirector doesn't redirect anything by default (2/2)"
1015 [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
1018 if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy
1019 dlog_redirect_stdout --outbuffer radio --outtag AN_INTERESTING_TAG --outprio W -- /usr/bin/echo Hi
1021 LOG_DETAILS="testing if redirector settings work correctly on stdout (1/2)"
1022 [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
1023 LOG_DETAILS="testing if redirector settings work correctly on stdout (2/2)"
1024 [ "$(dlogutil -db radio -v tag)" = "W/AN_INTERESTING_TAG: Hi" ] && ok || fail
1027 dlog_redirect_stdout --errbuffer radio --errtag ANOTHER_INTERESTING_TAG --errprio I -- /usr/bin/sh -c "echo Hi >&2"
1029 LOG_DETAILS="testing if redirector settings work correctly on stderr (1/2)"
1030 [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
1031 LOG_DETAILS="testing if redirector settings work correctly on stderr (2/2)"
1032 [ "$(dlogutil -db radio -v tag)" = "I/ANOTHER_INTERESTING_TAG: Hi" ] && ok || fail
1036 echo "Testing" | dlog_redirect_stdout --outtag BAZ -- /usr/bin/cat
1038 LOG_DETAILS="testing if redirector passes stdin correctly"
1039 [ "$(dlogutil -db main -v tag)" = "I/BAZ : Testing" ] && ok || fail
1042 dlog_redirect_stdout --outtag QUUX -- /usr/bin/cat << EOF
1050 LOG_DETAILS="testing if multiline logs are handled correctly"
1051 [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
1054 dlog_redirect_stdout --outtag QUUX -- /usr/bin/sh -c "printf \"line 1\0line 2\0line 3\0line 4\0line 5\""
1056 LOG_DETAILS="testing if logs with the '\\0' character are handled correctly"
1057 [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
1060 dlog_redirect_stdout --outtag QUUX -- /usr/bin/sh -c "printf \"line 1\0line 2\nline 3\0line 4\nline 5\""
1062 LOG_DETAILS="testing if logs with mixed delimiters are handled correctly"
1063 [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
1066 rm -f "$TESTDIR"/input
1067 rm -f "$TESTDIR"/output
1068 base64 -w 0 < /dev/urandom 2> /dev/null | head -c 250000 > "$TESTDIR"/input
1069 dlog_redirect_stdout --outtag XYZZY -- /usr/bin/cat "$TESTDIR"/input
1071 dlogutil -db main -v raw | tr -d '\n' > "$TESTDIR"/output
1072 LOG_DETAILS="testing if long lines are handled correctly"
1073 # Usually we would just diff or cmp the files. Unfortunately, as of writing, Tizen doesn't have such luxuries.
1074 [ "$(sha256sum < "$TESTDIR"/input)" = "$(sha256sum < "$TESTDIR"/output)" ] && ok || fail
1077 if [ "$type" = "pipe" ]; then
1078 # TODO: Actually implement and enable this in the logger backend
1079 dlogctl -b main --disable-stdout
1080 LOG_DETAILS="testing if redirection can be disabled (1/3)"
1081 [ "$(dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test)" = "" ] && ok || fail
1083 LOG_DETAILS="testing if redirection can be disabled (2/3)"
1084 [ "$(dlogutil -db main -v raw)" = "" ] && ok || fail
1085 LOG_DETAILS="testing if redirection can be disabled (3/3)"
1086 [ "$(dlogctl --get | grep 'main (regular)')" = "* main (regular): ENABLED" ] && ok || fail
1088 dlogctl -b main --enable-stdout
1089 LOG_DETAILS="testing if redirection can be reenabled (1/3)"
1090 [ "$(dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test)" = "" ] && ok || fail
1092 LOG_DETAILS="testing if redirection can be reenabled (2/3)"
1093 [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail
1094 LOG_DETAILS="testing if redirection can be reenabled (3/3)"
1095 [ "$(dlogctl --get | grep 'main (regular)')" = "* main (regular): ENABLED" ] && ok || fail
1099 if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy
1100 dlogctl -b radio --disable-stdout
1101 dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test
1103 LOG_DETAILS="testing if dlogctl --disable-stdout respects buffer choice"
1104 [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail
1108 LOG_DETAILS="testing if redirection check works (1/5)"
1109 test_libredirect 0 0 && ok || fail
1110 LOG_DETAILS="testing if redirection check works (2/5)"
1111 dlog_redirect_stdout -- /usr/libexec/libdlog/test_libredirect 0 0 && ok || fail
1112 LOG_DETAILS="testing if redirection check works (3/5)"
1113 dlog_redirect_stdout --outtag X -- /usr/libexec/libdlog/test_libredirect 1 0 && ok || fail
1114 LOG_DETAILS="testing if redirection check works (4/5)"
1115 dlog_redirect_stdout --errtag X -- /usr/libexec/libdlog/test_libredirect 0 1 && ok || fail
1116 LOG_DETAILS="testing if redirection check works (5/5)"
1117 dlog_redirect_stdout --outtag X --errtag Y -- /usr/libexec/libdlog/test_libredirect 1 1 && ok || fail
1119 if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy
1120 LOG_DETAILS="testing if multiple redirections work (1/4)"
1121 test_libredirect_multi && ok || fail
1122 LOG_DETAILS="testing if multiple redirections work (2/4)"
1123 [ "$(dlogutil -db main -v tag | grep "Message 1")" = "W/TAG1 : Message 1" ] && ok || fail
1124 LOG_DETAILS="testing if multiple redirections work (3/4)"
1125 [ "$(dlogutil -db main -v tag | grep "Message 2")" = "E/TAG2 : Message 2" ] && ok || fail
1126 LOG_DETAILS="testing if multiple redirections work (4/4)"
1127 [ "$(dlogutil -db system -v tag)" = "I/TAG3 : Message 3" ] && ok || fail
1128 dlogutil -cb main -b system
1132 if [ "$type" != "zero-copy" ]; then # No dynamic filters in zero-copy
1134 echo "deduplicate_method=only_identical_neighbours" > "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1135 echo "deduplicate_interval_ms=10" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1137 dlogsend -p Info -b main -c 9 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
1138 LOG_DETAILS="testing if deduplication with warnings works properly (1/12)"
1139 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 1 ] && ok || fail
1140 LOG_DETAILS="testing if deduplication with warnings works properly (2/12)"
1141 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 0 ] && ok || fail
1143 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
1144 LOG_DETAILS="testing if deduplication with warnings works properly (3/12)"
1145 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 3 ] && ok || fail
1146 LOG_DETAILS="testing if deduplication with warnings works properly (4/12)"
1147 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 1 ] && ok || fail
1149 echo "deduplicate_warn_quantity=8" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1151 dlogsend -p Info -b main -c 24 -t DLOG_DEDUP_TEST Message
1152 LOG_DETAILS="testing if deduplication with warnings works properly (5/12)"
1153 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 4 ] && ok || fail
1154 LOG_DETAILS="testing if deduplication with warnings works properly (6/12)"
1155 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Message LOG DUPLICATED')" -eq 3 ] && ok || fail
1157 dlogsend -p Info -b main -c 8 -t DLOG_DEDUP_TEST longerMessage
1158 LOG_DETAILS="testing if deduplication with warnings works properly (7/12)"
1159 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c longerMessage)" -eq 2 ] && ok || fail
1160 LOG_DETAILS="testing if deduplication with warnings works properly (8/12)"
1161 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 6 ] && ok || fail
1162 LOG_DETAILS="testing if deduplication with warnings works properly (9/12)"
1163 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'longerMessage LOG DUPLICATED')" -eq 1 ] && ok || fail
1165 echo "deduplicate_warn_quantity=-1" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1167 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, no warning"
1168 LOG_DETAILS="testing if deduplication with warnings works properly (10/12)"
1169 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning')" -eq 1 ] && ok || fail
1170 LOG_DETAILS="testing if deduplication with warnings works properly (11/12)"
1171 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication')" -eq 4 ] && ok || fail
1172 LOG_DETAILS="testing if deduplication with warnings works properly (12/12)"
1173 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning LOG DUPLICATED')" -eq 0 ] && ok || fail
1175 rm "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1178 LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
1179 test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
1181 if [ "$(date +%Y)" -le 2000 ]; then
1182 # This implies that the date isn't set. Let's set it to some date to better test timestamps.
1183 date -s "@2121212121" > /dev/null
1185 dlogsend -b main -t DLOG_TS_TEST "The future is now, old man"
1186 LOG_DETAILS="testing if the timestamps are correct"
1187 test_verifytime && ok || fail
1189 DLOG_PREV_PATH=$DLOG_CONFIG_PATH
1191 LOG_DETAILS="testing if config has control over redirecting to stdout (1/3)"
1192 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.stdout_enable.1"
1194 test_config_redirect 1 1 1 1 && ok || fail
1196 LOG_DETAILS="testing if config has control over redirecting to stdout (2/3)"
1197 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.stdout_enable.2"
1198 test_config_redirect 0 0 1 1 && ok || fail
1200 LOG_DETAILS="testing if config has control over redirecting to stdout (3/3)"
1201 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.stdout_enable.3"
1202 test_config_redirect 1 1 0 0 && ok || fail
1204 DLOG_CONFIG_PATH=$DLOG_PREV_PATH
1206 if [ "$quick" -ne 1 ]; then
1207 if [ "$type" != "zero-copy" ]; then # Backend autodection and logger daemon stuff don't really work on zero-copy
1208 PREAUTODETECT_CONFIG_PATH=$DLOG_CONFIG_PATH
1209 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.autodetect"
1210 kill $LOGGER > /dev/null
1212 if [ "$type" = "logger" ]; then
1219 LOG_DETAILS="testing if backend autodetection works properly (1/2)"
1220 dlogsend -b main -t DLOG_AUTODETECT "xd" && ok || fail
1223 DLOG_CONFIG_PATH=$PREAUTODETECT_CONFIG_PATH
1224 LOG_DETAILS="testing if backend autodetection works properly (2/2)"
1225 [ "$(dlogutil -db main -v raw)" = "xd" ] && ok || fail
1227 kill $LOGGER > /dev/null
1234 dlogsend -b main -t DLOG_LOGGER_TEST0 -c 100 "hi"
1236 LOG_DETAILS="testing if logger daemon persistent logging works (1/3)"
1237 [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test0)" -eq 100 ] && ok || fail
1238 LOG_DETAILS="testing if logger daemon persistent logging works (2/3)"
1239 [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test1)" -eq 100 ] && ok || fail
1240 LOG_DETAILS="testing if logger daemon persistent logging works (3/3)"
1241 [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test2)" -eq 0 ] && ok || fail
1243 dlogsend -b main -t DLOG_LOGGER_TEST1 -c 500000 "hi"
1245 RESULT=$(du -c "$TESTDIR"/test0* | tail -n 1 | cut -f 1)
1246 LOG_DETAILS="testing if logger daemon log rotating works (1/2)"
1247 [ "$RESULT" -gt 4096 ] && ok || fail # Min 4 MB
1248 LOG_DETAILS="testing if logger daemon log rotating works (2/2)"
1249 [ "$RESULT" -lt 6144 ] && ok || fail # Max 6 MB
1252 kill $LOGGER > /dev/null
1254 rm "$TESTDIR"/test0*
1255 dlog_logger -t 5 -b 100000 &
1259 dlogsend -b main -t DLOG_LOGGER_TEST2 -c 100 "hi"
1261 LOG_DETAILS="testing if logger daemon buffering works (1/5)"
1262 [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 0 ] && ok || fail
1265 LOG_DETAILS="testing if logger daemon buffering works (2/5)"
1266 [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 100 ] && ok || fail
1268 dlogsend -b main -t DLOG_LOGGER_TEST3 -c 100 "hi"
1270 LOG_DETAILS="testing if logger daemon buffering works (3/5)"
1271 [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 0 ] && ok || fail
1274 kill $LOGGER > /dev/null
1277 LOG_DETAILS="testing if logger daemon buffering works (4/5)"
1278 [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 100 ] && ok || fail
1282 dlog_logger -t 10000 -b 100 &
1286 dlogsend -b main -t DLOG_LOGGER_TEST4 -c 100 "hi"
1288 LOG_DETAILS="testing if logger daemon buffering works (5/5)"
1289 [ "$(grep -c DLOG_LOGGER_TEST4 "$TESTDIR"/test0)" -gt 90 ] && ok || fail
1292 kill $LOGGER > /dev/null
1299 LOG_DETAILS="testing if the library works with multithreaded app"
1300 dlogutil -f $TESTDIR/dlog_mt_test &
1302 test_libdlog && ok || fail
1311 # Spawn logging scripts and wait for them to finish.
1312 # We launch all the $SPAWN_CNT scripts in a subshell, and then use the wait command in order to
1313 # wait for all the jobs of the subshell, which means all the logging scripts.
1314 # Each of the logging scripts is a new subsubshell which waits a random amount of seconds and then logs
1315 # a single message. This gets us 5 groups of logs separated by a second; there are about 200 logs in each
1316 # group, sent about at the same time.
1318 for i in $(seq 1 $SPAWN_CNT); do
1319 delay=$(shuf -i 1-5 -n 1)
1320 ( sleep "$delay" && dlogsend -b main -t DLOG_TESTSUITE "$delay" ) &
1325 LOG_DETAILS="testing if libdlogutil sorts by the timestamp correctly"
1327 test_libdlogutil sorting $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
1329 if [ "$type" = "pipe" ]; then
1330 for P in recv sent; do
1331 for Q in mono real; do
1332 LOG_DETAILS="testing if dlogutil --sort-by works correctly (${P}_${Q})"
1333 [ "$(dlogutil -db main --sort-by "${P}_${Q}" | wc -l)" -eq "$SPAWN_CNT" ] && ok || fail
1336 for P in recv sent; do
1337 LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_mono)"
1338 dlogutil -db main --sort-by "${P}_mono" -v json | sed -Ee "s/^.*\"${P}_mono\":([^,}]*).*\$/\\1/" | sort -c && ok || fail
1339 LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_real)"
1340 dlogutil -db main --sort-by "${P}_real" -v json | sed -Ee "s/^.*\"${P}_real\":\"([^\"]*)\".*\$/\\1/" | sort -c && ok || fail
1344 sort_formats="kerneltime time recv_realtime rwtime threadtime long"
1346 for format in $sort_formats; do
1347 LOG_DETAILS="testing if sorting by timestamp from random sources on heavy load works ($format format)"
1349 # collect data and analyze timestamps
1350 dlogutil -b main -d -v "$format" | (
1354 while read -r line; do
1355 # filter out empty lines in "long" format
1356 [ -z "$line" ] && continue
1357 # filter out non-timestamp lines in "long" format
1358 if [ "$format" = "long" ] && [ "$(echo "$line" | sed -re 's/^\[[:print:]*\]$/line_ok/g')" != "line_ok" ]; then
1362 ts=$(extract_timestamp "$format" "$line")
1364 if [ "$ts" -ge "$prev_ts" ]; then
1367 printf "%s\n%s\n\n" "$prev_line" "$line" || break
1371 ) | grep -q ^ && fail || ok
1376 if [ "$type" = "pipe" ]; then
1377 kill $LOGGER > /dev/null
1380 PRERESIZE_CONFIG_PATH="$DLOG_CONFIG_PATH"
1381 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.compress"
1383 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
1384 mkdir -m 777 -p "$RUNTIME_FILTERS_DIR"
1390 dlogsend -b main -c 9999 resizetestblalbl &
1392 LOG_DETAILS="testing if compression-resize works (1/3)"
1393 [ "$(dlogutil -d -m xyz123 | wc -l)" -ge 1 ] && ok || fail
1395 dlogctl --compression-name xyz123 --compression-resize 1
1397 LOG_DETAILS="testing if compression-resize works (2/3)"
1398 [ "$(dlogutil -d -m xyz123 | wc -l)" -eq 0 ] && ok || fail
1400 dlogctl --compression-name xyz123 --compression-resize 200000
1401 dlogsend -b main -c 9999 resizetestblalbl &
1403 LOG_DETAILS="testing if compression-resize works (3/3)"
1404 [ "$(dlogutil -d -m xyz123 | wc -l)" -ge 1 ] && ok || fail
1407 kill $LOGGER > /dev/null
1408 DLOG_CONFIG_PATH=$PRERESIZE_CONFIG_PATH
1409 rm -rf $RUNTIME_FILTERS_DIR
1412 # show results, clean up and return an exit code
1414 echo "$OKS / $TOTAL tests passed"
1415 echo "$FAILS / $TOTAL tests failed"
1417 if [ "$quick" -eq 1 ]; then
1418 echo "WARNING: quick mode!"
1419 echo "About 20% slowest running tests are disabled. Some functionality might be untested."
1420 echo "Rerun without '--quick' to run all tests."
1421 elif [ "$LEGACY_LOGGER" -eq 1 ]; then
1422 echo "WARNING: legacy logger module!"
1423 echo "Some functionality is untested."
1424 echo "Rerun on a device with the out-of-tree logger module to run all tests."
1428 # THE LINE ABOVE MUST STAY THE LAST COMMAND IN THE FILE!
1429 # This is because it is used to pass the exit code. If another command
1430 # is executed after it, its exit code will be propagated instead.