Test cases now work when the builddir is not the srcdir.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 2 Sep 2010 20:56:44 +0000 (16:56 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 2 Sep 2010 20:56:44 +0000 (16:56 -0400)
test/Makefile.am
test/run-testcase.py

index 0dc11d02b666e7a9c2ba5936f7da0cf85488141a..ba7b3dbef04ced35adfbaa22c809ae82dd87b564 100644 (file)
@@ -1,6 +1,6 @@
 if HAVE_PYTHON
 TESTS_ENVIRONMENT = $(PYTHON) $(srcdir)/run-testcase.py --with-gcc=$(CC) \
        --with-ia-lib-dir=$(top_builddir)/src/.libs \
-       --with-ia-src-dir=$(top_srcdir)
+       --with-ia-src-dir=$(top_srcdir) --with-tests-dir=$(srcdir)
 TESTS = int-types.xml
 endif
index da54918e22b6db6c7f039d4bf32ae0eef9f1909e..85d939f7be37a1b97e763edd5cab1173fbb9c3c3 100755 (executable)
@@ -16,6 +16,7 @@ from xml.sax.handler import feature_namespaces
 gcc_path = 'gcc'
 gcc_interaspect_lib = None
 gcc_interaspect_src = None
+tests_dir = None
 verbose = False
 
 # Note that \ _must_ be first in this list, or else \s added for the
@@ -230,6 +231,14 @@ class TestcaseHandler(handler.ContentHandler):
 
         self.current_cdata += chars
 
+# If the tests_dir is set, prepend the tests_dir directory to the name
+# of the source file.
+def formatSourceFile(source_file):
+    if (tests_dir is not None):
+        return '{0:s}/{1:s}'.format(tests_dir, source_file)
+    else:
+        return source_file
+
 # Run GCC with the given arguments.  On failure, print an appropriate
 # error and return False.
 # If the compile fails because of an error in the C file, runGCC also
@@ -280,7 +289,7 @@ def compilePlugin(working_dir, plugin_id, plugin_base_name, plugin_source):
     plugin_lib_name = '{0:s}/{1:s}.so.1.0.0'.format(working_dir,
                                                     plugin_base_name)
 
-
+    plugin_source = formatSourceFile(plugin_source)
     include_flag = '-I{0:s}/src'.format(gcc_interaspect_src)
     cmd_args = ['-Wall', '-Werror', include_flag, '-fPIC', '-shared',
                 '-Wl,-soname,{0:s}.so.1'.format(plugin_base_name), '-o',
@@ -314,6 +323,7 @@ def compilePlugin(working_dir, plugin_id, plugin_base_name, plugin_source):
 # executable (which will be in working_dir).  On failure, the return
 # value is None.
 def compileTestcase(working_dir, target_source, hooks_source, plugin_libs):
+    hooks_source = formatSourceFile(hooks_source)
     test_include = '-I{0:s}/test'.format(gcc_interaspect_src)
     hook_o_file = working_dir + '/hooks.o'
     cmd_args = ['-Wall', '-Werror', test_include, '-c', '-o', hook_o_file,
@@ -331,6 +341,7 @@ def compileTestcase(working_dir, target_source, hooks_source, plugin_libs):
         return None
 
     # Compile the target itself.
+    target_source = formatSourceFile(target_source)
     target_o_file = working_dir + '/target.o'
     cmd_args = ['-fplugin={0:s}'.format(lib) for lib in plugin_libs]
     cmd_args += ['-Wall', '-Werror', '-c', '-o', target_o_file, target_source]
@@ -433,6 +444,7 @@ Options
   --with-gcc: Path to gcc to compile the tests with
   --with-ia-lib-dir: Directory with InterAspect library file
   --with-ia-src-dir: Directory with InterAspect source
+  --with-tests-dir: Directory with test C files (. by default)
 """)
     # End function usage()
 
@@ -452,7 +464,7 @@ if __name__ == '__main__':
     # Deal with command line arguments
     try:
         long_switches = ["verbose", "with-gcc=", "with-ia-lib-dir=",
-                         "with-ia-src-dir="]
+                         "with-ia-src-dir=", "with-tests-dir="]
         opts, args = getopt.gnu_getopt(sys.argv[1:], "v", long_switches)
     except getopt.GetoptError:
         usage()
@@ -465,6 +477,8 @@ if __name__ == '__main__':
             gcc_interaspect_lib = arg + '/libinteraspect.a'
         elif (opt == "--with-ia-src-dir"):
             gcc_interaspect_src = arg
+        elif (opt == "--with-tests-dir"):
+            tests_dir = arg
         elif (opt == "--verbose" or opt == "-v"):
             verbose = True
         else: