From a4d53f369ecbdfa68ca731e39f262e6ad18a8377 Mon Sep 17 00:00:00 2001 From: Martyn Welch <martyn.welch@collabora.co.uk> Date: Wed, 4 Jul 2018 17:08:41 +0100 Subject: [PATCH] Simplify by using csplit and not looking in old locations for scripts Signed-off-by: Martyn Welch <martyn.welch@collabora.co.uk> --- run-aa-test | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/run-aa-test b/run-aa-test index 680c79d..5939940 100755 --- a/run-aa-test +++ b/run-aa-test @@ -79,16 +79,8 @@ else CMD="$*" fi -CMDLINE="" -for PREFIX in '' '/usr/lib/apertis-tests/'; do - TOOL="${PREFIX}common/run-test-in-systemd" - if [ -x ${TOOL} ]; then - CMDLINE=${TOOL} - break - fi -done - -if [ "$CMDLINE" = "" ]; then +CMDLINE="common/run-test-in-systemd" +if [ ! -x $CMDLINE ]; then echo "common/run-test-in-systemd not found" exit 1 fi @@ -140,24 +132,12 @@ echo "#---8<--- expected output from aa_log_extract_tokens.pl" cat ${EXPECT_FILE} | sed 's/^/# /' echo "#--->8---" -cp ${EXPECT_FILE} ${TMP_DIR}/REMAIN - -EXPECT_COUNT=1 - -SEPARATOR=$( grep -m1 -x -n "${ALTERNATIVE_SEPARATOR}" ${TMP_DIR}/REMAIN | cut -d: -f1 ) -while [ "${SEPARATOR}" != "" ]; do - echo "SEPARATOR=\"${SEPARATOR}\"" - echo "REMAIN:" - cat ${TMP_DIR}/REMAIN - head -n $((${SEPARATOR}-1)) ${TMP_DIR}/REMAIN > ${TMP_DIR}/EXPECT${EXPECT_COUNT} - SEPARATOR=$((${SEPARATOR}+1)) - tail -n +${SEPARATOR} ${TMP_DIR}/REMAIN > ${TMP_DIR}/REMAIN.new - mv ${TMP_DIR}/REMAIN.new ${TMP_DIR}/REMAIN - EXPECT_COUNT=$((${EXPECT_COUNT}+1)) - SEPARATOR=$( grep -m1 -x -n "${ALTERNATIVE_SEPARATOR}" ${TMP_DIR}/REMAIN | cut -d: -f1 ) -done +csplit ${EXPECT_FILE} -f ${TMP_DIR}/EXPECT -b "%d" "/^${ALTERNATIVE_SEPARATOR}$/" {*} -mv ${TMP_DIR}/REMAIN ${TMP_DIR}/EXPECT${EXPECT_COUNT} +# Old versions of csplit don't provide "--suppress-matched", strip separator separately +for FILE in ${TMP_DIR}/EXPECT*; do + sed -i "/^${ALTERNATIVE_SEPARATOR}$/d" ${FILE} +done PARSE_FILE="${TMP_DIR}/PARSE" @@ -192,8 +172,8 @@ MATCH_EXPECTATION="False" # We might have alternative expectations, take that into consideration. OUTPUT_MD5=$( cat ${PARSE_FILE} | md5sum ) COUNT=$( ls -1 ${TMP_DIR}/EXPECT* | wc -l ) -NUM=1 -while [ $((${NUM} <= ${COUNT})) = 1 ]; do +NUM=0 +while [ $((${NUM} < ${COUNT})) = 1 ]; do EXPECTED_MD5=$( cat ${TMP_DIR}/EXPECT${NUM} | md5sum ) if [ "${OUTPUT_MD5}" = "${EXPECTED_MD5}" ]; then echo "# audit log matches alternative expectation ${NUM}/${COUNT}" -- GitLab