fix(hftest): fix parsing the test json in hftests
Printing to the UART prior to hftests parsing the JSON structure
of the available tests caused the parsing to fail and the tests
to stop. Wrap the JSON structure in hftest_ctrl tags which the
hftest script can use to identify which lines of the uart contain
the JSON structure.
This is important as future patches will introduce the ability to
run functions during an SPs initialsation stage and any prints in
this code would cause the HFTEST to crash without the hftest_ctrl flags.
Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: Ib63a06f876e80cd4e4e360282bffda2c68474346
diff --git a/test/hftest/common.c b/test/hftest/common.c
index d3c57c6..2469095 100644
--- a/test/hftest/common.c
+++ b/test/hftest/common.c
@@ -16,6 +16,9 @@
#include "hftest_common.h"
#include "test/hftest.h"
+#define HFTEST_CTRL_JSON_START "[hftest_ctrl:json_start]"
+#define HFTEST_CTRL_JSON_END "[hftest_ctrl:json_end]"
+
HFTEST_ENABLE();
static struct hftest_test hftest_constructed[HFTEST_MAX_TESTS];
@@ -69,6 +72,9 @@
size_t i;
size_t tests_in_suite = 0;
+ /* Wrap the JSON in tags for the hftest script to use. */
+ HFTEST_LOG(HFTEST_CTRL_JSON_START);
+
HFTEST_LOG("{");
HFTEST_LOG(" \"suites\": [");
for (i = 0; i < hftest_count; ++i) {
@@ -123,6 +129,9 @@
}
HFTEST_LOG(" ]");
HFTEST_LOG("}");
+
+ /* Wrap the JSON in tags for the hftest script to use. */
+ HFTEST_LOG(HFTEST_CTRL_JSON_END);
}
/**
diff --git a/test/hftest/hftest.py b/test/hftest/hftest.py
index 4a44e2f..cf24a94 100755
--- a/test/hftest/hftest.py
+++ b/test/hftest/hftest.py
@@ -35,6 +35,9 @@
HFTEST_LOG_FAILURE_PREFIX = "Failure:"
HFTEST_LOG_FINISHED = "FINISHED"
+HFTEST_CTRL_JSON_START = "[hftest_ctrl:json_start]"
+HFTEST_CTRL_JSON_END = "[hftest_ctrl:json_end]"
+
HFTEST_CTRL_GET_COMMAND_LINE = "[hftest_ctrl:get_command_line]"
HFTEST_CTRL_FINISHED = "[hftest_ctrl:finished]"
@@ -792,7 +795,10 @@
"""Invoke the test platform and request a JSON of available test and
test suites."""
out = self.driver.run("json", "json", self.force_long_running)
- hf_out = "\n".join(self.extract_hftest_lines(out))
+ hf_out = self.extract_hftest_lines(out)
+ hf_out = hf_out[hf_out.index(HFTEST_CTRL_JSON_START) + 1
+ :hf_out.index(HFTEST_CTRL_JSON_END)];
+ hf_out = "\n".join(hf_out)
try:
return json.loads(hf_out)
except ValueError as e: