[llvm-commits] [compiler-rt] r161406 - in /compiler-rt/trunk/lib: asan/lit_tests/CMakeLists.txt asan/lit_tests/Unit/ asan/lit_tests/Unit/lit.cfg asan/lit_tests/Unit/lit.site.cfg.in asan/lit_tests/lit.site.cfg.in asan/tests/CMakeLists.txt lit.common.unit.cfg

Alexey Samsonov samsonov at google.com
Tue Aug 7 01:59:15 PDT 2012


Author: samsonov
Date: Tue Aug  7 03:59:15 2012
New Revision: 161406

URL: http://llvm.org/viewvc/llvm-project?rev=161406&view=rev
Log:
[ASan] Add support for running unit tests by lit (as a part of 'make check-asan' command)

Added:
    compiler-rt/trunk/lib/asan/lit_tests/Unit/
    compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.cfg
    compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in
    compiler-rt/trunk/lib/lit.common.unit.cfg
Modified:
    compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt
    compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt

Modified: 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=161406&r1=161405&r2=161406&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/CMakeLists.txt Tue Aug  7 03:59:15 2012
@@ -1,15 +1,39 @@
+set(ASAN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
+set(ASAN_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/..)
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
   )
 
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
+  )
+
 set(ASAN_TEST_DEPS
-  clang clang-headers FileCheck count not
   clang-rt.asan-x86_64 clang-rt.asan-i386
   )
+if(LLVM_INCLUDE_TESTS)
+  list(APPEND ASAN_TEST_DEPS AsanUnitTests)
+endif()
 
-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")
+if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}")
+  # Run ASan output tests only if we're not cross-compiling,
+  # and can be sure that clang would produce working binaries.
+  list(APPEND ASAN_TEST_DEPS
+    clang clang-headers FileCheck count not
+    )
+  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")
+elseif(LLVM_INCLUDE_TESTS)
+  # Otherwise run only ASan unit tests.
+  add_lit_testsuite(check-asan "Running the AddressSanitizer unit tests"
+    ${CMAKE_CURRENT_BINARY_DIR}/Unit
+    DEPENDS ${ASAN_TEST_DEPS}
+    )
+  set_target_properties(check-asan PROPERTIES FOLDER "ASan unit tests")
+endif()

Added: compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.cfg?rev=161406&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.cfg (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.cfg Tue Aug  7 03:59:15 2012
@@ -0,0 +1,27 @@
+# -*- 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_unit_cfg = os.path.join(llvm_src_root, "projects",
+                                        "compiler-rt", "lib",
+                                        "lit.common.unit.cfg")
+lit.load_config(config, compiler_rt_lit_unit_cfg)
+
+# Setup config name.
+config.name = 'AddressSanitizer-Unit'
+
+# Setup test source and exec root. For unit tests, we define
+# it as build directory with ASan unit tests.
+asan_binary_dir = get_required_attr(config, "asan_binary_dir")
+config.test_exec_root = os.path.join(asan_binary_dir, "tests")
+config.test_source_root = config.test_exec_root

Added: compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in?rev=161406&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/Unit/lit.site.cfg.in Tue Aug  7 03:59:15 2012
@@ -0,0 +1,10 @@
+## Autogenerated by LLVM/Clang configuration.
+# Do not edit!
+
+config.target_triple = "@TARGET_TRIPLE@"
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.build_type = "@CMAKE_BUILD_TYPE@"
+config.asan_binary_dir = "@ASAN_BINARY_DIR@"
+
+# Let the main config do the real work.
+lit.load_config(config, "@ASAN_SOURCE_DIR@/lit_tests/Unit/lit.cfg")

Modified: 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=161406&r1=161405&r2=161406&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/lit.site.cfg.in Tue Aug  7 03:59:15 2012
@@ -6,4 +6,4 @@
 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")
+lit.load_config(config, "@ASAN_SOURCE_DIR@/lit_tests/lit.cfg")

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=161406&r1=161405&r2=161406&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Tue Aug  7 03:59:15 2012
@@ -47,10 +47,10 @@
   -DASAN_UAR=0
 )
 
-add_custom_target(AsanTests)
-set_target_properties(AsanTests PROPERTIES FOLDER "ASan tests")
+add_custom_target(AsanUnitTests)
+set_target_properties(AsanUnitTests PROPERTIES FOLDER "ASan unit tests")
 function(add_asan_test testname)
-  add_unittest(AsanTests ${testname} ${ARGN})
+  add_unittest(AsanUnitTests ${testname} ${ARGN})
   if(LLVM_BUILD_32_BITS)
     target_link_libraries(${testname} clang_rt.asan-i386)
   else()

Added: compiler-rt/trunk/lib/lit.common.unit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lit.common.unit.cfg?rev=161406&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lit.common.unit.cfg (added)
+++ compiler-rt/trunk/lib/lit.common.unit.cfg Tue Aug  7 03:59:15 2012
@@ -0,0 +1,21 @@
+# -*- Python -*-
+
+# Configuration file for 'lit' test runner.
+# This file contains common config setup rules for unit tests in various
+# compiler-rt testsuites.
+
+import os
+
+# Setup test format
+build_type = getattr(config, "build_type", "Debug")
+config.test_format = lit.formats.GoogleTest(build_type, "Test")
+
+# Setup test suffixes.
+config.suffixes = []
+
+# Propagate the temp directory. Windows requires this because it uses \Windows\
+# if none of these are present.
+if 'TMP' in os.environ:
+    config.environment['TMP'] = os.environ['TMP']
+if 'TEMP' in os.environ:
+    config.environment['TEMP'] = os.environ['TEMP']





More information about the llvm-commits mailing list