[llvm-commits] [compiler-rt] r161050 - in /compiler-rt/trunk/lib: asan/CMakeLists.txt asan/lit_tests/ asan/lit_tests/CMakeLists.txt asan/lit_tests/deep_tail_call.cc asan/lit_tests/lit.cfg asan/lit_tests/lit.site.cfg.in lit.common.cfg

Alexey Samsonov samsonov at google.com
Tue Jul 31 08:43:11 PDT 2012


Author: samsonov
Date: Tue Jul 31 10:43:11 2012
New Revision: 161050

URL: http://llvm.org/viewvc/llvm-project?rev=161050&view=rev
Log:
First tiny move towards integrating AddressSanitizer regressions test into LLVM lit-based testing infrastructure.
The goal is to be able to run ASan tests by simply running "make check-asan" command from CMake build tree:
* tests should use fresh clang binary from current build tree.
* tests should use the same RUN-lines syntax as llvm/clang reg tests.

Next steps:
- restricting tests to machines where target is equal to host, i.e. where we can produce working binaries.
- moving AddressSanitizer unit tests to lit as well.

Added:
    compiler-rt/trunk/lib/asan/lit_tests/
    compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt
    compiler-rt/trunk/lib/asan/lit_tests/deep_tail_call.cc
      - copied, changed from r160716, compiler-rt/trunk/lib/asan/output_tests/deep_tail_call.cc
    compiler-rt/trunk/lib/asan/lit_tests/lit.cfg
    compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in
    compiler-rt/trunk/lib/lit.common.cfg
Modified:
    compiler-rt/trunk/lib/asan/CMakeLists.txt

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=161050&r1=161049&r2=161050&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Tue Jul 31 10:43:11 2012
@@ -80,3 +80,8 @@
 if(LLVM_INCLUDE_TESTS)
   add_subdirectory(tests)
 endif()
+
+# ASan output tests.
+# FIXME: move all output tests from output_tests/ to lit_tests/ and get rid
+# of the first directory.
+add_subdirectory(lit_tests)

Added: compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt?rev=161050&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt Tue Jul 31 10:43:11 2012
@@ -0,0 +1,15 @@
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+set(ASAN_TEST_DEPS
+  clang clang-headers FileCheck count not
+  clang-rt.asan-x86_64 clang-rt.asan-i386
+  )
+
+add_lit_testsuite(check-asan "Running the AddressSanitizer tests"
+  ${CMAKE_CURRENT_BINARY_DIR}
+  DEPENDS ${ASAN_TEST_DEPS}
+  )
+set_target_properties(check-asan PROPERTIES FOLDER "ASan tests")

