Terminate the daemon if it's not needed
[platform/core/system/dlog.git] / tests / dlog_test.in
1 #!/bin/sh
2
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
7
8 # stuff for tracking test case counts
9 FAILS=0
10 OKS=0
11 TOTAL=0
12 LOG_DETAILS=
13
14 #relevant pids default vals
15 UTIL_PID=-1
16 DLOGSEND_PID=-1
17 MT_TEST=-1
18 LOGGER=-1
19
20 TEST_DYNAMIC_FILTERS="@DYNAMIC_FILTERS@"
21 TESTDIR=/var/lib/dlog-tests
22
23 extract_timestamp() {
24         ts=0
25         case "$1" in
26                 "threadtime")
27                         time=$(echo "$2" | awk -F '[ +]' '{print $2}')
28                         ts=$(date +%s%N -d "$time")
29                 ;;
30                 "long")
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))
35                         ts=$((sec + ns))
36                 ;;
37                 "rwtime")
38                         time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
39                         ts=$(date +%s%N -d "$time")
40                 ;;
41                 "recv_realtime")
42                         time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
43                         ts=$(date +%s%N -d "$time")
44                 ;;
45                 "time")
46                         time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
47                         ts=$(date +%s%N -d "$time")
48                 ;;
49                 "kerneltime")
50                         ts=$(echo "$2" | awk -F '[ +]' '{print $1}' | sed -e 's/\.//g')
51                 ;;
52         esac
53         echo "$ts"
54 }
55
56 cleanup() {
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"
65 }
66
67 trap cleanup 0
68
69 check_daemon() {
70         ret=1
71         if [ "$LOGGER" -ne -1 ] && [ -z "$(ps -o pid= -p "$LOGGER")" ]; then
72                 ret=0
73         fi
74         return "$ret"
75 }
76
77 fail() {
78         check_daemon && daemon_status="[logger daemon not running]"
79
80         FAILS=$((FAILS + 1))
81         TOTAL=$((TOTAL + 1))
82         printf "[%02d] FAILED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
83         LOG_DETAILS=
84 }
85
86 ok() {
87         check_daemon && daemon_status="[logger daemon not running]"
88
89         OKS=$((OKS + 1))
90         TOTAL=$((TOTAL + 1))
91         printf "[%02d] PASSED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
92         LOG_DETAILS=
93 }
94
95 USAGE_MESSAGE="usage: $0 [--verbose] [--quick] pipe|logger"
96
97 OPTS=$(getopt --shell sh --options "" --long verbose,quick --quiet -- "$@")
98 if [ "$?" -eq 1 ]; then
99         echo "$USAGE_MESSAGE"
100         exit 1
101 fi
102 eval set -- "$OPTS"
103
104 verbose=0
105 quick=0
106 while true; do
107         case "$1" in
108                 --verbose)
109                         verbose=1
110                         ;;
111                 --quick)
112                         quick=1
113                         ;;
114                 --)
115                         shift
116                         break
117                         ;;
118                 *)
119                         echo "This should never happen :)"
120                         exit 1
121                         ;;
122         esac
123         shift
124 done
125 if [ "$1" = "pipe" ]; then
126         type="pipe"
127 elif [ "$1" = "logger" ]; then
128         type="logger"
129 # We still accept the legacy {pipe,logger}_quick syntax because there's no reason not to.
130 elif [ "$1" = "pipe_quick" ]; then
131         type="pipe"
132         quick=1
133 elif [ "$1" = "logger_quick" ]; then
134         type="logger"
135         quick=1
136 else
137         echo "$USAGE_MESSAGE"
138         exit 1
139 fi
140
141 # supress stderr messages from subcommands
142 if [ "$verbose" -eq 0 ]; then
143         exec 2> /dev/null
144 fi
145
146 NEEDS_TO_QUIT=0
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
150
151 if [ "$type" = "pipe" ] || [ -f /lib/modules/"$(uname -r)"/extra/logger.ko ]; then
152         LEGACY_LOGGER=0
153 else
154         LEGACY_LOGGER=1
155 fi
156
157 if [ -z "$DLOG_CONFIG_PATH" ]; then
158         ORIGINAL_CONFIG_PATH="/etc/dlog.conf"
159 else
160         ORIGINAL_CONFIG_PATH="$DLOG_CONFIG_PATH"
161 fi
162
163 export DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.test"
164 PATH=$PATH:@libexecdir@/libdlog/
165
166 #create dir for runtime filters
167 RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
168 mkdir -p "$RUNTIME_FILTERS_DIR"
169
170 PREEARLYQUIT_CONFIG_PATH="$DLOG_CONFIG_PATH"
171 DLOG_CONFIG_PATH="$TESTDIR/earlyquit.conf"
172 if [ "$quick" -ne 1 ]; then
173         for PERSISTENT in 1 0; do
174         for KMSG in 1 0; do
175         for SYSLOG in 1 0; do
176         for QOS in 1 0; do
177                 # TODO: Does syslog even work? Disabling for now.
178                 [ "$SYSLOG" -eq 1 ] && continue
179
180                 if [ "$QOS" -eq 1 ]; then
181                         SOURCE="@datadir@/dlog-$type.conf.qos"
182                 else
183                         SOURCE="@datadir@/dlog-$type.conf.test"
184                 fi
185
186                 if [ "$PERSISTENT" -eq 1 ]; then
187                         cp "$SOURCE" "$DLOG_CONFIG_PATH"
188                 else
189                         sed 's/^dlog_logger_conf.*$/#\0/' <"$SOURCE" >"$DLOG_CONFIG_PATH"
190                 fi
191
192                 echo "handle_kmsg=$KMSG" >> "$DLOG_CONFIG_PATH"
193                 echo "syslog_force=$SYSLOG" >> "$DLOG_CONFIG_PATH"
194
195                 dlog_logger -t 0 &
196                 LOGGER=$!
197                 sleep 1
198
199                 kill $LOGGER > /dev/null
200                 STOPPED=$?
201                 LOGGER=-1
202
203                 if [ "$PERSISTENT" -eq 0 ] && [ "$KMSG" -eq 0 ] && [ "$SYSLOG" -eq 0 ] && [ "$QOS" -eq 0 ] && [ "$type" = "logger" ]; then
204                         EXPECTED=1
205                 else
206                         EXPECTED=0
207                 fi
208
209                 LOG_DETAILS="testing if daemon stops when not needed (persistent=$PERSISTENT, kmsg=$KMSG, syslog=$SYSLOG, qos=$QOS)"
210                 [ "$STOPPED" -eq "$EXPECTED" ] && ok || fail
211         done; done; done; done
212 fi
213 DLOG_CONFIG_PATH="$PREEARLYQUIT_CONFIG_PATH"
214
215 # Start the daemon
216 dlog_logger -t 0 &
217 LOGGER=$!
218 sleep 1
219
220 if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
221         dlogctl -c
222         dlogctl --enable
223         dlogutil -c -b radio -b system -b main
224         LOG_DETAILS="dlogctl --disable (no args)"
225         dlogctl --disable
226         [ "$(dlogctl -g | grep -c '^\* [a-z]*: ENABLED')" -eq 0 ] && ok || fail
227         LOG_DETAILS="testing if filters were applied"
228         dlogsend -b system -t TEST test
229         dlogsend -b main -t TEST test
230         dlogsend -b radio -t TEST test
231         [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
232
233         LOG_DETAILS="dlogctl --enable (no args)"
234         dlogctl --enable
235         [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED')" -eq 0 ] && ok || fail
236         LOG_DETAILS="testing if filters were applied"
237         dlogutil -c -b radio -b system -b main
238         dlogsend -b system -t TEST test
239         dlogsend -b main -t TEST test
240         dlogsend -b radio -t TEST test
241         [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
242
243         LOG_DETAILS="dlogctl --disable (1 arg)"
244         dlogctl --disable -b system
245         [ "$(dlogctl -g | grep    '^\* [a-z]*: DISABLED' | grep -c system)" -eq 1 ] &&
246         [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED'                 )" -eq 1 ] && ok || fail
247         LOG_DETAILS="testing if filters were applied"
248         dlogutil -c -b radio -b system -b main
249         dlogsend -b system -t TEST test
250         dlogsend -b main -t TEST test
251         dlogsend -b radio -t TEST test
252         [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
253
254         LOG_DETAILS="dlogctl --disable (multiple args)"
255         dlogctl --disable -b main -b radio
256         [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -cv system)" -eq 2 ] &&
257         [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c   radio)" -eq 1 ] &&
258         [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c    main)" -eq 1 ] && ok || fail
259         LOG_DETAILS="testing if filters were applied"
260         dlogutil -c -b radio -b system -b main
261         dlogsend -b system -t TEST test
262         dlogsend -b main -t TEST test
263         dlogsend -b radio -t TEST test
264         [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
265
266         LOG_DETAILS="dlogctl --enable (multiple args)"
267         dlogctl --enable -b radio -b system
268         [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED'                 )" -eq 1 ] &&
269         [ "$(dlogctl -g | grep    '^\* [a-z]*: DISABLED' | grep -c   main)" -eq 1 ] &&
270         [ "$(dlogctl -g | grep    '^\* [a-z]*: ENABLED'  | grep -c system)" -eq 1 ] &&
271         [ "$(dlogctl -g | grep    '^\* [a-z]*: ENABLED'  | grep -c  radio)" -eq 1 ] && ok || fail
272         LOG_DETAILS="testing if filters were applied"
273         dlogutil -c -b radio -b system -b main
274         dlogsend -b system -t TEST test
275         dlogsend -b main -t TEST test
276         dlogsend -b radio -t TEST test
277         [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail
278
279         LOG_DETAILS="dlogctl --enable (1 arg)"
280         dlogctl --enable -b main
281         [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED')" -eq 0 ] && ok || fail
282         LOG_DETAILS="testing if filters were applied"
283         dlogutil -c -b radio -b system -b main
284         dlogsend -b system -t TEST test
285         dlogsend -b main -t TEST test
286         dlogsend -b radio -t TEST test
287         [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail
288
289         LOG_DETAILS="dlogctl -s allow"
290         dlogutil -c -b radio -b system -b main
291         dlogctl -c
292         dlogctl -s deny
293         dlogctl -t TEST_TAG -s allow
294         dlogsend -b main -t TEST_TAG test
295         dlogsend -b main -t TEST test
296         [ "$(dlogutil -d -b main | wc -l)" -eq 1 ] && ok || fail
297
298         LOG_DETAILS="dlogctl -s [N]"
299         dlogutil -c -b radio -b system -b main
300         dlogctl -c
301         dlogctl -s deny
302         dlogctl -t TEST_TAG -s 3
303         dlogsend -b main -c 10 -t TEST_TAG test
304         dlogsend -b main -c 10 -t TEST test
305         [ "$(dlogutil -d -b main | wc -l)" -eq 4 ] && ok || fail
306
307         LOG_DETAILS="testing invalid parameters for dlogctl (1/13)"
308         dlogctl -s invalid > /dev/null && fail || ok
309
310         LOG_DETAILS="testing invalid parameters for dlogctl (2/13)"
311         dlogctl -p X -g > /dev/null && fail || ok
312
313         LOG_DETAILS="testing invalid parameters for dlogctl (3/13)"
314         dlogctl -b invalid --disable > /dev/null && fail || ok
315
316         LOG_DETAILS="testing invalid parameters for dlogctl (4/13)"
317         dlogctl -s allow -g -t xyz -p E > /dev/null && fail || ok
318
319         LOG_DETAILS="testing invalid parameters for dlogctl (5/13)"
320         dlogctl -s allow -c > /dev/null && fail || ok
321
322         LOG_DETAILS="testing invalid parameters for dlogctl (6/13)"
323         dlogctl -c -g -t xyz -p E > /dev/null && fail || ok
324
325         # -s out of range
326         LOG_DETAILS="testing invalid parameters for dlogctl (7/13)"
327         dlogctl -s -10 > /dev/null && fail || ok
328
329         LOG_DETAILS="testing invalid parameters for dlogctl (8/13)"
330         dlogctl -s 999999 > /dev/null && fail || ok
331
332         # -s correctness
333         LOG_DETAILS="testing invalid parameters for dlogctl (9/13)"
334         dlogctl -s 100 && ok || fail
335
336         LOG_DETAILS="testing invalid parameters for dlogctl (10/13)"
337         [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 1 ] && ok || fail
338
339         # -g correctness
340         LOG_DETAILS="testing invalid parameters for dlogctl (11/13)"
341         [ "$(dlogctl -g | grep -F '*:*' | grep -c 100)" -eq 1 ] && ok || fail
342
343         # -c correctness
344         LOG_DETAILS="testing invalid parameters for dlogctl (12/13)"
345         dlogctl -c -t '*' -p '*' && ok || fail
346
347         LOG_DETAILS="testing invalid parameters for dlogctl (13/13)"
348         [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 0 ] && ok || fail
349         dlogctl -c
350
351         LOG_DETAILS="testing if the whole dynamic config directory is respected"
352         dlogctl -s deny
353         cp $RUNTIME_FILTERS_DIR/05-logctl.conf $RUNTIME_FILTERS_DIR/10-other.conf
354         dlogctl -c
355         dlogutil -c -b radio -b system -b main
356         dlogsend -b system -t TEST test
357         dlogsend -b main -t TEST test
358         dlogsend -b radio -t TEST test
359         [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail
360         rm $RUNTIME_FILTERS_DIR/10-other.conf
361 fi
362
363 SEED=$(head -c 6 /dev/urandom | base64)
364 dlogsend -b main -k "$SEED"
365 # -k is async, unlike normal mode; therefore we have to wait until the logging process actually finishes.
366 while pgrep "dlogsend" > /dev/null || pgrep "dlog-log-critical" > /dev/null; do :; done
367 CRIT_PATH="@DLOG_CRITICAL_LOGFILE_PATH@"
368 LOG_DETAILS="testing if critical logging works"
369 cat "$CRIT_PATH".a "$CRIT_PATH".b | grep -F "$SEED" > /dev/null && ok || fail
370
371 if [ "$type" = "pipe" ] && [ "$quick" -ne 1 ]; then
372         dlogsend -c 2 -d 2 -t DLOGSEND_SIGPIPE_TEST test &
373         DLOGSEND_PID=$!
374         sleep 1
375         kill -s PIPE $DLOGSEND_PID
376         wait $DLOGSEND_PID
377         LOG_DETAILS="testing if dlogsend logs even after SIGPIPE"
378         [ "$(dlogutil -d DLOGSEND_SIGPIPE_TEST | wc -l)" -eq 2 ] && ok || fail
379 fi
380
381 # put 100 log entries in the "main" buffer
382 dlogutil -c
383 test_libdlog 100
384 sleep 1
385
386
387 LOG_DETAILS="testing if dlogutil -d exits with success after printing logs"
388 dlogutil -d > /dev/null && ok || fail
389
390 LOG_DETAILS="testing if -t argument is parsed properly"
391 dlogutil -t dummy > /dev/null && fail || ok
392
393 LOG_DETAILS="testing if -u argument is parsed properly"
394 dlogutil -du dummy > /dev/null && fail || ok
395
396 LOG_DETAILS="testing if limiting printed log entries to less than exists in the buffer returns proper value"
397 [ "$(dlogutil -b main -t  20 | wc -l)" -eq  20 ] && ok || fail # less logs than currently in buffer
398
399 LOG_DETAILS="testing if limiting printed log entries to more than exists in the buffer returns proper value"
400 [ "$(dlogutil -b main -t 200 | wc -l)" -eq 100 ] && ok || fail # more
401
402 LOG_DETAILS="testing if dlogutil returns exact amount of entries as there is in the buffer"
403 [ "$(dlogutil -b main -d     | wc -l)" -eq 100 ] && ok || fail # exactly
404
405 LOG_DETAILS="testing if reading from  dummy buffer returns an error as expected"
406 dlogutil -b nonexistent_buffer > /dev/null && fail || ok
407
408 LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)"
409 [ "$(dlogutil -d -b system | wc -l)" -eq 0 ] && ok || fail
410
411 LOG_DETAILS="testing if dlogutil -c empties all buffers"
412 dlogutil -cb main && ok || fail
413
414 LOG_DETAILS="testing if writing entries to empty buffer and reading them returns proper amount of entries"
415 test_libdlog 10
416 [ "$(dlogutil -b main -d | wc -l)" -eq 10 ] && ok || fail # should be 10, not 110
417
418 LOG_DETAILS="testing if filters work (1/3)"
419 [ "$(dlogutil -b main -d '*:E' | wc -l)" -eq 5 ] && ok || fail # half of current logs (test_libdlog alternates between error and info log levels)
420
421 LOG_DETAILS="testing if filters work (2/3)"
422 [ "$(dlogutil -b main -d '*:W' | wc -l)" -eq 5 ] && ok || fail
423
424 LOG_DETAILS="testing if filters work (3/3)"
425 [ "$(dlogutil -b main -d '*:I' | wc -l)" -eq 10 ] && ok || fail
426
427 LOG_DETAILS="testing if exact filters work (1/3)"
428 [ "$(dlogutil -b main -d '*:=E' | wc -l)" -eq 5 ] && ok || fail
429
430 LOG_DETAILS="testing if exact filters work (2/3)"
431 [ "$(dlogutil -b main -d '*:=W' | wc -l)" -eq 0 ] && ok || fail
432
433 LOG_DETAILS="testing if exact filters work (3/3)"
434 [ "$(dlogutil -b main -d '*:=I' | wc -l)" -eq 5 ] && ok || fail
435
436 LOG_DETAILS="testing if adding \"silent\" filter works"
437 [ "$(dlogutil -b main -s -d | wc -l)" -eq 0 ] && ok || fail
438
439 LOG_DETAILS="testing if reading buffer size returns proper exit code"
440 dlogutil -gb main > /dev/null && ok || fail
441
442 LOG_DETAILS="testing if writing all entries to single file works (-f)"
443 dlogutil -f $TESTDIR/dlog_test_file -d > /dev/null && ok || fail
444
445 if [ "$quick" -ne 1 ]; then
446         LOG_DETAILS="testing if the continuous mode works as expected (1/2)"
447         dlogutil -b main -f $TESTDIR/dlog_continuous1_file &
448         UTIL_PID=$!
449         sleep 1
450         kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
451         UTIL_PID=-1
452         [ "$WAS_ALIVE" -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous1_file)" -eq 10 ] && ok || fail
453
454         LOG_DETAILS="testing if the continuous mode works as expected (2/2)"
455         dlogutil -b main -f $TESTDIR/dlog_continuous2_file &
456         UTIL_PID=$!
457         sleep 1
458         dlogsend -b main "Hi!"
459         sleep 1
460         kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
461         UTIL_PID=-1
462         [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_continuous2_file)" -eq 11 ] && ok || fail
463
464         LOG_DETAILS="testing if the monitor mode works as expected (1/2)"
465         dlogutil -mb main -f $TESTDIR/dlog_monitor1_file &
466         UTIL_PID=$!
467         sleep 1
468         kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
469         UTIL_PID=-1
470         [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor1_file)" -eq 0 ] && ok || fail
471
472         LOG_DETAILS="testing if the monitor mode works as expected (2/2)"
473         dlogutil -mb main -f $TESTDIR/dlog_monitor2_file &
474         UTIL_PID=$!
475         sleep 1
476         dlogsend -b main "Hi!"
477         sleep 1
478         kill $UTIL_PID && WAS_ALIVE=1 || WAS_ALIVE=0
479         UTIL_PID=-1
480         [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor2_file)" -eq 1 ] && ok || fail
481 fi
482
483 test_libdlog 100000 &
484 LIBDLOGUTIL_CORRECT_PID=$!
485 wait $LIBDLOGUTIL_CORRECT_PID
486
487 # NB: rotation only really makes sense in the continuous mode
488 # from a user PoV, but the logic doesn't care about dumping
489 # so we do it to simplify things
490 dlogutil -df $TESTDIR/dlog_rotating_file -r 12 -n 3 # 3 files at 12 KB each
491
492 LOG_DETAILS="testing if single file is properly created"
493 if [ -e $TESTDIR/dlog_test_file ]; then ok; else fail; fi
494
495 LOG_DETAILS="testing if rotating file is properly created (1/4)"
496 if [ -e $TESTDIR/dlog_rotating_file.1 ]; then ok; else fail; fi
497
498 LOG_DETAILS="testing if rotating file is properly created (2/4)"
499 if [ -e $TESTDIR/dlog_rotating_file.2 ]; then ok; else fail; fi
500
501 LOG_DETAILS="testing if rotating file is properly created (3/4)"
502 if [ -e $TESTDIR/dlog_rotating_file.3 ]; then ok; else fail; fi
503
504 LOG_DETAILS="testing if rotating file is properly created (4/4)"
505 if [ -e $TESTDIR/dlog_rotating_file.4 ]; then fail; else ok; fi
506
507 LOG_DETAILS="testing the size of log files"
508 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
509
510 LOG_DETAILS="testing if libdlogutil works correctly in the dump mode"
511 test_libdlogutil dump $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
512 if [ "$quick" -ne 1 ]; then
513         LOG_DETAILS="testing if libdlogutil works correctly if processing the logs takes some time"
514         test_libdlogutil timer $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
515 fi
516 LOG_DETAILS="testing if libdlogutil works correctly in the continuous mode"
517 test_libdlogutil continuous $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
518 LOG_DETAILS="testing if libdlogutil skips all the logs in the monitor mode correctly"
519 test_libdlogutil monitor $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
520 LOG_DETAILS="testing if libdlogutil priority filter works correctly"
521 test_libdlogutil priority $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
522 LOG_DETAILS="testing if libdlogutil exact priority filter works correctly"
523 test_libdlogutil priority_exact $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
524 LOG_DETAILS="testing if libdlogutil limits the log amount correctly"
525 test_libdlogutil limit $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
526 LOG_DETAILS="testing if libdlogutil PID filter works correctly (1/2)"
527 test_libdlogutil pid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
528 LOG_DETAILS="testing if libdlogutil PID filter works correctly (2/2)"
529 test_libdlogutil pid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
530 LOG_DETAILS="testing if libdlogutil TID filter works correctly (1/2)"
531 test_libdlogutil tid_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
532 LOG_DETAILS="testing if libdlogutil TID filter works correctly (2/2)"
533 test_libdlogutil tid_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
534 LOG_DETAILS="testing if libdlogutil tag filter works correctly (1/2)"
535 test_libdlogutil tag_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
536 LOG_DETAILS="testing if libdlogutil tag filter works correctly (2/2)"
537 test_libdlogutil tag_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
538 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (1/2)"
539 test_libdlogutil prefix_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
540 LOG_DETAILS="testing if libdlogutil prefix filter works correctly (2/2)"
541 test_libdlogutil prefix_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
542 LOG_DETAILS="testing if libdlogutil returns the correct buffer traits"
543 test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
544 LOG_DETAILS="testing if libdlogutil aliasing works"
545 if [ "$type" = "pipe" ]; then
546         test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
547 else
548         DLOG_CONFIG_PATH="@datadir@/dlog-logger.conf.alias" test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
549 fi
550 LOG_DETAILS="testing if libdlogutil errors out correctly if used improperly"
551 test_libdlogutil negative $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
552
553 cmd_prefix="dlogutil -t 1 -u 0 -v"
554
555 format="process"
556 regex_prio="[VDIWEFS]{1}"
557 regex_pidtid="P[0-9[:space:]]{5,},\s{1}T[0-9[:space:]]{5,}"
558 regex_time="[0-9]{2}-[0-9]{2}\s{1}[0-9]{2}:[0-9]{2}:[0-9]{2}"
559 regex_timezone="[\+-]{1}[0-9]{4}"
560
561 for PARAM in always auto none never; do
562         for PRIO in info error; do
563                 for OUTPUT in pipe tty; do
564                         if [ "$PARAM" = "always" ]; then
565                                 COLOR_EXPECTED=1
566                         elif [ "$PARAM" = "never" ]; then
567                                 COLOR_EXPECTED=0
568                         elif [ "$OUTPUT" = "tty" ]; then
569                                 COLOR_EXPECTED=1
570                         else
571                                 COLOR_EXPECTED=0
572                         fi
573
574                         if [ "$PRIO" = "info" ]; then
575                                 REGEX="s/^I\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
576                         elif [ "$COLOR_EXPECTED" -eq 0 ]; then
577                                 REGEX="s/^E\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)@$/1/g"
578                         else
579                                 REGEX="s/^~\[31;1mE\([0-9[:space:]]{5,}\) ~\[0m[[:print:]]*~\[31;1m  \([[:print:]]*\)@~\[0m$/1/g"
580                         fi
581
582                         # -t 1 instead of | head -n 1 because the `script` command can't cope with SIGPIPE.
583                         COMMAND="$cmd_prefix $format"
584
585                         if [ "$PARAM" = "none" ]; then
586                                 LOG_DETAILS="testing if color output is correct (implicit --color=auto/$PRIO priority/$OUTPUT output)"
587                         else
588                                 COMMAND="$COMMAND --color=$PARAM"
589                                 LOG_DETAILS="testing if color output is correct (--color=$PARAM/$PRIO priority/$OUTPUT output)"
590                         fi
591
592                         if [ "$PRIO" = "info" ]; then
593                                 COMMAND="$COMMAND '*:=I'"
594                         else
595                                 COMMAND="$COMMAND '*:=E'"
596                         fi
597
598                         if [ "$OUTPUT" = "tty" ]; then
599                                 # This emulates a TTY. The sed call is because `script` likes to mess up the output for some reason.
600                                 COMMAND="script -qc\"$COMMAND\" /dev/null | sed 's/\r$//'"
601                         fi
602
603                         # $(eval) is needed since `$COMMAND` may contain `"`
604                         line="$(eval "$COMMAND" | tr '\033\n' '~@')"
605                         [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
606                 done
607         done
608 done
609 # TODO: It would be cool to also test warning messages (which have a different color),
610 # but this would require deeper changes to this script, which is already janky enough.
611
612 REGEX="s/^$regex_prio\([0-9[:space:]]{5,}\)[[:print:]]*\([[:print:]]*\)$/1/g"
613 LOG_DETAILS="testing if \"$format\" print format works"
614 line=$($cmd_prefix $format)
615 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
616
617 format="tag"
618 REGEX="s/^$regex_prio\/[[:print:]]{9,}:\s{1}[[:print:]]*$/1/g"
619 LOG_DETAILS="testing if \"$format\" print format works"
620 line=$($cmd_prefix $format)
621 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
622
623 format="thread"
624 REGEX="s/^$regex_prio\($regex_pidtid\)\s{1}[[:print:]]*$/1/g"
625 LOG_DETAILS="testing if \"$format\" print format works"
626 line=$($cmd_prefix $format)
627 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
628
629 format="time"
630 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
631 LOG_DETAILS="testing if \"$format\" print format works"
632 line=$($cmd_prefix $format)
633 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
634
635 format="threadtime"
636 REGEX="s/^$regex_time.[0-9]{3}$regex_timezone\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
637 LOG_DETAILS="testing if \"$format\" print format works"
638 line=$($cmd_prefix $format)
639 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
640
641 format="kerneltime"
642 REGEX="s/^[0-9[:space:]]{1,}.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
643 LOG_DETAILS="testing if \"$format\" print format works"
644 line=$($cmd_prefix $format)
645 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
646
647 format="recv_realtime"
648 REGEX="s/^$regex_time.[0-9]{3}\s{1}$regex_prio\/[[:print:]]{8,}\($regex_pidtid\):\s{1}[[:print:]]*$/1/g"
649 LOG_DETAILS="testing if \"$format\" print format works"
650 line=$($cmd_prefix $format)
651 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
652
653 format="rwtime"
654 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"
655 LOG_DETAILS="testing if \"$format\" print format works"
656 line=$($cmd_prefix $format)
657 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
658
659 format="long"
660 REGEX="s/^\[\s{1}$regex_time.[0-9]{3,}\s{1}$regex_prio\/[[:print:]]{8,}\s{1}$regex_pidtid\]@[[:print:]]+@$/1/g"
661 LOG_DETAILS="testing if \"$format\" print format works"
662 line=$($cmd_prefix $format)
663 [ "$(echo "$line" | tr '\n' '@' | sed -re "$REGEX")" = "1" ] && ok || fail
664
665 format="brief"
666 REGEX="s/^$regex_prio\/[[:print:]]{8,}\([0-9[:space:]]{5,}\):\s{1}[[:print:]]*$/1/g"
667 LOG_DETAILS="testing if \"$format\" print format works"
668 line=$($cmd_prefix $format)
669 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
670
671 format="json"
672 if [ "$type" = "pipe" ]; then
673         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"
674 else
675         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"
676 fi
677 LOG_DETAILS="testing if \"$format\" print format works"
678 line=$($cmd_prefix $format)
679 [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
680
681 format="raw"
682 LOG_DETAILS="testing if \"$format\" print format works"
683 dlogutil -c
684 dlogsend -b main -t DLOG_TESTSUITE rawformatTEST
685 line=$($cmd_prefix $format)
686 [ "$line" = "rawformatTEST" ] && ok || fail
687
688 if [ "$quick" -ne 1 ]; then
689         LOG_DETAILS="testing if dlogsend -d works"
690         dlogutil -c
691         dlogsend -b main -c 9999 -d 4 -f 7 -t DLOG_TESTSUITE "hi" &
692         DLOGSEND_PID=$!
693         sleep 10
694         kill $DLOGSEND_PID
695         # In 10 seconds, 3 cycles 7 logs each should have happened.
696         [ "$(dlogutil -d DLOG_TESTSUITE | wc -l)" -eq 21 ] && ok || fail
697 fi
698
699 if [ "$type" = "pipe" ]; then
700         for format in raw brief long; do
701                 for i in 1 2 3 4 5 6 7 8 10 15 20 25 513 514 515 516 517 518 519 520; do
702                         LOG_DETAILS="testing if padding works correctly (format $format/count $i)"
703                         log=$(printf '%0.s&' $(seq 1 $i)) # Print the '&' character $i times
704
705                         dlogutil -c
706                         dlogsend -b main "$log"
707                         line=$($cmd_prefix $format | tr '\n' '@')
708
709                         case $format in
710                                 raw)
711                                         REGEX="s/$log@/1/g"
712                                         ;;
713                                 brief)
714                                         REGEX="s/I\/DLOG_SEND\([0-9[:space:]]{5,}\):\s{1}$log@$/1/g"
715                                         ;;
716                                 long)
717                                         REGEX="s/\[\s{1}$regex_time.[0-9]{3,}\s{1}I\/DLOG_SEND\s{1}$regex_pidtid\]@$log@@/1/g"
718                                         ;;
719                         esac
720
721                         [ "$(echo "$line" | sed -re "$REGEX")" = "1" ] && ok || fail
722                 done
723         done
724 fi
725
726 LOG_DETAILS="testing if KMSG works in the default format"
727 # We check if the command returns at least 100 logs. This seems to be a safe value.
728 # Feel free to change it to a reasonable yet lower value if the test happens to fail otherwise.
729 [ "$(dlogutil -db kmsg | wc -l)" -gt 100 ] && ok || fail
730
731 if [ "$quick" -ne 1 ]; then
732         LOG_DETAILS="testing if KMSG works in the raw format"
733         last_dmesg=$(dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g")
734         sleep 1 # To make sure dlog has already parsed the log
735         dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail
736
737         LOG_DETAILS="testing if pid filtering works"
738         dlogsend -b main -t DLOG_TESTSUITE pidTEST &
739         sleep 1
740         line=$(dlogutil -v raw -d --pid $!)
741         [ "$line" = "pidTEST" ] && ok || fail
742
743         LOG_DETAILS="testing if tid filtering works"
744         dlogsend -b main -t DLOG_TESTSUITE tidTEST &
745         sleep 1
746         line=$(dlogutil -v raw -d --tid $!) #dlogsend is a single threaded app so tid is the same as pid
747         [ "$line" = "tidTEST" ] && ok || fail
748
749         mv $DLOG_CONFIG_PATH $DLOG_CONFIG_PATH.1
750         LOG_DETAILS="testing if secure logging works (1/2)"
751         grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
752         echo "enable_secure_logs=1" >> $DLOG_CONFIG_PATH
753         dlogutil -c
754         dlogsend -zb main -t DLOG_TESTSUITE secure &
755         sleep 1
756         dlogsend -b main -t DLOG_TESTSUITE insecure &
757         sleep 1
758         line=$(dlogutil -v raw -d | head -n1)
759         [ "$line" = "secure" ] && ok || fail
760         LOG_DETAILS="testing if secure logging works (2/2)"
761         grep -v enable_secure_logs $DLOG_CONFIG_PATH.1 > $DLOG_CONFIG_PATH
762         echo "enable_secure_logs=0" >> $DLOG_CONFIG_PATH
763         dlogutil -c
764         dlogsend -zb main -t DLOG_TESTSUITE secure &
765         sleep 1
766         dlogsend -b main -t DLOG_TESTSUITE insecure &
767         sleep 1
768         line=$(dlogutil -v raw -d | head -n1)
769         [ "$line" = "insecure" ] && ok || fail
770         mv $DLOG_CONFIG_PATH.1 $DLOG_CONFIG_PATH
771 fi
772
773 dlogsend -b main -t DLOG_TESTSUITE_TAG0 -pI tagTEST0
774 dlogsend -b main -t DLOG_TESTSUITE_TAG1 -pI tagTEST1
775 dlogsend -b main -t DLOG_TESTSUITE_TAG2 -pF tagTEST2
776
777 LOG_DETAILS="testing if tag filtering works (1/8)"
778 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG0' | wc -l)" -eq 1 ] && ok || fail
779 LOG_DETAILS="testing if tag filtering works (2/8)"
780 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG1' | wc -l)" -eq 1 ] && ok || fail
781 LOG_DETAILS="testing if tag filtering works (3/8)"
782 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG' | wc -l)" -eq 0 ] && ok || fail
783 LOG_DETAILS="testing if tag filtering works (4/8)"
784 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*' | wc -l)" -eq 3 ] && ok || fail
785 LOG_DETAILS="testing if tag filtering works (5/8)"
786 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:I' | wc -l)" -eq 3 ] && ok || fail
787 LOG_DETAILS="testing if tag filtering works (6/8)"
788 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_TAG*:W' | wc -l)" -eq 1 ] && ok || fail
789 LOG_DETAILS="testing if tag filtering works (7/8)"
790 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG' | wc -l)" -eq 0 ] && ok || fail
791 LOG_DETAILS="testing if tag filtering works (8/8)"
792 [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l)" -eq 0 ] && ok || fail
793
794 if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then
795         LOG_DETAILS="testing if limiter and runtime filtering works"
796         dlogutil -c -b radio
797         test_filters
798         [ "$(dlogutil -d -b radio | wc -l)" -eq 12 ] && ok || fail
799         dlogutil -c -b radio
800
801         LOG_DETAILS="testing proper SMACK label for dynamic config file location"
802         ORIG_FILTERS_DIR=$(grep dynamic_config_path "$ORIGINAL_CONFIG_PATH" | awk -F "=" '{print $2}')
803         # Running ls on an arbitrary directory and trying to make sense of results is problematic.
804         # However, this is not a problem in our usecase, as we only care about the first field, the security context.
805         # We don't even care about the filename, which isn't arbitrary anyway (-d on fixed path).
806         # shellcheck disable=SC2012
807         [ "$(ls -dZ "$ORIG_FILTERS_DIR" | awk -F ' ' '{print $1}')" = "System::Shared" ] && ok || fail
808
809         if [ "$quick" -ne 1 ]; then
810                 # This creates a process which will wait for SIGCONT and then spam logs. We know its PID, so we can add
811                 # PID-based limits and see what happens.
812                 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
813                 DLOGSEND_PID=$!
814                 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
815                 dlogctl --pid $DLOGSEND_PID -s deny
816                 kill -s CONT $DLOGSEND_PID
817                 wait $DLOGSEND_PID
818                 LOG_DETAILS="testing if PID limiting works (1/14)"
819                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 0 ] && ok || fail
820                 LOG_DETAILS="testing if PID limiting works (2/14)"
821                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c  blocked)" -eq 1 ] && ok || fail
822                 LOG_DETAILS="testing if PID limiting works (3/14)"
823                 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = "Denied" ] && ok || fail
824                 LOG_DETAILS="testing if PID limiting works (4/14)"
825                 dlogctl -g | grep -q "Denied for $DLOGSEND_PID" && ok || fail
826
827                 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
828                 DLOGSEND_PID=$!
829                 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
830                 dlogctl --pid $DLOGSEND_PID -s 25
831                 kill -s CONT $DLOGSEND_PID
832                 wait $DLOGSEND_PID
833                 LOG_DETAILS="testing if PID limiting works (5/14)"
834                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 25 ] && ok || fail
835                 LOG_DETAILS="testing if PID limiting works (6/14)"
836                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c  blocked)" -eq 1 ] && ok || fail
837                 LOG_DETAILS="testing if PID limiting works (7/14)"
838                 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = '25 logs/min' ] && ok || fail
839                 LOG_DETAILS="testing if PID limiting works (8/14)"
840                 dlogctl -g | grep -q "25 logs/min for $DLOGSEND_PID" && ok || fail
841
842                 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 100 "Pid test"' &
843                 DLOGSEND_PID=$!
844                 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
845                 dlogctl --pid $DLOGSEND_PID -s allow
846                 kill -s CONT $DLOGSEND_PID
847                 wait $DLOGSEND_PID
848                 LOG_DETAILS="testing if PID limiting works (9/14)"
849                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 100 ] && ok || fail
850                 LOG_DETAILS="testing if PID limiting works (10/14)"
851                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c  blocked)" -eq 0 ] && ok || fail
852                 LOG_DETAILS="testing if PID limiting works (11/14)"
853                 [ "$(dlogctl --pid $DLOGSEND_PID -g)" = 'Unlimited' ] && ok || fail
854                 LOG_DETAILS="testing if PID limiting works (12/14)"
855                 dlogctl -g | grep -q "Unlimited for $DLOGSEND_PID" && ok || fail
856
857                 echo "qos_refresh_rate_s=5" > "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
858                 sh -c 'kill -s STOP $$; exec dlogsend -b main -c 15 -d 1 "Pid test"' &
859                 DLOGSEND_PID=$!
860                 while [ "$(cut -d ' ' -f 3 < /proc/$DLOGSEND_PID/stat)" != "T" ]; do :; done
861                 dlogctl --pid $DLOGSEND_PID -s 2
862                 kill -s CONT $DLOGSEND_PID
863                 wait $DLOGSEND_PID
864                 rm "$RUNTIME_FILTERS_DIR/69-refresh-rate.conf"
865                 LOG_DETAILS="testing if PID limiting works (13/14)"
866                 # In each 5 second period, 5 logs are sent, so there are 3 periods.
867                 # 2 logs from each period are allowed.
868                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -cv blocked)" -eq 6 ] && ok || fail
869                 LOG_DETAILS="testing if PID limiting works (14/14)"
870                 [ "$(dlogutil --pid $DLOGSEND_PID -d | grep -c  blocked)" -eq 3 ] && ok || fail
871
872                 PREQOS_CONFIG_PATH=$DLOG_CONFIG_PATH
873                 DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.qos"
874                 kill $LOGGER > /dev/null
875                 sleep 1
876                 if [ "$type" = "logger" ]; then
877                         dlogutil -cb main
878                 fi
879                 dlog_logger -t 0 &
880                 LOGGER=$!
881                 sleep 1
882
883                 dlogsend -b main -t DLOG_QOS_TEST0 -c 30 -d 1 -f 2 "A normal app that just wants to log"
884                 LOG_DETAILS="testing if QoS works (1/4)"
885                 [ "$(dlogutil -d DLOG_QOS_TEST0 | grep -cv blocked)" -eq 30 ] && ok || fail
886                 kill $LOGGER > /dev/null
887                 sleep 1
888                 if [ "$type" = "logger" ]; then
889                         dlogutil -cb main
890                 fi
891                 dlog_logger -t 0 &
892                 LOGGER=$!
893                 sleep 1
894
895                 dlogsend -b main -t DLOG_QOS_TEST1 -c 300 -d 1 -f 20 "Some log spam"
896                 LOG_DETAILS="testing if QoS works (2/4)"
897                 [ "$(dlogutil -d DLOG_QOS_TEST1 | grep -cv blocked)" -le 210 ] && ok || fail
898                 kill $LOGGER > /dev/null
899                 sleep 1
900                 if [ "$type" = "logger" ]; then
901                         dlogutil -cb main
902                 fi
903                 dlog_logger -t 0 &
904                 LOGGER=$!
905                 sleep 1
906
907                 dlogsend -b main -t DLOG_QOS_TEST2 -c 30 -d 1 -f 2 "A normal app that just wants to log" &
908                 DLOGSEND_PID=$!
909                 dlogsend -b main -t DLOG_QOS_TEST3 -c 270 -d 1 -f 18 "Some log spam"
910                 wait $DLOGSEND_PID
911                 LOG_DETAILS="testing if QoS works (3/4)"
912                 [ "$(dlogutil -d DLOG_QOS_TEST2 DLOG_QOS_TEST3 | grep -cv blocked)" -le 210 ] && ok || fail
913                 LOG_DETAILS="testing if QoS works (4/4)"
914                 [ "$(dlogutil -d DLOG_QOS_TEST2 | grep -cv blocked)" -gt 24 ] && ok || fail
915
916                 DLOG_CONFIG_PATH=$PREQOS_CONFIG_PATH
917                 kill $LOGGER > /dev/null
918                 sleep 1
919                 dlog_logger -t 0 &
920                 LOGGER=$!
921                 sleep 1
922         fi
923 fi
924
925 if [ "$LEGACY_LOGGER" -ne 1 ] && [ "$quick" -ne 1 ]; then
926         dlogutil -cb main
927
928         LOG_DETAILS="testing if basic stdout redirection works correctly (1/2)"
929         [ "$(dlog_redirect_stdout --outtag FOO -- /usr/bin/echo Hi)" = "" ] && ok || fail
930         sleep 1
931         LOG_DETAILS="testing if basic stdout redirection works correctly (2/2)"
932         [ "$(dlogutil -db main -v tag)" = "I/FOO     : Hi" ] && ok || fail
933         dlogutil -cb main
934
935         # No need to check output in this case, as nothing is written to stdout anyway
936         dlog_redirect_stdout --errtag BAR -- /usr/bin/sh -c "echo Hi >&2"
937         sleep 1
938         LOG_DETAILS="testing if basic stderr redirection works correctly"
939         [ "$(dlogutil -db main -v tag)" = "E/BAR     : Hi" ] && ok || fail
940         dlogutil -cb main
941
942         LOG_DETAILS="testing if redirector doesn't redirect anything by default (1/2)"
943         [ "$(dlog_redirect_stdout -- /usr/bin/echo Hi)" = "Hi" ] && ok || fail
944         sleep 1
945         LOG_DETAILS="testing if redirector doesn't redirect anything by default (2/2)"
946         [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
947         dlogutil -cb main
948
949         dlog_redirect_stdout --outbuffer radio --outtag AN_INTERESTING_TAG --outprio W -- /usr/bin/echo Hi
950         sleep 1
951         LOG_DETAILS="testing if redirector settings work correctly on stdout (1/2)"
952         [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
953         LOG_DETAILS="testing if redirector settings work correctly on stdout (2/2)"
954         [ "$(dlogutil -db radio -v tag)" = "W/AN_INTERESTING_TAG: Hi" ] && ok || fail
955         dlogutil -cb radio
956
957         dlog_redirect_stdout --errbuffer radio --errtag ANOTHER_INTERESTING_TAG --errprio I -- /usr/bin/sh -c "echo Hi >&2"
958         sleep 1
959         LOG_DETAILS="testing if redirector settings work correctly on stderr (1/2)"
960         [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail
961         LOG_DETAILS="testing if redirector settings work correctly on stderr (2/2)"
962         [ "$(dlogutil -db radio -v tag)" = "I/ANOTHER_INTERESTING_TAG: Hi" ] && ok || fail
963         dlogutil -cb radio
964
965         echo "Testing" | dlog_redirect_stdout --outtag BAZ -- /usr/bin/cat
966         sleep 1
967         LOG_DETAILS="testing if redirector passes stdin correctly"
968         [ "$(dlogutil -db main -v tag)" = "I/BAZ     : Testing" ] && ok || fail
969         dlogutil -cb main
970
971         dlog_redirect_stdout --outtag QUUX -- /usr/bin/cat << EOF
972 line 1
973 line 2
974 line 3
975 line 4
976 line 5
977 EOF
978         sleep 1
979         LOG_DETAILS="testing if multiline logs are handled correctly"
980         [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
981         dlogutil -cb main
982
983         dlog_redirect_stdout --outtag QUUX -- /usr/bin/sh -c "printf \"line 1\0line 2\0line 3\0line 4\0line 5\""
984         sleep 1
985         LOG_DETAILS="testing if logs with the '\\0' character are handled correctly"
986         [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
987         dlogutil -cb main
988
989         dlog_redirect_stdout --outtag QUUX -- /usr/bin/sh -c "printf \"line 1\0line 2\nline 3\0line 4\nline 5\""
990         sleep 1
991         LOG_DETAILS="testing if logs with mixed delimiters are handled correctly"
992         [ "$(dlogutil -db main | wc -l)" -eq 5 ] && ok || fail
993         dlogutil -cb main
994
995         rm -f "$TESTDIR"/input
996         rm -f "$TESTDIR"/output
997         base64 -w 0 < /dev/urandom 2> /dev/null | head -c 250000 > "$TESTDIR"/input
998         dlog_redirect_stdout --outtag XYZZY -- /usr/bin/cat "$TESTDIR"/input
999         sleep 1
1000         dlogutil -db main -v raw | tr -d '\n' > "$TESTDIR"/output
1001         LOG_DETAILS="testing if long lines are handled correctly"
1002         # Usually we would just diff or cmp the files. Unfortunately, as of writing, Tizen doesn't have such luxuries.
1003         [ "$(sha256sum < "$TESTDIR"/input)" = "$(sha256sum < "$TESTDIR"/output)" ] && ok || fail
1004         dlogutil -cb main
1005
1006         if [ "$type" = "pipe" ]; then
1007                 # TODO: Actually implement and enable this in the logger backend
1008                 dlogctl -b main --disable-stdout
1009                 LOG_DETAILS="testing if redirection can be disabled (1/3)"
1010                 [ "$(dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test)" = "" ] && ok || fail
1011                 sleep 1
1012                 LOG_DETAILS="testing if redirection can be disabled (2/3)"
1013                 [ "$(dlogutil -db main -v raw)" = "" ] && ok || fail
1014                 LOG_DETAILS="testing if redirection can be disabled (3/3)"
1015                 [ "$(dlogctl --get | grep main)" = "* main: ENABLED (stdout: DISABLED)" ] && ok || fail
1016
1017                 dlogctl -b main --enable-stdout
1018                 LOG_DETAILS="testing if redirection can be reenabled (1/3)"
1019                 [ "$(dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test)" = "" ] && ok || fail
1020                 sleep 1
1021                 LOG_DETAILS="testing if redirection can be reenabled (2/3)"
1022                 [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail
1023                 LOG_DETAILS="testing if redirection can be reenabled (3/3)"
1024                 [ "$(dlogctl --get | grep main)" = "* main: ENABLED (stdout: ENABLED)" ] && ok || fail
1025                 dlogutil -cb main
1026         fi
1027
1028         dlogctl -b radio --disable-stdout
1029         dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test
1030         sleep 1
1031         LOG_DETAILS="testing if dlogctl --disable-stdout respects buffer choice"
1032         [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail
1033         dlogutil -cb main
1034
1035         LOG_DETAILS="testing if redirection check works (1/5)"
1036         test_libredirect 0 0 && ok || fail
1037         LOG_DETAILS="testing if redirection check works (2/5)"
1038         dlog_redirect_stdout -- /usr/libexec/libdlog/test_libredirect 0 0 && ok || fail
1039         LOG_DETAILS="testing if redirection check works (3/5)"
1040         dlog_redirect_stdout --outtag X -- /usr/libexec/libdlog/test_libredirect 1 0 && ok || fail
1041         LOG_DETAILS="testing if redirection check works (4/5)"
1042         dlog_redirect_stdout --errtag X -- /usr/libexec/libdlog/test_libredirect 0 1 && ok || fail
1043         LOG_DETAILS="testing if redirection check works (5/5)"
1044         dlog_redirect_stdout --outtag X --errtag Y -- /usr/libexec/libdlog/test_libredirect 1 1 && ok || fail
1045
1046         LOG_DETAILS="testing if multiple redirections work (1/4)"
1047         test_libredirect_multi && ok || fail
1048         LOG_DETAILS="testing if multiple redirections work (2/4)"
1049         [ "$(dlogutil -db main -v tag | grep "Message 1")" = "W/TAG1    : Message 1" ] && ok || fail
1050         LOG_DETAILS="testing if multiple redirections work (3/4)"
1051         [ "$(dlogutil -db main -v tag | grep "Message 2")" = "E/TAG2    : Message 2" ] && ok || fail
1052         LOG_DETAILS="testing if multiple redirections work (4/4)"
1053         [ "$(dlogutil -db system -v tag)" = "I/TAG3    : Message 3" ] && ok || fail
1054         dlogutil -cb main -b system
1055 fi
1056
1057 dlogutil -c
1058 echo "deduplicate_method=only_identical_neighbours" > "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1059 echo "deduplicate_interval_ms=10" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1060
1061 dlogsend -p Info -b main -c 9 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
1062 LOG_DETAILS="testing if deduplication with warnings works properly (1/12)"
1063 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 1 ] && ok || fail
1064 LOG_DETAILS="testing if deduplication with warnings works properly (2/12)"
1065 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 0 ] && ok || fail
1066
1067 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity"
1068 LOG_DETAILS="testing if deduplication with warnings works properly (3/12)"
1069 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 3 ] && ok || fail
1070 LOG_DETAILS="testing if deduplication with warnings works properly (4/12)"
1071 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 1 ] && ok || fail
1072
1073 echo "deduplicate_warn_quantity=8" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1074
1075 dlogsend -p Info -b main -c 24 -t DLOG_DEDUP_TEST Message
1076 LOG_DETAILS="testing if deduplication with warnings works properly (5/12)"
1077 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 4 ] && ok || fail
1078 LOG_DETAILS="testing if deduplication with warnings works properly (6/12)"
1079 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Message LOG DUPLICATED')" -eq 3 ] && ok || fail
1080
1081 dlogsend -p Info -b main -c 8 -t DLOG_DEDUP_TEST longerMessage
1082 LOG_DETAILS="testing if deduplication with warnings works properly (7/12)"
1083 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c longerMessage)" -eq 2 ] && ok || fail
1084 LOG_DETAILS="testing if deduplication with warnings works properly (8/12)"
1085 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 6 ] && ok || fail
1086 LOG_DETAILS="testing if deduplication with warnings works properly (9/12)"
1087 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'longerMessage LOG DUPLICATED')" -eq 1 ] && ok || fail
1088
1089 echo "deduplicate_warn_quantity=-1" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1090
1091 dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, no warning"
1092 LOG_DETAILS="testing if deduplication with warnings works properly (10/12)"
1093 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning')" -eq 1 ] && ok || fail
1094 LOG_DETAILS="testing if deduplication with warnings works properly (11/12)"
1095 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication')" -eq 4 ] && ok || fail
1096 LOG_DETAILS="testing if deduplication with warnings works properly (12/12)"
1097 [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning LOG DUPLICATED')" -eq 0 ] && ok || fail
1098
1099 rm "$RUNTIME_FILTERS_DIR/30-deduplicate.conf"
1100
1101 LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
1102 test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
1103
1104 if [ "$quick" -ne 1 ]; then
1105         PREAUTODETECT_CONFIG_PATH=$DLOG_CONFIG_PATH
1106         DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.autodetect"
1107         kill $LOGGER > /dev/null
1108         sleep 1
1109         if [ "$type" = "logger" ]; then
1110                 dlogutil -cb main
1111         fi
1112         dlog_logger -t 0 &
1113         LOGGER=$!
1114         sleep 1
1115
1116         LOG_DETAILS="testing if backend autodetection works properly (1/2)"
1117         dlogsend -b main -t DLOG_AUTODETECT "xd" && ok || fail
1118         sleep 1
1119
1120         DLOG_CONFIG_PATH=$PREAUTODETECT_CONFIG_PATH
1121         LOG_DETAILS="testing if backend autodetection works properly (2/2)"
1122         [ "$(dlogutil -db main -v raw)" = "xd" ] && ok || fail
1123
1124         kill $LOGGER > /dev/null
1125         sleep 1
1126         rm "$TESTDIR"/test*
1127         dlog_logger -t 0 &
1128         LOGGER=$!
1129         sleep 1
1130
1131         dlogsend -b main -t DLOG_LOGGER_TEST0 -c 100 "hi"
1132         sleep 1
1133         LOG_DETAILS="testing if logger daemon persistent logging works (1/3)"
1134         [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test0)" -eq 100 ] && ok || fail
1135         LOG_DETAILS="testing if logger daemon persistent logging works (2/3)"
1136         [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test1)" -eq 100 ] && ok || fail
1137         LOG_DETAILS="testing if logger daemon persistent logging works (3/3)"
1138         [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test2)" -eq 0 ] && ok || fail
1139
1140         dlogsend -b main -t DLOG_LOGGER_TEST1 -c 500000 "hi"
1141         sleep 1
1142         RESULT=$(du -c "$TESTDIR"/test0* | tail -n 1 | cut -f 1)
1143         LOG_DETAILS="testing if logger daemon log rotating works (1/2)"
1144         [ "$RESULT" -gt 4096 ] && ok || fail # Min 4 MB
1145         LOG_DETAILS="testing if logger daemon log rotating works (2/2)"
1146         [ "$RESULT" -lt 6144 ] && ok || fail # Max 6 MB
1147
1148         dlogutil -cb main
1149         kill $LOGGER > /dev/null
1150         sleep 1
1151         rm "$TESTDIR"/test0*
1152         dlog_logger -t 5 -b 100000 &
1153         LOGGER=$!
1154         sleep 1
1155
1156         dlogsend -b main -t DLOG_LOGGER_TEST2 -c 100 "hi"
1157         sleep 1
1158         LOG_DETAILS="testing if logger daemon buffering works (1/5)"
1159         [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 0 ] && ok || fail
1160
1161         sleep 6
1162         LOG_DETAILS="testing if logger daemon buffering works (2/5)"
1163         [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 100 ] && ok || fail
1164
1165         dlogsend -b main -t DLOG_LOGGER_TEST3 -c 100 "hi"
1166         sleep 1
1167         LOG_DETAILS="testing if logger daemon buffering works (3/5)"
1168         [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 0 ] && ok || fail
1169
1170         dlogutil -cb main
1171         kill $LOGGER > /dev/null
1172         sleep 1
1173         dlog_logger -t 10000 -b 100 &
1174         LOGGER=$!
1175         sleep 1
1176         LOG_DETAILS="testing if logger daemon buffering works (4/5)"
1177         [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 100 ] && ok || fail
1178
1179         dlogsend -b main -t DLOG_LOGGER_TEST4 -c 100 "hi"
1180         sleep 1
1181         LOG_DETAILS="testing if logger daemon buffering works (5/5)"
1182         [ "$(grep -c DLOG_LOGGER_TEST4 "$TESTDIR"/test0)" -gt 90 ] && ok || fail
1183
1184         dlogutil -cb main
1185         kill $LOGGER > /dev/null
1186         sleep 1
1187         dlog_logger -t 0 &
1188         LOGGER=$!
1189         sleep 1
1190
1191         LOG_DETAILS="testing if the library works with multithreaded app"
1192         dlogutil -f $TESTDIR/dlog_mt_test &
1193         MT_TEST=$!
1194         test_libdlog && ok || fail
1195
1196         sleep 1
1197         kill $MT_TEST
1198         MT_TEST=-1
1199
1200         dlogutil -c
1201         SPAWN_CNT=1000
1202
1203         # Spawn logging scripts and wait for them to finish.
1204         # We launch all the $SPAWN_CNT scripts in a subshell, and then use the wait command in order to
1205         # wait for all the jobs of the subshell, which means all the logging scripts.
1206         # Each of the logging scripts is a new subsubshell which waits a random amount of seconds and then logs
1207         # a single message. This gets us 5 groups of logs separated by a second; there are about 200 logs in each
1208         # group, sent about at the same time.
1209         (
1210                 for i in $(seq 1 $SPAWN_CNT); do
1211                         delay=$(shuf -i 1-5 -n 1)
1212                         ( sleep "$delay" && dlogsend -b main -t DLOG_TESTSUITE "$delay" ) &
1213                 done
1214                 wait
1215         )
1216
1217         LOG_DETAILS="testing if libdlogutil sorts by the timestamp correctly"
1218
1219         test_libdlogutil sorting $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
1220
1221         if [ "$type" = "pipe" ]; then
1222                 for P in recv sent; do
1223                         for Q in mono real; do
1224                                 LOG_DETAILS="testing if dlogutil --sort-by works correctly (${P}_${Q})"
1225                                 [ "$(dlogutil -db main --sort-by "${P}_${Q}" | wc -l)" -eq "$SPAWN_CNT" ] && ok || fail
1226                         done
1227                 done
1228                 for P in recv sent; do
1229                         LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_mono)"
1230                         dlogutil -db main --sort-by "${P}_mono" -v json | sed -Ee "s/^.*\"${P}_mono\":([^,}]*).*\$/\\1/" | sort -c && ok || fail
1231                         LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_real)"
1232                         dlogutil -db main --sort-by "${P}_real" -v json | sed -Ee "s/^.*\"${P}_real\":\"([^\"]*)\".*\$/\\1/" | sort -c && ok || fail
1233                 done
1234         fi
1235
1236         sort_formats="kerneltime time recv_realtime rwtime threadtime long"
1237
1238         for format in $sort_formats; do
1239                 LOG_DETAILS="testing if sorting by timestamp from random sources on heavy load works ($format format)"
1240
1241                 # collect data and analyze timestamps
1242                 dlogutil -b main -d -v "$format" | (
1243                         prev_ts=0
1244                         prev_line=""
1245
1246                         while read -r line; do
1247                                 # filter out empty lines in "long" format
1248                                 [ -z "$line" ] && continue
1249                                 # filter out non-timestamp lines in "long" format
1250                                 if [ "$format" = "long" ] && [ "$(echo "$line" | sed -re 's/^\[[:print:]*\]$/line_ok/g')" != "line_ok" ]; then
1251                                         continue
1252                                 fi
1253
1254                                 ts=$(extract_timestamp "$format" "$line")
1255
1256                                 if [ "$ts" -ge "$prev_ts" ]; then
1257                                         prev_ts=$ts
1258                                 else
1259                                         printf "%s\n%s\n\n" "$prev_line" "$line" || break
1260                                 fi
1261                                 prev_line=$line
1262                         done
1263                 ) | grep -q ^ && fail || ok
1264
1265         done
1266 fi
1267
1268 # show results, clean up and return an exit code
1269
1270 echo "$OKS / $TOTAL tests passed"
1271 echo "$FAILS / $TOTAL tests failed"
1272
1273 if [ "$quick" -eq 1 ]; then
1274         echo "WARNING: quick mode!"
1275         echo "About 20% slowest running tests are disabled. Some functionality might be untested."
1276         echo "Rerun without '--quick' to run all tests."
1277 elif [ "$LEGACY_LOGGER" -eq 1 ]; then
1278         echo "WARNING: legacy logger module!"
1279         echo "Some functionality is untested."
1280         echo "Rerun on a device with the out-of-tree logger module to run all tests."
1281 fi
1282
1283 [ "$FAILS" -eq 0 ]
1284 # THE LINE ABOVE MUST STAY THE LAST COMMAND IN THE FILE!
1285 # This is because it is used to pass the exit code. If another command
1286 # is executed after it, its exit code will be propagated instead.