aboutsummaryrefslogtreecommitdiff
path: root/lib/msan/tests
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
commit5c909fa013fc285f010a95e8d387e0ef3412da9c (patch)
tree1059d068ad281f4776ff44cd414574f99a460023 /lib/msan/tests
parentf31bcc68c72371a2bf63aead9f3373a1ff2053b6 (diff)
downloadsrc-5c909fa013fc285f010a95e8d387e0ef3412da9c.tar.gz
src-5c909fa013fc285f010a95e8d387e0ef3412da9c.zip
Vendor import of compiler-rt trunk r256633:vendor/compiler-rt/compiler-rt-trunk-r256633
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=292925 svn path=/vendor/compiler-rt/compiler-rt-trunk-r256633/; revision=292926; tag=vendor/compiler-rt/compiler-rt-trunk-r256633
Diffstat (limited to 'lib/msan/tests')
-rw-r--r--lib/msan/tests/CMakeLists.txt39
-rw-r--r--lib/msan/tests/msan_test.cc26
2 files changed, 42 insertions, 23 deletions
diff --git a/lib/msan/tests/CMakeLists.txt b/lib/msan/tests/CMakeLists.txt
index bf16a16bcf20..087b1afbd5b3 100644
--- a/lib/msan/tests/CMakeLists.txt
+++ b/lib/msan/tests/CMakeLists.txt
@@ -18,13 +18,13 @@ set(MSAN_UNITTEST_HEADERS
../../../include/sanitizer/msan_interface.h
)
set(MSAN_UNITTEST_COMMON_CFLAGS
- -I${COMPILER_RT_LIBCXX_PATH}/include
+ -nostdinc++
+ -isystem ${COMPILER_RT_LIBCXX_PATH}/include
${COMPILER_RT_TEST_CFLAGS}
${COMPILER_RT_GTEST_CFLAGS}
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/msan
- -stdlib=libc++
-g
-O2
-fno-exceptions
@@ -44,15 +44,13 @@ set(MSAN_UNITTEST_INSTRUMENTED_CFLAGS
)
set(MSAN_UNITTEST_LINK_FLAGS
-fsanitize=memory
+ # Don't need -stdlib=libc++ because we explicitly list libc++.so in the linker
+ # inputs.
# FIXME: we build libcxx without cxxabi and need libstdc++ to provide it.
-lstdc++
)
append_list_if(COMPILER_RT_HAS_LIBDL -ldl MSAN_UNITTEST_LINK_FLAGS)
-set(MSAN_LOADABLE_LINK_FLAGS
- -fsanitize=memory
- -shared
-)
# Compile source for the given architecture, using compiler
# options in ${ARGN}, and add it to the object list.
@@ -90,12 +88,6 @@ set_target_properties(MsanUnitTests PROPERTIES FOLDER "MSan unit tests")
# Adds MSan unit tests and benchmarks for architecture.
macro(add_msan_tests_for_arch arch kind)
- set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan${kind})
- add_custom_libcxx(libcxx_msan${kind} ${LIBCXX_PREFIX}
- DEPS ${MSAN_RUNTIME_LIBRARIES}
- CFLAGS ${MSAN_LIBCXX_CFLAGS} ${ARGN})
- set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so)
-
# Build gtest instrumented with MSan.
set(MSAN_INST_GTEST)
msan_compile(MSAN_INST_GTEST ${COMPILER_RT_GTEST_SOURCE} ${arch} "${kind}"
@@ -111,7 +103,7 @@ macro(add_msan_tests_for_arch arch kind)
# Instrumented loadable module objects.
set(MSAN_INST_LOADABLE_OBJECTS)
msan_compile(MSAN_INST_LOADABLE_OBJECTS ${MSAN_LOADABLE_SOURCE} ${arch} "${kind}"
- ${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} ${ARGN})
+ ${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} "-fPIC" ${ARGN})
# Instrumented loadable library tests.
set(MSAN_LOADABLE_SO)
@@ -120,24 +112,31 @@ macro(add_msan_tests_for_arch arch kind)
DEPS ${MSAN_INST_LOADABLE_OBJECTS})
set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
- set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan${kind}
+ set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}
${MSAN_LOADABLE_SO})
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND MSAN_TEST_DEPS msan)
endif()
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
- OBJECTS ${MSAN_TEST_OBJECTS} ${MSAN_LIBCXX_SO}
- DEPS ${MSAN_TEST_DEPS}
- LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
- ${TARGET_LINK_FLAGS}
- "-Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}"
- "-Wl,-rpath=${LIBCXX_PREFIX}/lib")
+ OBJECTS ${MSAN_TEST_OBJECTS} ${MSAN_LIBCXX_SO}
+ DEPS ${MSAN_TEST_DEPS}
+ LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
+ ${TARGET_LINK_FLAGS}
+ "-Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}"
+ "-Wl,-rpath=${LIBCXX_PREFIX}/lib")
endmacro()
# We should only build MSan unit tests if we can build instrumented libcxx.
if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_HAS_LIBCXX_SOURCES)
foreach(arch ${MSAN_SUPPORTED_ARCH})
+ get_target_flags_for_arch(${arch} TARGET_CFLAGS)
+ set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch})
+ add_custom_libcxx(libcxx_msan_${arch} ${LIBCXX_PREFIX}
+ DEPS ${MSAN_RUNTIME_LIBRARIES}
+ CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS})
+ set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so)
+
add_msan_tests_for_arch(${arch} "")
add_msan_tests_for_arch(${arch} "-with-call"
-mllvm -msan-instrumentation-with-call-threshold=0)
diff --git a/lib/msan/tests/msan_test.cc b/lib/msan/tests/msan_test.cc
index 00dd20a3d775..b7162b3c081b 100644
--- a/lib/msan/tests/msan_test.cc
+++ b/lib/msan/tests/msan_test.cc
@@ -1883,7 +1883,7 @@ TEST(MemorySanitizer, swprintf) {
ASSERT_EQ(buff[1], '2');
ASSERT_EQ(buff[2], '3');
ASSERT_EQ(buff[6], '7');
- ASSERT_EQ(buff[7], 0);
+ ASSERT_EQ(buff[7], L'\0');
EXPECT_POISONED(buff[8]);
}
@@ -1952,6 +1952,16 @@ TEST(MemorySanitizer, wcsnrtombs) {
EXPECT_POISONED(buff[2]);
}
+TEST(MemorySanitizer, wcrtomb) {
+ wchar_t x = L'a';
+ char buff[10];
+ mbstate_t mbs;
+ memset(&mbs, 0, sizeof(mbs));
+ size_t res = wcrtomb(buff, x, &mbs);
+ EXPECT_EQ(res, (size_t)1);
+ EXPECT_EQ(buff[0], 'a');
+}
+
TEST(MemorySanitizer, wmemset) {
wchar_t x[25];
break_optimization(x);
@@ -2876,6 +2886,8 @@ static void GetPathToLoadable(char *buf, size_t sz) {
static const char basename[] = "libmsan_loadable.mips64.so";
#elif defined(__mips64)
static const char basename[] = "libmsan_loadable.mips64el.so";
+#elif defined(__aarch64__)
+ static const char basename[] = "libmsan_loadable.aarch64.so";
#endif
int res = snprintf(buf, sz, "%.*s/%s",
(int)dir_len, program_path, basename);
@@ -2982,6 +2994,14 @@ static void *SmallStackThread_threadfn(void* data) {
return 0;
}
+#ifdef PTHREAD_STACK_MIN
+# define SMALLSTACKSIZE PTHREAD_STACK_MIN
+# define SMALLPRESTACKSIZE PTHREAD_STACK_MIN
+#else
+# define SMALLSTACKSIZE 64 * 1024
+# define SMALLPRESTACKSIZE 16 * 1024
+#endif
+
TEST(MemorySanitizer, SmallStackThread) {
pthread_attr_t attr;
pthread_t t;
@@ -2989,7 +3009,7 @@ TEST(MemorySanitizer, SmallStackThread) {
int res;
res = pthread_attr_init(&attr);
ASSERT_EQ(0, res);
- res = pthread_attr_setstacksize(&attr, 64 * 1024);
+ res = pthread_attr_setstacksize(&attr, SMALLSTACKSIZE);
ASSERT_EQ(0, res);
res = pthread_create(&t, &attr, SmallStackThread_threadfn, NULL);
ASSERT_EQ(0, res);
@@ -3006,7 +3026,7 @@ TEST(MemorySanitizer, SmallPreAllocatedStackThread) {
res = pthread_attr_init(&attr);
ASSERT_EQ(0, res);
void *stack;
- const size_t kStackSize = 16 * 1024;
+ const size_t kStackSize = SMALLPRESTACKSIZE;
res = posix_memalign(&stack, 4096, kStackSize);
ASSERT_EQ(0, res);
res = pthread_attr_setstack(&attr, stack, kStackSize);