system tests: add basic log_dump tests 87/200387/5
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 21 Feb 2019 15:36:45 +0000 (16:36 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 26 Feb 2019 13:40:40 +0000 (13:40 +0000)
Change-Id: Ibcbf680ba2b4c105d66c9f0c93acf6aaababe375

packaging/crash-worker_system-tests.spec
tests/system/CMakeLists.txt
tests/system/log_dump_normal/log_dump_normal.sh.template [new file with mode: 0644]
tests/system/log_dump_short/log_dump_short.sh.template [new file with mode: 0644]
tests/system/run.sh.template
tests/system/utils/minicore-utils.sh

index 11d644a..79ef265 100644 (file)
@@ -21,6 +21,7 @@ Requires:      gdb
 Requires:      coreutils
 Requires:      tlm
 Requires:      /bin/bash
+Requires:      /usr/bin/unzip
 
 Requires:      crash-worker
 Requires:      %{_sbindir}/minicoredumper
@@ -59,6 +60,8 @@ cd tests/system
 %{_libdir}/crash-worker_system-tests/time_test/cp.sh
 %{_libdir}/crash-worker_system-tests/wait_for_opt_usr/wait_for_opt_usr.sh
 %{_libdir}/crash-worker_system-tests/info_file/info_file.sh
+%{_libdir}/crash-worker_system-tests/log_dump_normal/log_dump_normal.sh
+%{_libdir}/crash-worker_system-tests/log_dump_short/log_dump_short.sh
 %{_libdir}/crash-worker_system-tests/log_file/log_file.sh
 %{_libdir}/crash-worker_system-tests/so_info_file/so_info_file.sh
 %{_libdir}/crash-worker_system-tests/report_type_info/report_type_info.sh
index 384a729..e57ad96 100644 (file)
@@ -28,6 +28,8 @@ configure_test("so_info_file")
 configure_test("report_type_info")
 configure_test("without_core")
 configure_test("crash_root_path")
+configure_test("log_dump_short")
+configure_test("log_dump_normal")
 
 configure_file("run.sh.template" "run.sh" @ONLY)
 INSTALL(FILES run.sh DESTINATION ${CRASH_SYSTEM_TESTS_PATH})
diff --git a/tests/system/log_dump_normal/log_dump_normal.sh.template b/tests/system/log_dump_normal/log_dump_normal.sh.template
new file mode 100644 (file)
index 0000000..ef22b69
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# Custom report path test
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+    CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+clean_logdump
+dummy="$CRASH_DUMP_DIR/logdump-short-test"
+touch "$dummy"
+
+log_dump --normal
+logfile="${LOGDUMP_RESULT_PATH}"/* # there shall be only one file
+
+check_file_exists "$logfile"
+check_zip_contains "$logfile" 'log/dump_systemstate.*log$'
+check_zip_contains "$logfile" 'log/system_log/$'
+check_zip_contains "$logfile" 'log/system_log/dlog/kernel$'
+check_zip_contains "$logfile" 'log/module_log/$'
+check_zip_contains "$logfile" 'dump/$'
+
+check_file_not_exists "$dummy"
+
+clean_logdump
+
+exit_with_code "SUCCESS" 0
diff --git a/tests/system/log_dump_short/log_dump_short.sh.template b/tests/system/log_dump_short/log_dump_short.sh.template
new file mode 100644 (file)
index 0000000..e4db298
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# Custom report path test
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+    CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+clean_logdump
+
+dummy="$CRASH_DUMP_DIR/logdump-short-test"
+touch "$dummy"
+
+log_dump --short
+logfile="${LOGDUMP_RESULT_PATH}"/* # there shall be only one file
+
+check_file_exists "$logfile"
+
+num=`unzip -qql "$logfile" | wc -l`
+if [ $num -ne 2 ]; then
+        exit_with_code "FAIL: 'log_dump --short' report contains $num files - 2 expected" 1
+fi
+
+check_zip_contains "$logfile" 'log/dump_systemstate.*log$'
+check_zip_contains "$logfile" 'log/$'
+
+check_file_not_exists "$dummy"
+
+clean_logdump
+
+exit_with_code "SUCCESS" 0
index 236151c..feece4f 100644 (file)
@@ -2,7 +2,8 @@
 
 TESTS=("check_minicore_mem" "cmp_backtraces" "info_file" "log_file"
        "report_type_info" "critical_process" "time_test" "wait_for_opt_usr"
-       "so_info_file" "without_core" "crash_root_path")
+       "so_info_file" "without_core" "crash_root_path" "log_dump_short"
+       "log_dump_normal")
 
 if [ -z "${CRASH_SYSTEM_TESTS_PATH}" ]; then
     CRASH_SYSTEM_TESTS_PATH="@CRASH_SYSTEM_TESTS_PATH@"
index 9cb8627..36e6d59 100644 (file)
@@ -30,6 +30,26 @@ function check {
     exit_with_code "FAIL: not found ${1} in ${RESULT}" 1
 }
 
+function check_file_exists {
+    if [ ! -f ${1} ]; then
+        exit_with_code "FAIL: file not exists $1" 1
+    fi
+}
+
+function check_file_not_exists {
+    if [ -f ${1} ]; then
+        exit_with_code "FAIL: file exists $1" 1
+    fi
+}
+
+function check_zip_contains {
+    zipfile=${1}
+    pattern="$2"
+    if ! unzip -qql "$logfile" | grep -E "$pattern"; then
+        exit_with_code "FAIL: zip file ${zipfile} does not contain ${pattern}" 1
+    fi
+}
+
 function tzplatform_var {
     VAL=`tzplatform-get ${1}`
     if [ $? == 0 ]; then
@@ -58,6 +78,22 @@ function clean_crash_dump {
     rm -rf ${CRASH_DUMP_PATH}/*
 }
 
+function clean_logdump {
+
+    export LOGDUMP_RESULT_PATH=`tzplatform_var TZ_SYS_CRASH_ROOT`/debug
+
+    killall log_dump
+    sleep 1
+
+    if [ "x${LOGDUMP_RESULT_PATH}" = 'x/debug' ]; then
+        exit_with_code "Couldn't get TZ_SYS_CRASH_ROOT" 1
+    fi
+
+    if [ -d ${LOGDUMP_RESULT_PATH} ]; then
+        rm -rf ${LOGDUMP_RESULT_PATH}/*
+    fi
+}
+
 function wait_for_file {
     TIMEOUT=240
     while [ ! -f ${1} ];