summaryrefslogtreecommitdiff
path: root/lib/msan
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-02-11 11:34:26 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-02-11 11:34:26 +0000
commit9af86761268fb0b0a1a5295370f68a503c8d38b5 (patch)
treea31eac57833b5d3ecf0470be4b6be7a88ce7dd92 /lib/msan
parent9c0b286e747c4a5a08027261d0ca7ef25ede03ee (diff)
[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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@174876 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/msan')
-rw-r--r--lib/msan/CMakeLists.txt2
-rw-r--r--lib/msan/lit_tests/CMakeLists.txt32
-rw-r--r--lib/msan/lit_tests/Unit/lit.cfg (renamed from lib/msan/tests/lit.cfg)10
-rw-r--r--lib/msan/lit_tests/Unit/lit.site.cfg.in (renamed from lib/msan/tests/lit.site.cfg.in)5
-rw-r--r--lib/msan/lit_tests/heap-origin.cc33
-rw-r--r--lib/msan/lit_tests/lit.cfg83
-rw-r--r--lib/msan/lit_tests/lit.site.cfg.in17
-rw-r--r--lib/msan/lit_tests/stack-origin.cc32
-rw-r--r--lib/msan/msan_report.cc4
-rw-r--r--lib/msan/tests/CMakeLists.txt12
10 files changed, 208 insertions, 22 deletions
diff --git a/lib/msan/CMakeLists.txt b/lib/msan/CMakeLists.txt
index 42c48ca9c..5677e5787 100644
--- a/lib/msan/CMakeLists.txt
+++ b/lib/msan/CMakeLists.txt
@@ -31,3 +31,5 @@ endif()
if(LLVM_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
+
+add_subdirectory(lit_tests)
diff --git a/lib/msan/lit_tests/CMakeLists.txt b/lib/msan/lit_tests/CMakeLists.txt
new file mode 100644
index 000000000..62b21013b
--- /dev/null
+++ b/lib/msan/lit_tests/CMakeLists.txt
@@ -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()
diff --git a/lib/msan/tests/lit.cfg b/lib/msan/lit_tests/Unit/lit.cfg
index 38aa13804..afb30e0a8 100644
--- a/lib/msan/tests/lit.cfg
+++ b/lib/msan/lit_tests/Unit/lit.cfg
@@ -18,12 +18,10 @@ compiler_rt_lit_unit_cfg = os.path.join(llvm_src_root, "projects",
lit.load_config(config, compiler_rt_lit_unit_cfg)
# Setup config name.
-config.name = 'MemorySanitizer'
+config.name = 'MemorySanitizer-Unit'
# 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")
+# 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
diff --git a/lib/msan/tests/lit.site.cfg.in b/lib/msan/lit_tests/Unit/lit.site.cfg.in
index ad0ff3c01..4ae84c42d 100644
--- a/lib/msan/tests/lit.site.cfg.in
+++ b/lib/msan/lit_tests/Unit/lit.site.cfg.in
@@ -1,9 +1,10 @@
## Autogenerated by LLVM/Clang configuration.
# Do not edit!
-config.llvm_obj_root = "@LLVM_BINARY_DIR@"
+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
@@ -12,4 +13,4 @@ except KeyError,e:
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")
+lit.load_config(config, "@MSAN_SOURCE_DIR@/lit_tests/Unit/lit.cfg")
diff --git a/lib/msan/lit_tests/heap-origin.cc b/lib/msan/lit_tests/heap-origin.cc
new file mode 100644
index 000000000..54e2c3143
--- /dev/null
+++ b/lib/msan/lit_tests/heap-origin.cc
@@ -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;
+}
diff --git a/lib/msan/lit_tests/lit.cfg b/lib/msan/lit_tests/lit.cfg
new file mode 100644
index 000000000..942905035
--- /dev/null
+++ b/lib/msan/lit_tests/lit.cfg
@@ -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
diff --git a/lib/msan/lit_tests/lit.site.cfg.in b/lib/msan/lit_tests/lit.site.cfg.in
new file mode 100644
index 000000000..cc7c7a0ec
--- /dev/null
+++ b/lib/msan/lit_tests/lit.site.cfg.in
@@ -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")
diff --git a/lib/msan/lit_tests/stack-origin.cc b/lib/msan/lit_tests/stack-origin.cc
new file mode 100644
index 000000000..90f527309
--- /dev/null
+++ b/lib/msan/lit_tests/stack-origin.cc
@@ -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;
+}
diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc
index 804c8ae1c..26f34d7b8 100644
--- a/lib/msan/msan_report.cc
+++ b/lib/msan/msan_report.cc
@@ -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);
}
diff --git a/lib/msan/tests/CMakeLists.txt b/lib/msan/tests/CMakeLists.txt
index f2be64780..7067c4578 100644
--- a/lib/msan/tests/CMakeLists.txt
+++ b/lib/msan/tests/CMakeLists.txt
@@ -151,16 +151,4 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND EXISTS ${MSAN_LIBCXX_PATH}/)
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()