intel/tools: rewrite run-test.sh in python
authorEric Engestrom <eric@engestrom.ch>
Wed, 31 Jul 2019 11:19:55 +0000 (12:19 +0100)
committerMarge Bot <eric+marge@anholt.net>
Sat, 13 Jun 2020 20:32:08 +0000 (20:32 +0000)
Old script created files in the source directory, which is generally
considered bad form.

The rewrite to python instead of duct-taping around in the shell script
goes towards the goal of only having cross-platform python scripts,
which is also harder to make mistakes in than shell scripts.

Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5155>

src/intel/tools/meson.build
src/intel/tools/tests/run-test.py [new file with mode: 0755]
src/intel/tools/tests/run-test.sh [deleted file]

index dbbac798ad35d5cb39cdf4d0e4ab4ad2d0958971..d83812bab08bd9cb3a75e06a77826eb6b8a2e880 100644 (file)
@@ -190,22 +190,29 @@ i965_asm = executable(
 )
 
 asm_testcases = [
-  ['brw', 'tests/gen4'],
-  ['g4x', 'tests/gen4.5'],
-  ['ilk', 'tests/gen5'],
-  ['snb', 'tests/gen6'],
-  ['ivb', 'tests/gen7'],
-  ['hsw', 'tests/gen7.5'],
-  ['bdw', 'tests/gen8'],
-  ['skl', 'tests/gen9'],
-  ['icl', 'tests/gen11'],
+  ['brw', 'gen4'],
+  ['g4x', 'gen4.5'],
+  ['ilk', 'gen5'],
+  ['snb', 'gen6'],
+  ['ivb', 'gen7'],
+  ['hsw', 'gen7.5'],
+  ['bdw', 'gen8'],
+  ['skl', 'gen9'],
+  ['icl', 'gen11'],
 ]
 
-test_runner = find_program('tests/run-test.sh')
+test_runner = find_program('tests/run-test.py')
 foreach testcase : asm_testcases
+  _gen_name = testcase[0]
+  _gen_num = testcase[1]
+  _gen_folder = join_paths(meson.current_source_dir(), 'tests', _gen_num)
   test(
-    'i965_asm : ' + testcase[1], test_runner,
-    args : [i965_asm, testcase[1], testcase[0]],
-    env : ['srcdir=' + meson.current_source_dir()]
+    'i965_asm : ' + _gen_num, test_runner,
+    args : [
+      '--i965_asm', i965_asm,
+      '--gen_name', _gen_name,
+      '--gen_folder', _gen_folder,
+    ],
+    suite : 'intel',
   )
 endforeach
diff --git a/src/intel/tools/tests/run-test.py b/src/intel/tools/tests/run-test.py
new file mode 100755 (executable)
index 0000000..2d1c1a5
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import argparse
+import difflib
+import pathlib
+import subprocess
+import tempfile
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--i965_asm',
+                    help='path to i965_asm binary')
+parser.add_argument('--gen_name',
+                    help='name of the hardware generation (as understood by i965_asm)')
+parser.add_argument('--gen_folder',
+                    type=pathlib.Path,
+                    help='name of the folder for the generation')
+args = parser.parse_args()
+
+success = True
+
+for asm_file in args.gen_folder.glob('*.asm'):
+    expected_file = asm_file.stem + '.expected'
+    expected_path = args.gen_folder / expected_file
+    out_path = tempfile.NamedTemporaryFile()
+
+    subprocess.run([args.i965_asm,
+                    '--type', 'hex',
+                    '--gen', args.gen_name,
+                    '--output', out_path.name,
+                    asm_file],
+                   stdout=subprocess.DEVNULL,
+                   stderr=subprocess.STDOUT)
+
+    with expected_path.open() as f:
+        lines_before = f.readlines()
+    lines_after = [line.decode('ascii') for line in out_path]
+
+    diff = ''.join(difflib.unified_diff(lines_before, lines_after,
+                                        expected_file, asm_file.stem + '.out'))
+
+    if diff:
+        print('Output comparison for {}:'.format(asm_file.name))
+        print(diff)
+        success = False
+    else:
+        print('{} : PASS'.format(asm_file.name))
+
+if not success:
+    exit(1)
diff --git a/src/intel/tools/tests/run-test.sh b/src/intel/tools/tests/run-test.sh
deleted file mode 100644 (file)
index c3a7336..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-
-SRCDIR="${srcdir}"
-I965_ASM="$1"
-
-test="TEST"
-
-if [ -n "$2" ] ; then
-   test="$2"
-fi
-
-if [ -n "$3" ] ; then
-   gen="$3"
-fi
-
-for file in ${SRCDIR}/${test}/*.asm; do
-   if [ -f "$file" ]; then
-      filename="${file%.*}"
-      "${I965_ASM}" -t hex -g ${gen} -o "${file}.out" "${file}"
-      if cmp "${file}.out" "${filename}.expected" 2> /dev/null; then
-         echo "${file} : PASS"
-      else
-         echo "Output comparison for ${file}"
-         diff -u "${filename}.expected" "${file}.out"
-      fi
-   fi
-done