From e8bba312cc4fa9765b5cdf494d13b0f58974d7d5 Mon Sep 17 00:00:00 2001 From: "Matt McCutchen (Correct Computation)" Date: Fri, 11 Dec 2020 11:38:57 -0500 Subject: [PATCH 1/2] Usability improvements to 3C regression test updating programs. - Make directly executable (on Linux at least). - Chdir to the containing directory if needed. - Search for `3c` via $LLVM_OBJ, the standard build directory location, and $PATH (in that order) rather than requiring the user to modify an absolute path hard-coded in the program. --- clang/test/3C/find_bin.py | 35 ++++++++++++++++++++++++++++++++++ clang/test/3C/processor.py | 8 +++++--- clang/test/3C/test_updater.py | 8 +++++--- clang/test/3C/testgenerator.py | 19 +++++++++--------- 4 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 clang/test/3C/find_bin.py mode change 100644 => 100755 clang/test/3C/processor.py mode change 100644 => 100755 clang/test/3C/test_updater.py mode change 100644 => 100755 clang/test/3C/testgenerator.py diff --git a/clang/test/3C/find_bin.py b/clang/test/3C/find_bin.py new file mode 100644 index 000000000000..b3a1be3eceae --- /dev/null +++ b/clang/test/3C/find_bin.py @@ -0,0 +1,35 @@ +# Set bin_path to the path that should be prepended to '3c', etc. to run them. +# bin_path will be empty (so $PATH is used) or have a trailing slash. +# +# TODO: Do we have other tools that should use this? + +import sys +import os +os.chdir(os.path.dirname(__file__)) +# Relative paths are now relative to clang/test/3C/ . + +sys.path.insert(0, '../../../llvm/utils/lit') +import lit.util +sys.path.pop(0) + +def die(msg): + sys.stderr.write('Error: %s\n' % msg) + sys.exit(1) + +llvm_obj_maybe = os.environ.get('LLVM_OBJ') +standard_build_dir = '../../../build' +if llvm_obj_maybe is not None: + bin_path = llvm_obj_maybe + '/bin/' + if not os.path.isfile(bin_path + '3c'): + die('$LLVM_OBJ is set but the bin directory does not contain 3c.') +elif os.path.isdir(standard_build_dir): + bin_path = standard_build_dir + '/bin/' + if not os.path.isfile(bin_path + '3c'): + die('The standard build directory exists but does not contain 3c.') +elif lit.util.which('3c') is not None: + # TODO: To help prevent mistakes, validate that the `3c` we found is under a + # build directory linked to the current source tree? Or might users want to + # do unusual things? + bin_path = '' +else: + die('Could not find 3c via $LLVM_OBJ, the standard build directory, or $PATH.') diff --git a/clang/test/3C/processor.py b/clang/test/3C/processor.py old mode 100644 new mode 100755 index 167c80333e31..360f213c4698 --- a/clang/test/3C/processor.py +++ b/clang/test/3C/processor.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python import fileinput import sys import os -path_to_monorepo = "/Users/shilpa-roy/checkedc-clang/build/bin/" +import find_bin +bin_path = find_bin.bin_path structs = """ struct np { @@ -134,8 +136,8 @@ def process_smart(filename): file.write('\n\n'.join(test)) file.close() - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(path_to_monorepo, filename)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(path_to_monorepo, filename)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(bin_path, filename)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(bin_path, filename)) process_file_smart(filename, cnameNOALL, cnameALL) return diff --git a/clang/test/3C/test_updater.py b/clang/test/3C/test_updater.py old mode 100644 new mode 100755 index 5aa96a64db20..77ff1a753aa2 --- a/clang/test/3C/test_updater.py +++ b/clang/test/3C/test_updater.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python import fileinput import sys import os -path_to_monorepo = "/Users/shilpa-roy/checkedc-clang/build/bin/" +import find_bin +bin_path = find_bin.bin_path structs = """ struct np { @@ -82,8 +84,8 @@ def process_smart(filename, diff): cnameNOALL = filename + "heckedNOALL.c" cnameALL = filename + "heckedALL.c" - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(path_to_monorepo, filename)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(path_to_monorepo, filename)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(bin_path, filename)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(bin_path, filename)) process_file_smart(filename, cnameNOALL, cnameALL, diff) return diff --git a/clang/test/3C/testgenerator.py b/clang/test/3C/testgenerator.py old mode 100644 new mode 100755 index 10be2793d09c..f88409c92e4a --- a/clang/test/3C/testgenerator.py +++ b/clang/test/3C/testgenerator.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # Author: Shilpa Roy # Last updated: June 16, 2020 @@ -5,10 +6,8 @@ import os import subprocess -#### USERS PUT YOUR INFO HERE ##### - -# Please remember to add a '/' at the very end! -path_to_monorepo = "/Users/shilpa-roy/checkedc/checkedc-clang/build/bin/" +import find_bin +bin_path = find_bin.bin_path @@ -726,23 +725,23 @@ def annot_gen_smart(prefix, proto, suffix): # run the porting tool on the file(s) if proto=="multi": - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {} {}".format(path_to_monorepo, name, name2)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {} {}".format(path_to_monorepo, name, name2)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {} {}".format(bin_path, name, name2)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {} {}".format(bin_path, name, name2)) else: - os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(path_to_monorepo, name)) - os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(path_to_monorepo, name)) + os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(bin_path, name)) + os.system("{}3c -addcr -output-postfix=checkedNOALL {}".format(bin_path, name)) # compile the files and if it doesn't compile, then let's indicate that a bug was generated for this file bug_generated = False if proto != "multi": - out = subprocess.Popen(['{}clang'.format(path_to_monorepo), '-c', cnameNOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + out = subprocess.Popen(['{}clang'.format(bin_path), '-c', cnameNOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() stdout = str(stdout) if "error:" in stdout: bug_generated = True # name = prefix + proto + suffix + "_BUG.c" else: - out = subprocess.Popen(['{}clang'.format(path_to_monorepo), '-c', cnameNOALL, cname2NOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + out = subprocess.Popen(['{}clang'.format(bin_path), '-c', cnameNOALL, cname2NOALL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() stdout = str(stdout) if "error:" in stdout: From 2e1bde3126079c95c421fd0c2c08f539b17639e5 Mon Sep 17 00:00:00 2001 From: "Matt McCutchen (Correct Computation)" Date: Thu, 10 Dec 2020 21:12:25 -0500 Subject: [PATCH 2/2] processor.py: Include a trailing newline when writing each test file. This is consistent with our prior cleanup in 8878fe56994102f94b1e6d32e7996fc163b2eb56. --- clang/test/3C/processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/3C/processor.py b/clang/test/3C/processor.py index 360f213c4698..ef00b8189c75 100755 --- a/clang/test/3C/processor.py +++ b/clang/test/3C/processor.py @@ -133,7 +133,7 @@ def process_smart(filename): elif susproto != "": test = [header, susproto, foo, bar, sus] file = open(filename, "w+") - file.write('\n\n'.join(test)) + file.write('\n\n'.join(test) + '\n') file.close() os.system("{}3c -alltypes -addcr -output-postfix=checkedALL {}".format(bin_path, filename))