[igt-dev] [PATCH i-g-t 2/2] runner/resultgen: Implement the totals field

Petri Latvala petri.latvala at intel.com
Thu Aug 16 11:14:16 UTC 2018


The totals field in the results json lists the total amount of
particular test results, both overall and by binary.

Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---
 runner/resultgen.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 86 insertions(+), 4 deletions(-)

diff --git a/runner/resultgen.c b/runner/resultgen.c
index 81e4fbda..7ac2c8d3 100644
--- a/runner/resultgen.c
+++ b/runner/resultgen.c
@@ -850,9 +850,89 @@ static void override_results(char *binary,
 	}
 }
 
+static struct json_object *get_totals_object(struct json_object *totals,
+					     const char *key)
+{
+	struct json_object *obj = NULL;
+
+	if (json_object_object_get_ex(totals, key, &obj))
+		return obj;
+
+	obj = json_object_new_object();
+	json_object_object_add(totals, key, obj);
+
+	json_object_object_add(obj, "crash", json_object_new_int(0));
+	json_object_object_add(obj, "pass", json_object_new_int(0));
+	json_object_object_add(obj, "dmesg-fail", json_object_new_int(0));
+	json_object_object_add(obj, "dmesg-warn", json_object_new_int(0));
+	json_object_object_add(obj, "skip", json_object_new_int(0));
+	json_object_object_add(obj, "incomplete", json_object_new_int(0));
+	json_object_object_add(obj, "timeout", json_object_new_int(0));
+	json_object_object_add(obj, "notrun", json_object_new_int(0));
+	json_object_object_add(obj, "fail", json_object_new_int(0));
+	json_object_object_add(obj, "warn", json_object_new_int(0));
+
+	return obj;
+}
+
+static void add_result_to_totals(struct json_object *totals,
+				 const char *result)
+{
+	json_object *numobj = NULL;
+	int old;
+
+	if (!json_object_object_get_ex(totals, result, &numobj)) {
+		fprintf(stderr, "Warning: Totals object without count for %s\n", result);
+		return;
+	}
+
+	old = json_object_get_int(numobj);
+	json_object_object_add(totals, result, json_object_new_int(old + 1));
+}
+
+static void add_to_totals(char *binary,
+			  struct subtests *subtests,
+			  struct json_object *tests,
+			  struct json_object *totals)
+{
+	struct json_object *test, *resultobj, *roottotal, *binarytotal;
+	char piglit_name[256];
+	const char *result;
+	size_t i;
+
+	generate_piglit_name(binary, NULL, piglit_name, sizeof(piglit_name));
+	roottotal = get_totals_object(totals, "");
+	binarytotal = get_totals_object(totals, piglit_name);
+
+	if (subtests->size == 0) {
+		test = get_or_create_json_object(tests, piglit_name);
+		if (!json_object_object_get_ex(test, "result", &resultobj)) {
+			fprintf(stderr, "Warning: No results set for %s\n", piglit_name);
+			return;
+		}
+		result = json_object_get_string(resultobj);
+		add_result_to_totals(roottotal, result);
+		add_result_to_totals(binarytotal, result);
+		return;
+	}
+
+	for (i = 0; i < subtests->size; i++) {
+		generate_piglit_name(binary, subtests->names[i], piglit_name, sizeof(piglit_name));
+		test = get_or_create_json_object(tests, piglit_name);
+		if (!json_object_object_get_ex(test, "result", &resultobj)) {
+			fprintf(stderr, "Warning: No results set for %s\n", piglit_name);
+			return;
+		}
+		result = json_object_get_string(resultobj);
+		add_result_to_totals(roottotal, result);
+		add_result_to_totals(binarytotal, result);
+	}
+}
+
 static bool parse_test_directory(int dirfd,
 				 struct job_list_entry *entry,
-				 struct json_object *tests)
+				 struct json_object *tests,
+				 struct json_object *totals)
 {
 	int fds[_F_LAST];
 	struct subtests subtests = {};
@@ -876,6 +956,7 @@ static bool parse_test_directory(int dirfd,
 	}
 
 	override_results(entry->binary, &subtests, tests);
+	add_to_totals(entry->binary, &subtests, tests, totals);
 
 	close_outputs(fds);
 
@@ -886,7 +967,7 @@ bool generate_results(int dirfd)
 {
 	struct settings settings;
 	struct job_list job_list;
-	struct json_object *obj, *tests;
+	struct json_object *obj, *tests, *totals;
 	int resultsfd, testdirfd, unamefd;
 	const char *json_string;
 	size_t i;
@@ -942,11 +1023,12 @@ bool generate_results(int dirfd)
 	 * - lspci
 	 * - options
 	 * - time_elapsed
-	 * - totals
 	 */
 
 	tests = json_object_new_object();
 	json_object_object_add(obj, "tests", tests);
+	totals = json_object_new_object();
+	json_object_object_add(obj, "totals", totals);
 
 	for (i = 0; i < job_list.size; i++) {
 		char name[16];
@@ -957,7 +1039,7 @@ bool generate_results(int dirfd)
 			break;
 		}
 
-		if (!parse_test_directory(testdirfd, &job_list.entries[i], tests)) {
+		if (!parse_test_directory(testdirfd, &job_list.entries[i], tests, totals)) {
 			close(resultsfd);
 			return false;
 		}
-- 
2.14.1



More information about the igt-dev mailing list