automated: linux: pi-stress: add iterations

This will make it possible to run multiple iterations to gather multiple
min/max/avg values.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
diff --git a/automated/linux/pi-stress/pi-stress.sh b/automated/linux/pi-stress/pi-stress.sh
index 938e3e6..a030e4c 100755
--- a/automated/linux/pi-stress/pi-stress.sh
+++ b/automated/linux/pi-stress/pi-stress.sh
@@ -7,7 +7,7 @@
 . ../../lib/sh-test-lib
 
 OUTPUT="$(pwd)/output"
-LOGFILE="${OUTPUT}/pi-stress.json"
+LOGFILE="${OUTPUT}/pi-stress"
 RESULT_FILE="${OUTPUT}/result.txt"
 export RESULT_FILE
 
@@ -15,18 +15,20 @@
 MLOCKALL="false"
 RR="false"
 BACKGROUND_CMD=""
+ITERATIONS=1
 
 usage() {
-    echo "Usage: $0 [-D runtime] [-m <true|false>] [-r <true|false>] [-w background_cmd]" 1>&2
+    echo "Usage: $0 [-D runtime] [-m <true|false>] [-r <true|false>] [-w background_cmd] [-i iterations]" 1>&2
     exit 1
 }
 
-while getopts ":D:m:r:w" opt; do
+while getopts ":D:m:r:w:i:" opt; do
     case "${opt}" in
         D) DURATION="${OPTARG}" ;;
         m) MLOCKALL="${OPTARG}" ;;
         r) RR="${OPTARG}" ;;
         w) BACKGROUND_CMD="${OPTARG}" ;;
+        i) ITERATIONS="${OPTARG}" ;;
         *) usage ;;
     esac
 done
@@ -57,10 +59,18 @@
 # test script. Catch and ignore it with trap.
 trap '' TERM
 # shellcheck disable=SC2086
-"${binary}" -q --duration "${DURATION}" ${MLOCKALL} ${RR} --json="${LOGFILE}"
+for i in $(seq ${ITERATIONS}); do
+    "${binary}" -q --duration "${DURATION}" ${MLOCKALL} ${RR} --json="${LOGFILE}-${i}.json"
+done
 
 background_process_stop bgcmd
 
 # Parse test log.
-../../lib/parse_rt_tests_results.py pi-stress "${LOGFILE}" \
-    | tee -a "${RESULT_FILE}"
+for i in $(seq ${ITERATIONS}); do
+    ../../lib/parse_rt_tests_results.py pi-stress "${LOGFILE}-${i}.json" \
+        | tee "${RESULT_FILE}"
+
+    if [ ${ITERATIONS} -ne 1 ]; then
+        sed -i "s|^|iteration-${i}-|g" "${RESULT_FILE}"
+    fi
+done
diff --git a/automated/linux/pi-stress/pi-stress.yaml b/automated/linux/pi-stress/pi-stress.yaml
index 64a5b78..2c553ca 100644
--- a/automated/linux/pi-stress/pi-stress.yaml
+++ b/automated/linux/pi-stress/pi-stress.yaml
@@ -40,10 +40,11 @@
     # Refer to https://validation.linaro.org/static/docs/v2/publishing-artifacts.html
     ARTIFACTORIAL_URL: "https://archive.validation.linaro.org/artifacts/team/qa/"
     ARTIFACTORIAL_TOKEN: ""
+    ITERATIONS: 1
 
 run:
     steps:
         - cd automated/linux/pi-stress
-        - ./pi-stress.sh -D "${DURATION}" -m "${MLOCKALL}" -r "${RR}" -w "${BACKGROUND_CMD}"
+        - ./pi-stress.sh -D "${DURATION}" -m "${MLOCKALL}" -r "${RR}" -i "${ITERATIONS}" -w "${BACKGROUND_CMD}"
         - ../../utils/upload-to-artifactorial.sh -a "output/pi-stress.json" -u "${ARTIFACTORIAL_URL}" -t "${ARTIFACTORIAL_TOKEN}"
         - ../../utils/send-to-lava.sh ./output/result.txt