[compiler-rt] r208378 - [Sanitizer] Add the machinery to run the same test under several sanitizers

Alexey Samsonov samsonov at google.com
Thu May 8 17:28:18 PDT 2014


Author: samsonov
Date: Thu May  8 19:28:18 2014
New Revision: 208378

URL: http://llvm.org/viewvc/llvm-project?rev=208378&view=rev
Log:
[Sanitizer] Add the machinery to run the same test under several sanitizers

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/
    compiler-rt/trunk/test/sanitizer_common/TestCases/ptrace.cc
      - copied, changed from r208363, compiler-rt/trunk/test/msan/ptrace.cc
    compiler-rt/trunk/test/sanitizer_common/lit.common.cfg
    compiler-rt/trunk/test/sanitizer_common/lit.site.cfg.in
Removed:
    compiler-rt/trunk/test/msan/ptrace.cc
Modified:
    compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt

Removed: compiler-rt/trunk/test/msan/ptrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/ptrace.cc?rev=208377&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/ptrace.cc (original)
+++ compiler-rt/trunk/test/msan/ptrace.cc (removed)
@@ -1,43 +0,0 @@
-// RUN: %clangxx_msan -m64 -O0 %s -o %t && %run %t
-
-#include <assert.h>
-#include <signal.h>
-#include <stdio.h>
-#include <sys/ptrace.h>
-#include <sys/types.h>
-#include <sys/user.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-int main(void) {
-  pid_t pid;
-  pid = fork();
-  if (pid == 0) { // child
-    ptrace(PTRACE_TRACEME, 0, NULL, NULL);
-    execl("/bin/true", "true", NULL);
-  } else {
-    wait(NULL);
-    user_regs_struct regs;
-    int res;
-    res = ptrace(PTRACE_GETREGS, pid, NULL, &regs);
-    assert(!res);
-    if (regs.rip)
-      printf("%zx\n", regs.rip);
-
-    user_fpregs_struct fpregs;
-    res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs);
-    assert(!res);
-    if (fpregs.mxcsr)
-      printf("%x\n", fpregs.mxcsr);
-
-    siginfo_t siginfo;
-    res = ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo);
-    assert(!res);
-    assert(siginfo.si_pid == pid);
-
-    ptrace(PTRACE_CONT, pid, NULL, NULL);
-
-    wait(NULL);
-  }
-  return 0;
-}

Modified: compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt?rev=208378&r1=208377&r2=208378&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt Thu May  8 19:28:18 2014
@@ -1,9 +1,36 @@
+set(SANITIZER_COMMON_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+set(SANITIZER_COMMON_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
+set(SANITIZER_COMMON_TESTSUITES)
+
+# Create a separate config for each tool we support.
+foreach(tool asan tsan msan)
+  string(TOUPPER ${tool} tool_toupper)
+  if(${tool_toupper}_SUPPORTED_ARCH)
+    set(SANITIZER_COMMON_LIT_TEST_MODE ${tool})
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+      ${CMAKE_CURRENT_BINARY_DIR}/${tool}/lit.site.cfg)
+    list(APPEND SANITIZER_COMMON_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${tool})
+    if(NOT COMPILER_RT_STANDALONE_BUILD)
+      list(APPEND SANITIZER_COMMON_TEST_DEPS ${tool})
+    endif()
+  endif()
+endforeach()
+
+# Unit tests.
 if(COMPILER_RT_INCLUDE_TESTS)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
     ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
-  add_lit_testsuite(check-sanitizer "Running sanitizer library unittests"
-    ${CMAKE_CURRENT_BINARY_DIR}/Unit
-    DEPENDS SanitizerUnitTests)
-  set_target_properties(check-sanitizer PROPERTIES FOLDER "Sanitizer unittests")
+  list(APPEND SANITIZER_COMMON_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
+  list(APPEND SANITIZER_COMMON_TEST_DEPS SanitizerUnitTests)
+endif()
+
+if(SANITIZER_COMMON_TESTSUITES)
+  add_lit_testsuite(check-sanitizer "Running sanitizer_common tests"
+    ${SANITIZER_COMMON_TESTSUITES}
+    DEPENDS ${SANITIZER_COMMON_TEST_DEPS})
+  set_target_properties(check-sanitizer PROPERTIES FOLDER
+                        "sanitizer_common tests")
 endif()

Copied: compiler-rt/trunk/test/sanitizer_common/TestCases/ptrace.cc (from r208363, compiler-rt/trunk/test/msan/ptrace.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/ptrace.cc?p2=compiler-rt/trunk/test/sanitizer_common/TestCases/ptrace.cc&p1=compiler-rt/trunk/test/msan/ptrace.cc&r1=208363&r2=208378&rev=208378&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/ptrace.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/ptrace.cc Thu May  8 19:28:18 2014
@@ -1,4 +1,4 @@
-// RUN: %clangxx_msan -m64 -O0 %s -o %t && %run %t
+// RUN: %clangxx -O0 %s -o %t && %run %t
 
 #include <assert.h>
 #include <signal.h>

Added: compiler-rt/trunk/test/sanitizer_common/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/lit.common.cfg?rev=208378&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/lit.common.cfg (added)
+++ compiler-rt/trunk/test/sanitizer_common/lit.common.cfg Thu May  8 19:28:18 2014
@@ -0,0 +1,30 @@
+# -*- Python -*-
+
+# Setup source root.
+config.test_source_root = os.path.join(os.path.dirname(__file__), "TestCases")
+
+config.name = "SanitizerCommon-" + config.tool_name
+
+if config.tool_name == "asan":
+  tool_cflags = ["-fsanitize=address"]
+elif config.tool_name == "tsan":
+  tool_cflags = ["-fsanitize=thread"]
+elif config.tool_name == "msan":
+  tool_cflags = ["-fsanitize=memory"]
+else:
+  lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)
+
+clang_cflags = ["-g"] + tool_cflags
+clang_cxxflags = config.cxx_mode_flags + clang_cflags
+
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
+config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
+
+config.suffixes = ['.c', '.cc', '.cpp']
+
+if config.host_os not in ['Linux', 'Darwin']:
+  config.unsupported = True
+

Added: compiler-rt/trunk/test/sanitizer_common/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/lit.site.cfg.in?rev=208378&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/lit.site.cfg.in (added)
+++ compiler-rt/trunk/test/sanitizer_common/lit.site.cfg.in Thu May  8 19:28:18 2014
@@ -0,0 +1,9 @@
+# Load common config for all compiler-rt lit tests.
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
+
+# Tool-specific config options.
+config.tool_name = "@SANITIZER_COMMON_LIT_TEST_MODE@"
+
+# Load tool-specific config that would do the real work.
+lit_config.load_config(config, "@SANITIZER_COMMON_LIT_SOURCE_DIR@/lit.common.cfg")
+





More information about the llvm-commits mailing list