[llvm-commits] [LNT] r154559 - in /lnt/trunk/tests: SharedInputs/FakeCompilers/ SharedInputs/FakeCompilers/README.txt SharedInputs/FakeCompilers/apple-clang-138.1 SharedInputs/FakeCompilers/clang-r154331 SharedInputs/FakeCompilers/fakecompiler.py SharedInputs/FakeCompilers/icc-12.1.3 lit.cfg testing/Compilers.py

Daniel Dunbar daniel at zuster.org
Wed Apr 11 16:15:17 PDT 2012


Author: ddunbar
Date: Wed Apr 11 18:15:17 2012
New Revision: 154559

URL: http://llvm.org/viewvc/llvm-project?rev=154559&view=rev
Log:
[tests] Add some minimal testing of the compiler sniffing in lnt.testing.utils.compilers.

Added:
    lnt/trunk/tests/SharedInputs/FakeCompilers/
    lnt/trunk/tests/SharedInputs/FakeCompilers/README.txt
    lnt/trunk/tests/SharedInputs/FakeCompilers/apple-clang-138.1   (with props)
    lnt/trunk/tests/SharedInputs/FakeCompilers/clang-r154331   (with props)
    lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py   (with props)
    lnt/trunk/tests/SharedInputs/FakeCompilers/icc-12.1.3   (with props)
    lnt/trunk/tests/testing/Compilers.py
Modified:
    lnt/trunk/tests/lit.cfg

Added: lnt/trunk/tests/SharedInputs/FakeCompilers/README.txt
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/FakeCompilers/README.txt?rev=154559&view=auto
==============================================================================
--- lnt/trunk/tests/SharedInputs/FakeCompilers/README.txt (added)
+++ lnt/trunk/tests/SharedInputs/FakeCompilers/README.txt Wed Apr 11 18:15:17 2012
@@ -0,0 +1,3 @@
+This directory contains some "fake" compilers, they just respond to arguments in
+a way to mimic what the actual compiler would do (for testing the
+lnt.testing.util.compilers module).

Added: lnt/trunk/tests/SharedInputs/FakeCompilers/apple-clang-138.1
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/FakeCompilers/apple-clang-138.1?rev=154559&view=auto
==============================================================================
--- lnt/trunk/tests/SharedInputs/FakeCompilers/apple-clang-138.1 (added)
+++ lnt/trunk/tests/SharedInputs/FakeCompilers/apple-clang-138.1 Wed Apr 11 18:15:17 2012
@@ -0,0 +1 @@
+link fakecompiler.py
\ No newline at end of file

Propchange: lnt/trunk/tests/SharedInputs/FakeCompilers/apple-clang-138.1
------------------------------------------------------------------------------
    svn:special = *

Added: lnt/trunk/tests/SharedInputs/FakeCompilers/clang-r154331
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/FakeCompilers/clang-r154331?rev=154559&view=auto
==============================================================================
--- lnt/trunk/tests/SharedInputs/FakeCompilers/clang-r154331 (added)
+++ lnt/trunk/tests/SharedInputs/FakeCompilers/clang-r154331 Wed Apr 11 18:15:17 2012
@@ -0,0 +1 @@
+link fakecompiler.py
\ No newline at end of file

Propchange: lnt/trunk/tests/SharedInputs/FakeCompilers/clang-r154331
------------------------------------------------------------------------------
    svn:special = *

Added: lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py?rev=154559&view=auto
==============================================================================
--- lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py (added)
+++ lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py Wed Apr 11 18:15:17 2012
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+
+"""
+Utilities for "faking" a compiler response.
+"""
+
+import inspect
+import os
+import sys
+
+from optparse import OptionParser, OptionGroup
+
+g_program = None
+
+class FakeCompiler(object):
+    compiler_name = None
+
+    def print_version(self):
+        raise NotImplementedError
+
+    def print_verbose_info(self):
+        raise NotImplementedError
+
+    def print_dumpmachine(self):
+        raise NotImplementedError
+
+    def print_llvm_target(self):
+        raise NotImplementedError
+
+    def print_as_version(self):
+        print >>sys.stderr, """(assembler version goes here)"""
+
+    def print_ld_version(self):
+        print >>sys.stderr, """(linker version goes here)"""
+    
+class ICCv12_1_3(FakeCompiler):
+    compiler_name = "icc-12.1.3"
+    def print_version(self):
+        print >>sys.stderr, """\
+icc version 12.1.3 (gcc version 4.2.1 compatibility)"""
+
+    def print_verbose_info(self):
+        print >>sys.stderr, """\
+icc: command line warning #10006: ignoring unknown option '-###'"""
+
+    def print_dumpmachine(self):
+        print """i686-apple-darwin11"""
+
+class LLVMCompiler(FakeCompiler):
+    def print_llvm_target(self):
+        print """\
+; ModuleID = '/dev/null'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
+f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-\
+n8:16:32:64"
+target triple = "x86_64-apple-darwin11.0.0"
+"""
+
+class Clang_r154331(LLVMCompiler):
+    compiler_name = "clang-r154331"
+
+    def print_verbose_info(self):
+        self.print_version()
+        print >>sys.stderr, """\
+ "%s" "-cc1" "-E" ... more boring stuff here ...""" % (
+            g_program,)
+
+    def print_version(self):
+        print >>sys.stderr, """\
+clang version 3.1 (trunk 154331) (llvm/trunk 154329)
+Target: x86_64-apple-darwin11.3.0
+Thread model: posix"""
+
+class AppleClang_138_1(LLVMCompiler):
+    compiler_name = "apple-clang-138.1"
+
+    def print_verbose_info(self):
+        self.print_version()
+        print >>sys.stderr, """\
+ "%s" "-cc1" "-E" ... more boring stuff here ...""" % (
+            g_program,)
+
+    def print_version(self):
+        print >>sys.stderr, """\
+Apple clang version 2.0 (tags/Apple/clang-138.1) (based on LLVM 2.9svn)
+Target: x86_64-apple-darwin11.3.0
+Thread model: posix"""
+
+fake_compilers = dict((value.compiler_name, value)
+                      for key,value in locals().items()
+                      if inspect.isclass(value) and \
+                          issubclass(value, FakeCompiler))
+
+def main():
+    global g_program
+    g_program = sys.argv[0]
+
+    compiler_name = os.path.basename(sys.argv[0])
+    compiler_class = fake_compilers.get(compiler_name)
+    if compiler_class is None:
+        raise SystemExit("unknown fake compiler %r" % (compiler_name,))
+
+    # Instantiate the compiler class.
+    compiler_instance = compiler_class()
+
+    # Pattern match on the arguments to determine what kind of response to fake.
+    args = tuple(sys.argv[1:])
+    if args == ('-v', '-E', '-x', 'c', '/dev/null', '-###'):
+        compiler_instance.print_verbose_info()
+    elif args == ('-v',):
+        compiler_instance.print_version()
+    elif args == ('-dumpmachine',):
+        compiler_instance.print_dumpmachine()
+    elif args == ('-c', '-Wa,-v', '-o', '/dev/null', '-x', 'assembler',
+                  '/dev/null'):
+        compiler_instance.print_as_version()
+    elif args == ('-S', '-flto', '-o', '-', '-x', 'c', '/dev/null'):
+        compiler_instance.print_llvm_target()
+    elif len(args) == 4 and \
+            args[0] == '-Wl,-v' and \
+            args[1] == '-o' and \
+            args[2] == '/dev/null':
+        compiler_instance.print_ld_version()
+    else:
+        raise SystemExit("unrecognized argument vector: %r" % (
+                args,))
+
+if __name__ == '__main__':
+    main()

