Mesa (master): intel/tools: rewrite run-test.sh in python
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Jun 13 20:43:36 UTC 2020
Module: Mesa
Branch: master
Commit: ccaa5b034f4845672e22c4bb990a8272a16da15e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ccaa5b034f4845672e22c4bb990a8272a16da15e
Author: Eric Engestrom <eric at engestrom.ch>
Date: Wed Jul 31 12:19:55 2019 +0100
intel/tools: rewrite run-test.sh in python
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 at engestrom.ch>
Reviewed-by: Sagar Ghuge <sagar.ghuge at intel.com>
Reviewed-by: Dylan Baker <dylan at pnwbakers.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5155>
---
src/intel/tools/meson.build | 33 +++++++++++++++-----------
src/intel/tools/tests/run-test.py | 49 +++++++++++++++++++++++++++++++++++++++
src/intel/tools/tests/run-test.sh | 27 ---------------------
3 files changed, 69 insertions(+), 40 deletions(-)
diff --git a/src/intel/tools/meson.build b/src/intel/tools/meson.build
index dbbac798ad3..d83812bab08 100644
--- a/src/intel/tools/meson.build
+++ b/src/intel/tools/meson.build
@@ -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
index 00000000000..2d1c1a596c1
--- /dev/null
+++ b/src/intel/tools/tests/run-test.py
@@ -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
index c3a733618d3..00000000000
--- a/src/intel/tools/tests/run-test.sh
+++ /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
More information about the mesa-commit
mailing list