Added verbose mode to test case framework.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Tue, 30 Mar 2010 22:09:21 +0000 (18:09 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Tue, 30 Mar 2010 22:09:21 +0000 (18:09 -0400)
Verbose mode prints each GCC command that the framework executes.

test/run-testcase.py

index e0966f9a692fac81de76dc50bf8877cead9f9436..513829506803fca88e8c5aa2e2d7836493883b25 100755 (executable)
@@ -16,6 +16,16 @@ from xml.sax.handler import feature_namespaces
 gcc_path = 'gcc'
 gcc_interaspect_lib = None
 gcc_interaspect_src = None
+verbose = False
+
+# Note that \ _must_ be first in this list, or else \s added for the
+# purpose of escaping will themselves get escaped.
+BASH_ESCAPED_CHARS = """\ *~"&`$';!|#<>"""
+
+def escapeBashArg(arg):
+    for char in BASH_ESCAPED_CHARS:
+        arg = arg.replace(char, "\\" + char)
+    return arg
 
 # A whole host of specialized exceptions for things that can go
 # horribly wrong with the input XML test case.
@@ -395,6 +405,13 @@ def printHook(stream, hook):
 # If the compile fails because of an error in the C file, runGCC also
 # prints compile_fail_msg.
 def runGCC(args, compile_fail_msg):
+    # Print the GCC command before running it when verbose mode is on.
+    if verbose:
+        print escapeBashArg(gcc_path),
+        for arg in args:
+            print escapeBashArg(arg),
+        print
+
     args = [gcc_path] + args
     try:
         gcc_proc = subprocess.Popen(args, stderr = subprocess.PIPE)
@@ -559,8 +576,9 @@ def checkFileReadable(filename):
 if __name__ == '__main__':
     # Deal with command line arguments
     try:
-        long_switches = ["with-gcc=", "with-ia-lib-dir=", "with-ia-src-dir="]
-        opts, args = getopt.gnu_getopt(sys.argv[1:], "", long_switches)
+        long_switches = ["verbose", "with-gcc=", "with-ia-lib-dir=",
+                         "with-ia-src-dir="]
+        opts, args = getopt.gnu_getopt(sys.argv[1:], "v", long_switches)
     except getopt.GetoptError:
         usage()
         sys.exit(1)
@@ -572,6 +590,8 @@ if __name__ == '__main__':
             gcc_interaspect_lib = arg + '/libinteraspect.a'
         elif (opt == "--with-ia-src-dir"):
             gcc_interaspect_src = arg
+        elif (opt == "--verbose" or opt == "-v"):
+            verbose = True
         else:
             assert(1)