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 # stuff for tracking test case counts
14 #relevant pids default vals
20 TEST_DYNAMIC_FILTERS="@DYNAMIC_FILTERS@"
21 TESTDIR=/var/lib/dlog-tests
27 time=$(echo "$2" | awk -F '[ +]' '{print $2}')
28 ts=$(date +%s%N -d "$time")
31 time=$(echo "$2" | awk -F '[ +.]' '{print $3}')
32 ms=$(echo "$2" | awk -F '[ +.]' '{print $4}')
33 sec=$(date +%s%N -d "$time")
34 ns=$((10#$ms * 1000000))
38 time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
39 ts=$(date +%s%N -d "$time")
42 time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
43 ts=$(date +%s%N -d "$time")
46 time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
47 ts=$(date +%s%N -d "$time")
50 ts=$(echo "$2" | awk -F '[ +]' '{print $1}' | sed -e 's/\.//g')
57 [ "$UTIL_PID" -ne -1 ] && kill "$UTIL_PID" > /dev/null 2>&1
58 [ "$MT_TEST" -ne -1 ] && kill "$MT_TEST" > /dev/null 2>&1
59 [ "$LOGGER" -ne -1 ] && kill "$LOGGER" > /dev/null 2>&1
60 # Shellcheck doesn't like this because the rm call is bad if $TESTDIR is empty.
61 # However, such cases would be caught by the conditional.
62 # shellcheck disable=SC2115
63 [ -d "$TESTDIR" ] && rm -rf "$TESTDIR"/*
64 [ -d "$RUNTIME_FILTERS_DIR" ] && rm -rf "$RUNTIME_FILTERS_DIR"
71 if [ "$LOGGER" -ne -1 ] && [ -z "$(ps -o pid= -p "$LOGGER")" ]; then
78 check_daemon && daemon_status="[logger daemon not running]"
82 printf "[%02d] FAILED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
87 check_daemon && daemon_status="[logger daemon not running]"
91 printf "[%02d] PASSED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
95 USAGE_MESSAGE="usage: $0 [--verbose] [--quick] pipe|logger"
97 OPTS=$(getopt --shell sh --options "" --long verbose,quick --quiet -- "$@")
98 if [ "$?" -eq 1 ]; then
119 echo "This should never happen :)"
125 if [ "$1" = "pipe" ]; then
127 elif [ "$1" = "logger" ]; then
129 # We still accept the legacy {pipe,logger}_quick syntax because there's no reason not to.
130 elif [ "$1" = "pipe_quick" ]; then
133 elif [ "$1" = "logger_quick" ]; then
137 echo "$USAGE_MESSAGE"
141 # supress stderr messages from subcommands
142 if [ "$verbose" -eq 0 ]; then
147 capsh --print | grep Current | grep cap_syslog > /dev/null || { echo "*** ERROR: cap_syslog missing"; NEEDS_TO_QUIT=1; }
148 mount | grep ' / ' | grep rw > /dev/null || { echo "*** ERROR: root not mounted read-write"; NEEDS_TO_QUIT=1; }
149 [ "$NEEDS_TO_QUIT" -eq 0 ] || exit 1
151 if [ -z "$DLOG_CONFIG_PATH" ]; then
152 ORIGINAL_CONFIG_PATH="/etc/dlog.conf"
154 ORIGINAL_CONFIG_PATH="$DLOG_CONFIG_PATH"
157 export DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.test"
158 PATH=$PATH:@libexecdir@/libdlog/
160 #create dir for runtime filters
161 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
162 mkdir -p "$RUNTIME_FILTERS_DIR"
169 if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
172 dlogutil -c -b radio -b system -b main
173 LOG_DETAILS="dlogctl --disable (no args)"
175 [ "$(dlogctl -g | grep -c ENABLED)" -eq 0 ] && ok || fail
176 LOG_DETAILS="testing if filters were applied"
177 dlogsend -b system -t TEST test
178 dlogsend -b main -t TEST test
179 dlogsend -b radio -t TEST test
180 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
182 LOG_DETAILS="dlogctl --enable (no args)"
184 [ "$(dlogctl -g | grep -c DISABLED)" -eq 0 ] && ok || fail
185 LOG_DETAILS="testing if filters were applied"
186 dlogutil -c -b radio -b system -b main
187 dlogsend -b system -t TEST test
188 dlogsend -b main -t TEST test
189 dlogsend -b radio -t TEST test
190 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
192 LOG_DETAILS="dlogctl --disable (1 arg)"
193 dlogctl --disable -b system
194 [ "$(dlogctl -g | grep DISABLED | grep -c system)" -eq 1 ] &&
195 [ "$(dlogctl -g | grep -c DISABLED )" -eq 1 ] && ok || fail
196 LOG_DETAILS="testing if filters were applied"
197 dlogutil -c -b radio -b system -b main
198 dlogsend -b system -t TEST test
199 dlogsend -b main -t TEST test
200 dlogsend -b radio -t TEST test
201 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
203 LOG_DETAILS="dlogctl --disable (multiple args)"
204 dlogctl --disable -b main -b radio
205 [ "$(dlogctl -g | grep DISABLED | grep -cv system)" -eq 2 ] &&
206 [ "$(dlogctl -g | grep DISABLED | grep -c radio)" -eq 1 ] &&
207 [ "$(dlogctl -g | grep DISABLED | grep -c main)" -eq 1 ] && ok || fail
208 LOG_DETAILS="testing if filters were applied"
209 dlogutil -c -b radio -b system -b main
210 dlogsend -b system -t TEST test
211 dlogsend -b main -t TEST test
212 dlogsend -b radio -t TEST test
213 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
215 LOG_DETAILS="dlogctl --enable (multiple args)"
216 dlogctl --enable -b radio -b system
217 [ "$(dlogctl -g | grep -c DISABLED )" -eq 1 ] &&
218 [ "$(dlogctl -g | grep DISABLED | grep -c main)" -eq 1 ] &&
219 [ "$(dlogctl -g | grep ENABLED | grep -c system)" -eq 1 ] &&
220 [ "$(dlogctl -g | grep ENABLED | grep -c radio)" -eq 1 ] && ok || fail
221 LOG_DETAILS="testing if filters were applied"
222 dlogutil -c -b radio -b system -b main
223 dlogsend -b system -t TEST test
224 dlogsend -b main -t TEST test
225 dlogsend -b radio -t TEST test
226 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
228 LOG_DETAILS="dlogctl --enable (1 arg)"
229 dlogctl --enable -b main
230 [ "$(dlogctl -g | grep -c DISABLED)" -eq 0 ] && ok || fail
231 LOG_DETAILS="testing if filters were applied"
232 dlogutil -c -b radio -b system -b main
233 dlogsend -b system -t TEST test
234 dlogsend -b main -t TEST test
235 dlogsend -b radio -t TEST test
236 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
238 LOG_DETAILS="dlogctl -s allow"
239 dlogutil -c -b radio -b system -b main
242 dlogctl -t TEST_TAG -s allow
243 dlogsend -b main -t TEST_TAG test
244 dlogsend -b main -t TEST test
245 [ "$(dlogutil -d -b main | wc -l)" -eq 1 ] && ok || fail
247 LOG_DETAILS="dlogctl -s [N]"
248 dlogutil -c -b radio -b system -b main
251 dlogctl -t TEST_TAG -s 3
252 dlogsend -b main -c 10 -t TEST_TAG test
253 dlogsend -b main -c 10 -t TEST test
254 [ "$(dlogutil -d -b main | wc -l)" -eq 4 ] && ok || fail
256 LOG_DETAILS="testing invalid parameters for dlogctl (1/13)"
257 dlogctl -s invalid > /dev/null && fail || ok
259 LOG_DETAILS="testing invalid parameters for dlogctl (2/13)"
260 dlogctl -p X -g > /dev/null && fail || ok
262 LOG_DETAILS="testing invalid parameters for dlogctl (3/13)"
263 dlogctl -b invalid --disable > /dev/null && fail || ok
265 LOG_DETAILS="testing invalid parameters for dlogctl (4/13)"
266 dlogctl -s allow -g -t xyz -p E > /dev/null && fail || ok
268 LOG_DETAILS="testing invalid parameters for dlogctl (5/13)"
269 dlogctl -s allow -c > /dev/null && fail || ok
271 LOG_DETAILS="testing invalid parameters for dlogctl (6/13)"
272 dlogctl -c -g -t xyz -p E > /dev/null && fail || ok
275 LOG_DETAILS="testing invalid parameters for dlogctl (7/13)"
276 dlogctl -s -10 > /dev/null && fail || ok
278 LOG_DETAILS="testing invalid parameters for dlogctl (8/13)"
279 dlogctl -s 999999 > /dev/null && fail || ok
282 LOG_DETAILS="testing invalid parameters for dlogctl (9/13)"
283 dlogctl -s 100 && ok || fail
285 LOG_DETAILS="testing invalid parameters for dlogctl (10/13)"
286 [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 1 ] && ok || fail
289 LOG_DETAILS="testing invalid parameters for dlogctl (11/13)"
290 [ "$(dlogctl -g | grep -F '*:*' | grep -c 100)" -eq 1 ] && ok || fail
293 LOG_DETAILS="testing invalid parameters for dlogctl (12/13)"
294 dlogctl -c -t '*' -p '*' && ok || fail
296 LOG_DETAILS="testing invalid parameters for dlogctl (13/13)"
297 [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 0 ] && ok || fail
300 LOG_DETAILS="testing if the whole dynamic config directory is respected"
302 cp $RUNTIME_FILTERS_DIR/05-logctl.conf $RUNTIME_FILTERS_DIR/10-other.conf
304 dlogutil -c -b radio -b system -b main
305 dlogsend -b system -t TEST test
306 dlogsend -b main -t TEST test
307 dlogsend -b radio -t TEST test
308 [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
309 rm $RUNTIME_FILTERS_DIR/10-other.conf
312 SEED=$(head -c 6 /dev/urandom | base64)
313 dlogsend -b main -k "$SEED"
314 # -k is async, unlike normal mode; therefore we have to wait until the logging process actually finishes.
315 while pgrep "dlogsend" > /dev/null || pgrep "dlog-log-critical" > /dev/null; do :; done
316 CRIT_PATH="@DLOG_CRITICAL_LOGFILE_PATH@"
317 LOG_DETAILS="testing if critical logging works"
318 cat "$CRIT_PATH".a "$CRIT_PATH".b | grep -F "$SEED" > /dev/null && ok || fail
320 if [ "$type" = "pipe" ] && [ "$quick" -ne 1 ]; then
321 dlogsend -c 2 -d 2 -t DLOGSEND_SIGPIPE_TEST test &
324 kill -s PIPE $DLOGSEND_PID
326 LOG_DETAILS="testing if dlogsend logs even after SIGPIPE"
327 [ "$(dlogutil -d DLOGSEND_SIGPIPE_TEST | wc -l)" -eq 2 ] && ok || fail
330 # put 100 log entries in the "main" buffer
336 LOG_DETAILS="testing if dlogutil -d exits with success after printing logs"
337 dlogutil -d > /dev/null && ok || fail
339 LOG_DETAILS="testing if -t argument is parsed properly"
340 dlogutil -t dummy > /dev/null && fail || ok
342 LOG_DETAILS="testing if -u argument is parsed properly"
343 dlogutil -du dummy > /dev/null && fail || ok
345 LOG_DETAILS="testing if limiting printed log entries to less than exists in the buffer returns proper value"
346 [ "$(dlogutil -b main -t 20 | wc -l)" -eq 20 ] && ok || fail # less logs than currently in buffer
348 LOG_DETAILS="testing if limiting printed log entries to more than exists in the buffer returns proper value"
349 [ "$(dlogutil -b main -t 200 | wc -l)" -eq 100 ] && ok || fail # more
351 LOG_DETAILS="testing if dlogutil returns exact amount of entries as there is in the buffer"
352 [ "$(dlogutil -b main -d | wc -l)" -eq 100 ] && ok || fail # exactly
354 LOG_DETAILS="testing if reading from dummy buffer returns an error as expected"
355 dlogutil -b nonexistent_buffer > /dev/null && fail || ok
357 LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)"
358 [ "$(dlogutil -d -b system | wc -l)" -eq 0 ] && ok || fail
360 LOG_DETAILS="testing if dlogutil -c empties all buffers"
361 dlogutil -cb main && ok || fail
363 LOG_DETAILS="testing if writing entries to empty buffer and reading them returns proper amount of entries"
365 [ "$(dlogutil -b main -d | wc -l)" -eq 10 ] && ok || fail # should be 10, not 110
367 LOG_DETAILS="testing if filters work (1/3)"
368 [ "$(dlogutil -b main -d '*:E' | wc -l)" -eq 5 ] && ok || fail # half of current logs (test_libdlog alternates between error and info log levels)
370 LOG_DETAILS="testing if filters work (2/3)"
371 [ "$(dlogutil -b main -d '*:W' | wc -l)" -eq 5 ] && ok || fail
373 LOG_DETAILS="testing if filters work (3/3)"
374 [ "$(dlogutil -b main -d '*:I' | wc -l)" -eq 10 ] && ok || fail
376 LOG_DETAILS="testing if exact filters work (1/3)"
377 [ "$(dlogutil -b main -d '*:=E' | wc -l)" -eq 5 ] && ok || fail
379 LOG_DETAILS="testing if exact filters work (2/3)"
380 [ "$(dlogutil -b main -d '*:=W' | wc -l)" -eq 0 ] && ok || fail
382 LOG_DETAILS="testing if exact filters work (3/3)"
383 [ "$(dlogutil -b main -d '*:=I' | wc -l)" -eq 5 ] && ok || fail
385 LOG_DETAILS="testing if adding \"silent\" filter works"
386 [ "$(dlogutil -b main -s -d | wc -l)" -eq 0 ] && ok || fail
388 LOG_DETAILS="testing if reading buffer size returns proper exit code"
389 dlogutil -gb main > /dev/null && ok || fail
391 LOG_DETAILS="testing if writing all entries to single file works (-f)"
392 dlogutil -f $TESTDIR/dlog_test_file -d > /dev/null && ok || fail
394 if [ "$quick" -ne 1 ]; then
395 LOG_DETAILS="testing if the continuous mode works as expected (1/2)"
396 dlogutil -b main -f $TESTDIR/dlog_continuous1_file &
399 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
401 [ "$WAS_ALIVE" -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous1_file)" -eq 10 ] && ok || fail
403 LOG_DETAILS="testing if the continuous mode works as expected (2/2)"
404 dlogutil -b main -f $TESTDIR/dlog_continuous2_file &
407 dlogsend -b main "Hi!"
409 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
411 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous2_file)" -eq 11 ] && ok || fail
413 LOG_DETAILS="testing if the monitor mode works as expected (1/2)"
414 dlogutil -mb main -f $TESTDIR/dlog_monitor1_file &
417 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
419 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor1_file)" -eq 0 ] && ok || fail
421 LOG_DETAILS="testing if the monitor mode works as expected (2/2)"
422 dlogutil -mb main -f $TESTDIR/dlog_monitor2_file &
425 dlogsend -b main "Hi!"
427 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
429 [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor2_file)" -eq 1 ] && ok || fail
432 test_libdlog 100000 &
433 LIBDLOGUTIL_CORRECT_PID=$!
434 wait $LIBDLOGUTIL_CORRECT_PID
436 # NB: rotation only really makes sense in the continuous mode
437 # from a user PoV, but the logic doesn't care about dumping
438 # so we do it to simplify things
439 dlogutil -df $TESTDIR/dlog_rotating_file -r 12 -n 3 # 3 files at 12 KB each
441 LOG_DETAILS="testing if single file is properly created"
442 if [ -e $TESTDIR/dlog_test_file ]; then ok; else fail; fi
444 LOG_DETAILS="testing if rotating file is properly created (1/4)"
445 if [ -e $TESTDIR/dlog_rotating_file.1 ]; then ok; else fail; fi
447 LOG_DETAILS="testing if rotating file is properly created (2/4)"
448 if [ -e $TESTDIR/dlog_rotating_file.2 ]; then ok; else fail; fi
450 LOG_DETAILS="testing if rotating file is properly created (3/4)"
451 if [ -e $TESTDIR/dlog_rotating_file.3 ]; then ok; else fail; fi
453 LOG_DETAILS="testing if rotating file is properly created (4/4)"
454 if [ -e $TESTDIR/dlog_rotating_file.4 ]; then fail; else ok; fi
456 LOG_DETAILS="testing the size of log files"
457 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
459 LOG_DETAILS="testing if libdlogutil works correctly in the dump mode"
460 test_libdlogutil dump $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
461 if [ "$quick" -ne 1 ]; then
462 LOG_DETAILS="testing if libdlogutil works correctly if processing the logs takes some time"
463 test_libdlogutil timer $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
465 LOG_DETAILS="testing if libdlogutil works correctly in the continuous mode"
466 test_libdlogutil continuous $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
467 LOG_DETAILS="testing if libdlogutil skips all the logs in the monitor mode correctly"
468 test_libdlogutil monitor $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
469 LOG_DETAILS="testing if libdlogutil priority filter works correctly"
470 test_libdlogutil priority $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
471 LOG_DETAILS="testing if libdlogutil exact priority filter works correctly"
472 test_libdlogutil priority_exact $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
473 LOG_DETAILS="testing if libdlogutil limits the log amount correctly"
474 test_libdlogutil limit $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
475 LOG_DETAILS="testing if libdlogutil PID filter works correctly (1/2)"
476 test_libdlogutil pid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
477 LOG_DETAILS="testing if libdlogutil PID filter works correctly (2/2)"
478 test_libdlogutil pid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
479 LOG_DETAILS="testing if libdlogutil TID filter works correctly (1/2)"
480 test_libdlogutil tid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
481 LOG_DETAILS="testing if libdlogutil TID filter works correctly (2/2)"
482 test_libdlogutil tid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
483 LOG_DETAILS="testing if libdlogutil tag filter works correctly (1/2)"
484 test_libdlogutil tag_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
485 LOG_DETAILS="testing if libdlogutil tag filter works correctly (2/2)"
486 test_libdlogutil tag_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
487 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (1/2)"
488 test_libdlogutil prefix_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
489 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (2/2)"
490 test_libdlogutil prefix_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
491 LOG_DETAILS="testing if libdlogutil returns the correct buffer traits"
492 test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
493 LOG_DETAILS="testing if libdlogutil aliasing works"
494 if [ "$type" = "pipe" ]; then
495 test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
497 DLOG_CONFIG_PATH="@datadir@/dlog-logger.conf.alias" test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
499 LOG_DETAILS="testing if libdlogutil errors out correctly if used improperly"
500 test_libdlogutil negative $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
502 cmd_prefix="dlogutil -t 1 -u 0 -v"
505 regex_prio="[VDIWEFS]{1}"
506 regex_pidtid="P[0-9[:space:]]{5,},\s{1}T[0-9[:space:]]{5,}"
507 regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
508 regex_timezone="[\+-]{1}[0-9]{4}"
510 for PARAM in always auto none never; do
511 for PRIO in info error; do
512 for OUTPUT in pipe tty; do
513 if [ "$PARAM" = "always" ]; then
515 elif [ "$PARAM" = "never" ]; then
517 elif [ "$OUTPUT" = "tty" ]; then
523 if [ "$PRIO" = "info" ]; then
524 REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
525 elif [ "$COLOR_EXPECTED" -eq 0 ]; then
526 REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
528 REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m \([[:print:]]*\)@~\[0m$/1/g"
531 # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
532 COMMAND="$cmd_prefix $format"
534 if [ "$PARAM" = "none" ]; then
535 LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
537 COMMAND="$COMMAND --color=$PARAM"
538 LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
541 if [ "$PRIO" = "info" ]; then
542 COMMAND="$COMMAND '*:=I'"
544 COMMAND="$COMMAND '*:=E'"
547 if [ "$OUTPUT" = "tty" ]; then
548 # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
549 COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
552 # $(eval) is needed since `$COMMAND` may contain `"`
553 line="$(eval "$COMMAND" | tr '\033\n' '~@')"
554 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
558 # TODO: It would be cool to also test warning messages (which have a different color),
559 # but this would require deeper changes to this script, which is already janky enough.
561 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
562 LOG_DETAILS="testing if \"$format\" print format works"
563 line=$($cmd_prefix $format)
564 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
567 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[:print:]]*$/1/g"
568 LOG_DETAILS="testing if \"$format\" print format works"
569 line=$($cmd_prefix $format)
570 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
573 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
574 LOG_DETAILS="testing if \"$format\" print format works"
575 line=$($cmd_prefix $format)
576 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
579 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[: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_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\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/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($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
596 format="recv_realtime"
597 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\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\s{1}\[[0-9[:space:]]{3,}.[0-9[:space:]]{3,}\]\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/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]@[[:print:]]+@$/1/g"
610 LOG_DETAILS="testing if \"$format\" print format works"
611 line=$($cmd_prefix $format)
612 [ "$(echo "$line" | tr '\n' '@' | sed -re "$REGEX")" = "1" ] && ok || fail
615 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\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 if [ "$type" = "pipe" ]; then
622 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"
624 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"
626 LOG_DETAILS="testing if \"$format\" print format works"
627 line=$($cmd_prefix $format)
628 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
631 LOG_DETAILS="testing if \"$format\" print format works"
633 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
634 line=$($cmd_prefix $format)
635 [ "$line" = "rawformatTEST" ] && ok || fail
637 if [ "$quick" -ne 1 ]; then
638 LOG_DETAILS="testing if dlogsend -d works"
640 dlogsend -b main -c 9999 -d 4 -f 7 -t DLOG_TESTSUITE "hi" &
644 # In 10 seconds, 3 cycles 7 logs each should have happened.
645 [ "$(dlogutil -d DLOG_TESTSUITE | wc -l)" -eq 21 ] && ok || fail
648 if [ "$type" = "pipe" ]; then
649 for format in raw brief long; do
650 for i in 1 2 3 4 5 6 7 8 10 15 20 25 513 514 515 516 517 518 519 520; do
651 LOG_DETAILS="testing if padding works correctly (format $format/count $i)"
652 log=$(printf '%0.s&' $(seq 1 $i)) # Print the '&' character $i times
655 dlogsend -b main "$log"
656 line=$($cmd_prefix $format | tr '\n' '@')
663 REGEX="s/I\/DLOG_SEND\([0-9[:space:]]{5,}\):\s{1}$log@$/1/g"
666 REGEX="s/\[\s{1}$regex_time.[0-9]{3,}\s{1}I\/DLOG_SEND\s{1}$regex_pidtid\]@$log@@/1/g"
670 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
675 LOG_DETAILS="testing if KMSG works in the default format"
676 # We check if the command returns at least 100 logs. This seems to be a safe value.
677 # Feel free to change it to a reasonable yet lower value if the test happens to fail otherwise.
678 [ "$(dlogutil -db kmsg | wc -l)" -gt 100 ] && ok || fail
680 if [ "$quick" -ne 1 ]; then
681 LOG_DETAILS="testing if KMSG works in the raw format"
682 last_dmesg=$(dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g")
683 sleep 1 # To make sure dlog has already parsed the log
684 dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail
686 LOG_DETAILS="testing if pid filtering works"
687 dlogsend -b main -t DLOG_TESTSUITE pidTEST &
689 line=$(dlogutil -v raw -d --pid $!)
690 [ "$line" = "pidTEST" ] && ok || fail
692 LOG_DETAILS="testing if tid filtering works"
693 dlogsend -b main -t DLOG_TESTSUITE tidTEST &
695 line=$(dlogutil -v raw -d --tid $!) #dlogsend is a single threaded app so tid is the same as pid
696 [ "$line" = "tidTEST" ] && ok || fail
698 mv $DLOG_CONFIG_PATH $DLOG_CONFIG_PATH.1
699 LOG_DETAILS="testing if secure logging works (1/2)"
700 grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
701 echo "enable_secure_logs=1" >> $DLOG_CONFIG_PATH
703 dlogsend -zb main -t DLOG_TESTSUITE secure &
705 dlogsend -b main -t DLOG_TESTSUITE insecure &
707 line=$(dlogutil -v raw -d | head -n1)
708 [ "$line" = "secure" ] && ok || fail
709 LOG_DETAILS="testing if secure logging works (2/2)"
710 grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
711 echo "enable_secure_logs=0" >> $DLOG_CONFIG_PATH
713 dlogsend -zb main -t DLOG_TESTSUITE secure &
715 dlogsend -b main -t DLOG_TESTSUITE insecure &
717 line=$(dlogutil -v raw -d | head -n1)
718 [ "$line" = "insecure" ] && ok || fail
719 mv $DLOG_CONFIG_PATH.1 $DLOG_CONFIG_PATH
722 dlogsend -b main -t DLOG_TESTSUITE_TAG0 -pI tagTEST0
723 dlogsend -b main -t DLOG_TESTSUITE_TAG1 -pI tagTEST1
724 dlogsend -b main -t DLOG_TESTSUITE_TAG2 -pF tagTEST2
726 LOG_DETAILS="testing if tag filtering works (1/8)"
727 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG0' | wc -l)" -eq 1 ] && ok || fail
728 LOG_DETAILS="testing if tag filtering works (2/8)"
729 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG1' | wc -l)" -eq 1 ] && ok || fail
730 LOG_DETAILS="testing if tag filtering works (3/8)"
731 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG' | wc -l)" -eq 0 ] && ok || fail
732 LOG_DETAILS="testing if tag filtering works (4/8)"
733 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*' | wc -l)" -eq 3 ] && ok || fail
734 LOG_DETAILS="testing if tag filtering works (5/8)"
735 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:I' | wc -l)" -eq 3 ] && ok || fail
736 LOG_DETAILS="testing if tag filtering works (6/8)"
737 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:W' | wc -l)" -eq 1 ] && ok || fail
738 LOG_DETAILS="testing if tag filtering works (7/8)"
739 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG' | wc -l)" -eq 0 ] && ok || fail
740 LOG_DETAILS="testing if tag filtering works (8/8)"
741 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l)" -eq 0 ] && ok || fail
743 if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
744 LOG_DETAILS="testing if limiter and runtime filtering works"
747 [ "$(dlogutil -d -b radio | wc -l)" -eq 12 ] && ok || fail
749 LOG_DETAILS="testing proper SMACK label for dynamic config file location"
750 ORIG_FILTERS_DIR=$(grep dynamic_config_path "$ORIGINAL_CONFIG_PATH" | awk -F "=" '{print $2}')
751 # Running ls on an arbitrary directory and trying to make sense of results is problematic.
752 # However, this is not a problem in our usecase, as we only care about the first field, the security context.
753 # We don't even care about the filename, which isn't arbitrary anyway (-d on fixed path).
754 # shellcheck disable=SC2012
755 [ "$(ls -dZ "$ORIG_FILTERS_DIR" | awk -F ' ' '{print $1}')" = "System::Shared" ] && ok || fail
757 if [ "$quick" -ne 1 ]; then
758 # This creates a process which will wait for SIGCONT and then spam logs. We know its PID, so we can add
759 # PID-based limits and see what happens.
760 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
762 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
763 dlogctl --pid $DLOGSEND_PID -s deny
764 kill -s CONT $DLOGSEND_PID
766 LOG_DETAILS="testing if PID limiting works (1/14)"
767 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 0 ] && ok || fail
768 LOG_DETAILS="testing if PID limiting works (2/14)"
769 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 1 ] && ok || fail
770 LOG_DETAILS="testing if PID limiting works (3/14)"
771 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = "Denied" ] && ok || fail
772 LOG_DETAILS="testing if PID limiting works (4/14)"
773 dlogctl -g | grep -q "Denied for $DLOGSEND_PID" && ok || fail
775 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
777 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
778 dlogctl --pid $DLOGSEND_PID -s 25
779 kill -s CONT $DLOGSEND_PID
781 LOG_DETAILS="testing if PID limiting works (5/14)"
782 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 25 ] && ok || fail
783 LOG_DETAILS="testing if PID limiting works (6/14)"
784 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 1 ] && ok || fail
785 LOG_DETAILS="testing if PID limiting works (7/14)"
786 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = '25 logs/min' ] && ok || fail
787 LOG_DETAILS="testing if PID limiting works (8/14)"
788 dlogctl -g | grep -q "25 logs/min for $DLOGSEND_PID" && ok || fail
790 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
792 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
793 dlogctl --pid $DLOGSEND_PID -s allow
794 kill -s CONT $DLOGSEND_PID
796 LOG_DETAILS="testing if PID limiting works (9/14)"
797 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 100 ] && ok || fail
798 LOG_DETAILS="testing if PID limiting works (10/14)"
799 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 0 ] && ok || fail
800 LOG_DETAILS="testing if PID limiting works (11/14)"
801 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = 'Unlimited' ] && ok || fail
802 LOG_DETAILS="testing if PID limiting works (12/14)"
803 dlogctl -g | grep -q "Unlimited for $DLOGSEND_PID" && ok || fail
805 echo "qos_refresh_rate_s=5" > "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
806 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 15 -d 1 "Pid test"' &
808 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
809 dlogctl --pid $DLOGSEND_PID -s 2
810 kill -s CONT $DLOGSEND_PID
812 rm "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
813 LOG_DETAILS="testing if PID limiting works (13/14)"
814 # In each 5 second period, 5 logs are sent, so there are 3 periods.
815 # 2 logs from each period are allowed.
816 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 6 ] && ok || fail
817 LOG_DETAILS="testing if PID limiting works (14/14)"
818 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c blocked)" -eq 3 ] && ok || fail
820 PREQOS_CONFIG_PATH=$DLOG_CONFIG_PATH
821 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.qos"
822 kill $LOGGER > /dev/null
824 if [ "$type" = "logger" ]; then
831 dlogsend -b main -t DLOG_QOS_TEST0 -c 30 -d 1 -f 2 "A normal app that just wants to log"
832 LOG_DETAILS="testing if QoS works (1/4)"
833 [ "$(dlogutil -d DLOG_QOS_TEST0 | grep -cv blocked)" -eq 30 ] && ok || fail
834 kill $LOGGER > /dev/null
836 if [ "$type" = "logger" ]; then
843 dlogsend -b main -t DLOG_QOS_TEST1 -c 300 -d 1 -f 20 "Some log spam"
844 LOG_DETAILS="testing if QoS works (2/4)"
845 [ "$(dlogutil -d DLOG_QOS_TEST1 | grep -cv blocked)" -le 210 ] && ok || fail
846 kill $LOGGER > /dev/null
848 if [ "$type" = "logger" ]; then
855 dlogsend -b main -t DLOG_QOS_TEST2 -c 30 -d 1 -f 2 "A normal app that just wants to log" &
857 dlogsend -b main -t DLOG_QOS_TEST3 -c 270 -d 1 -f 18 "Some log spam"
859 LOG_DETAILS="testing if QoS works (3/4)"
860 [ "$(dlogutil -d DLOG_QOS_TEST2 DLOG_QOS_TEST3 | grep -cv blocked)" -le 210 ] && ok || fail
861 LOG_DETAILS="testing if QoS works (4/4)"
862 [ "$(dlogutil -d DLOG_QOS_TEST2 | grep -cv blocked)" -gt 24 ] && ok || fail
864 DLOG_CONFIG_PATH=$PREQOS_CONFIG_PATH
865 kill $LOGGER > /dev/null
874 echo "deduplicate_method=only_identical_neighbours" > "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
875 echo "deduplicate_interval_ms=10" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
877 dlogsend -p Info -b main -c 9 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
878 LOG_DETAILS="testing if deduplication with warnings works properly (1/12)"
879 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 1 ] && ok || fail
880 LOG_DETAILS="testing if deduplication with warnings works properly (2/12)"
881 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 0 ] && ok || fail
883 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
884 LOG_DETAILS="testing if deduplication with warnings works properly (3/12)"
885 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 3 ] && ok || fail
886 LOG_DETAILS="testing if deduplication with warnings works properly (4/12)"
887 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 1 ] && ok || fail
889 echo "deduplicate_warn_quantity=8" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
891 dlogsend -p Info -b main -c 24 -t DLOG_DEDUP_TEST Message
892 LOG_DETAILS="testing if deduplication with warnings works properly (5/12)"
893 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 4 ] && ok || fail
894 LOG_DETAILS="testing if deduplication with warnings works properly (6/12)"
895 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Message LOG DUPLICATED')" -eq 3 ] && ok || fail
897 dlogsend -p Info -b main -c 8 -t DLOG_DEDUP_TEST longerMessage
898 LOG_DETAILS="testing if deduplication with warnings works properly (7/12)"
899 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c longerMessage)" -eq 2 ] && ok || fail
900 LOG_DETAILS="testing if deduplication with warnings works properly (8/12)"
901 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 6 ] && ok || fail
902 LOG_DETAILS="testing if deduplication with warnings works properly (9/12)"
903 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'longerMessage LOG DUPLICATED')" -eq 1 ] && ok || fail
905 echo "deduplicate_warn_quantity=-1" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
907 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, no warning"
908 LOG_DETAILS="testing if deduplication with warnings works properly (10/12)"
909 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning')" -eq 1 ] && ok || fail
910 LOG_DETAILS="testing if deduplication with warnings works properly (11/12)"
911 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication')" -eq 4 ] && ok || fail
912 LOG_DETAILS="testing if deduplication with warnings works properly (12/12)"
913 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning LOG DUPLICATED')" -eq 0 ] && ok || fail
915 rm "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
917 LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
918 test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
920 if [ "$quick" -ne 1 ]; then
921 kill $LOGGER > /dev/null
928 dlogsend -b main -t DLOG_LOGGER_TEST0 -c 100 "hi"
930 LOG_DETAILS="testing if logger daemon persistent logging works"
931 [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test)" -eq 100 ] && ok || fail
933 dlogsend -b main -t DLOG_LOGGER_TEST1 -c 500000 "hi"
935 RESULT=$(du -c "$TESTDIR"/test* | tail -n 1 | cut -f 1)
936 LOG_DETAILS="testing if logger daemon log rotating works (1/2)"
937 [ "$RESULT" -gt 4096 ] && ok || fail # Min 4 MB
938 LOG_DETAILS="testing if logger daemon log rotating works (2/2)"
939 [ "$RESULT" -lt 6144 ] && ok || fail # Max 6 MB
942 kill $LOGGER > /dev/null
945 dlog_logger -t 5 -b 100000 &
949 dlogsend -b main -t DLOG_LOGGER_TEST2 -c 100 "hi"
951 LOG_DETAILS="testing if logger daemon buffering works (1/5)"
952 [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test)" -eq 0 ] && ok || fail
955 LOG_DETAILS="testing if logger daemon buffering works (2/5)"
956 [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test)" -eq 100 ] && ok || fail
958 dlogsend -b main -t DLOG_LOGGER_TEST3 -c 100 "hi"
960 LOG_DETAILS="testing if logger daemon buffering works (3/5)"
961 [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test)" -eq 0 ] && ok || fail
964 kill $LOGGER > /dev/null
966 dlog_logger -t 10000 -b 100 &
969 LOG_DETAILS="testing if logger daemon buffering works (4/5)"
970 [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test)" -eq 100 ] && ok || fail
972 dlogsend -b main -t DLOG_LOGGER_TEST4 -c 100 "hi"
974 LOG_DETAILS="testing if logger daemon buffering works (5/5)"
975 [ "$(grep -c DLOG_LOGGER_TEST4 "$TESTDIR"/test)" -gt 90 ] && ok || fail
978 kill $LOGGER > /dev/null
984 LOG_DETAILS="testing if the library works with multithreaded app"
985 dlogutil -f $TESTDIR/dlog_mt_test &
987 test_libdlog && ok || fail
996 # Spawn logging scripts and wait for them to finish.
997 # We launch all the $SPAWN_CNT scripts in a subshell, and then use the wait command in order to
998 # wait for all the jobs of the subshell, which means all the logging scripts.
999 # Each of the logging scripts is a new subsubshell which waits a random amount of seconds and then logs
1000 # a single message. This gets us 5 groups of logs separated by a second; there are about 200 logs in each
1001 # group, sent about at the same time.
1003 for i in $(seq 1 $SPAWN_CNT); do
1004 delay=$(shuf -i 1-5 -n 1)
1005 ( sleep "$delay" && dlogsend -b main -t DLOG_TESTSUITE "$delay" ) &
1010 LOG_DETAILS="testing if libdlogutil sorts by the timestamp correctly"
1012 test_libdlogutil sorting $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
1014 if [ "$type" = "pipe" ]; then
1015 for P in recv sent; do
1016 for Q in mono real; do
1017 LOG_DETAILS="testing if dlogutil --sort-by works correctly (${P}_${Q})"
1018 [ "$(dlogutil -db main --sort-by "${P}_${Q}" | wc -l)" -eq "$SPAWN_CNT" ] && ok || fail
1021 for P in recv sent; do
1022 LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_mono)"
1023 dlogutil -db main --sort-by "${P}_mono" -v json | sed -Ee "s/^.*\"${P}_mono\":([^,}]*).*\$/\\1/" | sort -c && ok || fail
1024 LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_real)"
1025 dlogutil -db main --sort-by "${P}_real" -v json | sed -Ee "s/^.*\"${P}_real\":\"([^\"]*)\".*\$/\\1/" | sort -c && ok || fail
1029 sort_formats="kerneltime time recv_realtime rwtime threadtime long"
1031 for format in $sort_formats; do
1032 LOG_DETAILS="testing if sorting by timestamp from random sources on heavy load works ($format format)"
1034 # collect data and analyze timestamps
1035 dlogutil -b main -d -v "$format" | (
1039 while read -r line; do
1040 # filter out empty lines in "long" format
1041 [ -z "$line" ] && continue
1042 # filter out non-timestamp lines in "long" format
1043 if [ "$format" = "long" ] && [ "$(echo "$line" | sed -re 's/^\[[:print:]*\]$/line_ok/g')" != "line_ok" ]; then
1047 ts=$(extract_timestamp "$format" "$line")
1049 if [ "$ts" -ge "$prev_ts" ]; then
1052 printf "%s\n%s\n\n" "$prev_line" "$line" || break
1056 ) | grep -q ^ && fail || ok
1061 # show results, clean up and return an exit code
1063 echo "$OKS / $TOTAL tests passed"
1064 echo "$FAILS / $TOTAL tests failed"
1066 if [ "$quick" -eq 1 ]; then
1067 echo "WARNING: quick mode!"
1068 echo "About 20% slowest running tests are disabled. Some functionality might be untested."
1069 echo "Rerun without '--quick' to run all tests."
1073 # THE LINE ABOVE MUST STAY THE LAST COMMAND IN THE FILE!
1074 # This is because it is used to pass the exit code. If another command
1075 # is executed after it, its exit code will be propagated instead.