[compiler-rt] r174876 - [msan] Lit tests for MemorySanitizer.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Feb 11 03:34:26 PST 2013


Author: eugenis
Date: Mon Feb 11 05:34:26 2013
New Revision: 174876

URL: http://llvm.org/viewvc/llvm-project?rev=174876&view=rev
Log:
[msan] Lit tests for MemorySanitizer.

Build system setup for MSan lit tests (build with freshly-built clang, run,
check output) - a nearly exact copy from ASan.
First 2 lit tests for MSan.

Added:
    compiler-rt/trunk/lib/msan/lit_tests/
    compiler-rt/trunk/lib/msan/lit_tests/CMakeLists.txt   (with props)
    compiler-rt/trunk/lib/msan/lit_tests/Unit/
    compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.cfg
    compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.site.cfg.in
    compiler-rt/trunk/lib/msan/lit_tests/heap-origin.cc   (with props)
    compiler-rt/trunk/lib/msan/lit_tests/lit.cfg
    compiler-rt/trunk/lib/msan/lit_tests/lit.site.cfg.in
    compiler-rt/trunk/lib/msan/lit_tests/stack-origin.cc   (with props)
Removed:
    compiler-rt/trunk/lib/msan/tests/lit.cfg
    compiler-rt/trunk/lib/msan/tests/lit.site.cfg.in
Modified:
    compiler-rt/trunk/lib/msan/CMakeLists.txt
    compiler-rt/trunk/lib/msan/msan_report.cc
    compiler-rt/trunk/lib/msan/tests/CMakeLists.txt

Modified: compiler-rt/trunk/lib/msan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/CMakeLists.txt?rev=174876&r1=174875&r2=174876&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/msan/CMakeLists.txt Mon Feb 11 05:34:26 2013
@@ -31,3 +31,5 @@ endif()
 if(LLVM_INCLUDE_TESTS)
   add_subdirectory(tests)
 endif()
+
+add_subdirectory(lit_tests)

