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 (1/2)"
357 test_libdlogutil priority $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
358 LOG_DETAILS="testing if libdlogutil works correctly with filtering on priority (2/2)"
359 test_libdlogutil priority_exact $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
360 LOG_DETAILS="testing if libdlogutil works correctly with log count limit"
361 test_libdlogutil limit $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
362 LOG_DETAILS="testing if libdlogutil works correctly with PID filtering"
363 test_libdlogutil pid $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
364 LOG_DETAILS="testing if libdlogutil works correctly with TID filtering"
365 test_libdlogutil tid $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
366 LOG_DETAILS="testing if libdlogutil works correctly with tag filtering (1/2)"
367 test_libdlogutil tag_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
368 LOG_DETAILS="testing if libdlogutil works correctly with tag filtering (2/2)"
369 test_libdlogutil tag_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
370 LOG_DETAILS="testing if libdlogutil works correctly with prefix filtering (1/2)"
371 test_libdlogutil prefix_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
372 LOG_DETAILS="testing if libdlogutil works correctly with prefix filtering (2/2)"
373 test_libdlogutil prefix_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
374 LOG_DETAILS="testing if libdlogutil propagates the callback return value correctly"
375 test_libdlogutil return $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
377 LOG_DETAILS="testing if libdlogutil works correctly in continuous mode"
378 test_libdlogutil continuous $LIBDLOGUTIL_CORRECT_PID $type &
379 TEST_LIBDLOGUTIL_PID=$!
381 kill $TEST_LIBDLOGUTIL_PID && ok || fail
382 TEST_LIBDLOGUTIL_PID=-1
384 LOG_DETAILS="testing if libdlogutil returns the correct buffer traits"
385 test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
387 cmd_prefix="dlogutil -d -u 0 -v"
388 cmd_postfix="head -n 1 "
391 regex_prio="[VDIWEFS]{1}"
392 regex_pidtid="P[0-9[:space:]]{5,},\s{1}T[0-9[:space:]]{5,}"
393 regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
394 regex_timezone="[\+-]{1}[0-9]{4}"
396 for PARAM in always auto none never; do
397 for PRIO in info error; do
398 for OUTPUT in pipe tty; do
399 if [[ "$PARAM" == "always" ]]; then
401 elif [[ "$PARAM" == "never" ]]; then
403 elif [[ "$OUTPUT" == "tty" ]]; then
409 if [[ "$PRIO" == "info" ]]; then
410 REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
411 elif [[ "$COLOR_EXPECTED" -eq 0 ]]; then
412 REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
414 REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m \([[:print:]]*\)@~\[0m$/1/g"
417 # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
418 COMMAND="$cmd_prefix $format -t 1"
420 if [[ "$PARAM" == "none" ]]; then
421 LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
423 COMMAND="$COMMAND --color=$PARAM"
424 LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
427 if [[ "$PRIO" == "info" ]]; then
428 COMMAND="$COMMAND '*:=I'"
430 COMMAND="$COMMAND '*:=E'"
433 if [[ "$OUTPUT" == "tty" ]]; then
434 # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
435 COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
438 # `eval` is needed since `$COMMAND` may contain `"`
439 line=`eval $COMMAND | tr '\033\n' '~@'`
440 [[ `echo "$line" | sed -re "$REGEX"` == "1" ]] && ok || fail
444 # TODO: It would be cool to also test warning messages (which have a different color),
445 # but this would require deeper changes to this script, which is already janky enough.
447 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
448 LOG_DETAILS="testing if \"$format\" print format works"
449 line=`$cmd_prefix $format | $cmd_postfix`
450 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
453 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[:print:]]*$/1/g"
454 LOG_DETAILS="testing if \"$format\" print format works"
455 line=`$cmd_prefix $format | $cmd_postfix`
456 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
459 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
460 LOG_DETAILS="testing if \"$format\" print format works"
461 line=`$cmd_prefix $format | $cmd_postfix`
462 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
465 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
466 LOG_DETAILS="testing if \"$format\" print format works"
467 line=`$cmd_prefix $format | $cmd_postfix`
468 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
471 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
472 LOG_DETAILS="testing if \"$format\" print format works"
473 line=`$cmd_prefix $format | $cmd_postfix`
474 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
477 REGEX="s/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
478 LOG_DETAILS="testing if \"$format\" print format works"
479 line=`$cmd_prefix $format | $cmd_postfix`
480 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
482 format="recv_realtime"
483 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
484 LOG_DETAILS="testing if \"$format\" print format works"
485 line=`$cmd_prefix $format | $cmd_postfix`
486 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
489 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"
490 LOG_DETAILS="testing if \"$format\" print format works"
491 line=`$cmd_prefix $format | $cmd_postfix`
492 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
495 REGEX="s/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]\s{1}[[:print:]]*$/1/g"
496 LOG_DETAILS="testing if \"$format\" print format works"
497 line=`$cmd_prefix $format | $cmd_postfix`
498 [[ `echo "$line" | tr '\n' ' ' | sed -re $REGEX` == "1" ]] && ok || fail
501 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[: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 if [[ "$type" == "pipe" ]]; then
508 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"
510 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"
512 LOG_DETAILS="testing if \"$format\" print format works"
513 line=`$cmd_prefix $format | $cmd_postfix`
514 [[ `echo "$line" | sed -re $REGEX` == "1" ]] && ok || fail
517 LOG_DETAILS="testing if \"$format\" print format works"
519 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
520 line=`$cmd_prefix $format | $cmd_postfix`
521 [[ "$line" == "rawformatTEST" ]] && ok || fail
523 LOG_DETAILS="testing if KMSG works in the default format"
524 # We check if the command returns at least 1000 logs. This seems to be a safe value. In my test,
525 # my target reaches it in about 2 seconds after the boot. Feel free to change it to a reasonable
526 # yet lower value if the test happens to fail otherwise, but it would be extremely surprising.
527 [[ "$(dlogutil -db kmsg | wc -l)" -gt 1000 ]] && ok || fail
529 LOG_DETAILS="testing if KMSG works in the raw format"
530 last_dmesg=`dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g"`
531 sleep 1 # To make sure dlog has already parsed the log
532 dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail
534 LOG_DETAILS="testing if pid filtering works"
535 dlogsend -b main -t DLOG_TESTSUITE pidTEST &
537 line=`dlogutil -v raw -d --pid $!`
538 [[ "$line" == "pidTEST" ]] && ok || fail
540 LOG_DETAILS="testing if tid filtering works"
541 dlogsend -b main -t DLOG_TESTSUITE tidTEST &
543 line=`dlogutil -v raw -d --tid $!` #dlogsend is a single threaded app so tid is the same as pid
544 [[ "$line" == "tidTEST" ]] && ok || fail
546 dlogsend -b main -t DLOG_TESTSUITE_TAG0 -pI tagTEST0
547 dlogsend -b main -t DLOG_TESTSUITE_TAG1 -pI tagTEST1
548 dlogsend -b main -t DLOG_TESTSUITE_TAG2 -pF tagTEST2
550 LOG_DETAILS="testing if tag filtering works (1/8)"
551 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG0' | wc -l` -eq 1 ]] && ok || fail
552 LOG_DETAILS="testing if tag filtering works (2/8)"
553 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG1' | wc -l` -eq 1 ]] && ok || fail
554 LOG_DETAILS="testing if tag filtering works (3/8)"
555 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG' | wc -l` -eq 0 ]] && ok || fail
556 LOG_DETAILS="testing if tag filtering works (4/8)"
557 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*' | wc -l` -eq 3 ]] && ok || fail
558 LOG_DETAILS="testing if tag filtering works (5/8)"
559 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:I' | wc -l` -eq 3 ]] && ok || fail
560 LOG_DETAILS="testing if tag filtering works (6/8)"
561 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:W' | wc -l` -eq 1 ]] && ok || fail
562 LOG_DETAILS="testing if tag filtering works (7/8)"
563 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG' | wc -l` -eq 0 ]] && ok || fail
564 LOG_DETAILS="testing if tag filtering works (8/8)"
565 [[ `dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l` -eq 0 ]] && ok || fail
567 if [ "$TEST_DYNAMIC_FILTERS" == "true" ]; then
568 LOG_DETAILS="testing if limiter and runtime filtering works"
571 [ $(dlogutil -d -b radio | wc -l) -eq 12 ] && ok || fail
573 LOG_DETAILS="testing proper SMACK label for dynamic config file location"
574 ORIG_FILTERS_DIR=$(cat $ORIGINAL_CONFIG_PATH | grep dynamic_config_path | awk -F "=" '{print $2}')
575 [ $(ls -dZ $ORIG_FILTERS_DIR | awk -F " " '{print $1}') == "System::Shared" ] && ok || fail
578 LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
579 test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
581 LOG_DETAILS="testing if the library works with multithreaded app"
582 dlogutil -f $TESTDIR/dlog_mt_test &
584 test_libdlog && ok || fail
593 # Spawn logging scripts and wait for them to finish.
594 # We launch all the $SPAWN_CNT scripts in a subshell, and then use the wait command in order to
595 # wait for all the jobs of the subshell, which means all the logging scripts.
596 # Each of the logging scripts is a new subsubshell which waits a random amount of seconds and then logs
597 # a single message. This gets us 5 groups of logs separated by a second; there are about 200 logs in each
598 # group, sent about at the same time.
600 for i in `seq 1 $SPAWN_CNT`; do
601 delay=$(( (RANDOM) % 5 ))
602 ( sleep $delay && dlogsend -b main -t DLOG_TESTSUITE $delay ) &
607 LOG_DETAILS="testing if libdlogutil sorts by the timestamp correctly"
609 test_libdlogutil sorting $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
611 sort_formats="kerneltime time recv_realtime rwtime threadtime long"
613 for format in $sort_formats; do
614 LOG_DETAILS="testing if sorting by timestamp from random sources on heavy load works ($format format)"
619 # collect data and analyze timestamps
620 lines=`dlogutil -b main -d -v $format`
622 # filter out empty lines in "long" format
623 [ -z "$line" ] && continue
624 # filter out non-timestamp lines in "long" format
625 if [ $format == "long" ] && [ "`echo "$line" | sed -re 's/^\[[[:print:]]*\]$/line_ok/g'`" != "line_ok" ]; then
629 [ "$line" -eq "$line" ] 2>/dev/null && continue
631 ts=$(extract_timestamp "$format" "$line")
633 if [ "$ts" -ge "$prev_ts" ]; then
636 printf -v unsorted '%s\n\n%s\n%s' "$unsorted" "$prev_line" "$line"
642 [ -z "$unsorted" ] && ok || fail
647 if [ $type == "pipe" ]; then
649 # spawn a new daemon with limited FDs for the FD checks
650 kill $LOGGER > /dev/null
652 ULIMIT_CURRENT=`ulimit -n`
654 dlog_logger -b 99 -t 600 &> /dev/null &
656 ulimit -n $ULIMIT_CURRENT
658 LOG_DETAILS="checking if the daemon closes util connections without logs stored"
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 libdlog connections"
665 dlogsend -c $i -b main -p e -t FOO BAR BAZ &
667 dlogsend -c 99999 -b main -p e -t FOO BAR BAZ &
671 [ `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
673 LOG_DETAILS="checking if the daemon closes util connections with logs stored"
676 killall dlogutil &> /dev/null
678 [ `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
681 # show results and clean up
683 echo "$OKS / $TOTAL tests passed"
684 echo "$FAILS / $TOTAL tests failed"