From dc73f0fc0b81a70e71899592f9969026f450420c Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Mon, 15 Jan 2024 15:52:45 -0300 Subject: [PATCH] tests: parse result of multiple lines in output There are some tests like attach_disconnected and posix_mq that can have a program that calls another. For example, posix_mq_rcv calls posix_mq_snd. Both of them write to the same output file, but the code that checks the result expects only one line. This change enables checking multiple lines in the output file and passing or failing accordingly. Signed-off-by: Georgia Garcia --- tests/regression/apparmor/prologue.inc | 72 +++++++++++++------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/tests/regression/apparmor/prologue.inc b/tests/regression/apparmor/prologue.inc index 78d2a4888..3bbea9b8e 100755 --- a/tests/regression/apparmor/prologue.inc +++ b/tests/regression/apparmor/prologue.inc @@ -300,46 +300,48 @@ checktestfg() ret=`cat $outfile 2>/dev/null` teststatus=pass - - case "$ret" in - PASS) if [ "$_pfmode" != "pass" -a -z "${_known}" ] - then - echo "Error: ${testname} passed. Test '${_testdesc}' was expected to '${_pfmode}'" - testfailed - return - elif [ "$_pfmode" == "pass" -a -n "${_known}" ] - then - echo "Alert: ${testname} passed. Test '${_testdesc}' was marked as expected pass but known problem (xpass)" - fi - ;; - FAIL*) if [ "$_pfmode" != "fail" -a -z "${_known}" ] - then - echo "Error: ${testname} failed. Test '${_testdesc}' was expected to '${_pfmode}'. Reason for failure '${ret}'" - testfailed - return - elif [ "$_pfmode" == "fail" -a -n "${_known}" ] - then - echo "Alert: ${testname} failed. Test '${_testdesc}' was marked as expected fail but known problem (xfail)." - fi - ;; - SIGNAL*) killedsig=`echo $ret | sed 's/SIGNAL//'` - case "$_pfmode" in - signal*) expectedsig=`echo ${_pfmode} | sed 's/signal//'` - if [ -n "${expectedsig}" -a ${expectedsig} != ${killedsig} ] - then - echo "Error: ${testname} failed. Test '${_testdesc}' was expected to terminate with signal ${expectedsig}${_known}. Instead it terminated with signal ${killedsig}" + testresult=pass + failurereason="" + while IFS= read -r line; do + case "$line" in + PASS) ;; + FAIL*) testresult=fail + failurereason=". Reason for failure '${line}'" + break + ;; + SIGNAL*) killedsig=`echo $line | sed 's/SIGNAL//'` + case "$_pfmode" in + signal*) expectedsig=`echo ${_pfmode} | sed 's/signal//'` + if [ -n "${expectedsig}" -a ${expectedsig} != ${killedsig} ] + then + echo "Error: ${testname} failed. Test '${_testdesc}' was expected to terminate with signal ${expectedsig}${_known}. Instead it terminated with signal ${killedsig}" + testfailed + return + fi + ;; + *) echo "Error: ${testname} failed. Test '${_testdesc}' was expected to '${_pfmode}'${_known}. Reason for failure 'killed by signal ${killedsig}'" testfailed return - fi + ;; + esac + ;; + *) testerror + return ;; - *) echo "Error: ${testname} failed. Test '${_testdesc}' was expected to '${_pfmode}'${_known}. Reason for failure 'killed by signal ${killedsig}'" + esac + done <<< "$ret" + + case "$_pfmode" in + signal*) ;; + *) if [ "$_pfmode" != "$testresult" -a -z "${_known}" ] + then + echo "Error: ${testname} ${testresult}ed. Test '${_testdesc}' was expected to '${_pfmode}'$failurereason" testfailed return - ;; - esac - ;; - *) testerror - return + elif [ "$_pfmode" == "$testresult" -a -n "${_known}" ] + then + echo "Alert: ${testname} ${testresult}ed. Test '${_testdesc}' was marked as expected $_pfmode but known problem (x$_pfmode)" + fi ;; esac