Copied: compiler-rt/trunk/lib/asan/lit_tests/deep_tail_call.cc (from r160716, compiler-rt/trunk/lib/asan/output_tests/deep_tail_call.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/deep_tail_call.cc?p2=compiler-rt/trunk/lib/asan/lit_tests/deep_tail_call.cc&p1=compiler-rt/trunk/lib/asan/output_tests/deep_tail_call.cc&r1=160716&r2=161050&rev=161050&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/output_tests/deep_tail_call.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/deep_tail_call.cc Tue Jul 31 10:43:11 2012
@@ -1,14 +1,17 @@
-// Check-Common: AddressSanitizer global-buffer-overflow
+// RUN: %clang_asan -m64 -O2 %s -o %t
+// RUN: %t 2>&1 | %symbolizer | FileCheck %s
+
+// CHECK: AddressSanitizer global-buffer-overflow
 int global[10];
-// Check-Common: {{#0.*call4}}
+// CHECK: {{#0.*call4}}
 void __attribute__((noinline)) call4(int i) { global[i+10]++; }
-// Check-Common: {{#1.*call3}}
+// CHECK: {{#1.*call3}}
 void __attribute__((noinline)) call3(int i) { call4(i); }
-// Check-Common: {{#2.*call2}}
+// CHECK: {{#2.*call2}}
 void __attribute__((noinline)) call2(int i) { call3(i); }
-// Check-Common: {{#3.*call1}}
+// CHECK: {{#3.*call1}}
 void __attribute__((noinline)) call1(int i) { call2(i); }
-// Check-Common: {{#4.*main}}
+// CHECK: {{#4.*main}}
 int main(int argc, char **argv) {
   call1(argc);
   return global[0];

Added: compiler-rt/trunk/lib/asan/lit_tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/lit.cfg?rev=161050&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/lit.cfg (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/lit.cfg Tue Jul 31 10:43:11 2012
@@ -0,0 +1,46 @@
+# -*- Python -*-
+
+import os
+
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if not attr_value:
+    lit.fatal("No attribute %r in test configuration! You may need to run "
+              "tests from your build directory or add this attribute "
+              "to lit.site.cfg " % attr_name)
+  return attr_value
+
+# Setup attributes common for all compiler-rt projects.
+llvm_src_root = get_required_attr(config, 'llvm_src_root')
+compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
+                                   "lib", "lit.common.cfg")
+lit.load_config(config, compiler_rt_lit_cfg)
+
+# Setup config name.
+config.name = 'AddressSanitizer'
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Setup default compiler flags used with -faddress-sanitizer option.
+# FIXME: Review the set of required flags and check if it can be reduced.
+clang_asan_cxxflags = ("-faddress-sanitizer "
+                      + "-mno-omit-leaf-frame-pointer "
+                      + "-fno-omit-frame-pointer "
+                      + "-fno-optimize-sibling-calls "
+                      + "-g")
+config.substitutions.append( ("%clang_asan ", (" " + config.clang + " " +
+                                              clang_asan_cxxflags + " ")) )
+
+# Setup path to symbolizer script.
+# FIXME: Instead we should copy this script to the build tree and point
+#        at it there.
+asan_source_dir = os.path.join(config.test_source_root, "..")
+symbolizer = os.path.join(asan_source_dir,
+                         'scripts', 'asan_symbolize.py')
+if not os.path.exists(symbolizer):
+  lit.fatal("Can't find symbolizer script on path %r" % symbolizer)
+config.substitutions.append( ('%symbolizer', (" " + symbolizer + " " )))
+
+# Default test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp']

Added: compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in?rev=161050&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in Tue Jul 31 10:43:11 2012
@@ -0,0 +1,9 @@
+## Autogenerated by LLVM/Clang configuration.
+# Do not edit!
+
+config.target_triple = "@TARGET_TRIPLE@"
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.clang = "@LLVM_BINARY_DIR@/bin/clang"
+
+# Let the main config do the real work.
+lit.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")

Added: compiler-rt/trunk/lib/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lit.common.cfg?rev=161050&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lit.common.cfg (added)
+++ compiler-rt/trunk/lib/lit.common.cfg Tue Jul 31 10:43:11 2012
@@ -0,0 +1,45 @@
+# -*- Python -*-
+
+# Configuration file for 'lit' test runner.
+# This file contains common rules for various compiler-rt testsuites.
+# It is mostly copied from lit.cfg used by Clang.
+import os
+import platform
+
+# Setup test format
+execute_external = (platform.system() != 'Windows'
+                    or lit.getBashPath() not in [None, ""])
+config.test_format = lit.formats.ShTest(execute_external)
+
+# Setup clang binary.
+clang_path = getattr(config, 'clang', None)
+if (not clang_path) or (not os.path.exists(clang_path)):
+  lit.fatal("Can't find Clang on path %r" % clang_path)
+if not lit.quiet:
+  lit.note("using clang: %r" % clang_path)
+
+# Clear some environment variables that might affect Clang.
+possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
+                               'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
+                               'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
+                               'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
+                               'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
+                               'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
+                               'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
+                               'LIBCLANG_RESOURCE_USAGE',
+                               'LIBCLANG_CODE_COMPLETION_LOGGING']
+# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
+if platform.system() != 'Windows':
+    possibly_dangerous_env_vars.append('INCLUDE')
+for name in possibly_dangerous_env_vars:
+  if name in config.environment:
+    del config.environment[name]
+
+# Define %clang substitution to use in test RUN lines.
+config.substitutions.append( ("%clang ", (" " + config.clang + " ")) )
+
+# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
+# in RUN lines.
+config.substitutions.append(
+    (' clang', """\n\n*** Do not use 'clangXXX' in tests,
+     instead define '%clangXXX' substitution in lit config. ***\n\n""") )





More information about the llvm-commits mailing list