system tests: Simplify exit helper functions 58/211258/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 25 Jul 2019 11:13:09 +0000 (13:13 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 25 Jul 2019 11:49:55 +0000 (13:49 +0200)
Change-Id: Iecafa3632ac0c81454c2692037de34b486dfa2e2

20 files changed:
tests/system/check_minicore_mem/check_minicore_mem.sh.template
tests/system/cmp_backtraces/cmp_backtraces.sh.template
tests/system/crash_root_path/crash_root_path.sh.template
tests/system/critical_process/critical_process.sh.template
tests/system/dbus_notify/dbus_notify.sh.template
tests/system/dump_systemstate_extras/dump_systemstate_extras.sh.template
tests/system/extra_script/extra_script.sh.template
tests/system/info_file/info_file.sh.template
tests/system/livedumper/livedumper.sh.template
tests/system/log_dump_crash_root_path/log_dump_crash_root_path.sh.template
tests/system/log_dump_normal/log_dump_normal.sh.template
tests/system/log_dump_short/log_dump_short.sh.template
tests/system/log_file/log_file.sh.template
tests/system/report_basic/report_basic.sh.template
tests/system/report_type_info/report_type_info.sh.template
tests/system/so_info_file/so_info_file.sh.template
tests/system/time_test/time_test.sh.template
tests/system/utils/minicore-utils.sh
tests/system/wait_for_opt_usr/wait_for_opt_usr.sh.template
tests/system/without_core/without_core.sh.template

index 7858da9..b1532bb 100755 (executable)
@@ -35,4 +35,4 @@ RESULT=`gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_MINI} --
 check "MAGICNAME.*id=.*kenny.cpp:31"
 check "run.*id=.*kenny.cpp:56"
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index 9bbb081..417cadd 100755 (executable)
@@ -48,8 +48,8 @@ gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_ORIG}  -ex "thre
 gdb ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny ${BASE_DIR}/${CORE_MINI}  -ex "thread apply all bt" -ex "q" 2> /dev/null | grep -e '^#' > ${BASE_DIR}/${THREADS_MINI}
 
 if ! diff ${BASE_DIR}/${THREADS_ORIG} ${BASE_DIR}/${THREADS_MINI} > /dev/null; then
-    exit_with_code "FAIL: backtraces are different" ${FAIL_CODE}
+    fail "backtraces are different"
 fi
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
 
index bffda78..0f59b55 100644 (file)
@@ -18,7 +18,7 @@ fi
 
 function check_file_exists {
     if [ ! -f ${NEW_PATH}/dump/kenny*/kenny*.${1} ]; then
-        exit_with_code "FAIL: no ${1} file in report" ${FAIL_CODE}
+        fail "no ${1} file in report"
     fi
 }
 
@@ -41,7 +41,7 @@ wait_for_app crash-manager
 pushd ${NEW_PATH}/dump
 if ! unzip kenny*zip > /dev/null; then
     popd
-    exit_with_code "FAIL: report not found in ${NEW_PATH}/dump" ${FAIL_CODE}
+    fail "report not found in ${NEW_PATH}/dump"
 fi
 popd
 
@@ -50,4 +50,4 @@ check_file_exists info
 check_file_exists so_info
 check_file_exists log
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index 63568b4..7b5fdbb 100755 (executable)
@@ -14,7 +14,7 @@ fi
 . ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
 
 if is_emulator; then
-    exit_with_code "SKIP" ${SKIP_CODE}
+    skip "test not applicable on emulator"
 fi;
 
 clean_crash_dump
@@ -68,7 +68,7 @@ while true; do
         sleep 4
         gum-utils -d --username test1 1> /dev/null 2>&1
         clean_after_test
-        exit_with_code "SUCCESS" ${SUCCESS_CODE}
+        exit_ok
     fi
 
     if endoftime; then
@@ -83,4 +83,4 @@ sleep 4
 gum-utils -d --username test1 1> /dev/null 2>&1
 
 clean_after_test
-exit_with_code "FAIL" ${FAIL_CODE}
+fail "expected crash not found in timeout $TIMEOUT"
index 9e51679..d6b0bb2 100644 (file)
@@ -81,11 +81,11 @@ for i in $(seq 1 10); do
                fi
 
                if [ $score -eq 5 ]; then
-                       exit_with_code "SUCCESS" ${SUCCESS_CODE}
+                       exit_ok
                fi
        fi
 
        sleep 1
 done
 
-exit_with_code "FAIL: dbus signal does not match" ${FAIL_CODE}
+fail "dbus signal does not match"
index 5b799ec..41e270f 100644 (file)
@@ -13,7 +13,7 @@ function do_check {
     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" ${FAIL_CODE}
+        fail "section ${section_pat} does not contain $body_pat"
     fi
 }
 
@@ -61,4 +61,4 @@ 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" ${SUCCESS_CODE}
+exit_ok
index 1c8fe5e..40f743b 100644 (file)
@@ -43,4 +43,4 @@ check_zip_contains "$dumpfile" '.*log$'
 check_zip_contains "$dumpfile" '.*info$'
 check_zip_contains "$dumpfile" '.*cookie$'
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index 052f4f9..12628e0 100644 (file)
@@ -24,13 +24,13 @@ REPORT_ZIP=$(ls ${CRASH_DUMP_PATH})
 REPORT_DIR=$(basename ${REPORT_ZIP} .zip)
 
 if [ ! -f ${CRASH_DUMP_PATH}/${REPORT_ZIP} ]; then
-    exit_with_code "FAIL: no report in ${CRASH_DUMP_PATH}" ${FAIL_CODE}
+    fail "no report in ${CRASH_DUMP_PATH}"
 fi
 
 pushd ${CRASH_DUMP_PATH}
 if ! unzip ${REPORT_ZIP} > /dev/nulll; then
     popd
-    exit_with_code "FAIL: report ${REPORT_ZIP} does not exist" ${FAIL_CODE}
+    fail "report ${REPORT_ZIP} does not exist"
 fi
 popd
 
@@ -67,4 +67,4 @@ check ': .*sleep.*'
 check ': .*start.*kenny'
 check ': main.*kenny'
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index d22e073..5657bcd 100644 (file)
@@ -9,7 +9,7 @@ fi
 . ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
 
 if [ ! -x /usr/bin/livedumper ]; then
-    exit_with_code "SKIP" ${SKIP_CODE}
+    skip "livedumper binary not installed"
 fi
 
 mount -o rw,remount /
@@ -32,12 +32,12 @@ wait_for_app crash-manager
 pushd ${LIVE_DUMP_PATH}
 
 if [ ! -f ${REPORT_PATH} ]; then
-    exit_with_code "Report path does not exist" ${FAIL_CODE}
+    fail "report path does not exist"
 fi
 
 if ! unzip ${REPORT_PATH} > /dev/null; then
     popd
-    exit_with_code "FAIL: report not found in ${LIVE_DUMP_PATH}" ${FAIL_CODE}
+    fail "report not found in ${LIVE_DUMP_PATH}"
 fi
 
 COREDUMP=`find -name "kenny*coredump*"`
@@ -55,7 +55,7 @@ check "run.*id=.*kenny.cpp:56"
 if [[ $(pidof kenny) ]]; then
     kill -9 `pidof kenny`
 else
-    exit_with_code "FAIL" ${FAIL_CODE}
+    fail "victim process not found"
 fi
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index 543690b..aabc739 100644 (file)
@@ -23,9 +23,9 @@ 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" ${FAIL_CODE}
+        fail "'log_dump --short' report contains $num files - 2 expected"
 fi
 
 restore_file ${CRASH_MANAGER_CONF}
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index e9e3990..38d7885 100644 (file)
@@ -19,7 +19,7 @@ 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" ${FAIL_CODE}
+        fail "'log_dump --short' report contains $num files - 2 expected"
 fi
 
 check_zip_contains "$logfile" 'log/dump_systemstate.*log$'
@@ -29,4 +29,4 @@ check_file_exists "$dummy"
 
 clean_logdump
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index d1cdfa1..d684c2d 100644 (file)
@@ -12,7 +12,7 @@ function check_section_not_empty {
     if [ ${RES} -eq ${COUNT} ]; then
         return 0
     fi
-    exit_with_code "FAIL: section ${1} does not contain enough data" ${FAIL_CODE}
+    fail "section ${1} does not contain enough data"
 }
 
 function check_section {
@@ -38,13 +38,13 @@ REPORT_ZIP=$(ls ${CRASH_DUMP_PATH})
 REPORT_DIR=$(basename ${REPORT_ZIP} .zip)
 
 if [ ! -f ${CRASH_DUMP_PATH}/${REPORT_ZIP} ]; then
-    exit_with_code "FAIL: no report in ${CRASH_DUMP_PATH}" ${FAIL_CODE}
+    fail "no report in ${CRASH_DUMP_PATH}"
 fi
 
 pushd ${CRASH_DUMP_PATH}
 if ! unzip ${REPORT_ZIP} > /dev/nulll; then
     popd
-    exit_with_code "FAIL: report ${REPORT_ZIP} does not exist" ${FAIL_CODE}
+    fail "report ${REPORT_ZIP} does not exist"
 fi
 popd
 
@@ -70,4 +70,4 @@ check_section "==== Kernel messages" 10
 check_section "==== Log messages" 10
 check_section "==== Journal messages" 10
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index 4243ccf..18d7836 100644 (file)
@@ -24,18 +24,18 @@ pushd ${CRASH_DUMP_PATH}
 name=$(echo kenny_${pid}_*)
 name=${name%.zip}
 
-test -f "${name}.zip" || exit_with_code "FAIL: crash report not found" ${FAIL_CODE}
-unzip "${name}.zip" || exit_with_code "FAIL: unable to extract archive" ${FAIL_CODE}
+test -f "${name}.zip" || fail "crash report not found"
+unzip "${name}.zip" || fail "unable to extract archive"
 
 # assumes default configuration - with coredump
-test -s "${name}/${name}.coredump.tar" || test -f ${name}/${name}.coredump || exit_with_code "FAIL: coredump corrupt or not found" ${FAIL_CODE}
+test -s "${name}/${name}.coredump.tar" || test -f ${name}/${name}.coredump || fail "coredump corrupt or not found"
 
-test -s "${name}/${name}.log" || exit_with_code "FAIL: log corrupt or not found" ${FAIL_CODE}
-test -s "${name}/${name}.so_info" || exit_with_code "FAIL: info corrupt or not found" ${FAIL_CODE}
-test -s "${name}/${name}.info" || exit_with_code "FAIL: info corrupt or not found" ${FAIL_CODE}
+test -s "${name}/${name}.log" || fail "log corrupt or not found"
+test -s "${name}/${name}.so_info" || fail "info corrupt or not found"
+test -s "${name}/${name}.info" || fail "info corrupt or not found"
 
 for i in ${CRASH_TEMP_PATH}/*; do
-    test -a "${i}" && exit_with_code "FAIL: temp directory not cleaned up" ${FAIL_CODE}
+    test -a "${i}" && fail "temp directory not cleaned up"
 done
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index 515e32e..d8056f8 100644 (file)
@@ -29,7 +29,7 @@ restore_file ${CRASH_MANAGER_CONF}
 wait_for_app crash-manager
 
 if ! compgen -G ${CRASH_DUMP_PATH}/kenny*info > /dev/null; then
-    exit_with_code "FAIL: info file not found" ${FAIL_CODE}
+    fail "info file not found"
 fi
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index b73d589..d8437ac 100644 (file)
@@ -24,12 +24,12 @@ REPORT_ZIP=$(ls ${CRASH_DUMP_PATH})
 REPORT_DIR=$(basename ${REPORT_ZIP} .zip)
 
 if [ ! -f ${CRASH_DUMP_PATH}/${REPORT_ZIP} ]; then
-    exit_with_code "FAIL: no report in ${CRASH_DUMP_PATH}" ${FAIL_CODE}
+    fail "no report in ${CRASH_DUMP_PATH}"
 fi
 
 pushd ${CRASH_DUMP_PATH}
 if ! unzip ${REPORT_ZIP} > /dev/nulll; then
-    exit_with_code "FAIL: report ${REPORT_ZIP} does not exist" ${FAIL_CODE}
+    fail "report ${REPORT_ZIP} does not exist"
 fi
 popd
 
@@ -43,4 +43,4 @@ check "/usr/lib/libstdc[^ ]+ [a-z0-9]+ libstd[^;]+;[^;]+;[^;]+;[a-z0-9]+"
 check "/usr/lib/libpthread[^ ]+ [a-z0-9]+ glibc;[^;]+;[^;]+;[a-z0-9]+"
 check "/usr/lib/ld[^ ]+ [a-z0-9]+ glibc;[^;]+;[^;]+;[a-z0-9]+"
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok
index 2366e5a..2edb71e 100755 (executable)
@@ -43,7 +43,7 @@ wait_for_file ${TEMP_DIR}/${MINICORE_TIME_FILE}
 MINICORE_TIME=$(< ${TEMP_DIR}/${MINICORE_TIME_FILE})
 
 if [ ${MINICORE_TIME} -le ${TIME_LIMIT} ]; then
-    exit_with_code "SUCCESS" ${SUCCESS_CODE}
+    exit_ok
 else
-    exit_with_code "FAIL: dumping time: ${MINICORE_TIME} but limit was: ${TIME_LIMIT}" ${FAIL_CODE}
+    fail "dumping time: ${MINICORE_TIME} but limit was: ${TIME_LIMIT}"
 fi
index 747809a..dd64a99 100644 (file)
@@ -1,6 +1,9 @@
 #!/bin/bash
 
 __CORE_PATTERN=""
+SUCCESS_CODE=0
+FAIL_CODE=1
+SKIP_CODE=2
 
 function save_core_pattern {
     __CORE_PATTERN=$(< /proc/sys/kernel/core_pattern)
@@ -11,6 +14,18 @@ function exit_with_code {
     exit ${2}
 }
 
+function exit_ok {
+    exit_with_code "SUCCESS" ${SUCCESS_CODE}
+}
+
+function fail {
+    exit_with_code "FAIL: $1" ${FAIL_CODE}
+}
+
+function skip {
+    exit_with_code "SKIP: $1" ${SKIP_CODE}
+}
+
 function restore_core_pattern {
     echo ${__CORE_PATTERN} > /proc/sys/kernel/core_pattern
 }
@@ -27,18 +42,18 @@ function check {
     if [[ ${RESULT} =~ ${1} ]]; then
         return 0
     fi
-    exit_with_code "FAIL: not found ${1} in ${RESULT}" ${FAIL_CODE}
+    fail "not found ${1} in ${RESULT}"
 }
 
 function check_file_exists {
     if [ ! -f ${1} ]; then
-        exit_with_code "FAIL: file not exists $1" ${FAIL_CODE}
+        fail "file not exists $1"
     fi
 }
 
 function check_file_not_exists {
     if [ -f ${1} ]; then
-        exit_with_code "FAIL: file exists $1" ${FAIL_CODE}
+        fail "file exists $1"
     fi
 }
 
@@ -46,7 +61,7 @@ function check_zip_contains {
     zipfile=${1}
     pattern="$2"
     if ! unzip -qql "$zipfile" | grep -E "$pattern"; then
-        exit_with_code "FAIL: zip file ${zipfile} does not contain ${pattern}" ${FAIL_CODE}
+        fail "zip file ${zipfile} does not contain ${pattern}"
     fi
 }
 
@@ -67,7 +82,7 @@ function clean_crash_dump {
     sleep 1
 
     if [ ! -d ${CRASH_DUMP_PATH} ]; then
-        exit_with_code "${CRASH_DUMP_PATH} does not exist" ${FAIL_CODE}
+        fail "${CRASH_DUMP_PATH} does not exist"
     fi
 
     rm -rf ${CRASH_DUMP_PATH}/*
@@ -95,7 +110,7 @@ function wait_for_file {
     while [ ! -f ${1} ];
     do
         if endoftime; then
-            exit_with_code "FAIL: ${1} does not exist" ${FAIL_CODE}
+            fail "${1} does not exist"
         else
             sleep 1
         fi
@@ -111,7 +126,7 @@ function wait_for_app {
             break;
         fi
         if endoftime; then
-            exit_with_code "FAIL: ${1} is still running" ${FAIL_CODE}
+            fail "${1} is still running"
         else
             sleep 1
         fi
@@ -138,27 +153,24 @@ function __export_vars__ {
 
     export CRASH_TEMP_PATH=`tzplatform_var TZ_SYS_CRASH_ROOT`/temp
     if [ "x${CRASH_TEMP_PATH}" = 'x/temp' ]; then
-        exit_with_code "Couldn't get TZ_SYS_CRASH_ROOT" ${FAIL_CODE}
+        fail "Couldn't get TZ_SYS_CRASH_ROOT"
     fi
 
     export LOGDUMP_RESULT_PATH=`tzplatform_var TZ_SYS_CRASH_ROOT`/debug
     if [ "x${LOGDUMP_RESULT_PATH}" = 'x/debug' ]; then
-        exit_with_code "Couldn't get TZ_SYS_CRASH_ROOT" ${FAIL_CODE}
+        fail "Couldn't get TZ_SYS_CRASH_ROOT"
     fi
 
     export CRASH_DUMP_PATH=`tzplatform_var TZ_SYS_CRASH`
     if [ -z ${CRASH_DUMP_PATH} ]; then
-        exit_with_code "Couldn't get TZ_SYS_CRASH or TZ_SYS_CRASH is empty" ${FAIL_CODE}
+        fail "Couldn't get TZ_SYS_CRASH or TZ_SYS_CRASH is empty"
     fi
 
     export LIVE_DUMP_PATH=`tzplatform_var TZ_SYS_CRASH_ROOT`/livedump
     if [ -z ${LIVE_DUMP_PATH} ]; then
-        exit_with_code "Couldn't get TZ_SYS_CRASH_ROOT or TZ_SYS_CRASH_ROOT is empty" ${FAIL_CODE}
+        fail "Couldn't get TZ_SYS_CRASH_ROOT or TZ_SYS_CRASH_ROOT is empty"
     fi
 
-    export SUCCESS_CODE=0
-    export FAIL_CODE=1
-    export SKIP_CODE=2
 }
 
 function is_emulator {
index caefaee..3120bb4 100755 (executable)
@@ -16,7 +16,7 @@ MTAB=`cat /etc/mtab | grep " ${OPT_MOUNTPOINT}"`
 clean_crash_dump
 
 if ! umount -l ${OPT_MOUNTPOINT}; then
-    exit_with_code "umount ${OPT_MOUNTPOINT} error" ${FAIL_CODE}
+    fail "umount ${OPT_MOUNTPOINT} error"
 fi
 
 save_core_pattern
@@ -39,7 +39,7 @@ echo "${MTAB}" | while read OPT_LINE; do
     OPT_CUR_MOUNTPOINT=`echo ${OPT_LINE} | cut -d' ' -f2`
 
     if ! mount -t ${OPT_FS} -o ${OPT_OPTS} ${OPT_DEV} ${OPT_CUR_MOUNTPOINT}; then
-        exit_with_code "ERROR: mount -t ${OPT_FS} -o ${OPT_OPTS} ${OPT_DEV} ${OPT_CUR_MOUNTPOINT}" ${FAIL_CODE}
+        fail " mount -t ${OPT_FS} -o ${OPT_OPTS} ${OPT_DEV} ${OPT_CUR_MOUNTPOINT}"
     fi
 done
 
index cfdee7a..ca13adf 100644 (file)
@@ -31,12 +31,12 @@ wait_for_app crash-manager
 pushd ${CRASH_DUMP_PATH}
 if ! unzip kenny*zip > /dev/null; then
     popd
-    exit_with_code "FAIL: report does not exist" ${FAIL_CODE}
+    fail "report does not exist"
 fi
 popd
 
 if ls ${CRASH_DUMP_PATH}/kenny*/kenny*.coredump.tar > /dev/null; then
-    exit_with_code "FAIL: coredump file exists" ${FAIL_CODE}
+    fail "coredump file exists"
 fi
 
-exit_with_code "SUCCESS" ${SUCCESS_CODE}
+exit_ok