system tests: add `dump_systemstate -e' test 24/204824/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 26 Apr 2019 13:48:32 +0000 (15:48 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 30 Apr 2019 15:15:51 +0000 (17:15 +0200)
Change-Id: I4fa93d87bffaf2178b213eda2861a2522ce531ad

packaging/crash-worker_system-tests.spec
tests/system/CMakeLists.txt
tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template [new file with mode: 0644]

index 660872d..a9cf4d4 100644 (file)
@@ -22,7 +22,7 @@ Requires:      coreutils
 Requires:      tlm
 Requires:      /bin/bash
 Requires:      /usr/bin/unzip
-
+Requires:      /usr/bin/mcookie
 Requires:      crash-worker
 Requires:      %{_sbindir}/minicoredumper
 
@@ -69,6 +69,7 @@ cd tests/system
 %{_libdir}/crash-worker_system-tests/report_type_info/report_type_info.sh
 %{_libdir}/crash-worker_system-tests/without_core/without_core.sh
 %{_libdir}/crash-worker_system-tests/crash_root_path/crash_root_path.sh
+%{_libdir}/crash-worker_system-tests/dump_systemstate_extras/dump_systemstate_extras.sh
 %{_libdir}/crash-worker_system-tests/utils/btee
 %{_libdir}/crash-worker_system-tests/utils/kenny
 %{_libdir}/crash-worker_system-tests/utils/minicore-utils.sh
index 0767dc1..b8015d7 100644 (file)
@@ -35,6 +35,7 @@ configure_test("crash_root_path")
 configure_test("log_dump_short")
 configure_test("log_dump_normal")
 configure_test("log_dump_crash_root_path")
+configure_test("dump_systemstate_extras")
 
 get_property(TESTS_LIST GLOBAL PROPERTY TMP_TESTS_LIST)
 
diff --git a/tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template b/tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template
new file mode 100644 (file)
index 0000000..3899ae1
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+# Check dump_systemstate -e
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+    CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+function do_check {
+    f="$1"
+    section_pat="$2"
+    section_len="$3"
+    body_pat="$4"
+
+    if ! grep -EA "$section_len" "$section_pat" "$f" | grep -qE "$body_pat"; then
+        exit_with_code "FAIL: section ${section_pat} does not contain $body_pat" 1
+    fi
+}
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+mount -o rw,remount /
+
+cookie1=$(mcookie)
+cookie2=$(mcookie)
+cookie3=$(mcookie)
+cookie3_tmpfile=$(mktemp /tmp/cookie3.XXXXXX)
+echo $cookie3 > $cookie3_tmpfile
+tmpfile=$(mktemp /tmp/dump_systemstate_extra.XXXXXX)
+
+cleanup()
+{
+    rm -f "$cookie3_tmpfile" "$tmpfile"
+    rm -f /etc/dump_systemstate.conf.d/files/dump_systemstate_extras_system_test.conf
+    rm -f /etc/dump_systemstate.conf.d/programs/dump_systemstate_extras_system_test.conf
+    mount -o ro,remount /
+}
+trap cleanup 0
+
+cat > /etc/dump_systemstate.conf.d/programs/dump_systemstate_extras_system_test.conf <<EOF
+[Prog1]
+title=$cookie1
+path=/bin/echo
+args=magic_cookie is $cookie1
+
+[Prog2]
+title=/bin/env test
+path=/bin/env
+env=MAGIC_SECRET=$cookie2
+EOF
+
+cat > /etc/dump_systemstate.conf.d/files/dump_systemstate_extras_system_test.conf <<EOF
+[File1]
+title=file for cookie3
+path=$cookie3_tmpfile
+EOF
+
+dump_systemstate -e > $tmpfile
+
+do_check $tmpfile "==== $cookie1" 1 "^magic_cookie is $cookie1"
+do_check $tmpfile "==== /bin/env test" 999 "^MAGIC_SECRET=$cookie2"
+do_check $tmpfile "==== file for cookie3" 1 "^$cookie3"
+
+exit_with_code "SUCCESS" 0