3 # stuff for tracking test case counts
9 #relevant pids default vals
14 TEST_DYNAMIC_FILTERS="@DYNAMIC_FILTERS@"
15 TESTDIR=/var/lib/dlog-tests
21 time=`echo $2 | awk -F '[ +]' '{print $2}'`
22 ts=`date +%s%N -d $time`
25 time=`echo $2 | awk -F '[ +.]' '{print $3}'`
26 ms=`echo $2 | awk -F '[ +.]' '{print $4}'`
27 sec=`date +%s%N -d $time`
28 ns=$((10#$ms * 1000000))
32 time=`echo $2 | awk -F '[ +.]' '{print $2}'`
33 ts=`date +%s%N -d $time`
36 time=`echo $2 | awk -F '[ +.]' '{print $2}'`
37 ts=`date +%s%N -d $time`
40 time=`echo $2 | awk -F '[ +.]' '{print $2}'`
41 ts=`date +%s%N -d $time`
44 ts=`echo $2 | awk -F '[ +]' '{print $1}' | sed -e 's/\.//g'`
51 [ $UTIL_PID -ne -1 ] && kill $UTIL_PID > /dev/null 2>&1
52 [ $MT_TEST -ne -1 ] && kill $MT_TEST > /dev/null 2>&1
53 [ $LOGGER -ne -1 ] && kill $LOGGER > /dev/null 2>&1
54 [ -d $TESTDIR ] && rm -rf $TESTDIR/*
55 [ -d $RUNTIME_FILTERS_DIR ] && rm -rf $RUNTIME_FILTERS_DIR
62 if [ $LOGGER -ne -1 ] && [ -z "$(ps -o pid= -p $LOGGER)" ]; then
70 [ $? -eq 0 ] && daemon_status="[logger daemon not running]"
74 printf "[%02d] FAILED: %s %s\n" $TOTAL "$LOG_DETAILS" "$daemon_status"
80 [ $? -eq 0 ] && daemon_status="[logger daemon not running]"
84 printf "[%02d] PASSED: %s %s\n" $TOTAL "$LOG_DETAILS" "$daemon_status"
88 # supress stderr messages from subcommands
92 echo "usage: $0 pipe|logger"
96 if [ "$1" == "pipe" ]; then
98 elif [ "$1" == "logger" ]; then
101 echo "usage: $0 pipe|logger"
105 if [ -z "$DLOG_CONFIG_PATH" ]; then
106 ORIGINAL_CONFIG_PATH="/etc/dlog.conf"
108 ORIGINAL_CONFIG_PATH="$DLOG_CONFIG_PATH"
111 export DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.test"
112 PATH=$PATH:@libexecdir@/libdlog/
114 #create dir for runtime filters
115 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
116 mkdir -p "$RUNTIME_FILTERS_DIR"
119 if [ $type == "pipe" ]; then
120 dlog_logger -b 99 -t 0 &
125 if [ "$TEST_DYNAMIC_FILTERS" == "true" ]; then
128 dlogutil -c -b radio -b system -b main
129 LOG_DETAILS="dlogctl --disable (no args)"
131 [ `dlogctl -g | grep ENABLED | wc -l` -eq 0 ] && ok || fail
132 LOG_DETAILS="testing if filters were applied"
133 dlogsend -b system -t TEST test
134 dlogsend -b main -t TEST test
135 dlogsend -b radio -t TEST test
136 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 0 ] && ok || fail
138 LOG_DETAILS="dlogctl --enable (no args)"
140 [ `dlogctl -g | grep DISABLED | wc -l` -eq 0 ] && ok || fail
141 LOG_DETAILS="testing if filters were applied"
142 dlogutil -c -b radio -b system -b main
143 dlogsend -b system -t TEST test
144 dlogsend -b main -t TEST test
145 dlogsend -b radio -t TEST test
146 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 3 ] && ok || fail
148 LOG_DETAILS="dlogctl --disable (1 arg)"
149 dlogctl --disable -b system
150 [ `dlogctl -g | grep DISABLED | grep system | wc -l` -eq 1 ] &&
151 [ `dlogctl -g | grep DISABLED | wc -l` -eq 1 ] && ok || fail
152 LOG_DETAILS="testing if filters were applied"
153 dlogutil -c -b radio -b system -b main
154 dlogsend -b system -t TEST test
155 dlogsend -b main -t TEST test
156 dlogsend -b radio -t TEST test
157 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 2 ] && ok || fail
159 LOG_DETAILS="dlogctl --disable (multiple args)"
160 dlogctl --disable -b main -b radio
161 [ `dlogctl -g | grep DISABLED | grep -v system | wc -l` -eq 2 ] &&
162 [ `dlogctl -g | grep DISABLED | grep radio | wc -l` -eq 1 ] &&
163 [ `dlogctl -g | grep DISABLED | grep main | wc -l` -eq 1 ] && ok || fail
164 LOG_DETAILS="testing if filters were applied"
165 dlogutil -c -b radio -b system -b main
166 dlogsend -b system -t TEST test
167 dlogsend -b main -t TEST test
168 dlogsend -b radio -t TEST test
169 [ `dlogutil -d -b radio -b system -b main | wc -l` -eq 0 ] && ok || fail
171 LOG_DETAILS="dlogctl --enable (multiple args)"
172 dlogctl --enable -b radio -b system
173 [ `dlogctl -g | grep DISABLED | wc -l` -eq 1 ] &&
174 [ `dlogctl -g | grep DISABLED | grep main | wc -l` -eq 1 ] &&
175 [ `dlogctl -g | grep ENABLED | grep system | wc -l` -eq 1 ] &&
176 [ `dlogctl -g | grep ENABLED | grep radio | wc -l` -eq 1 ] && ok || fail
177 LOG_DETAILS="testing if filters were applied"
178 dlogutil -c -b radio -b system -b main
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 2 ] && ok || fail
184 LOG_DETAILS="dlogctl --enable (1 arg)"
185 dlogctl --enable -b main
186 [ `dlogctl -g | grep DISABLED | wc -l` -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 -s allow"
195 dlogutil -c -b radio -b system -b main
198 dlogctl -t TEST_TAG -s allow
199 dlogsend -b main -t TEST_TAG test
200 dlogsend -b main -t TEST test
201 [ `dlogutil -d -b main | wc -l` -eq 1 ] && ok || fail
203 LOG_DETAILS="dlogctl -s [N]"
204 dlogutil -c -b radio -b system -b main
207 dlogctl -t TEST_TAG -s 3
208 dlogsend -b main -c 10 -t TEST_TAG test
209 dlogsend -b main -c 10 -t TEST test
210 [ `dlogutil -d -b main | wc -l` -eq 4 ] && ok || fail
212 LOG_DETAILS="testing invalid parameters for dlogctl (1/13)"
213 dlogctl -s invalid &> /dev/null && fail || ok
215 LOG_DETAILS="testing invalid parameters for dlogctl (2/13)"
216 dlogctl -p X -g &> /dev/null && fail || ok
218 LOG_DETAILS="testing invalid parameters for dlogctl (3/13)"
219 dlogctl -b invalid --disable &> /dev/null && fail || ok
221 LOG_DETAILS="testing invalid parameters for dlogctl (4/13)"
222 dlogctl -s allow -g -t xyz -p E &> /dev/null && fail || ok
224 LOG_DETAILS="testing invalid parameters for dlogctl (5/13)"
225 dlogctl -s allow -c &> /dev/null && fail || ok
227 LOG_DETAILS="testing invalid parameters for dlogctl (6/13)"
228 dlogctl -c -g -t xyz -p E &> /dev/null && fail || ok
231 LOG_DETAILS="testing invalid parameters for dlogctl (7/13)"
232 dlogctl -s -10 &> /dev/null && fail || ok
234 LOG_DETAILS="testing invalid parameters for dlogctl (8/13)"
235 dlogctl -s 999999 &> /dev/null && fail || ok
238 LOG_DETAILS="testing invalid parameters for dlogctl (9/13)"
239 dlogctl -s 100 && ok || fail
241 LOG_DETAILS="testing invalid parameters for dlogctl (10/13)"
242 [ `cat $RUNTIME_FILTERS_DIR/FILTERS | grep -E 'limiter\|\*\|\*=100' | wc -l` -eq 1 ] && ok || fail
245 LOG_DETAILS="testing invalid parameters for dlogctl (11/13)"
246 [ `dlogctl -g | grep '*:*' | grep 100 | wc -l` -eq 1 ] && ok || fail
249 LOG_DETAILS="testing invalid parameters for dlogctl (12/13)"
250 dlogctl -c -t '*' -p '*' && ok || fail
252 LOG_DETAILS="testing invalid parameters for dlogctl (13/13)"
253 [ `cat $RUNTIME_FILTERS_DIR/FILTERS | grep -E 'limiter\|\*\|\*=100' | wc -l` -eq 0 ] && ok || fail
257 # put 100 log entries in the "main" buffer
263 LOG_DETAILS="testing if dlogutil -d exits with success after printing logs"
264 dlogutil -d &> /dev/null && ok || fail
266 LOG_DETAILS="testing if -t argument is parsed properly"
267 dlogutil -t dummy &> /dev/null && fail || ok
269 LOG_DETAILS="testing if -u argument is parsed properly"
270 dlogutil -du dummy &> /dev/null && fail || ok
272 LOG_DETAILS="testing if limiting printed log entries to less than exists in the buffer returns proper value"
273 [ $(dlogutil -b main -t 20 | wc -l) -eq 20 ] && ok || fail # less logs than currently in buffer
275 LOG_DETAILS="testing if limiting printed log entries to more than exists in the buffer returns proper value"
276 [ $(dlogutil -b main -t 200 | wc -l) -eq 100 ] && ok || fail # more
278 LOG_DETAILS="testing if dlogutil returns exact amount of entries as there is in the buffer"
279 [ $(dlogutil -b main -d | wc -l) -eq 100 ] && ok || fail # exactly
281 LOG_DETAILS="testing if reading from dummy buffer returns an error as expected"
282 dlogutil -b nonexistent_buffer &> /dev/null && fail || ok
284 LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)"
285 [ $(dlogutil -d -b system | wc -l) -eq 0 ] && ok || fail
287 LOG_DETAILS="testing if dlogutil -c empties all buffers"
288 dlogutil -cb main && ok || fail
290 LOG_DETAILS="testing if writing entries to empty buffer and reading them returns proper amount of entries"
292 [ $(dlogutil -b main -d | wc -l) -eq 10 ] && ok || fail # should be 10, not 110
294 LOG_DETAILS="testing if filters work (1/3)"
295 [ $(dlogutil -b main -d *:E | wc -l) -eq 5 ] && ok || fail # half of current logs (test_libdlog alternates between error and info log levels)
297 LOG_DETAILS="testing if filters work (2/3)"
298 [ $(dlogutil -b main -d *:W | wc -l) -eq 5 ] && ok || fail
300 LOG_DETAILS="testing if filters work (3/3)"
301 [ $(dlogutil -b main -d *:I | wc -l) -eq 10 ] && ok || fail
303 LOG_DETAILS="testing if exact filters work (1/3)"
304 [ $(dlogutil -b main -d *:=E | wc -l) -eq 5 ] && ok || fail
306 LOG_DETAILS="testing if exact filters work (2/3)"
307 [ $(dlogutil -b main -d *:=W | wc -l) -eq 0 ] && ok || fail
309 LOG_DETAILS="testing if exact filters work (3/3)"
310 [ $(dlogutil -b main -d *:=I | wc -l) -eq 5 ] && ok || fail
312 LOG_DETAILS="testing if adding \"silent\" filter works"
313 [ $(dlogutil -b main -s -d | wc -l) -eq 0 ] && ok || fail
315 LOG_DETAILS="testing if reading buffer size returns proper exit code"
316 dlogutil -gb main &> /dev/null && ok || fail
318 LOG_DETAILS="testing if writing all entries to single file works (-f)"
319 dlogutil -f $TESTDIR/dlog_test_file -d &> /dev/null && ok || fail
321 LOG_DETAILS="testing if writing entries to rotating files works (-r/-n)"
322 dlogutil -f $TESTDIR/dlog_rotating_file -r 12 -n 3 & # 3 files at 12 KB each
325 test_libdlog 100000 &
326 LIBDLOGUTIL_CORRECT_PID=$!
327 wait $LIBDLOGUTIL_CORRECT_PID
329 LOG_DETAILS="testing if single file is properly created"
330 if [ -e $TESTDIR/dlog_test_file ]; then ok; else fail; fi
332 LOG_DETAILS="testing if rotating file is properly created (1/4)"
333 if [ -e $TESTDIR/dlog_rotating_file.1 ]; then ok; else fail; fi
335 LOG_DETAILS="testing if rotating file is properly created (2/4)"
336 if [ -e $TESTDIR/dlog_rotating_file.2 ]; then ok; else fail; fi
338 LOG_DETAILS="testing if rotating file is properly created (3/4)"
339 if [ -e $TESTDIR/dlog_rotating_file.3 ]; then ok; else fail; fi
341 LOG_DETAILS="testing if rotating file is properly created (4/4)"
342 if [ -e $TESTDIR/dlog_rotating_file.4 ]; then fail; else ok; fi
344 LOG_DETAILS="testing the size of log files"
345 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
350 LOG_DETAILS="testing if libdlogutil works correctly in a simple scenario"
351 test_libdlogutil normal $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
352 LOG_DETAILS="testing if libdlogutil works correctly without any additional settings"
353 test_libdlogutil defaults $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
354 LOG_DETAILS="testing if libdlogutil works correctly if the callback takes some time"
355 test_libdlogutil timer $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
356 LOG_DETAILS="testing if libdlogutil works correctly with filtering on priority"
357 test_libdlogutil priority $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
358 LOG_DETAILS="testing if libdlogutil works correctly with log count limit"
359 test_libdlogutil limit $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
360 LOG_DETAILS="testing if libdlogutil works correctly with PID filtering"
361 test_libdlogutil pid $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
362 LOG_DETAILS="testing if libdlogutil works correctly with TID filtering"
363 test_libdlogutil tid $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
364 LOG_DETAILS="testing if libdlogutil propagates the callback return value correctly"
365 test_libdlogutil return $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
367 LOG_DETAILS="testing if libdlogutil works correctly in continuous mode"
368 test_libdlogutil continuous $LIBDLOGUTIL_CORRECT_PID $type &
369 TEST_LIBDLOGUTIL_PID=$!
371 kill $TEST_LIBDLOGUTIL_PID && ok || fail
372 TEST_LIBDLOGUTIL_PID=-1
374 LOG_DETAILS="testing if libdlogutil returns the correct buffer traits"
375 test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
377 cmd_prefix="dlogutil -d -u 0 -v"
378 cmd_postfix="head -n 1 "
381 regex_prio="[VDIWEFS]{1}"
382 regex_pidtid="P[0-9[:space:]]{5,},\s{1}T[0-9[:space:]]{5,}"
383 regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
384 regex_timezone="[\+-]{1}[0-9]{4}"
386 for PARAM in always auto none never; do
387 for PRIO in info error; do
388 for OUTPUT in pipe tty; do
389 if [[ "$PARAM" == "always" ]]; then
391 elif [[ "$PARAM" == "never" ]]; then
393 elif [[ "$OUTPUT" == "tty" ]]; then
399 if [[ "$PRIO" == "info" ]]; then
400 REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
401 elif [[ "$COLOR_EXPECTED" -eq 0 ]]; then
402 REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
404 REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m \([[:print:]]*\)@~\[0m$/1/g"
407 # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
408 COMMAND="$cmd_prefix $format -t 1"
410 if [[ "$PARAM" == "none" ]]; then
411 LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
413 COMMAND="$COMMAND --color=$PARAM"
414 LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
417 if [[ "$PRIO" == "info" ]]; then
418 COMMAND="$COMMAND '*:=I'"
420 COMMAND="$COMMAND '*:=E'"
423 if [[ "$OUTPUT" == "tty" ]]; then
424 # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
425 COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
428 # `eval` is needed since `$COMMAND` may contain `"`
429 line=`eval $COMMAND | tr '\033\n' '~@'`
430 [[ `echo "$line" | sed -re "$REGEX"` == "1" ]] && ok || fail
434 # TODO: It would be cool to also test warning messages (which have a different color),
435 # but this would require deeper changes to this script, which is already janky enough.
437 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
438 LOG_DETAILS="testing if \"$format\" print format works"
439 line=`$cmd_prefix $format | $cmd_postfix`
440 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
443 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[:print:]]*$/1/g"
444 LOG_DETAILS="testing if \"$format\" print format works"
445 line=`$cmd_prefix $format | $cmd_postfix`
446 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
449 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
450 LOG_DETAILS="testing if \"$format\" print format works"
451 line=`$cmd_prefix $format | $cmd_postfix`
452 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
455 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
456 LOG_DETAILS="testing if \"$format\" print format works"
457 line=`$cmd_prefix $format | $cmd_postfix`
458 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
461 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
462 LOG_DETAILS="testing if \"$format\" print format works"
463 line=`$cmd_prefix $format | $cmd_postfix`
464 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
467 REGEX="s/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
468 LOG_DETAILS="testing if \"$format\" print format works"
469 line=`$cmd_prefix $format | $cmd_postfix`
470 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
472 format="recv_realtime"
473 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
474 LOG_DETAILS="testing if \"$format\" print format works"
475 line=`$cmd_prefix $format | $cmd_postfix`
476 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
479 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"
480 LOG_DETAILS="testing if \"$format\" print format works"
481 line=`$cmd_prefix $format | $cmd_postfix`
482 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
485 REGEX="s/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]\s{1}[[:print:]]*$/1/g"
486 LOG_DETAILS="testing if \"$format\" print format works"
487 line=`$cmd_prefix $format | $cmd_postfix`
488 [[ `echo "$line" | tr '\n' ' ' | sed -re $REGEX` == "1" ]] && ok || fail
491 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
492 LOG_DETAILS="testing if \"$format\" print format works"
493 line=`$cmd_prefix $format | $cmd_postfix`
494 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
497 if [[ "$type" == "pipe" ]]; then
498 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"
500 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"
502 LOG_DETAILS="testing if \"$format\" print format works"
503 line=`$cmd_prefix $format | $cmd_postfix`
504 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
507 LOG_DETAILS="testing if \"$format\" print format works"
509 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
510 line=`$cmd_prefix $format | $cmd_postfix`
511 [[ "$line" == "rawformatTEST" ]] && ok || fail
513 LOG_DETAILS="testing if KMSG works in the default format"
514 # We check if the command returns at least 1000 logs. This seems to be a safe value. In my test,
515 # my target reaches it in about 2 seconds after the boot. Feel free to change it to a reasonable
516 # yet lower value if the test happens to fail otherwise, but it would be extremely surprising.
517 [[ "$(dlogutil -db kmsg | wc -l)" -gt 1000 ]] && ok || fail
519 LOG_DETAILS="testing if KMSG works in the raw format"
520 last_dmesg=`dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g"`
521 sleep 1 # To make sure dlog has already parsed the log
522 dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail
524 LOG_DETAILS="testing if pid filtering works"
525 dlogsend -b main -t DLOG_TESTSUITE pidTEST &
527 line=`dlogutil -v raw -d --pid $!`
528 [[ "$line" == "pidTEST" ]] && ok || fail
530 LOG_DETAILS="testing if tid filtering works"
531 dlogsend -b main -t DLOG_TESTSUITE tidTEST &
533 line=`dlogutil -v raw -d --tid $!` #dlogsend is a single threaded app so tid is the same as pid
534 [[ "$line" == "tidTEST" ]] && ok || fail
536 dlogsend -b main -t DLOG_TESTSUITE_TAG0 -pI tagTEST0
537 dlogsend -b main -t DLOG_TESTSUITE_TAG1 -pI tagTEST1
538 dlogsend -b main -t DLOG_TESTSUITE_TAG2 -pF tagTEST2
540 LOG_DETAILS="testing if tag filtering works (1/8)"
541 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG0' | wc -l` -eq 1 ]] && ok || fail
542 LOG_DETAILS="testing if tag filtering works (2/8)"
543 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG1' | wc -l` -eq 1 ]] && ok || fail
544 LOG_DETAILS="testing if tag filtering works (3/8)"
545 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG' | wc -l` -eq 0 ]] && ok || fail
546 LOG_DETAILS="testing if tag filtering works (4/8)"
547 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*' | wc -l` -eq 3 ]] && ok || fail
548 LOG_DETAILS="testing if tag filtering works (5/8)"
549 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:I' | wc -l` -eq 3 ]] && ok || fail
550 LOG_DETAILS="testing if tag filtering works (6/8)"
551 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:W' | wc -l` -eq 1 ]] && ok || fail
552 LOG_DETAILS="testing if tag filtering works (7/8)"
553 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG' | wc -l` -eq 0 ]] && ok || fail
554 LOG_DETAILS="testing if tag filtering works (8/8)"
555 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l` -eq 0 ]] && ok || fail
557 if [ "$TEST_DYNAMIC_FILTERS" == "true" ]; then
558 LOG_DETAILS="testing if limiter and runtime filtering works"
561 [ $(dlogutil -d -b radio | wc -l) -eq 12 ] && ok || fail
563 LOG_DETAILS="testing proper SMACK label for dynamic config file location"
564 ORIG_FILTERS_DIR=$(cat $ORIGINAL_CONFIG_PATH | grep dynamic_config_path | awk -F "=" '{print $2}')
565 [ $(ls -dZ $ORIG_FILTERS_DIR | awk -F " " '{print $1}') == "System::Shared" ] && ok || fail
568 LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
569 test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
571 LOG_DETAILS="testing if the library works with multithreaded app"
572 dlogutil -f $TESTDIR/dlog_mt_test &
574 test_libdlog && ok || fail
583 # Spawn logging scripts and wait for them to finish.
584 # We launch all the $SPAWN_CNT scripts in a subshell, and then use the wait command in order to
585 # wait for all the jobs of the subshell, which means all the logging scripts.
586 # Each of the logging scripts is a new subsubshell which waits a random amount of seconds and then logs
587 # a single message. This gets us 5 groups of logs separated by a second; there are about 200 logs in each
588 # group, sent about at the same time.
590 for i in `seq 1 $SPAWN_CNT`; do
591 delay=$(( (RANDOM) % 5 ))
592 ( sleep $delay && dlogsend -b main -t DLOG_TESTSUITE $delay ) &
597 LOG_DETAILS="testing if libdlogutil sorts by the timestamp correctly"
599 test_libdlogutil sorting $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
601 sort_formats="kerneltime time recv_realtime rwtime threadtime long"
603 for format in $sort_formats; do
604 LOG_DETAILS="testing if sorting by timestamp from random sources on heavy load works ($format format)"
609 # collect data and analyze timestamps
610 lines=`dlogutil -b main -d -v $format`
612 # filter out empty lines in "long" format
613 [ -z "$line" ] && continue
614 # filter out non-timestamp lines in "long" format
615 if [ $format == "long" ] && [ "`echo "$line" | sed -re 's/^\[[[:print:]]*\]$/line_ok/g'`" != "line_ok" ]; then
619 [ "$line" -eq "$line" ] 2>/dev/null && continue
621 ts=$(extract_timestamp "$format" "$line")
623 if [ "$ts" -ge "$prev_ts" ]; then
626 printf -v unsorted '%s\n\n%s\n%s' "$unsorted" "$prev_line" "$line"
632 [ -z "$unsorted" ] && ok || fail
637 if [ $type == "pipe" ]; then
639 # spawn a new daemon with limited FDs for the FD checks
640 kill $LOGGER > /dev/null
642 ULIMIT_CURRENT=`ulimit -n`
644 dlog_logger -b 99 -t 600 &> /dev/null &
646 ulimit -n $ULIMIT_CURRENT
648 LOG_DETAILS="checking if the daemon closes util connections without logs stored"
651 [ `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
653 LOG_DETAILS="checking if the daemon closes libdlog connections"
655 dlogsend -c $i -b main -p e -t FOO BAR BAZ &
657 dlogsend -c 99999 -b main -p e -t FOO BAR BAZ &
661 [ `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
663 LOG_DETAILS="checking if the daemon closes util connections with logs stored"
666 killall dlogutil &> /dev/null
668 [ `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
671 # show results and clean up
673 echo "$OKS / $TOTAL tests passed"
674 echo "$FAILS / $TOTAL tests failed"