Added: compiler-rt/trunk/lib/msan/lit_tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/CMakeLists.txt?rev=174876&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/CMakeLists.txt (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/CMakeLists.txt Mon Feb 11 05:34:26 2013
@@ -0,0 +1,32 @@
+set(MSAN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
+set(MSAN_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
+  )
+
+if(COMPILER_RT_CAN_EXECUTE_TESTS)
+  # Run MSan tests only if we're sure we may produce working binaries.
+  set(MSAN_TEST_DEPS
+    clang clang-headers FileCheck count not llvm-nm llvm-symbolizer
+    ${MSAN_RUNTIME_LIBRARIES}
+    )
+  set(MSAN_TEST_PARAMS
+    msan_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+    )
+  if(LLVM_INCLUDE_TESTS)
+    list(APPEND MSAN_TEST_DEPS MsanUnitTests)
+  endif()
+  add_lit_testsuite(check-msan "Running the MemorySanitizer tests"
+    ${CMAKE_CURRENT_BINARY_DIR}
+    PARAMS ${MSAN_TEST_PARAMS}
+    DEPENDS ${MSAN_TEST_DEPS}
+    )
+  set_target_properties(check-msan PROPERTIES FOLDER "MSan tests")
+endif()

Propchange: compiler-rt/trunk/lib/msan/lit_tests/CMakeLists.txt
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.cfg?rev=174876&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.cfg (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.cfg Mon Feb 11 05:34:26 2013
@@ -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 = 'MemorySanitizer-Unit'
+
+# Setup test source and exec root. For unit tests, we define
+# it as build directory with MSan unit tests.
+msan_binary_dir = get_required_attr(config, "msan_binary_dir")
+config.test_exec_root = os.path.join(msan_binary_dir, "tests")
+config.test_source_root = config.test_exec_root

Added: compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.site.cfg.in?rev=174876&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.site.cfg.in (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/Unit/lit.site.cfg.in Mon Feb 11 05:34:26 2013
@@ -0,0 +1,16 @@
+## Autogenerated by LLVM/Clang configuration.
+# Do not edit!
+
+config.target_triple = "@TARGET_TRIPLE@"
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.llvm_build_mode = "@LLVM_BUILD_MODE@"
+config.msan_binary_dir = "@MSAN_BINARY_DIR@"
+
+try:
+  config.llvm_build_mode = config.llvm_build_mode % lit.params
+except KeyError,e:
+  key, = e.args
+  lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key))
+
+# Let the main config do the real work.
+lit.load_config(config, "@MSAN_SOURCE_DIR@/lit_tests/Unit/lit.cfg")

Added: compiler-rt/trunk/lib/msan/lit_tests/heap-origin.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/heap-origin.cc?rev=174876&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/heap-origin.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/heap-origin.cc Mon Feb 11 05:34:26 2013
@@ -0,0 +1,33 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O1 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O2 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O1 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O2 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O3 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+
+#include <stdlib.h>
+int main(int argc, char **argv) {
+  char *volatile x = (char*)malloc(5 * sizeof(char));
+  if (*x)
+    exit(0);
+  // CHECK: WARNING: Use of uninitialized value
+  // CHECK: {{#0 0x.* in main .*heap-origin.cc:}}[[@LINE-3]]
+
+  // CHECK-ORIGINS: Uninitialized value was created by a heap allocation
+  // CHECK-ORIGINS: {{#0 0x.* in .*malloc}}
+  // CHECK-ORIGINS: {{#1 0x.* in main .*heap-origin.cc:}}[[@LINE-8]]
+
+  // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*heap-origin.cc:.* main}}
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/heap-origin.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: compiler-rt/trunk/lib/msan/lit_tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/lit.cfg?rev=174876&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/lit.cfg (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/lit.cfg Mon Feb 11 05:34:26 2013
@@ -0,0 +1,83 @@
+# -*- Python -*-
+
+import os
+
+# Setup config name.
+config.name = 'MemorySanitizer'
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+def DisplayNoConfigMessage():
+  lit.fatal("No site specific configuration available! " +
+            "Try running your test from the build tree or running " +
+            "make check-msan")
+
+# Figure out LLVM source root.
+llvm_src_root = getattr(config, 'llvm_src_root', None)
+if llvm_src_root is None:
+  # We probably haven't loaded the site-specific configuration: the user
+  # is likely trying to run a test file directly, and the site configuration
+  # wasn't created by the build system.
+  msan_site_cfg = lit.params.get('msan_site_config', None)
+  if (msan_site_cfg) and (os.path.exists(msan_site_cfg)):
+    lit.load_config(config, msan_site_cfg)
+    raise SystemExit
+
+  # Try to guess the location of site-specific configuration using llvm-config
+  # util that can point where the build tree is.
+  llvm_config = lit.util.which("llvm-config", config.environment["PATH"])
+  if not llvm_config:
+    DisplayNoConfigMessage()
+
+  # Validate that llvm-config points to the same source tree.
+  llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
+  msan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
+                                    "lib", "msan", "lit_tests")
+  if (os.path.realpath(msan_test_src_root) !=
+      os.path.realpath(config.test_source_root)):
+    DisplayNoConfigMessage()
+
+  # Find out the presumed location of generated site config.
+  llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
+  msan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
+                               "lib", "msan", "lit_tests", "lit.site.cfg")
+  if (not msan_site_cfg) or (not os.path.exists(msan_site_cfg)):
+    DisplayNoConfigMessage()
+
+  lit.load_config(config, msan_site_cfg)
+  raise SystemExit
+
+# Setup attributes common for all compiler-rt projects.
+compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
+                                   "lib", "lit.common.cfg")
+if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)):
+  lit.fatal("Can't find common compiler-rt lit config at: %r"
+            % compiler_rt_lit_cfg)
+lit.load_config(config, compiler_rt_lit_cfg)
+
+# Setup default compiler flags used with -fsanitize=memory option.
+clang_msan_cxxflags = ["-ccc-cxx ",
+                       "-fsanitize=memory",
+                       "-mno-omit-leaf-frame-pointer",
+                       "-fno-omit-frame-pointer",
+                       "-fno-optimize-sibling-calls",
+                       "-g",
+                       "-fPIE",
+                       "-pie"]
+config.substitutions.append( ("%clangxx_msan ",
+                              " ".join([config.clang] + clang_msan_cxxflags) + 
+                              " ") )
+
+# Setup path to external LLVM symbolizer to run MemorySanitizer output tests.
+llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
+if llvm_tools_dir:
+  llvm_symbolizer_path = os.path.join(llvm_tools_dir, "llvm-symbolizer")
+  config.environment['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer_path
+
+# Default test suffixes.
+config.suffixes = ['.c', '.cc', '.cpp']
+
+# MemorySanitizer tests are currently supported on Linux only.
+if config.host_os not in ['Linux']:
+  config.unsupported = True

Added: compiler-rt/trunk/lib/msan/lit_tests/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/lit.site.cfg.in?rev=174876&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/lit.site.cfg.in (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/lit.site.cfg.in Mon Feb 11 05:34:26 2013
@@ -0,0 +1,17 @@
+config.target_triple = "@TARGET_TRIPLE@"
+config.host_os = "@HOST_OS@"
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.llvm_obj_root = "@LLVM_BINARY_DIR@"
+config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
+config.clang = "@LLVM_BINARY_DIR@/bin/clang"
+
+# LLVM tools dir can be passed in lit parameters, so try to
+# apply substitution.
+try:
+  config.llvm_tools_dir = config.llvm_tools_dir % lit.params
+except KeyError,e:
+  key, = e.args
+  lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key))
+
+# Let the main config do the real work.
+lit.load_config(config, "@MSAN_SOURCE_DIR@/lit_tests/lit.cfg")

