[compiler-rt] r182770 - [nolibc] Add a test case for Linux/x86_64.
Peter Collingbourne
peter at pcc.me.uk
Tue May 28 05:37:34 PDT 2013
Author: pcc
Date: Tue May 28 07:37:34 2013
New Revision: 182770
URL: http://llvm.org/viewvc/llvm-project?rev=182770&view=rev
Log:
[nolibc] Add a test case for Linux/x86_64.
Differential Revision: http://llvm-reviews.chandlerc.com/D873
Added:
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc
- copied, changed from r182765, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=182770&r1=182769&r2=182770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Tue May 28 07:37:34 2013
@@ -9,6 +9,7 @@ set(SANITIZER_UNITTESTS
sanitizer_linux_test.cc
sanitizer_list_test.cc
sanitizer_mutex_test.cc
+ sanitizer_nolibc_test.cc
sanitizer_printf_test.cc
sanitizer_scanf_interceptor_test.cc
sanitizer_stackdepot_test.cc
@@ -86,6 +87,24 @@ macro(add_sanitizer_tests_for_arch arch)
DEPS ${SANITIZER_TEST_OBJECTS} ${SANITIZER_COMMON_LIB}
LINK_FLAGS ${SANITIZER_TEST_LINK_FLAGS_COMMON}
-lpthread ${TARGET_FLAGS})
+
+ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND "${arch}" STREQUAL "x86_64")
+ # Test that the libc-independent part of sanitizer_common is indeed
+ # independent of libc, by linking this binary without libc (here) and
+ # executing it (unit test in sanitizer_nolibc_test.cc).
+ clang_compile(sanitizer_nolibc_test_main.${arch}.o
+ sanitizer_nolibc_test_main.cc
+ CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
+ DEPS ${SANITIZER_RUNTIME_LIBRARIES} ${SANITIZER_TEST_HEADERS})
+ add_compiler_rt_test(SanitizerUnitTests "Sanitizer-${arch}-Test-Nolibc"
+ OBJECTS sanitizer_nolibc_test_main.${arch}.o
+ -Wl,-whole-archive
+ libRTSanitizerCommon.test.nolibc.${arch}.a
+ -Wl,-no-whole-archive
+ DEPS sanitizer_nolibc_test_main.${arch}.o
+ RTSanitizerCommon.test.nolibc.${arch}
+ LINK_FLAGS -nostdlib ${TARGET_FLAGS})
+ endif()
endmacro()
if(COMPILER_RT_CAN_EXECUTE_TESTS)
@@ -99,6 +118,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS)
add_sanitizer_common_lib("RTSanitizerCommon.test.x86_64"
$<TARGET_OBJECTS:RTSanitizerCommon.x86_64>
$<TARGET_OBJECTS:RTSanitizerCommonLibc.x86_64>)
+ add_sanitizer_common_lib("RTSanitizerCommon.test.nolibc.x86_64"
+ $<TARGET_OBJECTS:RTSanitizerCommon.x86_64>)
endif()
if(CAN_TARGET_i386)
add_sanitizer_common_lib("RTSanitizerCommon.test.i386"
Added: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc?rev=182770&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc Tue May 28 07:37:34 2013
@@ -0,0 +1,31 @@
+//===-- sanitizer_nolibc_test.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 ThreadSanitizer/AddressSanitizer runtime.
+// Tests for libc independence of sanitizer_common.
+//
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_common/sanitizer_platform.h"
+
+#include "gtest/gtest.h"
+
+#include <stdlib.h>
+
+extern const char *argv0;
+
+#if SANITIZER_LINUX && defined(__x86_64__)
+TEST(SanitizerCommon, NolibcMain) {
+ std::string NolibcTestPath = argv0;
+ NolibcTestPath += "-Nolibc";
+ int status = system(NolibcTestPath.c_str());
+ EXPECT_EQ(true, WIFEXITED(status));
+ EXPECT_EQ(0, WEXITSTATUS(status));
+}
+#endif
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc (from r182765, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc&r1=182765&r2=182770&rev=182770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc Tue May 28 07:37:34 2013
@@ -1,4 +1,4 @@
-//===-- sanitizer_test_main.cc --------------------------------------------===//
+//===-- sanitizer_nolibc_test_main.cc -------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -8,12 +8,16 @@
//===----------------------------------------------------------------------===//
//
// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
+// Tests for libc independence of sanitizer_common.
//
//===----------------------------------------------------------------------===//
-#include "gtest/gtest.h"
-int main(int argc, char **argv) {
- testing::GTEST_FLAG(death_test_style) = "threadsafe";
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+#include "sanitizer_common/sanitizer_libc.h"
+
+// TODO(pcc): Remove these once the allocator dependency is gone.
+extern "C" void *__libc_malloc() { return 0; }
+extern "C" void __libc_free(void *p) {}
+
+extern "C" void _start() {
+ internal__exit(0);
}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc?rev=182770&r1=182769&r2=182770&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc Tue May 28 07:37:34 2013
@@ -12,7 +12,10 @@
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
+const char *argv0;
+
int main(int argc, char **argv) {
+ argv0 = argv[0];
testing::GTEST_FLAG(death_test_style) = "threadsafe";
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
More information about the llvm-commits
mailing list