• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import argparse
4import difflib
5import errno
6import os
7import pathlib
8import subprocess
9import sys
10import tempfile
11
12# The meson version handles windows paths better, but if it's not available
13# fall back to shlex
14try:
15    from meson.mesonlib import split_args
16except ImportError:
17    from shlex import split as split_args
18
19parser = argparse.ArgumentParser()
20parser.add_argument('--i965_asm',
21                    help='path to i965_asm binary')
22parser.add_argument('--gen_name',
23                    help='name of the hardware generation (as understood by i965_asm)')
24parser.add_argument('--gen_folder',
25                    type=pathlib.Path,
26                    help='name of the folder for the generation')
27args = parser.parse_args()
28
29wrapper = os.environ.get('MESON_EXE_WRAPPER')
30if wrapper is not None:
31    i965_asm = split_args(wrapper) + [args.i965_asm]
32else:
33    i965_asm = [args.i965_asm]
34
35success = True
36
37for asm_file in args.gen_folder.glob('*.asm'):
38    expected_file = asm_file.stem + '.expected'
39    expected_path = args.gen_folder / expected_file
40    out_path = tempfile.NamedTemporaryFile()
41
42    try:
43        command = i965_asm + [
44            '--type', 'hex',
45            '--gen', args.gen_name,
46            '--output', out_path.name,
47            asm_file
48        ]
49        subprocess.run(command,
50                       stdout=subprocess.DEVNULL,
51                       stderr=subprocess.STDOUT)
52    except OSError as e:
53        if e.errno == errno.ENOEXEC:
54            print('Skipping due to inability to run host binaries.',
55                  file=sys.stderr)
56            exit(77)
57        raise
58
59    with expected_path.open() as f:
60        lines_before = f.readlines()
61    lines_after = [line.decode('ascii') for line in out_path]
62
63    diff = ''.join(difflib.unified_diff(lines_before, lines_after,
64                                        expected_file, asm_file.stem + '.out'))
65
66    if diff:
67        print('Output comparison for {}:'.format(asm_file.name))
68        print(diff)
69        success = False
70    else:
71        print('{} : PASS'.format(asm_file.name))
72
73if not success:
74    exit(1)
75