Added: compiler-rt/trunk/lib/msan/lit_tests/stack-origin.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/stack-origin.cc?rev=174876&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/stack-origin.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/stack-origin.cc Mon Feb 11 05:34:26 2013
@@ -0,0 +1,32 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O1 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O2 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O1 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O2 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O3 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+
+#include <stdlib.h>
+int main(int argc, char **argv) {
+  int x;
+  int *volatile p = &x;
+  if (*p)
+    exit(0);
+  // CHECK: WARNING: Use of uninitialized value
+  // CHECK: {{#0 0x.* in main .*stack-origin.cc:}}[[@LINE-3]]
+
+  // CHECK-ORIGINS: Uninitialized value was created by an allocation of 'x' in the stack frame of function 'main'
+
+  // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*stack-origin.cc:.* main}}
+  return 0;
+}

Propchange: compiler-rt/trunk/lib/msan/lit_tests/stack-origin.cc
------------------------------------------------------------------------------
    svn:eol-style = LF

Modified: compiler-rt/trunk/lib/msan/msan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cc?rev=174876&r1=174875&r2=174876&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc Mon Feb 11 05:34:26 2013
@@ -54,7 +54,7 @@ static void DescribeOrigin(u32 origin) {
     CHECK(sep);
     *sep = '\0';
     Printf("%s", d.Origin());
-    Printf("  %sUninitialised value was created by an allocation of '%s%s%s'"
+    Printf("  %sUninitialized value was created by an allocation of '%s%s%s'"
            " in the stack frame of function '%s%s%s'%s\n",
            d.Origin(), d.Name(), s, d.Origin(), d.Name(), sep + 1,
            d.Origin(), d.End());
@@ -62,7 +62,7 @@ static void DescribeOrigin(u32 origin) {
   } else {
     uptr size = 0;
     const uptr *trace = StackDepotGet(origin, &size);
-    Printf("  %sUninitialised value was created by a heap allocation%s\n",
+    Printf("  %sUninitialized value was created by a heap allocation%s\n",
            d.Origin(), d.End());
     StackTrace::PrintStack(trace, size, true, flags()->strip_path_prefix, 0);
   }

Modified: compiler-rt/trunk/lib/msan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/CMakeLists.txt?rev=174876&r1=174875&r2=174876&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/msan/tests/CMakeLists.txt Mon Feb 11 05:34:26 2013
@@ -151,16 +151,4 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND EXI
   if(CAN_TARGET_x86_64)
     add_msan_tests_for_arch(x86_64)
   endif()
-
-  # Run unittests as a part of lit testsuite.
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-    ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
-    )
-
-  add_lit_testsuite(check-msan "Running MemorySanitizer unittests"
-    ${CMAKE_CURRENT_BINARY_DIR}
-    DEPENDS MsanUnitTests
-    )
-  set_target_properties(check-msan PROPERTIES FOLDER "MemorySanitizer unittests")
 endif()

Removed: compiler-rt/trunk/lib/msan/tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/lit.cfg?rev=174875&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/lit.cfg (original)
+++ compiler-rt/trunk/lib/msan/tests/lit.cfg (removed)
@@ -1,29 +0,0 @@
-# -*- 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 = 'MemorySanitizer'
-
-# Setup test source and exec root. For unit tests, we define
-# it as build directory with sanitizer_common unit tests.
-llvm_obj_root = get_required_attr(config, "llvm_obj_root")
-config.test_exec_root = os.path.join(llvm_obj_root, "projects",
-                                     "compiler-rt", "lib",
-                                     "msan", "tests")
-config.test_source_root = config.test_exec_root

Removed: compiler-rt/trunk/lib/msan/tests/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/lit.site.cfg.in?rev=174875&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/lit.site.cfg.in (original)
+++ compiler-rt/trunk/lib/msan/tests/lit.site.cfg.in (removed)
@@ -1,15 +0,0 @@
-## Autogenerated by LLVM/Clang configuration.
-# Do not edit!
-
-config.llvm_obj_root = "@LLVM_BINARY_DIR@"
-config.llvm_src_root = "@LLVM_SOURCE_DIR@"
-config.llvm_build_mode = "@LLVM_BUILD_MODE@"
-
-try:
-  config.llvm_build_mode = config.llvm_build_mode % lit.params
-except KeyError,e:
-  key, = e.args
-  lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key))
-
-# Let the main config do the real work.
-lit.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")





More information about the llvm-commits mailing list