3 # stuff for tracking test case counts
9 #relevant pids default vals
15 TEST_DYNAMIC_FILTERS="@DYNAMIC_FILTERS@"
16 TESTDIR=/var/lib/dlog-tests
22 time=`echo $2 | awk -F '[ +]' '{print $2}'`
23 ts=`date +%s%N -d $time`
26 time=`echo $2 | awk -F '[ +.]' '{print $3}'`
27 ms=`echo $2 | awk -F '[ +.]' '{print $4}'`
28 sec=`date +%s%N -d $time`
29 ns=$((10#$ms * 1000000))
33 time=`echo $2 | awk -F '[ +.]' '{print $2}'`
34 ts=`date +%s%N -d $time`
37 time=`echo $2 | awk -F '[ +.]' '{print $2}'`
38 ts=`date +%s%N -d $time`
41 time=`echo $2 | awk -F '[ +.]' '{print $2}'`
42 ts=`date +%s%N -d $time`
45 ts=`echo $2 | awk -F '[ +]' '{print $1}' | sed -e 's/\.//g'`
52 [ $UTIL_PID -ne -1 ] && kill $UTIL_PID > /dev/null 2>&1
53 [ $MT_TEST -ne -1 ] && kill $MT_TEST > /dev/null 2>&1
54 [ $LOGGER -ne -1 ] && kill $LOGGER > /dev/null 2>&1
55 [ -d $TESTDIR ] && rm -rf $TESTDIR/*
56 [ -d $RUNTIME_FILTERS_DIR ] && rm -rf $RUNTIME_FILTERS_DIR
63 if [ $LOGGER -ne -1 ] && [ -z "$(ps -o pid= -p $LOGGER)" ]; then
71 [ $? -eq 0 ] && daemon_status="[logger daemon not running]"
75 printf "[%02d] FAILED: %s %s\n" $TOTAL "$LOG_DETAILS" "$daemon_status"
81 [ $? -eq 0 ] && daemon_status="[logger daemon not running]"
85 printf "[%02d] PASSED: %s %s\n" $TOTAL "$LOG_DETAILS" "$daemon_status"
89 # supress stderr messages from subcommands
92 USAGE_MESSAGE="usage: $0 pipe|logger|pipe_quick|logger_quick"
99 if [ "$1" == "pipe" ]; then
102 elif [ "$1" == "logger" ]; then
105 elif [ "$1" == "pipe_quick" ]; then
108 elif [ "$1" == "logger_quick" ]; then
117 capsh --print | grep Current | grep cap_syslog > /dev/null || { echo "*** ERROR: cap_syslog missing"; NEEDS_TO_QUIT=1; }
118 mount | grep ' / ' | grep rw > /dev/null || { echo "*** ERROR: root not mounted read-write"; NEEDS_TO_QUIT=1; }
119 [[ $NEEDS_TO_QUIT -eq 0 ]] || exit 1
121 if [ -z "$DLOG_CONFIG_PATH" ]; then
122 ORIGINAL_CONFIG_PATH="/etc/dlog.conf"
124 ORIGINAL_CONFIG_PATH="$DLOG_CONFIG_PATH"
127 export DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.test"
128 PATH=$PATH:@libexecdir@/libdlog/
130 #create dir for runtime filters
131 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
132 mkdir -p "$RUNTIME_FILTERS_DIR"
135 if [ $type == "pipe" ]; then
136 dlog_logger -b 99 -t 0 &
141 if [ "$TEST_DYNAMIC_FILTERS" == "true" ]; then
144 dlogutil -c -b radio -b system -b main
145 LOG_DETAILS="dlogctl --disable (no args)"
147 [ `dlogctl -g | grep ENABLED | wc -l` -eq 0 ] && ok || fail
148 LOG_DETAILS="testing if filters were applied"
149 dlogsend -b system -t TEST test
150 dlogsend -b main -t TEST test
151 dlogsend -b radio -t TEST test
152 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 0 ] && ok || fail
154 LOG_DETAILS="dlogctl --enable (no args)"
156 [ `dlogctl -g | grep DISABLED | wc -l` -eq 0 ] && ok || fail
157 LOG_DETAILS="testing if filters were applied"
158 dlogutil -c -b radio -b system -b main
159 dlogsend -b system -t TEST test
160 dlogsend -b main -t TEST test
161 dlogsend -b radio -t TEST test
162 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 3 ] && ok || fail
164 LOG_DETAILS="dlogctl --disable (1 arg)"
165 dlogctl --disable -b system
166 [ `dlogctl -g | grep DISABLED | grep system | wc -l` -eq 1 ] &&
167 [ `dlogctl -g | grep DISABLED | wc -l` -eq 1 ] && ok || fail
168 LOG_DETAILS="testing if filters were applied"
169 dlogutil -c -b radio -b system -b main
170 dlogsend -b system -t TEST test
171 dlogsend -b main -t TEST test
172 dlogsend -b radio -t TEST test
173 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 2 ] && ok || fail
175 LOG_DETAILS="dlogctl --disable (multiple args)"
176 dlogctl --disable -b main -b radio
177 [ `dlogctl -g | grep DISABLED | grep -v system | wc -l` -eq 2 ] &&
178 [ `dlogctl -g | grep DISABLED | grep radio | wc -l` -eq 1 ] &&
179 [ `dlogctl -g | grep DISABLED | grep main | wc -l` -eq 1 ] && ok || fail
180 LOG_DETAILS="testing if filters were applied"
181 dlogutil -c -b radio -b system -b main
182 dlogsend -b system -t TEST test
183 dlogsend -b main -t TEST test
184 dlogsend -b radio -t TEST test
185 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 0 ] && ok || fail
187 LOG_DETAILS="dlogctl --enable (multiple args)"
188 dlogctl --enable -b radio -b system
189 [ `dlogctl -g | grep DISABLED | wc -l` -eq 1 ] &&
190 [ `dlogctl -g | grep DISABLED | grep main | wc -l` -eq 1 ] &&
191 [ `dlogctl -g | grep ENABLED | grep system | wc -l` -eq 1 ] &&
192 [ `dlogctl -g | grep ENABLED | grep radio | wc -l` -eq 1 ] && ok || fail
193 LOG_DETAILS="testing if filters were applied"
194 dlogutil -c -b radio -b system -b main
195 dlogsend -b system -t TEST test
196 dlogsend -b main -t TEST test
197 dlogsend -b radio -t TEST test
198 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 2 ] && ok || fail
200 LOG_DETAILS="dlogctl --enable (1 arg)"
201 dlogctl --enable -b main
202 [ `dlogctl -g | grep DISABLED | wc -l` -eq 0 ] && ok || fail
203 LOG_DETAILS="testing if filters were applied"
204 dlogutil -c -b radio -b system -b main
205 dlogsend -b system -t TEST test
206 dlogsend -b main -t TEST test
207 dlogsend -b radio -t TEST test
208 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 3 ] && ok || fail
210 LOG_DETAILS="dlogctl -s allow"
211 dlogutil -c -b radio -b system -b main
214 dlogctl -t TEST_TAG -s allow
215 dlogsend -b main -t TEST_TAG test
216 dlogsend -b main -t TEST test
217 [ `dlogutil -d -b main | wc -l` -eq 1 ] && ok || fail
219 LOG_DETAILS="dlogctl -s [N]"
220 dlogutil -c -b radio -b system -b main
223 dlogctl -t TEST_TAG -s 3
224 dlogsend -b main -c 10 -t TEST_TAG test
225 dlogsend -b main -c 10 -t TEST test
226 [ `dlogutil -d -b main | wc -l` -eq 4 ] && ok || fail
228 LOG_DETAILS="testing invalid parameters for dlogctl (1/13)"
229 dlogctl -s invalid &> /dev/null && fail || ok
231 LOG_DETAILS="testing invalid parameters for dlogctl (2/13)"
232 dlogctl -p X -g &> /dev/null && fail || ok
234 LOG_DETAILS="testing invalid parameters for dlogctl (3/13)"
235 dlogctl -b invalid --disable &> /dev/null && fail || ok
237 LOG_DETAILS="testing invalid parameters for dlogctl (4/13)"
238 dlogctl -s allow -g -t xyz -p E &> /dev/null && fail || ok
240 LOG_DETAILS="testing invalid parameters for dlogctl (5/13)"
241 dlogctl -s allow -c &> /dev/null && fail || ok
243 LOG_DETAILS="testing invalid parameters for dlogctl (6/13)"
244 dlogctl -c -g -t xyz -p E &> /dev/null && fail || ok
247 LOG_DETAILS="testing invalid parameters for dlogctl (7/13)"
248 dlogctl -s -10 &> /dev/null && fail || ok
250 LOG_DETAILS="testing invalid parameters for dlogctl (8/13)"
251 dlogctl -s 999999 &> /dev/null && fail || ok
254 LOG_DETAILS="testing invalid parameters for dlogctl (9/13)"
255 dlogctl -s 100 && ok || fail
257 LOG_DETAILS="testing invalid parameters for dlogctl (10/13)"
258 [ `cat $RUNTIME_FILTERS_DIR/05-logctl.conf | grep -E 'limiter\|\*\|\*=100' | wc -l` -eq 1 ] && ok || fail
261 LOG_DETAILS="testing invalid parameters for dlogctl (11/13)"
262 [ `dlogctl -g | grep '*:*' | grep 100 | wc -l` -eq 1 ] && ok || fail
265 LOG_DETAILS="testing invalid parameters for dlogctl (12/13)"
266 dlogctl -c -t '*' -p '*' && ok || fail
268 LOG_DETAILS="testing invalid parameters for dlogctl (13/13)"
269 [ `cat $RUNTIME_FILTERS_DIR/05-logctl.conf | grep -E 'limiter\|\*\|\*=100' | wc -l` -eq 0 ] && ok || fail
272 LOG_DETAILS="testing if the whole dynamic config directory is respected"
274 cp $RUNTIME_FILTERS_DIR/{05-logctl.conf,10-other.conf}
276 dlogutil -c -b radio -b system -b main
277 dlogsend -b system -t TEST test
278 dlogsend -b main -t TEST test
279 dlogsend -b radio -t TEST test
280 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 0 ] && ok || fail
281 rm $RUNTIME_FILTERS_DIR/10-other.conf
284 # put 100 log entries in the "main" buffer
290 LOG_DETAILS="testing if dlogutil -d exits with success after printing logs"
291 dlogutil -d &> /dev/null && ok || fail
293 LOG_DETAILS="testing if -t argument is parsed properly"
294 dlogutil -t dummy &> /dev/null && fail || ok
296 LOG_DETAILS="testing if -u argument is parsed properly"
297 dlogutil -du dummy &> /dev/null && fail || ok
299 LOG_DETAILS="testing if limiting printed log entries to less than exists in the buffer returns proper value"
300 [ $(dlogutil -b main -t 20 | wc -l) -eq 20 ] && ok || fail # less logs than currently in buffer
302 LOG_DETAILS="testing if limiting printed log entries to more than exists in the buffer returns proper value"
303 [ $(dlogutil -b main -t 200 | wc -l) -eq 100 ] && ok || fail # more
305 LOG_DETAILS="testing if dlogutil returns exact amount of entries as there is in the buffer"
306 [ $(dlogutil -b main -d | wc -l) -eq 100 ] && ok || fail # exactly
308 LOG_DETAILS="testing if reading from dummy buffer returns an error as expected"
309 dlogutil -b nonexistent_buffer &> /dev/null && fail || ok
311 LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)"
312 [ $(dlogutil -d -b system | wc -l) -eq 0 ] && ok || fail
314 LOG_DETAILS="testing if dlogutil -c empties all buffers"
315 dlogutil -cb main && ok || fail
317 LOG_DETAILS="testing if writing entries to empty buffer and reading them returns proper amount of entries"
319 [ $(dlogutil -b main -d | wc -l) -eq 10 ] && ok || fail # should be 10, not 110
321 LOG_DETAILS="testing if filters work (1/3)"
322 [ $(dlogutil -b main -d *:E | wc -l) -eq 5 ] && ok || fail # half of current logs (test_libdlog alternates between error and info log levels)
324 LOG_DETAILS="testing if filters work (2/3)"
325 [ $(dlogutil -b main -d *:W | wc -l) -eq 5 ] && ok || fail
327 LOG_DETAILS="testing if filters work (3/3)"
328 [ $(dlogutil -b main -d *:I | wc -l) -eq 10 ] && ok || fail
330 LOG_DETAILS="testing if exact filters work (1/3)"
331 [ $(dlogutil -b main -d *:=E | wc -l) -eq 5 ] && ok || fail
333 LOG_DETAILS="testing if exact filters work (2/3)"
334 [ $(dlogutil -b main -d *:=W | wc -l) -eq 0 ] && ok || fail
336 LOG_DETAILS="testing if exact filters work (3/3)"
337 [ $(dlogutil -b main -d *:=I | wc -l) -eq 5 ] && ok || fail
339 LOG_DETAILS="testing if adding \"silent\" filter works"
340 [ $(dlogutil -b main -s -d | wc -l) -eq 0 ] && ok || fail
342 LOG_DETAILS="testing if reading buffer size returns proper exit code"
343 dlogutil -gb main &> /dev/null && ok || fail
345 LOG_DETAILS="testing if writing all entries to single file works (-f)"
346 dlogutil -f $TESTDIR/dlog_test_file -d &> /dev/null && ok || fail
348 if [ $quick -ne 1 ]; then
349 LOG_DETAILS="testing if the continuous mode works as expected (1/2)"
350 dlogutil -b main -f $TESTDIR/dlog_continuous1_file &
353 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
355 [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_continuous1_file` -eq 10 ]] && ok || fail
357 LOG_DETAILS="testing if the continuous mode works as expected (2/2)"
358 dlogutil -b main -f $TESTDIR/dlog_continuous2_file &
361 dlogsend -b main "Hi!"
363 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
365 [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_continuous2_file` -eq 11 ]] && ok || fail
367 LOG_DETAILS="testing if the monitor mode works as expected (1/2)"
368 dlogutil -mb main -f $TESTDIR/dlog_monitor1_file &
371 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
373 [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_monitor1_file` -eq 0 ]] && ok || fail
375 LOG_DETAILS="testing if the monitor mode works as expected (2/2)"
376 dlogutil -mb main -f $TESTDIR/dlog_monitor2_file &
379 dlogsend -b main "Hi!"
381 kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
383 [[ $WAS_ALIVE -eq 1 && `wc -l < $TESTDIR/dlog_monitor2_file` -eq 1 ]] && ok || fail
386 LOG_DETAILS="testing if writing entries to rotating files works (-r/-n)"
387 dlogutil -f $TESTDIR/dlog_rotating_file -r 12 -n 3 & # 3 files at 12 KB each
390 test_libdlog 100000 &
391 LIBDLOGUTIL_CORRECT_PID=$!
392 wait $LIBDLOGUTIL_CORRECT_PID
394 LOG_DETAILS="testing if single file is properly created"
395 if [ -e $TESTDIR/dlog_test_file ]; then ok; else fail; fi
397 LOG_DETAILS="testing if rotating file is properly created (1/4)"
398 if [ -e $TESTDIR/dlog_rotating_file.1 ]; then ok; else fail; fi
400 LOG_DETAILS="testing if rotating file is properly created (2/4)"
401 if [ -e $TESTDIR/dlog_rotating_file.2 ]; then ok; else fail; fi
403 LOG_DETAILS="testing if rotating file is properly created (3/4)"
404 if [ -e $TESTDIR/dlog_rotating_file.3 ]; then ok; else fail; fi
406 LOG_DETAILS="testing if rotating file is properly created (4/4)"
407 if [ -e $TESTDIR/dlog_rotating_file.4 ]; then fail; else ok; fi
409 LOG_DETAILS="testing the size of log files"
410 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
415 LOG_DETAILS="testing if libdlogutil works correctly in the dump mode"
416 test_libdlogutil dump $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
417 if [ $quick -ne 1 ]; then
418 LOG_DETAILS="testing if libdlogutil works correctly if processing the logs takes some time"
419 test_libdlogutil timer $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
421 LOG_DETAILS="testing if libdlogutil works correctly in the continuous mode"
422 test_libdlogutil continuous $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
423 LOG_DETAILS="testing if libdlogutil skips all the logs in the monitor mode correctly"
424 test_libdlogutil monitor $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
425 LOG_DETAILS="testing if libdlogutil priority filter works correctly"
426 test_libdlogutil priority $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
427 LOG_DETAILS="testing if libdlogutil exact priority filter works correctly"
428 test_libdlogutil priority_exact $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
429 LOG_DETAILS="testing if libdlogutil limits the log amount correctly"
430 test_libdlogutil limit $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
431 LOG_DETAILS="testing if libdlogutil PID filter works correctly (1/2)"
432 test_libdlogutil pid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
433 LOG_DETAILS="testing if libdlogutil PID filter works correctly (2/2)"
434 test_libdlogutil pid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
435 LOG_DETAILS="testing if libdlogutil TID filter works correctly (1/2)"
436 test_libdlogutil tid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
437 LOG_DETAILS="testing if libdlogutil TID filter works correctly (2/2)"
438 test_libdlogutil tid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
439 LOG_DETAILS="testing if libdlogutil tag filter works correctly (1/2)"
440 test_libdlogutil tag_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
441 LOG_DETAILS="testing if libdlogutil tag filter works correctly (2/2)"
442 test_libdlogutil tag_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
443 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (1/2)"
444 test_libdlogutil prefix_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
445 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (2/2)"
446 test_libdlogutil prefix_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
447 LOG_DETAILS="testing if libdlogutil returns the correct buffer traits"
448 test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
449 LOG_DETAILS="testing if libdlogutil aliasing works"
450 if [ $type == "pipe" ]; then
451 test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
453 DLOG_CONFIG_PATH="@datadir@/dlog-logger.conf.alias" test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
455 LOG_DETAILS="testing if libdlogutil errors out correctly if used improperly"
456 test_libdlogutil negative $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
458 cmd_prefix="dlogutil -t 1 -u 0 -v"
461 regex_prio="[VDIWEFS]{1}"
462 regex_pidtid="P[0-9[:space:]]{5,},\s{1}T[0-9[:space:]]{5,}"
463 regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
464 regex_timezone="[\+-]{1}[0-9]{4}"
466 for PARAM in always auto none never; do
467 for PRIO in info error; do
468 for OUTPUT in pipe tty; do
469 if [[ "$PARAM" == "always" ]]; then
471 elif [[ "$PARAM" == "never" ]]; then
473 elif [[ "$OUTPUT" == "tty" ]]; then
479 if [[ "$PRIO" == "info" ]]; then
480 REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
481 elif [[ "$COLOR_EXPECTED" -eq 0 ]]; then
482 REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
484 REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m \([[:print:]]*\)@~\[0m$/1/g"
487 # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
488 COMMAND="$cmd_prefix $format"
490 if [[ "$PARAM" == "none" ]]; then
491 LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
493 COMMAND="$COMMAND --color=$PARAM"
494 LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
497 if [[ "$PRIO" == "info" ]]; then
498 COMMAND="$COMMAND '*:=I'"
500 COMMAND="$COMMAND '*:=E'"
503 if [[ "$OUTPUT" == "tty" ]]; then
504 # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
505 COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
508 # `eval` is needed since `$COMMAND` may contain `"`
509 line=`eval $COMMAND | tr '\033\n' '~@'`
510 [[ `echo "$line" | sed -re "$REGEX"` == "1" ]] && ok || fail
514 # TODO: It would be cool to also test warning messages (which have a different color),
515 # but this would require deeper changes to this script, which is already janky enough.
517 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
518 LOG_DETAILS="testing if \"$format\" print format works"
519 line=`$cmd_prefix $format`
520 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
523 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[:print:]]*$/1/g"
524 LOG_DETAILS="testing if \"$format\" print format works"
525 line=`$cmd_prefix $format`
526 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
529 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
530 LOG_DETAILS="testing if \"$format\" print format works"
531 line=`$cmd_prefix $format`
532 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
535 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
536 LOG_DETAILS="testing if \"$format\" print format works"
537 line=`$cmd_prefix $format`
538 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
541 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
542 LOG_DETAILS="testing if \"$format\" print format works"
543 line=`$cmd_prefix $format`
544 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
547 REGEX="s/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
548 LOG_DETAILS="testing if \"$format\" print format works"
549 line=`$cmd_prefix $format`
550 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
552 format="recv_realtime"
553 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
554 LOG_DETAILS="testing if \"$format\" print format works"
555 line=`$cmd_prefix $format`
556 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
559 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"
560 LOG_DETAILS="testing if \"$format\" print format works"
561 line=`$cmd_prefix $format`
562 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
565 REGEX="s/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]@[[:print:]]+@$/1/g"
566 LOG_DETAILS="testing if \"$format\" print format works"
567 line=`$cmd_prefix $format`
568 [[ `echo "$line" | tr '\n' '@' | sed -re $REGEX` == "1" ]] && ok || fail
571 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
572 LOG_DETAILS="testing if \"$format\" print format works"
573 line=`$cmd_prefix $format`
574 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
577 if [[ "$type" == "pipe" ]]; then
578 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"
580 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"
582 LOG_DETAILS="testing if \"$format\" print format works"
583 line=`$cmd_prefix $format`
584 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
587 LOG_DETAILS="testing if \"$format\" print format works"
589 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
590 line=`$cmd_prefix $format`
591 [[ "$line" == "rawformatTEST" ]] && ok || fail
593 if [ $quick -ne 1 ]; then
594 LOG_DETAILS="testing if dlogsend -d works"
596 dlogsend -b main -c 9999 -d 4 -f 7 -t DLOG_TESTSUITE "hi" &
600 # In 10 seconds, 3 cycles 7 logs each should have happened.
601 [[ "$(dlogutil -d DLOG_TESTSUITE | wc -l)" -eq 21 ]] && ok || fail
604 if [ $type == "pipe" ]; then
605 for format in raw brief long; do
606 for i in {1..8} 10 15 20 25 {513..520}; do
607 LOG_DETAILS="testing if padding works correctly (format $format/count $i)"
608 log=$(printf '%0.s&' $(seq 1 $i)) # Print the '&' character $i times
611 dlogsend -b main $log
612 line=$($cmd_prefix $format | tr '\n' '@')
619 REGEX="s/I\/DLOG_SEND\([0-9[:space:]]{5,}\):\s{1}$log@$/1/g"
622 REGEX="s/\[\s{1}$regex_time.[0-9]{3,}\s{1}I\/DLOG_SEND\s{1}$regex_pidtid\]@$log@@/1/g"
626 [[ $(echo "$line" | sed -re $REGEX) == "1" ]] && ok || fail
631 LOG_DETAILS="testing if KMSG works in the default format"
632 # We check if the command returns at least 100 logs. This seems to be a safe value.
633 # Feel free to change it to a reasonable yet lower value if the test happens to fail otherwise.
634 [[ "$(dlogutil -db kmsg | wc -l)" -gt 100 ]] && ok || fail
636 if [ $quick -ne 1 ]; then
637 LOG_DETAILS="testing if KMSG works in the raw format"
638 last_dmesg=`dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g"`
639 sleep 1 # To make sure dlog has already parsed the log
640 dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail
642 LOG_DETAILS="testing if pid filtering works"
643 dlogsend -b main -t DLOG_TESTSUITE pidTEST &
645 line=`dlogutil -v raw -d --pid $!`
646 [[ "$line" == "pidTEST" ]] && ok || fail
648 LOG_DETAILS="testing if tid filtering works"
649 dlogsend -b main -t DLOG_TESTSUITE tidTEST &
651 line=`dlogutil -v raw -d --tid $!` #dlogsend is a single threaded app so tid is the same as pid
652 [[ "$line" == "tidTEST" ]] && ok || fail
654 mv $DLOG_CONFIG_PATH $DLOG_CONFIG_PATH.1
655 LOG_DETAILS="testing if secure logging works (1/2)"
656 grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
657 echo "enable_secure_logs=1" >> $DLOG_CONFIG_PATH
659 dlogsend -zb main -t DLOG_TESTSUITE secure &
661 dlogsend -b main -t DLOG_TESTSUITE insecure &
663 line=`dlogutil -v raw -d | head -n1`
664 [[ "$line" == "secure" ]] && ok || fail
665 LOG_DETAILS="testing if secure logging works (2/2)"
666 grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
667 echo "enable_secure_logs=0" >> $DLOG_CONFIG_PATH
669 dlogsend -zb main -t DLOG_TESTSUITE secure &
671 dlogsend -b main -t DLOG_TESTSUITE insecure &
673 line=`dlogutil -v raw -d | head -n1`
674 [[ "$line" == "insecure" ]] && ok || fail
675 mv $DLOG_CONFIG_PATH.1 $DLOG_CONFIG_PATH
678 dlogsend -b main -t DLOG_TESTSUITE_TAG0 -pI tagTEST0
679 dlogsend -b main -t DLOG_TESTSUITE_TAG1 -pI tagTEST1
680 dlogsend -b main -t DLOG_TESTSUITE_TAG2 -pF tagTEST2
682 LOG_DETAILS="testing if tag filtering works (1/8)"
683 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG0' | wc -l` -eq 1 ]] && ok || fail
684 LOG_DETAILS="testing if tag filtering works (2/8)"
685 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG1' | wc -l` -eq 1 ]] && ok || fail
686 LOG_DETAILS="testing if tag filtering works (3/8)"
687 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG' | wc -l` -eq 0 ]] && ok || fail
688 LOG_DETAILS="testing if tag filtering works (4/8)"
689 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*' | wc -l` -eq 3 ]] && ok || fail
690 LOG_DETAILS="testing if tag filtering works (5/8)"
691 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:I' | wc -l` -eq 3 ]] && ok || fail
692 LOG_DETAILS="testing if tag filtering works (6/8)"
693 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:W' | wc -l` -eq 1 ]] && ok || fail
694 LOG_DETAILS="testing if tag filtering works (7/8)"
695 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG' | wc -l` -eq 0 ]] && ok || fail
696 LOG_DETAILS="testing if tag filtering works (8/8)"
697 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l` -eq 0 ]] && ok || fail
699 if [ "$TEST_DYNAMIC_FILTERS" == "true" ]; then
700 LOG_DETAILS="testing if limiter and runtime filtering works"
703 [ $(dlogutil -d -b radio | wc -l) -eq 12 ] && ok || fail
705 LOG_DETAILS="testing proper SMACK label for dynamic config file location"
706 ORIG_FILTERS_DIR=$(cat $ORIGINAL_CONFIG_PATH | grep dynamic_config_path | awk -F "=" '{print $2}')
707 [ $(ls -dZ $ORIG_FILTERS_DIR | awk -F " " '{print $1}') == "System::Shared" ] && ok || fail
709 if [ $quick -ne 1 ]; then
710 # This creates a process which will wait for SIGCONT and then spam logs. We know its PID, so we can add
711 # PID-based limits and see what happens.
712 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
714 while [[ $(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat) != "T" ]]; do :; done
715 dlogctl --pid $DLOGSEND_PID -s deny
716 kill -s CONT $DLOGSEND_PID
718 LOG_DETAILS="testing if PID limiting works (1/10)"
719 [[ $(dlogutil --pid $DLOGSEND_PID -d | wc -l) -eq 0 ]] && ok || fail
720 LOG_DETAILS="testing if PID limiting works (2/10)"
721 [[ $(dlogctl --pid $DLOGSEND_PID -g) == "Denied" ]] && ok || fail
722 LOG_DETAILS="testing if PID limiting works (3/10)"
723 dlogctl -g | grep -q "Denied for $DLOGSEND_PID" && ok || fail
725 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
727 while [[ $(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat) != "T" ]]; do :; done
728 dlogctl --pid $DLOGSEND_PID -s 25
729 kill -s CONT $DLOGSEND_PID
731 LOG_DETAILS="testing if PID limiting works (4/10)"
732 [[ $(dlogutil --pid $DLOGSEND_PID -d | wc -l) -eq 25 ]] && ok || fail
733 LOG_DETAILS="testing if PID limiting works (5/10)"
734 [[ $(dlogctl --pid $DLOGSEND_PID -g) == '25 logs/min' ]] && ok || fail
735 LOG_DETAILS="testing if PID limiting works (6/10)"
736 dlogctl -g | grep -q "25 logs/min for $DLOGSEND_PID" && ok || fail
738 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
740 while [[ $(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat) != "T" ]]; do :; done
741 dlogctl --pid $DLOGSEND_PID -s allow
742 kill -s CONT $DLOGSEND_PID
744 LOG_DETAILS="testing if PID limiting works (7/10)"
745 [[ $(dlogutil --pid $DLOGSEND_PID -d | wc -l) -eq 100 ]] && ok || fail
746 LOG_DETAILS="testing if PID limiting works (8/10)"
747 [[ $(dlogctl --pid $DLOGSEND_PID -g) == 'Unlimited' ]] && ok || fail
748 LOG_DETAILS="testing if PID limiting works (9/10)"
749 dlogctl -g | grep -q "Unlimited for $DLOGSEND_PID" && ok || fail
751 echo "qos_refresh_rate_s=5" > "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
752 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 15 -d 1 "Pid test"' &
754 while [[ $(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat) != "T" ]]; do :; done
755 dlogctl --pid $DLOGSEND_PID -s 2
756 kill -s CONT $DLOGSEND_PID
758 rm "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
759 LOG_DETAILS="testing if PID limiting works (10/10)"
760 # In each 5 second period, 5 logs are sent, so there are 3 periods.
761 # 2 logs from each period are allowed.
762 [[ $(dlogutil --pid $DLOGSEND_PID -d | wc -l) -eq 6 ]] && ok || fail
764 if [ $type == "pipe" ]; then
765 PREQOS_CONFIG_PATH=$DLOG_CONFIG_PATH
766 DLOG_CONFIG_PATH="$TESTDIR/qos.conf"
767 cat $PREQOS_CONFIG_PATH "@datadir@/qos-additions" > $DLOG_CONFIG_PATH
768 kill $LOGGER > /dev/null
770 dlog_logger -b 99 -t 0 &
774 dlogsend -b main -t DLOG_QOS_TEST0 -c 60 -d 1 -f 4 "A normal app that just wants to log"
775 LOG_DETAILS="testing if QoS works (1/4)"
776 [[ $(dlogutil -d DLOG_QOS_TEST0 | wc -l) -eq 60 ]] && ok || fail
778 dlogsend -b main -t DLOG_QOS_TEST1 -c 300 -d 1 -f 20 "Some log spam"
779 LOG_DETAILS="testing if QoS works (2/4)"
780 [[ $(dlogutil -d DLOG_QOS_TEST1 | wc -l) -le 180 ]] && ok || fail
782 dlogsend -b main -t DLOG_QOS_TEST2 -c 60 -d 1 -f 4 "A normal app that just wants to log" &
783 LOG_DETAILS="testing if QoS works (3/4)"
784 [[ $(dlogutil -d DLOG_QOS_TEST2 DLOG_QOS_TEST3 | wc -l) -le 180 ]] && ok || fail
785 LOG_DETAILS="testing if QoS works (4/4)"
786 [[ $(dlogutil -d DLOG_QOS_TEST2 | wc -l) -gt 40 ]] && ok || fail
788 DLOG_CONFIG_PATH=$PREQOS_CONFIG_PATH
789 kill $LOGGER > /dev/null
791 dlog_logger -b 99 -t 0 &
798 LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
799 test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
801 if [ $quick -ne 1 ]; then
802 LOG_DETAILS="testing if the library works with multithreaded app"
803 dlogutil -f $TESTDIR/dlog_mt_test &
805 test_libdlog && ok || fail
814 # Spawn logging scripts and wait for them to finish.
815 # We launch all the $SPAWN_CNT scripts in a subshell, and then use the wait command in order to
816 # wait for all the jobs of the subshell, which means all the logging scripts.
817 # Each of the logging scripts is a new subsubshell which waits a random amount of seconds and then logs
818 # a single message. This gets us 5 groups of logs separated by a second; there are about 200 logs in each
819 # group, sent about at the same time.
821 for i in `seq 1 $SPAWN_CNT`; do
822 delay=$(( (RANDOM) % 5 ))
823 ( sleep $delay && dlogsend -b main -t DLOG_TESTSUITE $delay ) &
828 LOG_DETAILS="testing if libdlogutil sorts by the timestamp correctly"
830 test_libdlogutil sorting $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
832 sort_formats="kerneltime time recv_realtime rwtime threadtime long"
834 for format in $sort_formats; do
835 LOG_DETAILS="testing if sorting by timestamp from random sources on heavy load works ($format format)"
840 # collect data and analyze timestamps
841 lines=`dlogutil -b main -d -v $format`
843 # filter out empty lines in "long" format
844 [ -z "$line" ] && continue
845 # filter out non-timestamp lines in "long" format
846 if [ $format == "long" ] && [ "`echo "$line" | sed -re 's/^\[[[:print:]]*\]$/line_ok/g'`" != "line_ok" ]; then
850 [ "$line" -eq "$line" ] 2>/dev/null && continue
852 ts=$(extract_timestamp "$format" "$line")
854 if [ "$ts" -ge "$prev_ts" ]; then
857 printf -v unsorted '%s\n\n%s\n%s' "$unsorted" "$prev_line" "$line"
863 [ -z "$unsorted" ] && ok || fail
868 if [ $type == "pipe" ]; then
870 # spawn a new daemon with limited FDs for the FD checks
871 kill $LOGGER > /dev/null
873 ULIMIT_CURRENT=`ulimit -n`
875 dlog_logger -b 99 -t 600 &> /dev/null &
877 ulimit -n $ULIMIT_CURRENT
879 LOG_DETAILS="checking if the daemon closes util connections without logs stored"
882 [ `ls -la /proc/$LOGGER/fd | grep fifo | wc -l` -eq 0 -a `ls -la /proc/$LOGGER/fd | grep pipe | wc -l` -eq 0 ] && ok || fail
884 LOG_DETAILS="checking if the daemon closes libdlog connections"
886 dlogsend -c $i -b main -p e -t FOO BAR BAZ &
888 dlogsend -c 99999 -b main -p e -t FOO BAR BAZ &
892 [ `ls -la /proc/$LOGGER/fd | grep fifo | wc -l` -eq 0 -a `ls -la /proc/$LOGGER/fd | grep pipe | wc -l` -eq 0 ] && ok || fail
894 LOG_DETAILS="checking if the daemon closes util connections with logs stored"
897 killall dlogutil &> /dev/null
899 [ `ls -la /proc/$LOGGER/fd | grep fifo | wc -l` -eq 0 -a `ls -la /proc/$LOGGER/fd | grep pipe | wc -l` -eq 0 ] && ok || fail
903 # show results, clean up and return an exit code
905 echo "$OKS / $TOTAL tests passed"
906 echo "$FAILS / $TOTAL tests failed"
908 if [ $quick -eq 1 ]; then
909 echo "WARNING: quick mode!"
910 echo "About 20% slowest running tests are disabled. Some functionality might be untested."
911 echo "Rerun with '$type' instead of '${type}_quick' to run all tests."
915 # THE LINE ABOVE MUST STAY THE LAST COMMAND IN THE FILE!
916 # This is because it is used to pass the exit code. If another command
917 # is executed after it, its exit code will be propagated instead.