summaryrefslogtreecommitdiff
path: root/runner/resultgen.c
diff options
context:
space:
mode:
authorPetri Latvala <petri.latvala@intel.com>2019-12-17 11:47:56 +0200
committerPetri Latvala <petri.latvala@intel.com>2020-01-03 12:28:05 +0200
commitdde11cefbf7d7b40d6d084d6de4acd8f7236b148 (patch)
treebcebf8112d473dc25bc1b8525478cafc7ca9defb /runner/resultgen.c
parent1e438b203d0c688ff09ac601af43024a491cd69a (diff)
runner/resultgen: Make subtest result line finding more robust
On an assertion failure, the string "Subtest xyz failed" is printed. Make sure we don't match that for SUBTEST_RESULT, or the equivalent for dynamic subtests. Parsing the results already explicitly searched for the proper result line, the difference is when we delimit output up to "the next line of interest". Signed-off-by: Petri Latvala <petri.latvala@intel.com> Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Diffstat (limited to 'runner/resultgen.c')
-rw-r--r--runner/resultgen.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/runner/resultgen.c b/runner/resultgen.c
index 8cd1aa49..f93a673c 100644
--- a/runner/resultgen.c
+++ b/runner/resultgen.c
@@ -367,6 +367,39 @@ static struct matches find_matches(const char *buf, const char *bufend,
return ret;
}
+static bool valid_char_for_subtest_name(char x)
+{
+ return x == '-' || x == '_' || isalnum(x);
+}
+
+static bool is_subtest_result_line(const char *needle, const char *line, const char *bufend)
+{
+ line += strlen(needle);
+
+ /*
+ * At this point of the string we're expecting:
+ * - The subtest name (one or more of a-z, A-Z, 0-9, '-' and '_')
+ * - The characters ':' and ' '
+ *
+ * If we find all those, allow parsing this line as [dynamic]
+ * subtest result.
+ */
+
+ if (!valid_char_for_subtest_name(*line))
+ return false;
+
+ while (line < bufend && valid_char_for_subtest_name(*line))
+ line++;
+
+ if (line >= bufend || *line++ != ':')
+ return false;
+
+ if (line >= bufend || *line++ != ' ')
+ return false;
+
+ return true;
+}
+
static void free_matches(struct matches *matches)
{
free(matches->items);
@@ -605,9 +638,9 @@ static bool fill_from_output(int fd, const char *binary, const char *key,
struct json_object *current_test = NULL;
struct match_needle needles[] = {
{ STARTING_SUBTEST, NULL },
- { SUBTEST_RESULT, NULL },
+ { SUBTEST_RESULT, is_subtest_result_line },
{ STARTING_DYNAMIC_SUBTEST, NULL },
- { DYNAMIC_SUBTEST_RESULT, NULL },
+ { DYNAMIC_SUBTEST_RESULT, is_subtest_result_line },
{ NULL, NULL },
};
struct matches matches = {};
@@ -1126,9 +1159,9 @@ static bool stderr_contains_warnings(const char *beg, const char *end)
{
struct match_needle needles[] = {
{ STARTING_SUBTEST, NULL },
- { SUBTEST_RESULT, NULL },
+ { SUBTEST_RESULT, is_subtest_result_line },
{ STARTING_DYNAMIC_SUBTEST, NULL },
- { DYNAMIC_SUBTEST_RESULT, NULL },
+ { DYNAMIC_SUBTEST_RESULT, is_subtest_result_line },
{ NULL, NULL },
};
struct matches matches;