tracie: Print results in a machine readable format
authorRohan Garg <rohan.garg@collabora.com>
Wed, 1 Apr 2020 16:06:49 +0000 (18:06 +0200)
committerRohan Garg <rohan@garg.io>
Tue, 7 Apr 2020 18:21:32 +0000 (18:21 +0000)
Signed-off-by: Rohan Garg <rohan.garg@collabora.com>
Reviewed-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4435>

.gitlab-ci/tracie/tests/test.sh
.gitlab-ci/tracie/tracie.py

index cd0f08e4efdb79ce88ead3be20a2a04fb33cfea5..5030e31e0496b2f70c18c8bb83987242a3354c6b 100755 (executable)
@@ -56,9 +56,24 @@ run_test() {
     cleanup
 }
 
+assert_results_yaml_contains() {
+    grep -q "actual: $1" $4
+    assert "[ $? = 0 ]"
+
+    grep -q "expected: $2" $4
+    assert "[ $? = 0 ]"
+
+    if [ $3 != "" ]; then
+        grep -q $3 $4
+    fi
+
+    assert "[ $? = 0 ]"
+}
+
 tracie_succeeds_if_all_images_match() {
     run_tracie
     assert "[ $? = 0 ]"
+    assert_results_yaml_contains 5efda83854befe0155ff8517a58d5b51 5efda83854befe0155ff8517a58d5b51 "" "$PWD/results/results.yml"
 }
 
 tracie_fails_on_image_mismatch() {
@@ -67,6 +82,7 @@ tracie_fails_on_image_mismatch() {
 
     run_tracie
     assert "[ $? != 0 ]"
+    assert_results_yaml_contains 5efda83854befe0155ff8517a58d5b51 8e0a801367e1714463475a824dab363b "trace2/test/vk-test-device/olive.testtrace-0.png" "$PWD/results/results.yml"
 }
 
 tracie_skips_traces_without_checksum() {
index efedcbc4880fd616ec9374758192ffa57280223a..7ed54cb179e88f0f26b6d5a29b1779db53e713ea 100644 (file)
@@ -112,6 +112,9 @@ def ensure_trace(repo_url, repo_commit, trace):
 def check_trace(repo_url, repo_commit, device_name, trace, expectation):
     ensure_trace(repo_url, repo_commit, trace)
 
+    result = {}
+    result[trace['path']] = {}
+
     trace_path = Path(TRACES_DB_PATH + trace['path'])
     checksum, image_file, log_file = replay(trace_path, device_name)
     if checksum is None:
@@ -127,13 +130,19 @@ def check_trace(repo_url, repo_commit, device_name, trace, expectation):
             ok = False
 
     trace_dir = os.path.split(trace['path'])[0]
-    results_path = os.path.join(RESULTS_PATH, trace_dir, "test", device_name)
+    dir_in_results = os.path.join(trace_dir, "test", device_name)
+    results_path = os.path.join(RESULTS_PATH, dir_in_results)
     os.makedirs(results_path, exist_ok=True)
     shutil.move(log_file, os.path.join(results_path, os.path.split(log_file)[1]))
     if not ok or os.environ.get('TRACIE_STORE_IMAGES', '0') == '1':
-            shutil.move(image_file, os.path.join(results_path, os.path.split(image_file)[1]))
+        image_name = os.path.split(image_file)[1]
+        shutil.move(image_file, os.path.join(results_path, image_name))
+        result[trace['path']]['image'] = os.path.join(dir_in_results, image_name)
+
+    result[trace['path']]['expected'] = expectation['checksum']
+    result[trace['path']]['actual'] = checksum
 
-    return ok
+    return ok, result
 
 def main():
     parser = argparse.ArgumentParser()
@@ -156,11 +165,17 @@ def main():
 
     traces = y['traces']
     all_ok = True
+    results = {}
     for trace in traces:
         for expectation in trace['expectations']:
-                if expectation['device'] == args.device_name:
-                        ok = check_trace(repo, commit_id, args.device_name, trace, expectation)
-                        all_ok = all_ok and ok
+            if expectation['device'] == args.device_name:
+                ok, result = check_trace(repo, commit_id, args.device_name, trace, expectation)
+                all_ok = all_ok and ok
+                results.update(result)
+
+    with open(os.path.join(RESULTS_PATH, 'results.yml'), 'w') as f:
+        yaml.safe_dump(results, f, default_flow_style=False)
+
 
     sys.exit(0 if all_ok else 1)