diff --git a/lib/msan/tests/CMakeLists.txt b/lib/msan/tests/CMakeLists.txt index 813aad02a2..abfb96a08b 100644 --- a/lib/msan/tests/CMakeLists.txt +++ b/lib/msan/tests/CMakeLists.txt @@ -31,9 +31,10 @@ set(MSAN_LIBCXX_LINK_FLAGS -fsanitize=memory) # Unittest sources and build flags. -set(MSAN_UNITTEST_SOURCE msan_test.cc) +set(MSAN_UNITTEST_SOURCES msan_test.cc msan_test_main.cc) set(MSAN_LOADABLE_SOURCE msan_loadable.cc) set(MSAN_UNITTEST_HEADERS + msan_test_config.h msandr_test_so.h ../../../include/sanitizer/msan_interface.h ) @@ -133,8 +134,10 @@ macro(add_msan_tests_for_arch arch) # Instrumented tests. set(MSAN_INST_TEST_OBJECTS) - msan_compile(MSAN_INST_TEST_OBJECTS ${MSAN_UNITTEST_SOURCE} ${arch} - ${MSAN_UNITTEST_INSTRUMENTED_CFLAGS}) + foreach (SOURCE ${MSAN_UNITTEST_SOURCES}) + msan_compile(MSAN_INST_TEST_OBJECTS ${SOURCE} ${arch} + ${MSAN_UNITTEST_INSTRUMENTED_CFLAGS}) + endforeach(SOURCE) # Instrumented loadable module objects. set(MSAN_INST_LOADABLE_OBJECTS) diff --git a/lib/msan/tests/msan_test.cc b/lib/msan/tests/msan_test.cc index fbd35cb22f..2120f0efa3 100644 --- a/lib/msan/tests/msan_test.cc +++ b/lib/msan/tests/msan_test.cc @@ -12,9 +12,12 @@ // MemorySanitizer unit tests. //===----------------------------------------------------------------------===// +#ifndef MSAN_EXTERNAL_TEST_CONFIG +#include "msan_test_config.h" +#endif // MSAN_EXTERNAL_TEST_CONFIG + #include "sanitizer/msan_interface.h" #include "msandr_test_so.h" -#include "gtest/gtest.h" #include #include @@ -1943,9 +1946,3 @@ TEST(MemorySanitizer, CallocOverflow) { TEST(MemorySanitizerStress, DISABLED_MallocStackTrace) { RecursiveMalloc(22); } - -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - int res = RUN_ALL_TESTS(); - return res; -} diff --git a/lib/msan/tests/msan_test_config.h b/lib/msan/tests/msan_test_config.h new file mode 100644 index 0000000000..5404c434d0 --- /dev/null +++ b/lib/msan/tests/msan_test_config.h @@ -0,0 +1,20 @@ +//===-- msan_test_config.h ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of MemorySanitizer. +// +// MemorySanitizer unit tests. +//===----------------------------------------------------------------------===// + +#ifndef MSAN_TEST_CONFIG_H +#define MSAN_TEST_CONFIG_H + +#include "gtest/gtest.h" + +#endif // MSAN_TEST_CONFIG_H diff --git a/lib/msan/tests/msan_test_main.cc b/lib/msan/tests/msan_test_main.cc new file mode 100644 index 0000000000..c8c5fefb19 --- /dev/null +++ b/lib/msan/tests/msan_test_main.cc @@ -0,0 +1,21 @@ +//===-- msan_test_main.cc -------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of MemorySanitizer. +// +//===----------------------------------------------------------------------===// +#ifndef MSAN_EXTERNAL_TEST_CONFIG +#include "msan_test_config.h" +#endif // MSAN_EXTERNAL_TEST_CONFIG + +int main(int argc, char **argv) { + testing::GTEST_FLAG(death_test_style) = "threadsafe"; + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}