automated: linux: pmqtest: 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/pmqtest/pmqtest.sh b/automated/linux/pmqtest/pmqtest.sh
index d06bbb9..fc7068a 100755
--- a/automated/linux/pmqtest/pmqtest.sh
+++ b/automated/linux/pmqtest/pmqtest.sh
@@ -6,20 +6,22 @@
 
 TEST_DIR=$(dirname "$(realpath "$0")")
 OUTPUT="${TEST_DIR}/output"
-LOGFILE="${OUTPUT}/pmqtest.json"
+LOGFILE="${OUTPUT}/pmqtest"
 RESULT_FILE="${OUTPUT}/result.txt"
 DURATION="5m"
 BACKGROUND_CMD=""
+ITERATIONS=1
 
 usage() {
-    echo "Usage: $0 [-D duration] [-w background_cmd]" 1>&2
+    echo "Usage: $0 [-D duration] [-w background_cmd] [-i iterations]" 1>&2
     exit 1
 }
 
-while getopts ":D:w:" opt; do
+while getopts ":D:w:i:" opt; do
     case "${opt}" in
         D) DURATION="${OPTARG}" ;;
         w) BACKGROUND_CMD="${OPTARG}" ;;
+        i) ITERATIONS="${OPTARG}" ;;
         *) usage ;;
     esac
 done
@@ -38,10 +40,18 @@
 
 background_process_start bgcmd --cmd "${BACKGROUND_CMD}"
 
-"${binary}" -q -S -p 98 -D "${DURATION}" --json="${LOGFILE}"
+for i in $(seq ${ITERATIONS}); do
+    "${binary}" -q -S -p 98 -D "${DURATION}" --json="${LOGFILE}-${i}.json"
+done
 
 background_process_stop bgcmd
 
 # Parse test log.
-../../lib/parse_rt_tests_results.py pmqtest "${LOGFILE}" \
-    | tee -a "${RESULT_FILE}"
+for i in $(seq ${ITERATIONS}); do
+    ../../lib/parse_rt_tests_results.py pmqtest "${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/pmqtest/pmqtest.yaml b/automated/linux/pmqtest/pmqtest.yaml
index b23b543..0987152 100644
--- a/automated/linux/pmqtest/pmqtest.yaml
+++ b/automated/linux/pmqtest/pmqtest.yaml
@@ -35,10 +35,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/pmqtest/
-        - ./pmqtest.sh -D "${DURATION}" -w "${BACKGROUND_CMD}"
+        - ./pmqtest.sh -D "${DURATION}" -i "${ITERATIONS}" -w "${BACKGROUND_CMD}"
         - ../../utils/upload-to-artifactorial.sh -a "output/pmqtest.json" -u "${ARTIFACTORIAL_URL}" -t "${ARTIFACTORIAL_TOKEN}"
         - ../../utils/send-to-lava.sh ./output/result.txt