diff options
author | Sebastian Neubauer <Sebastian.Neubauer@amd.com> | 2021-09-21 16:31:00 +0200 |
---|---|---|
committer | Sebastian Neubauer <Sebastian.Neubauer@amd.com> | 2021-09-22 10:10:35 +0200 |
commit | ecd5145c27e819f95036cc0be8f22ce174f19238 (patch) | |
tree | 015f870700041b969cbefb60f26e8eac421b11e4 /llvm/utils/UpdateTestChecks/common.py | |
parent | 7ce638538bcf323cd15ed5dfbc43013312b0e3e3 (diff) | |
download | llvm-ecd5145c27e819f95036cc0be8f22ce174f19238.zip llvm-ecd5145c27e819f95036cc0be8f22ce174f19238.tar.gz llvm-ecd5145c27e819f95036cc0be8f22ce174f19238.tar.bz2 |
[Utils] Replace llc with cat for tests
Make the update_llc_test_checks script test independant of llc behavior
by using cat with static files to simulate llc output.
This allows changing llc without breaking the script test case.
The update script is executed in a temporary directory, so the
llc-generated assembly files are copied there. %T is deprecated, but it
allows copying a file with a predictable filename.
Differential Revision: https://reviews.llvm.org/D110143
Diffstat (limited to 'llvm/utils/UpdateTestChecks/common.py')
-rw-r--r-- | llvm/utils/UpdateTestChecks/common.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py index bc4b0738..3bc9089 100644 --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -147,16 +147,31 @@ def should_add_line_to_output(input_line, prefix_set, skip_global_checks = False return True +# Perform lit-like substitutions +def getSubstitutions(sourcepath): + sourcedir = os.path.dirname(sourcepath) + return [('%s', sourcepath), + ('%S', sourcedir), + ('%p', sourcedir), + ('%{pathsep}', os.pathsep)] + +def applySubstitutions(s, substitutions): + for a,b in substitutions: + s = s.replace(a, b) + return s + # Invoke the tool that is being tested. def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False): with open(ir) as ir_file: + substitutions = getSubstitutions(ir) + # TODO Remove the str form which is used by update_test_checks.py and # update_llc_test_checks.py # The safer list form is used by update_cc_test_checks.py if preprocess_cmd: # Allow pre-processing the IR file (e.g. using sed): assert isinstance(preprocess_cmd, str) # TODO: use a list instead of using shell - preprocess_cmd = preprocess_cmd.replace('%s', ir).strip() + preprocess_cmd = applySubstitutions(preprocess_cmd, substitutions).strip() if verbose: print('Pre-processing input file: ', ir, " with command '", preprocess_cmd, "'", sep="", file=sys.stderr) @@ -165,10 +180,12 @@ def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False): pp = subprocess.Popen(preprocess_cmd, shell=True, stdin=devnull, stdout=subprocess.PIPE) ir_file = pp.stdout + if isinstance(cmd_args, list): - stdout = subprocess.check_output([exe] + cmd_args, stdin=ir_file) + args = [applySubstitutions(a, substitutions) for a in cmd_args] + stdout = subprocess.check_output([exe] + args, stdin=ir_file) else: - stdout = subprocess.check_output(exe + ' ' + cmd_args, + stdout = subprocess.check_output(exe + ' ' + applySubstitutions(cmd_args, substitutions), shell=True, stdin=ir_file) if sys.version_info[0] > 2: stdout = stdout.decode() |