tests: extract header to a separate file 23/286423/3
authorMichal Bloch <m.bloch@samsung.com>
Thu, 5 Jan 2023 18:50:03 +0000 (19:50 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 12 Jan 2023 12:51:20 +0000 (13:51 +0100)
Can be included by specific, focused tests in the future,
allowing to reduce the time it takes to test individual
features (since a lot of time is wasted waiting for other
irrelevant tests to run).

Change-Id: Id5046219726a7cdeb2177ea10ac36d46fa717923

Makefile.am
configure.ac
packaging/dlog.spec
tests/dlog_test.in
tests/dlog_test_header.in [new file with mode: 0644]

index ee8327b..6aee5be 100644 (file)
@@ -901,7 +901,7 @@ modulesloadddir = /usr/lib/modules/modules-load.d
 modulesloadd_DATA = \
        configs/tizen-modules-dlog-zero-copy.conf
 
-bin_SCRIPTS = dlog_test dlog_cpu
+bin_SCRIPTS = dlog_test dlog_test_header dlog_cpu
 
 docdir = $(datadir)/doc/dlog
 doc_DATA = \
index f35441e..099b636 100644 (file)
@@ -90,6 +90,7 @@ AC_SUBST([datadir])
 AC_SUBST([libexecdir])
 AC_CONFIG_FILES([Makefile dlog.pc dlogutil.pc dlog-redirect-stdout.pc]
                 [dlog_test:tests/dlog_test.in]
+                [dlog_test_header:tests/dlog_test_header.in]
                 [dlog_cpu:tests/dlog_cpu.in]
                 [README.testsuite:tests/README.testsuite.in]
                 [units/dlog_logger.service]
index c55c073..c3ac429 100644 (file)
@@ -304,6 +304,7 @@ chsmack -e 'System' %{_libexecdir}/dlog-log-critical
 %manifest dlog.manifest
 %license LICENSE.APACHE2.0 LICENSE.MIT
 %{_bindir}/dlog_test
+%{_bindir}/dlog_test_header
 %{_bindir}/dlog_cpu
 /usr/share/doc/dlog/README.testsuite
 %{_libexecdir}/libdlog/perf_libdlog
index a022670..a1540bc 100644 (file)
@@ -5,11 +5,7 @@
 # the ok function will never fail.
 # shellcheck disable=SC2015
 
-# stuff for tracking test case counts
-FAILS=0
-OKS=0
-TOTAL=0
-LOG_DETAILS=
+source dlog_test_header
 
 #relevant pids default vals
 UTIL_PID=-1
@@ -17,41 +13,6 @@ DLOGSEND_PID=-1
 MT_TEST=-1
 LOGGER=-1
 
-TEST_DYNAMIC_FILTERS="@DYNAMIC_FILTERS@"
-TESTDIR=/var/lib/dlog-tests
-
-extract_timestamp() {
-       ts=0
-       case "$1" in
-               "threadtime")
-                       time=$(echo "$2" | awk -F '[ +]' '{print $2}')
-                       ts=$(date +%s%N -d "$time")
-               ;;
-               "long")
-                       time=$(echo "$2" | awk -F '[ +.]' '{print $3}')
-                       ms=$(echo "$2" | awk -F '[ +.]' '{print $4}')
-                       sec=$(date +%s%N -d "$time")
-                       ns=$((10#$ms * 1000000))
-                       ts=$((sec + ns))
-               ;;
-               "rwtime")
-                       time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
-                       ts=$(date +%s%N -d "$time")
-               ;;
-               "recv_realtime")
-                       time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
-                       ts=$(date +%s%N -d "$time")
-               ;;
-               "time")
-                       time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
-                       ts=$(date +%s%N -d "$time")
-               ;;
-               "kerneltime")
-                       ts=$(echo "$2" | awk -F '[ +]' '{print $1}' | sed -e 's/\.//g')
-               ;;
-       esac
-       echo "$ts"
-}
 
 cleanup() {
        [ "$UTIL_PID" -ne -1 ] && kill "$UTIL_PID" > /dev/null 2>&1
@@ -66,32 +27,6 @@ cleanup() {
 
 trap cleanup 0
 
-check_daemon() {
-       ret=1
-       if [ "$LOGGER" -ne -1 ] && [ -z "$(ps -o pid= -p "$LOGGER")" ]; then
-               ret=0
-       fi
-       return "$ret"
-}
-
-fail() {
-       check_daemon && daemon_status="[logger daemon not running]"
-
-       FAILS=$((FAILS + 1))
-       TOTAL=$((TOTAL + 1))
-       printf "[%02d] FAILED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
-       LOG_DETAILS=
-}
-
-ok() {
-       check_daemon && daemon_status="[logger daemon not running]"
-
-       OKS=$((OKS + 1))
-       TOTAL=$((TOTAL + 1))
-       printf "[%02d] PASSED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
-       LOG_DETAILS=
-}
-
 USAGE_MESSAGE="usage: $0 [--verbose] [--quick] pipe|logger"
 
 OPTS=$(getopt --shell sh --options "" --long verbose,quick --quiet -- "$@")
diff --git a/tests/dlog_test_header.in b/tests/dlog_test_header.in
new file mode 100644 (file)
index 0000000..253374f
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+######## Stuff for tracking test case counts
+
+FAILS=0
+OKS=0
+TOTAL=0
+LOG_DETAILS=
+
+check_daemon() {
+       ret=1
+       if [ "$LOGGER" -ne -1 ] && [ -z "$(ps -o pid= -p "$LOGGER")" ]; then
+               ret=0
+       fi
+       return "$ret"
+}
+
+fail() {
+       check_daemon && daemon_status="[logger daemon not running]"
+
+       FAILS=$((FAILS + 1))
+       TOTAL=$((TOTAL + 1))
+       printf "[%02d] FAILED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
+       LOG_DETAILS=
+}
+
+ok() {
+       check_daemon && daemon_status="[logger daemon not running]"
+
+       OKS=$((OKS + 1))
+       TOTAL=$((TOTAL + 1))
+       printf "[%02d] PASSED: %s %s\n" "$TOTAL" "$LOG_DETAILS" "$daemon_status"
+       LOG_DETAILS=
+}
+
+######## Paths to test folders etc
+
+TESTDIR=/var/lib/dlog-tests
+TEST_DYNAMIC_FILTERS="@DYNAMIC_FILTERS@"
+
+######## Utility functions
+
+extract_timestamp() {
+       ts=0
+       case "$1" in
+               "threadtime")
+                       time=$(echo "$2" | awk -F '[ +]' '{print $2}')
+                       ts=$(date +%s%N -d "$time")
+               ;;
+               "long")
+                       time=$(echo "$2" | awk -F '[ +.]' '{print $3}')
+                       ms=$(echo "$2" | awk -F '[ +.]' '{print $4}')
+                       sec=$(date +%s%N -d "$time")
+                       ns=$((10#$ms * 1000000))
+                       ts=$((sec + ns))
+               ;;
+               "rwtime")
+                       time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
+                       ts=$(date +%s%N -d "$time")
+               ;;
+               "recv_realtime")
+                       time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
+                       ts=$(date +%s%N -d "$time")
+               ;;
+               "time")
+                       time=$(echo "$2" | awk -F '[ +.]' '{print $2}')
+                       ts=$(date +%s%N -d "$time")
+               ;;
+               "kerneltime")
+                       ts=$(echo "$2" | awk -F '[ +]' '{print $1}' | sed -e 's/\.//g')
+               ;;
+       esac
+       echo "$ts"
+}
+