From add13880dcfbd2e6b74ebc280b3bdaf0b99f5cac Mon Sep 17 00:00:00 2001 From: Mateusz Majewski Date: Wed, 7 Sep 2022 14:57:16 +0200 Subject: [PATCH] Enable tests for zero-copy backend Change-Id: I963d42019ae4f1106cc9dc24f288b59539ee3103 --- Makefile.am | 1 + configs/dlog-zero-copy.conf.test | 7 + packaging/dlog.spec | 5 +- tests/dlog_test.in | 733 ++++++++++++++++++++------------------- tests/test_libdlogutil.c | 44 ++- 5 files changed, 416 insertions(+), 374 deletions(-) create mode 100644 configs/dlog-zero-copy.conf.test diff --git a/Makefile.am b/Makefile.am index 6041915..082134f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -851,6 +851,7 @@ pkgconfig_DATA = dlog.pc dlogutil.pc dlog-redirect-stdout.pc data_DATA = \ configs/dlog-pipe.conf.test \ configs/dlog-logger.conf.test \ + configs/dlog-zero-copy.conf.test \ configs/dlog-logger.conf.alias \ configs/dlog-pipe.conf.cpu \ configs/dlog-logger.conf.cpu \ diff --git a/configs/dlog-zero-copy.conf.test b/configs/dlog-zero-copy.conf.test new file mode 100644 index 0000000..b904ee0 --- /dev/null +++ b/configs/dlog-zero-copy.conf.test @@ -0,0 +1,7 @@ +##### Settings used by the logging library +backend=zero-copy + +plog=1 +debugmode=1 +limiter=1 +limiter|*|*=allow diff --git a/packaging/dlog.spec b/packaging/dlog.spec index f401bdf..ee08898 100644 --- a/packaging/dlog.spec +++ b/packaging/dlog.spec @@ -317,6 +317,7 @@ chsmack -e 'System' %{_libexecdir}/dlog-log-critical %{_libexecdir}/libdlog/test_filters %{_datadir}/dlog-pipe.conf.test %{_datadir}/dlog-logger.conf.test +%{_datadir}/dlog-zero-copy.conf.test %{_datadir}/dlog-logger.conf.alias %{_datadir}/dlog-pipe.conf.cpu %{_datadir}/dlog-logger.conf.cpu @@ -331,12 +332,12 @@ chsmack -e 'System' %{_libexecdir}/dlog-log-critical %post tests chsmack -a System /var/lib/dlog-tests echo "Warning! Installation of dlog-tests will break platform logging." -echo "This is done intentionally, to make logger backend testing possible." +echo "This is done intentionally, to make logger and zero-copy backend testing possible." echo "To restore normal behavior, please uninstall dlog-tests package." echo "" echo "For more information please read the /usr/share/doc/dlog/README.testsuite file" echo "" -echo "A reboot is required to properly configure logger backend for testing." +echo "A reboot is required to properly configure logger and zero-copy backend for testing." %if 0%{?gcov:1} %files gcov diff --git a/tests/dlog_test.in b/tests/dlog_test.in index 17a764f..10e4f00 100644 --- a/tests/dlog_test.in +++ b/tests/dlog_test.in @@ -126,6 +126,8 @@ if [ "$1" = "pipe" ]; then type="pipe" elif [ "$1" = "logger" ]; then type="logger" +elif [ "$1" = "zero-copy" ]; then + type="zero-copy" # We still accept the legacy {pipe,logger}_quick syntax because there's no reason not to. elif [ "$1" = "pipe_quick" ]; then type="pipe" @@ -163,201 +165,203 @@ fi export DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.test" PATH=$PATH:@libexecdir@/libdlog/ -#create dir for runtime filters -RUNTIME_FILTERS_DIR="/tmp/dlog-filters/" -mkdir -m 777 -p "$RUNTIME_FILTERS_DIR" +if [ "$type" != "zero-copy" ]; then # These tests are inherently dynamic. + #create dir for runtime filters + RUNTIME_FILTERS_DIR="/tmp/dlog-filters/" + mkdir -m 777 -p "$RUNTIME_FILTERS_DIR" -PREEARLYQUIT_CONFIG_PATH="$DLOG_CONFIG_PATH" -DLOG_CONFIG_PATH="$TESTDIR/earlyquit.conf" -if [ "$quick" -ne 1 ]; then - for PERSISTENT in 1 0; do - for KMSG in 1 0; do - for SYSLOG in 1 0; do - for QOS in 1 0; do - # TODO: Does syslog even work? Disabling for now. - [ "$SYSLOG" -eq 1 ] && continue - - if [ "$QOS" -eq 1 ]; then - SOURCE="@datadir@/dlog-$type.conf.qos" - else - SOURCE="@datadir@/dlog-$type.conf.test" - fi + PREEARLYQUIT_CONFIG_PATH="$DLOG_CONFIG_PATH" + DLOG_CONFIG_PATH="$TESTDIR/earlyquit.conf" + if [ "$quick" -ne 1 ]; then + for PERSISTENT in 1 0; do + for KMSG in 1 0; do + for SYSLOG in 1 0; do + for QOS in 1 0; do + # TODO: Does syslog even work? Disabling for now. + [ "$SYSLOG" -eq 1 ] && continue + + if [ "$QOS" -eq 1 ]; then + SOURCE="@datadir@/dlog-$type.conf.qos" + else + SOURCE="@datadir@/dlog-$type.conf.test" + fi - if [ "$PERSISTENT" -eq 1 ]; then - cp "$SOURCE" "$DLOG_CONFIG_PATH" - else - sed 's/^dlog_logger_conf.*$/#\0/' <"$SOURCE" >"$DLOG_CONFIG_PATH" - fi + if [ "$PERSISTENT" -eq 1 ]; then + cp "$SOURCE" "$DLOG_CONFIG_PATH" + else + sed 's/^dlog_logger_conf.*$/#\0/' <"$SOURCE" >"$DLOG_CONFIG_PATH" + fi - echo "handle_kmsg=$KMSG" >> "$DLOG_CONFIG_PATH" - echo "syslog_force=$SYSLOG" >> "$DLOG_CONFIG_PATH" + echo "handle_kmsg=$KMSG" >> "$DLOG_CONFIG_PATH" + echo "syslog_force=$SYSLOG" >> "$DLOG_CONFIG_PATH" - dlog_logger -t 0 & - LOGGER=$! - sleep 1 + dlog_logger -t 0 & + LOGGER=$! + sleep 1 - kill $LOGGER > /dev/null - STOPPED=$? - LOGGER=-1 + kill $LOGGER > /dev/null + STOPPED=$? + LOGGER=-1 - if [ "$PERSISTENT" -eq 0 ] && [ "$KMSG" -eq 0 ] && [ "$SYSLOG" -eq 0 ] && [ "$QOS" -eq 0 ] && [ "$type" = "logger" ]; then - EXPECTED=1 - else - EXPECTED=0 - fi + if [ "$PERSISTENT" -eq 0 ] && [ "$KMSG" -eq 0 ] && [ "$SYSLOG" -eq 0 ] && [ "$QOS" -eq 0 ] && [ "$type" = "logger" ]; then + EXPECTED=1 + else + EXPECTED=0 + fi - LOG_DETAILS="testing if daemon stops when not needed (persistent=$PERSISTENT, kmsg=$KMSG, syslog=$SYSLOG, qos=$QOS)" - [ "$STOPPED" -eq "$EXPECTED" ] && ok || fail - done; done; done; done -fi -DLOG_CONFIG_PATH="$PREEARLYQUIT_CONFIG_PATH" + LOG_DETAILS="testing if daemon stops when not needed (persistent=$PERSISTENT, kmsg=$KMSG, syslog=$SYSLOG, qos=$QOS)" + [ "$STOPPED" -eq "$EXPECTED" ] && ok || fail + done; done; done; done + fi + DLOG_CONFIG_PATH="$PREEARLYQUIT_CONFIG_PATH" -# Start the daemon -dlog_logger -t 0 & -LOGGER=$! -sleep 1 + # Start the daemon + dlog_logger -t 0 & + LOGGER=$! + sleep 1 -if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then - dlogctl -c - dlogctl --enable - dlogutil -c -b radio -b system -b main - LOG_DETAILS="dlogctl --disable (no args)" - dlogctl --disable - [ "$(dlogctl -g | grep -c '^\* [a-z]*: ENABLED')" -eq 0 ] && ok || fail - LOG_DETAILS="testing if filters were applied" - dlogsend -b system -t TEST test - dlogsend -b main -t TEST test - dlogsend -b radio -t TEST test - [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail - - LOG_DETAILS="dlogctl --enable (no args)" - dlogctl --enable - [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED')" -eq 0 ] && ok || fail - LOG_DETAILS="testing if filters were applied" - dlogutil -c -b radio -b system -b main - dlogsend -b system -t TEST test - dlogsend -b main -t TEST test - dlogsend -b radio -t TEST test - [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail - - LOG_DETAILS="dlogctl --disable (1 arg)" - dlogctl --disable -b system - [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c system)" -eq 1 ] && - [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED' )" -eq 1 ] && ok || fail - LOG_DETAILS="testing if filters were applied" - dlogutil -c -b radio -b system -b main - dlogsend -b system -t TEST test - dlogsend -b main -t TEST test - dlogsend -b radio -t TEST test - [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail - - LOG_DETAILS="dlogctl --disable (multiple args)" - dlogctl --disable -b main -b radio - [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -cv system)" -eq 2 ] && - [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c radio)" -eq 1 ] && - [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c main)" -eq 1 ] && ok || fail - LOG_DETAILS="testing if filters were applied" - dlogutil -c -b radio -b system -b main - dlogsend -b system -t TEST test - dlogsend -b main -t TEST test - dlogsend -b radio -t TEST test - [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail - - LOG_DETAILS="dlogctl --enable (multiple args)" - dlogctl --enable -b radio -b system - [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED' )" -eq 1 ] && - [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c main)" -eq 1 ] && - [ "$(dlogctl -g | grep '^\* [a-z]*: ENABLED' | grep -c system)" -eq 1 ] && - [ "$(dlogctl -g | grep '^\* [a-z]*: ENABLED' | grep -c radio)" -eq 1 ] && ok || fail - LOG_DETAILS="testing if filters were applied" - dlogutil -c -b radio -b system -b main - dlogsend -b system -t TEST test - dlogsend -b main -t TEST test - dlogsend -b radio -t TEST test - [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail - - LOG_DETAILS="dlogctl --enable (1 arg)" - dlogctl --enable -b main - [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED')" -eq 0 ] && ok || fail - LOG_DETAILS="testing if filters were applied" - dlogutil -c -b radio -b system -b main - dlogsend -b system -t TEST test - dlogsend -b main -t TEST test - dlogsend -b radio -t TEST test - [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail - - LOG_DETAILS="dlogctl -s allow" - dlogutil -c -b radio -b system -b main - dlogctl -c - dlogctl -s deny - dlogctl -t TEST_TAG -s allow - dlogsend -b main -t TEST_TAG test - dlogsend -b main -t TEST test - [ "$(dlogutil -d -b main | wc -l)" -eq 1 ] && ok || fail - - LOG_DETAILS="dlogctl -s [N]" - dlogutil -c -b radio -b system -b main - dlogctl -c - dlogctl -s deny - dlogctl -t TEST_TAG -s 3 - dlogsend -b main -c 10 -t TEST_TAG test - dlogsend -b main -c 10 -t TEST test - [ "$(dlogutil -d -b main | wc -l)" -eq 4 ] && ok || fail - - LOG_DETAILS="testing invalid parameters for dlogctl (1/13)" - dlogctl -s invalid > /dev/null && fail || ok - - LOG_DETAILS="testing invalid parameters for dlogctl (2/13)" - dlogctl -p X -g > /dev/null && fail || ok - - LOG_DETAILS="testing invalid parameters for dlogctl (3/13)" - dlogctl -b invalid --disable > /dev/null && fail || ok - - LOG_DETAILS="testing invalid parameters for dlogctl (4/13)" - dlogctl -s allow -g -t xyz -p E > /dev/null && fail || ok - - LOG_DETAILS="testing invalid parameters for dlogctl (5/13)" - dlogctl -s allow -c > /dev/null && fail || ok - - LOG_DETAILS="testing invalid parameters for dlogctl (6/13)" - dlogctl -c -g -t xyz -p E > /dev/null && fail || ok - - # -s out of range - LOG_DETAILS="testing invalid parameters for dlogctl (7/13)" - dlogctl -s -10 > /dev/null && fail || ok - - LOG_DETAILS="testing invalid parameters for dlogctl (8/13)" - dlogctl -s 999999 > /dev/null && fail || ok - - # -s correctness - LOG_DETAILS="testing invalid parameters for dlogctl (9/13)" - dlogctl -s 100 && ok || fail - - LOG_DETAILS="testing invalid parameters for dlogctl (10/13)" - [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 1 ] && ok || fail - - # -g correctness - LOG_DETAILS="testing invalid parameters for dlogctl (11/13)" - [ "$(dlogctl -g | grep -F '*:*' | grep -c 100)" -eq 1 ] && ok || fail - - # -c correctness - LOG_DETAILS="testing invalid parameters for dlogctl (12/13)" - dlogctl -c -t '*' -p '*' && ok || fail - - LOG_DETAILS="testing invalid parameters for dlogctl (13/13)" - [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 0 ] && ok || fail - dlogctl -c - - LOG_DETAILS="testing if the whole dynamic config directory is respected" - dlogctl -s deny - cp $RUNTIME_FILTERS_DIR/05-logctl.conf $RUNTIME_FILTERS_DIR/10-other.conf - dlogctl -c - dlogutil -c -b radio -b system -b main - dlogsend -b system -t TEST test - dlogsend -b main -t TEST test - dlogsend -b radio -t TEST test - [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail - rm $RUNTIME_FILTERS_DIR/10-other.conf + if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then + dlogctl -c + dlogctl --enable + dlogutil -c -b radio -b system -b main + LOG_DETAILS="dlogctl --disable (no args)" + dlogctl --disable + [ "$(dlogctl -g | grep -c '^\* [a-z]*: ENABLED')" -eq 0 ] && ok || fail + LOG_DETAILS="testing if filters were applied" + dlogsend -b system -t TEST test + dlogsend -b main -t TEST test + dlogsend -b radio -t TEST test + [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail + + LOG_DETAILS="dlogctl --enable (no args)" + dlogctl --enable + [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED')" -eq 0 ] && ok || fail + LOG_DETAILS="testing if filters were applied" + dlogutil -c -b radio -b system -b main + dlogsend -b system -t TEST test + dlogsend -b main -t TEST test + dlogsend -b radio -t TEST test + [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail + + LOG_DETAILS="dlogctl --disable (1 arg)" + dlogctl --disable -b system + [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c system)" -eq 1 ] && + [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED' )" -eq 1 ] && ok || fail + LOG_DETAILS="testing if filters were applied" + dlogutil -c -b radio -b system -b main + dlogsend -b system -t TEST test + dlogsend -b main -t TEST test + dlogsend -b radio -t TEST test + [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail + + LOG_DETAILS="dlogctl --disable (multiple args)" + dlogctl --disable -b main -b radio + [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -cv system)" -eq 2 ] && + [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c radio)" -eq 1 ] && + [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c main)" -eq 1 ] && ok || fail + LOG_DETAILS="testing if filters were applied" + dlogutil -c -b radio -b system -b main + dlogsend -b system -t TEST test + dlogsend -b main -t TEST test + dlogsend -b radio -t TEST test + [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail + + LOG_DETAILS="dlogctl --enable (multiple args)" + dlogctl --enable -b radio -b system + [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED' )" -eq 1 ] && + [ "$(dlogctl -g | grep '^\* [a-z]*: DISABLED' | grep -c main)" -eq 1 ] && + [ "$(dlogctl -g | grep '^\* [a-z]*: ENABLED' | grep -c system)" -eq 1 ] && + [ "$(dlogctl -g | grep '^\* [a-z]*: ENABLED' | grep -c radio)" -eq 1 ] && ok || fail + LOG_DETAILS="testing if filters were applied" + dlogutil -c -b radio -b system -b main + dlogsend -b system -t TEST test + dlogsend -b main -t TEST test + dlogsend -b radio -t TEST test + [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 2 ] && ok || fail + + LOG_DETAILS="dlogctl --enable (1 arg)" + dlogctl --enable -b main + [ "$(dlogctl -g | grep -c '^\* [a-z]*: DISABLED')" -eq 0 ] && ok || fail + LOG_DETAILS="testing if filters were applied" + dlogutil -c -b radio -b system -b main + dlogsend -b system -t TEST test + dlogsend -b main -t TEST test + dlogsend -b radio -t TEST test + [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 3 ] && ok || fail + + LOG_DETAILS="dlogctl -s allow" + dlogutil -c -b radio -b system -b main + dlogctl -c + dlogctl -s deny + dlogctl -t TEST_TAG -s allow + dlogsend -b main -t TEST_TAG test + dlogsend -b main -t TEST test + [ "$(dlogutil -d -b main | wc -l)" -eq 1 ] && ok || fail + + LOG_DETAILS="dlogctl -s [N]" + dlogutil -c -b radio -b system -b main + dlogctl -c + dlogctl -s deny + dlogctl -t TEST_TAG -s 3 + dlogsend -b main -c 10 -t TEST_TAG test + dlogsend -b main -c 10 -t TEST test + [ "$(dlogutil -d -b main | wc -l)" -eq 4 ] && ok || fail + + LOG_DETAILS="testing invalid parameters for dlogctl (1/13)" + dlogctl -s invalid > /dev/null && fail || ok + + LOG_DETAILS="testing invalid parameters for dlogctl (2/13)" + dlogctl -p X -g > /dev/null && fail || ok + + LOG_DETAILS="testing invalid parameters for dlogctl (3/13)" + dlogctl -b invalid --disable > /dev/null && fail || ok + + LOG_DETAILS="testing invalid parameters for dlogctl (4/13)" + dlogctl -s allow -g -t xyz -p E > /dev/null && fail || ok + + LOG_DETAILS="testing invalid parameters for dlogctl (5/13)" + dlogctl -s allow -c > /dev/null && fail || ok + + LOG_DETAILS="testing invalid parameters for dlogctl (6/13)" + dlogctl -c -g -t xyz -p E > /dev/null && fail || ok + + # -s out of range + LOG_DETAILS="testing invalid parameters for dlogctl (7/13)" + dlogctl -s -10 > /dev/null && fail || ok + + LOG_DETAILS="testing invalid parameters for dlogctl (8/13)" + dlogctl -s 999999 > /dev/null && fail || ok + + # -s correctness + LOG_DETAILS="testing invalid parameters for dlogctl (9/13)" + dlogctl -s 100 && ok || fail + + LOG_DETAILS="testing invalid parameters for dlogctl (10/13)" + [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 1 ] && ok || fail + + # -g correctness + LOG_DETAILS="testing invalid parameters for dlogctl (11/13)" + [ "$(dlogctl -g | grep -F '*:*' | grep -c 100)" -eq 1 ] && ok || fail + + # -c correctness + LOG_DETAILS="testing invalid parameters for dlogctl (12/13)" + dlogctl -c -t '*' -p '*' && ok || fail + + LOG_DETAILS="testing invalid parameters for dlogctl (13/13)" + [ "$(grep -cE 'limiter\|\*\|\*=100' "$RUNTIME_FILTERS_DIR"/05-logctl.conf)" -eq 0 ] && ok || fail + dlogctl -c + + LOG_DETAILS="testing if the whole dynamic config directory is respected" + dlogctl -s deny + cp $RUNTIME_FILTERS_DIR/05-logctl.conf $RUNTIME_FILTERS_DIR/10-other.conf + dlogctl -c + dlogutil -c -b radio -b system -b main + dlogsend -b system -t TEST test + dlogsend -b main -t TEST test + dlogsend -b radio -t TEST test + [ "$(dlogutil -d -b radio -b system -b main | wc -l)" -eq 0 ] && ok || fail + rm $RUNTIME_FILTERS_DIR/10-other.conf + fi fi SEED=$(head -c 6 /dev/urandom | base64) @@ -405,8 +409,10 @@ LOG_DETAILS="testing if dlogutil returns exact amount of entries as there is in LOG_DETAILS="testing if reading from dummy buffer returns an error as expected" dlogutil -b nonexistent_buffer > /dev/null && fail || ok -LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)" -[ "$(dlogutil -d -b system | wc -l)" -eq 0 ] && ok || fail +if [ "$type" != "zero-copy" ]; then # No buffer split in zero-copy + LOG_DETAILS="testing if reading from \"system\" buffer returns zero entries (logs are in the \"main\" buffer)" + [ "$(dlogutil -d -b system | wc -l)" -eq 0 ] && ok || fail +fi LOG_DETAILS="testing if dlogutil -c empties all buffers" dlogutil -cb main && ok || fail @@ -436,8 +442,10 @@ LOG_DETAILS="testing if exact filters work (3/3)" LOG_DETAILS="testing if adding \"silent\" filter works" [ "$(dlogutil -b main -s -d | wc -l)" -eq 0 ] && ok || fail -LOG_DETAILS="testing if reading buffer size returns proper exit code" -dlogutil -gb main > /dev/null && ok || fail +if [ "$type" != "zero-copy" ]; then # No buffer size access in zero-copy + LOG_DETAILS="testing if reading buffer size returns proper exit code" + dlogutil -gb main > /dev/null && ok || fail +fi LOG_DETAILS="testing if writing all entries to single file works (-f)" dlogutil -f $TESTDIR/dlog_test_file -d > /dev/null && ok || fail @@ -480,6 +488,7 @@ if [ "$quick" -ne 1 ]; then [ $WAS_ALIVE -eq 1 ] && [ "$(wc -l < "$TESTDIR"/dlog_monitor2_file)" -eq 1 ] && ok || fail fi +dlogutil -cb main test_libdlog 100000 & LIBDLOGUTIL_CORRECT_PID=$! wait $LIBDLOGUTIL_CORRECT_PID @@ -539,13 +548,15 @@ LOG_DETAILS="testing if libdlogutil prefix filter works correctly (1/2)" test_libdlogutil prefix_correct $LIBDLOGUTIL_CORRECT_PID $type && ok || fail LOG_DETAILS="testing if libdlogutil prefix filter works correctly (2/2)" test_libdlogutil prefix_wrong $LIBDLOGUTIL_CORRECT_PID $type && ok || fail -LOG_DETAILS="testing if libdlogutil returns the correct buffer traits" -test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail -LOG_DETAILS="testing if libdlogutil aliasing works" -if [ "$type" = "pipe" ]; then - test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail -else - DLOG_CONFIG_PATH="@datadir@/dlog-logger.conf.alias" test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail +if [ "$type" != "zero-copy" ]; then # These rely on things not available in zero-copy + LOG_DETAILS="testing if libdlogutil returns the correct buffer traits" + test_libdlogutil traits $LIBDLOGUTIL_CORRECT_PID $type && ok || fail + LOG_DETAILS="testing if libdlogutil aliasing works" + if [ "$type" = "pipe" ]; then + test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail + else + DLOG_CONFIG_PATH="@datadir@/dlog-logger.conf.alias" test_libdlogutil alias $LIBDLOGUTIL_CORRECT_PID $type && ok || fail + fi fi LOG_DETAILS="testing if libdlogutil errors out correctly if used improperly" test_libdlogutil negative $LIBDLOGUTIL_CORRECT_PID $type && ok || fail @@ -672,8 +683,10 @@ line=$($cmd_prefix $format) format="json" if [ "$type" = "pipe" ]; then 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" -else +elif [ "$type" = "logger" ]; then 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" +else # zero-copy + REGEX="s/^\{\"priority\":\"(verbose|debug|info|warning|error|fatal|silent)\",\"pid\":[1-9][0-9]*,\"tid\":[1-9][0-9]*,\"sent_mono\":[1-9][0-9]+\.[0-9]{9},\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g" fi LOG_DETAILS="testing if \"$format\" print format works" line=$($cmd_prefix $format) @@ -742,16 +755,20 @@ if [ "$type" = "pipe" ]; then done fi -LOG_DETAILS="testing if KMSG works in the default format" -# We check if the command returns at least 100 logs. This seems to be a safe value. -# Feel free to change it to a reasonable yet lower value if the test happens to fail otherwise. -[ "$(dlogutil -db kmsg | wc -l)" -gt 100 ] && ok || fail +if [ "$type" != "zero-copy" ]; then # No KMSG in zero-copy + LOG_DETAILS="testing if KMSG works in the default format" + # We check if the command returns at least 100 logs. This seems to be a safe value. + # Feel free to change it to a reasonable yet lower value if the test happens to fail otherwise. + [ "$(dlogutil -db kmsg | wc -l)" -gt 100 ] && ok || fail +fi if [ "$quick" -ne 1 ]; then - LOG_DETAILS="testing if KMSG works in the raw format" - last_dmesg=$(dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g") - sleep 1 # To make sure dlog has already parsed the log - dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail + if [ "$type" != "zero-copy" ]; then # No KMSG in zero-copy + LOG_DETAILS="testing if KMSG works in the raw format" + last_dmesg=$(dmesg | tail -n1 | sed -re "s/^\[[ 0-9]{5,}\.[0-9]{6}\] (.*)$/\1/g") + sleep 1 # To make sure dlog has already parsed the log + dlogutil -db kmsg -v raw | grep -Fm1 "$last_dmesg" >/dev/null && ok || fail + fi LOG_DETAILS="testing if pid filtering works" dlogsend -b main -t DLOG_TESTSUITE pidTEST & @@ -810,7 +827,7 @@ LOG_DETAILS="testing if tag filtering works (7/8)" LOG_DETAILS="testing if tag filtering works (8/8)" [ "$(dlogutil -dv raw 'DLOG_TESTSUITE_SAMSUNG*' | wc -l)" -eq 0 ] && ok || fail -if [ "$TEST_DYNAMIC_FILTERS" = "true" ]; then +if [ "$TEST_DYNAMIC_FILTERS" = "true" ] && [ "$type" != "zero-copy" ]; then # No dynamic things in zero-copy LOG_DETAILS="testing if limiter and runtime filtering works" dlogutil -c -b radio test_filters @@ -965,21 +982,23 @@ if [ "$LEGACY_LOGGER" -ne 1 ] && [ "$quick" -ne 1 ]; then [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail dlogutil -cb main - dlog_redirect_stdout --outbuffer radio --outtag AN_INTERESTING_TAG --outprio W -- /usr/bin/echo Hi - sleep 1 - LOG_DETAILS="testing if redirector settings work correctly on stdout (1/2)" - [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail - LOG_DETAILS="testing if redirector settings work correctly on stdout (2/2)" - [ "$(dlogutil -db radio -v tag)" = "W/AN_INTERESTING_TAG: Hi" ] && ok || fail - dlogutil -cb radio + if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy + dlog_redirect_stdout --outbuffer radio --outtag AN_INTERESTING_TAG --outprio W -- /usr/bin/echo Hi + sleep 1 + LOG_DETAILS="testing if redirector settings work correctly on stdout (1/2)" + [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail + LOG_DETAILS="testing if redirector settings work correctly on stdout (2/2)" + [ "$(dlogutil -db radio -v tag)" = "W/AN_INTERESTING_TAG: Hi" ] && ok || fail + dlogutil -cb radio - dlog_redirect_stdout --errbuffer radio --errtag ANOTHER_INTERESTING_TAG --errprio I -- /usr/bin/sh -c "echo Hi >&2" - sleep 1 - LOG_DETAILS="testing if redirector settings work correctly on stderr (1/2)" - [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail - LOG_DETAILS="testing if redirector settings work correctly on stderr (2/2)" - [ "$(dlogutil -db radio -v tag)" = "I/ANOTHER_INTERESTING_TAG: Hi" ] && ok || fail - dlogutil -cb radio + dlog_redirect_stdout --errbuffer radio --errtag ANOTHER_INTERESTING_TAG --errprio I -- /usr/bin/sh -c "echo Hi >&2" + sleep 1 + LOG_DETAILS="testing if redirector settings work correctly on stderr (1/2)" + [ "$(dlogutil -db main -v tag)" = "" ] && ok || fail + LOG_DETAILS="testing if redirector settings work correctly on stderr (2/2)" + [ "$(dlogutil -db radio -v tag)" = "I/ANOTHER_INTERESTING_TAG: Hi" ] && ok || fail + dlogutil -cb radio + fi echo "Testing" | dlog_redirect_stdout --outtag BAZ -- /usr/bin/cat sleep 1 @@ -1044,12 +1063,14 @@ EOF dlogutil -cb main fi - dlogctl -b radio --disable-stdout - dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test - sleep 1 - LOG_DETAILS="testing if dlogctl --disable-stdout respects buffer choice" - [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail - dlogutil -cb main + if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy + dlogctl -b radio --disable-stdout + dlog_redirect_stdout --outtag THETAG -- /usr/bin/echo test + sleep 1 + LOG_DETAILS="testing if dlogctl --disable-stdout respects buffer choice" + [ "$(dlogutil -db main -v raw)" = "test" ] && ok || fail + dlogutil -cb main + fi LOG_DETAILS="testing if redirection check works (1/5)" test_libredirect 0 0 && ok || fail @@ -1062,60 +1083,64 @@ EOF LOG_DETAILS="testing if redirection check works (5/5)" dlog_redirect_stdout --outtag X --errtag Y -- /usr/libexec/libdlog/test_libredirect 1 1 && ok || fail - LOG_DETAILS="testing if multiple redirections work (1/4)" - test_libredirect_multi && ok || fail - LOG_DETAILS="testing if multiple redirections work (2/4)" - [ "$(dlogutil -db main -v tag | grep "Message 1")" = "W/TAG1 : Message 1" ] && ok || fail - LOG_DETAILS="testing if multiple redirections work (3/4)" - [ "$(dlogutil -db main -v tag | grep "Message 2")" = "E/TAG2 : Message 2" ] && ok || fail - LOG_DETAILS="testing if multiple redirections work (4/4)" - [ "$(dlogutil -db system -v tag)" = "I/TAG3 : Message 3" ] && ok || fail - dlogutil -cb main -b system + if [ "$type" != "zero-copy" ]; then # No buffers in zero-copy + LOG_DETAILS="testing if multiple redirections work (1/4)" + test_libredirect_multi && ok || fail + LOG_DETAILS="testing if multiple redirections work (2/4)" + [ "$(dlogutil -db main -v tag | grep "Message 1")" = "W/TAG1 : Message 1" ] && ok || fail + LOG_DETAILS="testing if multiple redirections work (3/4)" + [ "$(dlogutil -db main -v tag | grep "Message 2")" = "E/TAG2 : Message 2" ] && ok || fail + LOG_DETAILS="testing if multiple redirections work (4/4)" + [ "$(dlogutil -db system -v tag)" = "I/TAG3 : Message 3" ] && ok || fail + dlogutil -cb main -b system + fi fi -dlogutil -c -echo "deduplicate_method=only_identical_neighbours" > "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" -echo "deduplicate_interval_ms=10" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" - -dlogsend -p Info -b main -c 9 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity" -LOG_DETAILS="testing if deduplication with warnings works properly (1/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 1 ] && ok || fail -LOG_DETAILS="testing if deduplication with warnings works properly (2/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 0 ] && ok || fail - -dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity" -LOG_DETAILS="testing if deduplication with warnings works properly (3/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 3 ] && ok || fail -LOG_DETAILS="testing if deduplication with warnings works properly (4/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 1 ] && ok || fail - -echo "deduplicate_warn_quantity=8" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" - -dlogsend -p Info -b main -c 24 -t DLOG_DEDUP_TEST Message -LOG_DETAILS="testing if deduplication with warnings works properly (5/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 4 ] && ok || fail -LOG_DETAILS="testing if deduplication with warnings works properly (6/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Message LOG DUPLICATED')" -eq 3 ] && ok || fail - -dlogsend -p Info -b main -c 8 -t DLOG_DEDUP_TEST longerMessage -LOG_DETAILS="testing if deduplication with warnings works properly (7/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c longerMessage)" -eq 2 ] && ok || fail -LOG_DETAILS="testing if deduplication with warnings works properly (8/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 6 ] && ok || fail -LOG_DETAILS="testing if deduplication with warnings works properly (9/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'longerMessage LOG DUPLICATED')" -eq 1 ] && ok || fail - -echo "deduplicate_warn_quantity=-1" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" - -dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, no warning" -LOG_DETAILS="testing if deduplication with warnings works properly (10/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning')" -eq 1 ] && ok || fail -LOG_DETAILS="testing if deduplication with warnings works properly (11/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication')" -eq 4 ] && ok || fail -LOG_DETAILS="testing if deduplication with warnings works properly (12/12)" -[ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning LOG DUPLICATED')" -eq 0 ] && ok || fail - -rm "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" +if [ "$type" != "zero-copy" ]; then # No dynamic filters in zero-copy + dlogutil -c + echo "deduplicate_method=only_identical_neighbours" > "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" + echo "deduplicate_interval_ms=10" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" + + dlogsend -p Info -b main -c 9 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity" + LOG_DETAILS="testing if deduplication with warnings works properly (1/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 1 ] && ok || fail + LOG_DETAILS="testing if deduplication with warnings works properly (2/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 0 ] && ok || fail + + dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, default warn_quantity" + LOG_DETAILS="testing if deduplication with warnings works properly (3/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity')" -eq 3 ] && ok || fail + LOG_DETAILS="testing if deduplication with warnings works properly (4/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, default warn_quantity LOG DUPLICATED')" -eq 1 ] && ok || fail + + echo "deduplicate_warn_quantity=8" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" + + dlogsend -p Info -b main -c 24 -t DLOG_DEDUP_TEST Message + LOG_DETAILS="testing if deduplication with warnings works properly (5/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 4 ] && ok || fail + LOG_DETAILS="testing if deduplication with warnings works properly (6/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Message LOG DUPLICATED')" -eq 3 ] && ok || fail + + dlogsend -p Info -b main -c 8 -t DLOG_DEDUP_TEST longerMessage + LOG_DETAILS="testing if deduplication with warnings works properly (7/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c longerMessage)" -eq 2 ] && ok || fail + LOG_DETAILS="testing if deduplication with warnings works properly (8/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c Message)" -eq 6 ] && ok || fail + LOG_DETAILS="testing if deduplication with warnings works properly (9/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'longerMessage LOG DUPLICATED')" -eq 1 ] && ok || fail + + echo "deduplicate_warn_quantity=-1" >> "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" + + dlogsend -p Info -b main -c 12 -t DLOG_DEDUP_TEST "Basic deduplication, no warning" + LOG_DETAILS="testing if deduplication with warnings works properly (10/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning')" -eq 1 ] && ok || fail + LOG_DETAILS="testing if deduplication with warnings works properly (11/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication')" -eq 4 ] && ok || fail + LOG_DETAILS="testing if deduplication with warnings works properly (12/12)" + [ "$(dlogutil -d DLOG_DEDUP_TEST | grep -c 'Basic deduplication, no warning LOG DUPLICATED')" -eq 0 ] && ok || fail + + rm "$RUNTIME_FILTERS_DIR/30-deduplicate.conf" +fi LOG_DETAILS="testing if libdlogutil clears the buffer correctly" test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail @@ -1129,91 +1154,93 @@ LOG_DETAILS="testing if the timestamps are correct" test_verifytime && ok || fail if [ "$quick" -ne 1 ]; then - PREAUTODETECT_CONFIG_PATH=$DLOG_CONFIG_PATH - DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.autodetect" - kill $LOGGER > /dev/null - sleep 1 - if [ "$type" = "logger" ]; then - dlogutil -cb main - fi - dlog_logger -t 0 & - LOGGER=$! - sleep 1 + if [ "$type" != "zero-copy" ]; then # Backend autodection and logger daemon stuff don't really work on zero-copy + PREAUTODETECT_CONFIG_PATH=$DLOG_CONFIG_PATH + DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.autodetect" + kill $LOGGER > /dev/null + sleep 1 + if [ "$type" = "logger" ]; then + dlogutil -cb main + fi + dlog_logger -t 0 & + LOGGER=$! + sleep 1 - LOG_DETAILS="testing if backend autodetection works properly (1/2)" - dlogsend -b main -t DLOG_AUTODETECT "xd" && ok || fail - sleep 1 + LOG_DETAILS="testing if backend autodetection works properly (1/2)" + dlogsend -b main -t DLOG_AUTODETECT "xd" && ok || fail + sleep 1 - DLOG_CONFIG_PATH=$PREAUTODETECT_CONFIG_PATH - LOG_DETAILS="testing if backend autodetection works properly (2/2)" - [ "$(dlogutil -db main -v raw)" = "xd" ] && ok || fail + DLOG_CONFIG_PATH=$PREAUTODETECT_CONFIG_PATH + LOG_DETAILS="testing if backend autodetection works properly (2/2)" + [ "$(dlogutil -db main -v raw)" = "xd" ] && ok || fail - kill $LOGGER > /dev/null - sleep 1 - rm "$TESTDIR"/test* - dlog_logger -t 0 & - LOGGER=$! - sleep 1 + kill $LOGGER > /dev/null + sleep 1 + rm "$TESTDIR"/test* + dlog_logger -t 0 & + LOGGER=$! + sleep 1 - dlogsend -b main -t DLOG_LOGGER_TEST0 -c 100 "hi" - sleep 1 - LOG_DETAILS="testing if logger daemon persistent logging works (1/3)" - [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test0)" -eq 100 ] && ok || fail - LOG_DETAILS="testing if logger daemon persistent logging works (2/3)" - [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test1)" -eq 100 ] && ok || fail - LOG_DETAILS="testing if logger daemon persistent logging works (3/3)" - [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test2)" -eq 0 ] && ok || fail - - dlogsend -b main -t DLOG_LOGGER_TEST1 -c 500000 "hi" - sleep 1 - RESULT=$(du -c "$TESTDIR"/test0* | tail -n 1 | cut -f 1) - LOG_DETAILS="testing if logger daemon log rotating works (1/2)" - [ "$RESULT" -gt 4096 ] && ok || fail # Min 4 MB - LOG_DETAILS="testing if logger daemon log rotating works (2/2)" - [ "$RESULT" -lt 6144 ] && ok || fail # Max 6 MB + dlogsend -b main -t DLOG_LOGGER_TEST0 -c 100 "hi" + sleep 1 + LOG_DETAILS="testing if logger daemon persistent logging works (1/3)" + [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test0)" -eq 100 ] && ok || fail + LOG_DETAILS="testing if logger daemon persistent logging works (2/3)" + [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test1)" -eq 100 ] && ok || fail + LOG_DETAILS="testing if logger daemon persistent logging works (3/3)" + [ "$(grep -c DLOG_LOGGER_TEST0 "$TESTDIR"/test2)" -eq 0 ] && ok || fail + + dlogsend -b main -t DLOG_LOGGER_TEST1 -c 500000 "hi" + sleep 1 + RESULT=$(du -c "$TESTDIR"/test0* | tail -n 1 | cut -f 1) + LOG_DETAILS="testing if logger daemon log rotating works (1/2)" + [ "$RESULT" -gt 4096 ] && ok || fail # Min 4 MB + LOG_DETAILS="testing if logger daemon log rotating works (2/2)" + [ "$RESULT" -lt 6144 ] && ok || fail # Max 6 MB - dlogutil -cb main - kill $LOGGER > /dev/null - sleep 1 - rm "$TESTDIR"/test0* - dlog_logger -t 5 -b 100000 & - LOGGER=$! - sleep 1 + dlogutil -cb main + kill $LOGGER > /dev/null + sleep 1 + rm "$TESTDIR"/test0* + dlog_logger -t 5 -b 100000 & + LOGGER=$! + sleep 1 - dlogsend -b main -t DLOG_LOGGER_TEST2 -c 100 "hi" - sleep 1 - LOG_DETAILS="testing if logger daemon buffering works (1/5)" - [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 0 ] && ok || fail + dlogsend -b main -t DLOG_LOGGER_TEST2 -c 100 "hi" + sleep 1 + LOG_DETAILS="testing if logger daemon buffering works (1/5)" + [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 0 ] && ok || fail - sleep 6 - LOG_DETAILS="testing if logger daemon buffering works (2/5)" - [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 100 ] && ok || fail + sleep 6 + LOG_DETAILS="testing if logger daemon buffering works (2/5)" + [ "$(grep -c DLOG_LOGGER_TEST2 "$TESTDIR"/test0)" -eq 100 ] && ok || fail - dlogsend -b main -t DLOG_LOGGER_TEST3 -c 100 "hi" - sleep 1 - LOG_DETAILS="testing if logger daemon buffering works (3/5)" - [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 0 ] && ok || fail + dlogsend -b main -t DLOG_LOGGER_TEST3 -c 100 "hi" + sleep 1 + LOG_DETAILS="testing if logger daemon buffering works (3/5)" + [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 0 ] && ok || fail - dlogutil -cb main - kill $LOGGER > /dev/null - sleep 1 - dlog_logger -t 10000 -b 100 & - LOGGER=$! - sleep 1 - LOG_DETAILS="testing if logger daemon buffering works (4/5)" - [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 100 ] && ok || fail + dlogutil -cb main + kill $LOGGER > /dev/null + sleep 1 + dlog_logger -t 10000 -b 100 & + LOGGER=$! + sleep 1 + LOG_DETAILS="testing if logger daemon buffering works (4/5)" + [ "$(grep -c DLOG_LOGGER_TEST3 "$TESTDIR"/test0)" -eq 100 ] && ok || fail - dlogsend -b main -t DLOG_LOGGER_TEST4 -c 100 "hi" - sleep 1 - LOG_DETAILS="testing if logger daemon buffering works (5/5)" - [ "$(grep -c DLOG_LOGGER_TEST4 "$TESTDIR"/test0)" -gt 90 ] && ok || fail + dlogsend -b main -t DLOG_LOGGER_TEST4 -c 100 "hi" + sleep 1 + LOG_DETAILS="testing if logger daemon buffering works (5/5)" + [ "$(grep -c DLOG_LOGGER_TEST4 "$TESTDIR"/test0)" -gt 90 ] && ok || fail - dlogutil -cb main - kill $LOGGER > /dev/null - sleep 1 - dlog_logger -t 0 & - LOGGER=$! - sleep 1 + dlogutil -cb main + kill $LOGGER > /dev/null + sleep 1 + dlog_logger -t 0 & + LOGGER=$! + sleep 1 + fi LOG_DETAILS="testing if the library works with multithreaded app" dlogutil -f $TESTDIR/dlog_mt_test & diff --git a/tests/test_libdlogutil.c b/tests/test_libdlogutil.c index 545e258..b5ce962 100644 --- a/tests/test_libdlogutil.c +++ b/tests/test_libdlogutil.c @@ -128,7 +128,7 @@ void assert_suffix(const char *string, const char *suffix) #define PIPE_ERRORS 4681 #define PIPE_INFOS 4681 -void get_logs_main(enum test_mode mode, bool pipe, pid_t pid) +void get_logs_main(enum test_mode mode, backend_t backend, pid_t pid) { bool continuous = mode == MODE_CONTINUOUS; bool monitor = mode == MODE_MONITOR; @@ -268,7 +268,7 @@ void get_logs_main(enum test_mode mode, bool pipe, pid_t pid) case MODE_TID_CORRECT: case MODE_TAG_CORRECT: case MODE_PREFIX_CORRECT: - if (pipe) { + if (backend == BACKEND_PIPE) { assert(error_count == PIPE_ERRORS); assert(info_count == PIPE_INFOS); } else { @@ -276,7 +276,7 @@ void get_logs_main(enum test_mode mode, bool pipe, pid_t pid) } break; case MODE_PRIORITY: - if (pipe) + if (backend == BACKEND_PIPE) assert(error_count == PIPE_ERRORS); else assert(error_count > 0); @@ -305,8 +305,10 @@ unsigned int MB(unsigned int x) return 1024 * 1024 * x; } -void traits_main(bool pipe) +void traits_main(backend_t backend) { + assert(backend != BACKEND_ZERO_COPY); + dlogutil_config_s *config = dlogutil_config_create(); assert(config); @@ -327,7 +329,7 @@ void traits_main(bool pipe) unsigned int capacity, usage; assert(dlogutil_buffer_get_capacity(state, LOG_ID_MAIN, &capacity) == 0); assert(dlogutil_buffer_get_usage(state, LOG_ID_MAIN, &usage) == 0); - if (pipe) + if (backend == BACKEND_PIPE) assert(capacity == MB(1)); else { int fd = open("/dev/log_main", O_RDONLY); @@ -343,20 +345,20 @@ void traits_main(bool pipe) dlogutil_sorting_order_e type; assert(dlogutil_buffer_get_default_ts_type(LOG_ID_MAIN, &type) == 0); - assert(type == (pipe ? DLOGUTIL_SORT_RECV_MONO : DLOGUTIL_SORT_SENT_REAL)); + assert(type == (backend == BACKEND_PIPE ? DLOGUTIL_SORT_RECV_MONO : DLOGUTIL_SORT_SENT_REAL)); bool available; assert(dlogutil_buffer_check_ts_type_available(LOG_ID_MAIN, DLOGUTIL_SORT_SENT_MONO, &available) == 0); - assert(available == pipe); + assert(available == (backend == BACKEND_PIPE)); assert(dlogutil_buffer_check_ts_type_available(LOG_ID_MAIN, DLOGUTIL_SORT_SENT_REAL, &available) == 0); assert(available); assert(dlogutil_buffer_check_ts_type_available(LOG_ID_MAIN, DLOGUTIL_SORT_RECV_MONO, &available) == 0); - assert(available == pipe); + assert(available == (backend == BACKEND_PIPE)); assert(dlogutil_buffer_check_ts_type_available(LOG_ID_MAIN, DLOGUTIL_SORT_RECV_REAL, &available) == 0); - assert(available == pipe); + assert(available == (backend == BACKEND_PIPE)); assert(dlogutil_buffer_check_ts_type_available(LOG_ID_KMSG, DLOGUTIL_SORT_SENT_MONO, &available) == 0); assert(available); @@ -454,8 +456,10 @@ void sorting_main(int left) assert(left == 0); } -void alias_main(bool pipe) +void alias_main(backend_t backend) { + assert(backend != BACKEND_ZERO_COPY); + dlogutil_config_s *config = dlogutil_config_create(); assert(config); assert(dlogutil_config_buffer_add(config, LOG_ID_MAIN) == 0); @@ -472,11 +476,11 @@ void alias_main(bool pipe) assert(dlogutil_buffer_get_alias(state, LOG_ID_MAIN, &id) == 0); assert(id == LOG_ID_MAIN); assert(dlogutil_buffer_get_alias(state, LOG_ID_APPS, &id) == 0); - assert(id == (pipe ? LOG_ID_APPS : LOG_ID_INVALID)); + assert(id == (backend == BACKEND_PIPE ? LOG_ID_APPS : LOG_ID_INVALID)); assert(dlogutil_buffer_get_alias(state, LOG_ID_RADIO, &id) == 0); - assert(id == (pipe ? LOG_ID_RADIO : LOG_ID_RADIO)); + assert(id == (backend == BACKEND_PIPE ? LOG_ID_RADIO : LOG_ID_RADIO)); assert(dlogutil_buffer_get_alias(state, LOG_ID_SYSTEM, &id) == 0); - assert(id == (pipe ? LOG_ID_SYSTEM : LOG_ID_MAIN)); + assert(id == (backend == BACKEND_PIPE ? LOG_ID_SYSTEM : LOG_ID_MAIN)); assert(dlogutil_buffer_get_alias(state, LOG_ID_KMSG, &id) == 0); assert(id == LOG_ID_KMSG); @@ -534,9 +538,11 @@ int main(int argc, char **argv) pid_t pid = atoi(argv[2]); - bool pipe = false; + backend_t backend = BACKEND_ANDROID_LOGGER; if (!strcmp(argv[3], "pipe")) - pipe = true; + backend = BACKEND_PIPE; + else if (!strcmp(argv[3], "zero-copy")) + backend = BACKEND_ZERO_COPY; else if (strcmp(argv[3], "logger")) print_usage_and_die(argv[0]); @@ -556,19 +562,19 @@ int main(int argc, char **argv) case MODE_TAG_WRONG: case MODE_PREFIX_CORRECT: case MODE_PREFIX_WRONG: - get_logs_main(t, pipe, pid); + get_logs_main(t, backend, pid); break; case MODE_SORTING: - sorting_main(pipe ? 4 : 1); + sorting_main(backend == BACKEND_PIPE ? 4 : 1); break; case MODE_TRAITS: - traits_main(pipe); + traits_main(backend); break; case MODE_CLEAR: clear_main(); break; case MODE_ALIAS: - alias_main(pipe); + alias_main(backend); break; case MODE_NEGATIVE: negative_main(); -- 2.7.4