source dlog_test_header
-#relevant pids default vals
-UTIL_PID=-1
-DLOGSEND_PID=-1
-MT_TEST=-1
-LOGGER=-1
-TEST_DYNAMIC_FILTERS=true
-
-
-cleanup() {
- [ "$UTIL_PID" -ne -1 ] && kill "$UTIL_PID" > /dev/null 2>&1
- [ "$MT_TEST" -ne -1 ] && kill "$MT_TEST" > /dev/null 2>&1
- [ "$LOGGER" -ne -1 ] && kill "$LOGGER" > /dev/null 2>&1
- # Shellcheck doesn't like this because the rm call is bad if $TESTDIR is empty.
- # However, such cases would be caught by the conditional.
- # shellcheck disable=SC2115
- [ -d "$TESTDIR" ] && rm -rf "$TESTDIR"/*
- [ -d "$RUNTIME_FILTERS_DIR" ] && rm -rf "$RUNTIME_FILTERS_DIR"
-}
-
trap cleanup 0
USAGE_MESSAGE="usage: $0 [--verbose] [--quick] pipe|logger|zero-copy"
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
-
- 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"
-
- dlog_logger -t 0 &
- LOGGER=$!
- sleep 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
-
- 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
+ dlog_test_daemon_early_quit $type
fi
- DLOG_CONFIG_PATH="$PREEARLYQUIT_CONFIG_PATH"
# Start the daemon
dlog_logger -t 0 &
sleep 0.25
[ "$(dlogutil -d -b apps | wc -l)" -eq 14 ] && ok || fail
-dlogutil -c
-LOG_DETAILS="testing if blocking dotnet and regular apps is separate (1/4)"
-dlogctl -b apps --enable
-dlogctl -b dotnet_api --disable
-dlogsend -b dotnet_api "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
-LOG_DETAILS="testing if blocking dotnet and regular apps is separate (2/4)"
-dlogsend -b apps "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
-LOG_DETAILS="testing if blocking dotnet and regular apps is separate (3/4)"
-dlogctl -b apps --disable
-dlogctl -b dotnet_api --enable
-dlogsend -b dotnet_api "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
-LOG_DETAILS="testing if blocking dotnet and regular apps is separate (4/4)"
-dlogsend -b apps "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
+if [ "$type" != "zero-copy" ]; then # These tests are inherently dynamic.
+ dlogutil -c
+ LOG_DETAILS="testing if blocking dotnet and regular apps is separate (1/4)"
+ dlogctl -b apps --enable
+ dlogctl -b dotnet_api --disable
+ dlogsend -b dotnet_api "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
+ LOG_DETAILS="testing if blocking dotnet and regular apps is separate (2/4)"
+ dlogsend -b apps "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
+ LOG_DETAILS="testing if blocking dotnet and regular apps is separate (3/4)"
+ dlogctl -b apps --disable
+ dlogctl -b dotnet_api --enable
+ dlogsend -b dotnet_api "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
+ LOG_DETAILS="testing if blocking dotnet and regular apps is separate (4/4)"
+ dlogsend -b apps "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
-dlogutil -c
-LOG_DETAILS="testing if blocking native and regular apps is separate (1/4)"
-dlogctl -b apps --enable
-dlogctl -b native_api --disable
-dlogsend -b native_api "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
-LOG_DETAILS="testing if blocking native and regular apps is separate (2/4)"
-dlogsend -b apps "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
-LOG_DETAILS="testing if blocking native and regular apps is separate (3/4)"
-dlogctl -b apps --disable
-dlogctl -b native_api --enable
-dlogsend -b native_api "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
-LOG_DETAILS="testing if blocking native and regular apps is separate (4/4)"
-dlogsend -b apps "TEST"
-[ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
+ dlogutil -c
+ LOG_DETAILS="testing if blocking native and regular apps is separate (1/4)"
+ dlogctl -b apps --enable
+ dlogctl -b native_api --disable
+ dlogsend -b native_api "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 0 ] && ok || fail
+ LOG_DETAILS="testing if blocking native and regular apps is separate (2/4)"
+ dlogsend -b apps "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 1 ] && ok || fail
+ LOG_DETAILS="testing if blocking native and regular apps is separate (3/4)"
+ dlogctl -b apps --disable
+ dlogctl -b native_api --enable
+ dlogsend -b native_api "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
+ LOG_DETAILS="testing if blocking native and regular apps is separate (4/4)"
+ dlogsend -b apps "TEST"
+ [ "$(dlogutil -d -b apps | wc -l)" -eq 2 ] && ok || fail
+fi
# put 100 log entries in the "main" buffer
dlogutil -c
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"
+ 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_real_ns\":[1-9][0-9]*,\"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_real_ns\":[1-9][0-9]*,\"sent_mono\":[1-9][0-9]+\.[0-9]{9},\"tag\":\"[[:print:]]*\",\"msg\":\"[[:print:]]*\"\}$/1/g"
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"
+ 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\",\"sent_real_ns\":[1-9][0-9]*,\"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
fi
LOG_DETAILS="testing if libdlogutil clears the buffer correctly"
+sleep 1 # make sure the earlier logs are handled so that they don't end up handled after the clear
test_libdlogutil clear $LIBDLOGUTIL_CORRECT_PID $type && ok || fail
if [ "$(date +%Y)" -le 2000 ]; then
LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_mono)"
dlogutil -db main --sort-by "${P}_mono" -v json | sed -Ee "s/^.*\"${P}_mono\":([^,}]*).*\$/\\1/" | sort -c && ok || fail
LOG_DETAILS="testing if dlogutil --sort-by sorts correctly (${P}_real)"
- dlogutil -db main --sort-by "${P}_real" -v json | sed -Ee "s/^.*\"${P}_real\":\"([^\"]*)\".*\$/\\1/" | sort -c && ok || fail
+ dlogutil -db main --sort-by "${P}_real" -v json | sed -Ee "s/^.*\"${P}_real\":\"([^\"]*)\",\"${P}_real_ns\":([^,}]*).*\$/\\1 \2/" | sort -c -k1,1 -k2,2g && ok || fail
done
fi