Propchange: lnt/trunk/tests/SharedInputs/FakeCompilers/fakecompiler.py
------------------------------------------------------------------------------
    svn:executable = *

Added: lnt/trunk/tests/SharedInputs/FakeCompilers/icc-12.1.3
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/FakeCompilers/icc-12.1.3?rev=154559&view=auto
==============================================================================
--- lnt/trunk/tests/SharedInputs/FakeCompilers/icc-12.1.3 (added)
+++ lnt/trunk/tests/SharedInputs/FakeCompilers/icc-12.1.3 Wed Apr 11 18:15:17 2012
@@ -0,0 +1 @@
+link fakecompiler.py
\ No newline at end of file

Propchange: lnt/trunk/tests/SharedInputs/FakeCompilers/icc-12.1.3
------------------------------------------------------------------------------
    svn:special = *

Modified: lnt/trunk/tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lit.cfg?rev=154559&r1=154558&r2=154559&view=diff
==============================================================================
--- lnt/trunk/tests/lit.cfg (original)
+++ lnt/trunk/tests/lit.cfg Wed Apr 11 18:15:17 2012
@@ -16,7 +16,7 @@
 config.suffixes = ['.py']
 
 # excludes: A list of individual files to exclude.
-config.excludes = ['__init__.py']
+config.excludes = ['__init__.py', 'Inputs', 'SharedInputs']
 
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
@@ -31,8 +31,8 @@
 config.substitutions.append(('%{shared_inputs}', os.path.join(
             src_root, 'tests', 'SharedInputs')))
 
-# Enable coverage.py reporting, assuming sitecustomize.py in the virtualenv has
-# been modified appropriately.
+# Enable coverage.py reporting, assuming the coverage module has been installed
+# and sitecustomize.py in the virtualenv has been modified appropriately.
 if lit.params.get('check-coverage', None):
     config.environment['COVERAGE_PROCESS_START'] = os.path.join(
         os.path.dirname(__file__), ".coveragerc")

Added: lnt/trunk/tests/testing/Compilers.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/testing/Compilers.py?rev=154559&view=auto
==============================================================================
--- lnt/trunk/tests/testing/Compilers.py (added)
+++ lnt/trunk/tests/testing/Compilers.py Wed Apr 11 18:15:17 2012
@@ -0,0 +1,41 @@
+# Check the 'lnt.testing.utils.compilers' version sniffing code.
+#
+# RUN: python %s %{shared_inputs}/FakeCompilers
+
+import logging
+import os
+import pprint
+import sys
+
+import lnt.testing.util.compilers
+
+basedir = sys.argv[1]
+
+logging.basicConfig(level=logging.DEBUG)
+
+def get_info(name):
+    logging.info("checking compiler: %r", name)
+    return lnt.testing.util.compilers.get_cc_info(
+        os.path.join(basedir, name))
+
+# Check icc.
+info = get_info("icc-12.1.3")
+pprint.pprint(info)
+assert info['cc_name'] == 'icc'
+assert info['cc_build'] == 'PROD'
+assert info['cc_target'] == 'i686-apple-darwin11'
+assert info['inferred_run_order'] == '      0'
+
+# Check a random Clang from SVN.
+info = get_info("clang-r154331")
+pprint.pprint(info)
+assert info['cc_name'] == 'clang'
+assert info['cc_build'] == 'DEV'
+assert info['inferred_run_order'] == ' 154331'
+
+# Check an Apple Clang.
+info = get_info("apple-clang-138.1")
+pprint.pprint(info)
+assert info['cc_name'] == 'apple_clang'
+assert info['cc_build'] == 'PROD'
+assert info['inferred_run_order'] == '    138'





More information about the llvm-commits mailing list