[compiler-rt] r367467 - compiler-rt: Rename .cc file in lib/sanitizer_common/tests to .cpp
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 31 12:11:14 PDT 2019
Author: nico
Date: Wed Jul 31 12:11:14 2019
New Revision: 367467
URL: http://llvm.org/viewvc/llvm-project?rev=367467&view=rev
Log:
compiler-rt: Rename .cc file in lib/sanitizer_common/tests to .cpp
See https://reviews.llvm.org/D58620 for discussion, and for the commands
I ran. In addition I also ran
for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $(basename $f) . ; done
and manually updated references to renamed files found by that.
Added:
compiler-rt/trunk/lib/sanitizer_common/tests/malloc_stress_transfer_test.cpp
- copied unchanged from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/malloc_stress_transfer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cpp
- copied, changed from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/standalone_malloc_test.cpp
- copied unchanged from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/standalone_malloc_test.cc
Removed:
compiler-rt/trunk/lib/sanitizer_common/tests/malloc_stress_transfer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/standalone_malloc_test.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
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=367467&r1=367466&r2=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Wed Jul 31 12:11:14 2019
@@ -9,40 +9,42 @@ if(APPLE)
endif()
set(SANITIZER_UNITTESTS
- sanitizer_allocator_test.cc
- sanitizer_atomic_test.cc
- sanitizer_bitvector_test.cc
- sanitizer_bvgraph_test.cc
- sanitizer_common_test.cc
- sanitizer_deadlock_detector_test.cc
- sanitizer_flags_test.cc
- sanitizer_format_interceptor_test.cc
- sanitizer_ioctl_test.cc
- sanitizer_libc_test.cc
- sanitizer_linux_test.cc
- sanitizer_list_test.cc
- sanitizer_mutex_test.cc
- sanitizer_nolibc_test.cc
- sanitizer_posix_test.cc
- sanitizer_printf_test.cc
- sanitizer_procmaps_test.cc
- sanitizer_ring_buffer_test.cc
- sanitizer_quarantine_test.cc
- sanitizer_stackdepot_test.cc
- sanitizer_stacktrace_printer_test.cc
- sanitizer_stacktrace_test.cc
- sanitizer_stoptheworld_test.cc
- sanitizer_suppressions_test.cc
- sanitizer_symbolizer_test.cc
- sanitizer_test_main.cc
- sanitizer_thread_registry_test.cc
- sanitizer_type_traits_test.cc
- sanitizer_vector_test.cc)
+ sanitizer_allocator_test.cpp
+ sanitizer_atomic_test.cpp
+ sanitizer_bitvector_test.cpp
+ sanitizer_bvgraph_test.cpp
+ sanitizer_common_test.cpp
+ sanitizer_deadlock_detector_test.cpp
+ sanitizer_flags_test.cpp
+ sanitizer_format_interceptor_test.cpp
+ sanitizer_ioctl_test.cpp
+ sanitizer_libc_test.cpp
+ sanitizer_linux_test.cpp
+ sanitizer_list_test.cpp
+ sanitizer_mutex_test.cpp
+ sanitizer_nolibc_test.cpp
+ sanitizer_posix_test.cpp
+ sanitizer_printf_test.cpp
+ sanitizer_procmaps_test.cpp
+ sanitizer_ring_buffer_test.cpp
+ sanitizer_quarantine_test.cpp
+ sanitizer_stackdepot_test.cpp
+ sanitizer_stacktrace_printer_test.cpp
+ sanitizer_stacktrace_test.cpp
+ sanitizer_stoptheworld_test.cpp
+ sanitizer_suppressions_test.cpp
+ sanitizer_symbolizer_test.cpp
+ sanitizer_test_main.cpp
+ sanitizer_thread_registry_test.cpp
+ sanitizer_type_traits_test.cpp
+ sanitizer_vector_test.cpp
+ )
set(SANITIZER_TEST_HEADERS
sanitizer_pthread_wrappers.h
sanitizer_test_config.h
- sanitizer_test_utils.h)
+ sanitizer_test_utils.h
+ )
foreach(header ${SANITIZER_IMPL_HEADERS})
list(APPEND SANITIZER_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
endforeach()
@@ -57,7 +59,8 @@ set(SANITIZER_TEST_CFLAGS_COMMON
-O2
-Werror=sign-compare
-Wno-non-virtual-dtor
- -Wno-gnu-zero-variadic-macro-arguments)
+ -Wno-gnu-zero-variadic-macro-arguments
+ )
set(SANITIZER_TEST_LINK_FLAGS_COMMON ${COMPILER_RT_UNITTEST_LINK_FLAGS})
@@ -156,9 +159,9 @@ macro(add_sanitizer_tests_for_arch arch)
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).
+ # executing it (unit test in sanitizer_nolibc_test.cpp).
clang_compile(sanitizer_nolibc_test_main.${arch}.o
- sanitizer_nolibc_test_main.cc
+ sanitizer_nolibc_test_main.cpp
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
DEPS ${SANITIZER_TEST_COMPILE_DEPS})
add_compiler_rt_test(SanitizerUnitTests "Sanitizer-${arch}-Test-Nolibc" ${arch}
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/malloc_stress_transfer_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/malloc_stress_transfer_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/malloc_stress_transfer_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/malloc_stress_transfer_test.cc (removed)
@@ -1,37 +0,0 @@
-#include <thread>
-#include <iostream>
-
-const size_t kAllocSize = 16;
-const size_t kInitialNumAllocs = 1 << 10;
-const size_t kPeriodicNumAllocs = 1 << 10;
-const size_t kNumIterations = 1 << 7;
-const size_t kNumThreads = 16;
-
-void Thread() {
- // int sp;
- // std::cerr << "Thread starting, sp = " << &sp << std::endl;
- char *InitialAllocations[kInitialNumAllocs];
- char *PeriodicaAllocations[kPeriodicNumAllocs];
- for (auto &p : InitialAllocations) p = new char[kAllocSize];
- for (size_t i = 0; i < kNumIterations; i++) {
- for (size_t j = 0; j < kPeriodicNumAllocs; j++) {
- for (auto &p : PeriodicaAllocations) {
- p = new char[kAllocSize];
- *p = 0;
- }
- for (auto p : PeriodicaAllocations) delete [] p;
- }
- }
- for (auto p : InitialAllocations) delete [] p;
-}
-
-int main() {
-// Thread();
-// return 0;
- std::thread *Threads[kNumThreads];
- for (auto &T : Threads) T = new std::thread(&Thread);
- for (auto T : Threads) {
- T->join();
- delete T;
- }
-}
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (removed)
@@ -1,1407 +0,0 @@
-//===-- sanitizer_allocator_test.cc ---------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-// Tests for sanitizer_allocator.h.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_allocator.h"
-#include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "sanitizer_common/sanitizer_common.h"
-
-#include "sanitizer_test_utils.h"
-#include "sanitizer_pthread_wrappers.h"
-
-#include "gtest/gtest.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <algorithm>
-#include <vector>
-#include <random>
-#include <set>
-
-using namespace __sanitizer;
-
-// Too slow for debug build
-#if !SANITIZER_DEBUG
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-#if SANITIZER_WINDOWS
-// On Windows 64-bit there is no easy way to find a large enough fixed address
-// space that is always available. Thus, a dynamically allocated address space
-// is used instead (i.e. ~(uptr)0).
-static const uptr kAllocatorSpace = ~(uptr)0;
-static const uptr kAllocatorSize = 0x8000000000ULL; // 500G
-static const u64 kAddressSpaceSize = 1ULL << 47;
-typedef DefaultSizeClassMap SizeClassMap;
-#elif SANITIZER_ANDROID && defined(__aarch64__)
-static const uptr kAllocatorSpace = 0x3000000000ULL;
-static const uptr kAllocatorSize = 0x2000000000ULL;
-static const u64 kAddressSpaceSize = 1ULL << 39;
-typedef VeryCompactSizeClassMap SizeClassMap;
-#else
-static const uptr kAllocatorSpace = 0x700000000000ULL;
-static const uptr kAllocatorSize = 0x010000000000ULL; // 1T.
-static const u64 kAddressSpaceSize = 1ULL << 47;
-typedef DefaultSizeClassMap SizeClassMap;
-#endif
-
-template <typename AddressSpaceViewTy>
-struct AP64 { // Allocator Params. Short name for shorter demangled names..
- static const uptr kSpaceBeg = kAllocatorSpace;
- static const uptr kSpaceSize = kAllocatorSize;
- static const uptr kMetadataSize = 16;
- typedef ::SizeClassMap SizeClassMap;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
- using AddressSpaceView = AddressSpaceViewTy;
-};
-
-template <typename AddressSpaceViewTy>
-struct AP64Dyn {
- static const uptr kSpaceBeg = ~(uptr)0;
- static const uptr kSpaceSize = kAllocatorSize;
- static const uptr kMetadataSize = 16;
- typedef ::SizeClassMap SizeClassMap;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
- using AddressSpaceView = AddressSpaceViewTy;
-};
-
-template <typename AddressSpaceViewTy>
-struct AP64Compact {
- static const uptr kSpaceBeg = ~(uptr)0;
- static const uptr kSpaceSize = kAllocatorSize;
- static const uptr kMetadataSize = 16;
- typedef CompactSizeClassMap SizeClassMap;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
- using AddressSpaceView = AddressSpaceViewTy;
-};
-
-template <typename AddressSpaceViewTy>
-struct AP64VeryCompact {
- static const uptr kSpaceBeg = ~(uptr)0;
- static const uptr kSpaceSize = 1ULL << 37;
- static const uptr kMetadataSize = 16;
- typedef VeryCompactSizeClassMap SizeClassMap;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
- using AddressSpaceView = AddressSpaceViewTy;
-};
-
-template <typename AddressSpaceViewTy>
-struct AP64Dense {
- static const uptr kSpaceBeg = kAllocatorSpace;
- static const uptr kSpaceSize = kAllocatorSize;
- static const uptr kMetadataSize = 16;
- typedef DenseSizeClassMap SizeClassMap;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
- using AddressSpaceView = AddressSpaceViewTy;
-};
-
-template <typename AddressSpaceView>
-using Allocator64ASVT = SizeClassAllocator64<AP64<AddressSpaceView>>;
-using Allocator64 = Allocator64ASVT<LocalAddressSpaceView>;
-
-template <typename AddressSpaceView>
-using Allocator64DynamicASVT = SizeClassAllocator64<AP64Dyn<AddressSpaceView>>;
-using Allocator64Dynamic = Allocator64DynamicASVT<LocalAddressSpaceView>;
-
-template <typename AddressSpaceView>
-using Allocator64CompactASVT =
- SizeClassAllocator64<AP64Compact<AddressSpaceView>>;
-using Allocator64Compact = Allocator64CompactASVT<LocalAddressSpaceView>;
-
-template <typename AddressSpaceView>
-using Allocator64VeryCompactASVT =
- SizeClassAllocator64<AP64VeryCompact<AddressSpaceView>>;
-using Allocator64VeryCompact =
- Allocator64VeryCompactASVT<LocalAddressSpaceView>;
-
-template <typename AddressSpaceView>
-using Allocator64DenseASVT = SizeClassAllocator64<AP64Dense<AddressSpaceView>>;
-using Allocator64Dense = Allocator64DenseASVT<LocalAddressSpaceView>;
-
-#elif defined(__mips64)
-static const u64 kAddressSpaceSize = 1ULL << 40;
-#elif defined(__aarch64__)
-static const u64 kAddressSpaceSize = 1ULL << 39;
-#elif defined(__s390x__)
-static const u64 kAddressSpaceSize = 1ULL << 53;
-#elif defined(__s390__)
-static const u64 kAddressSpaceSize = 1ULL << 31;
-#else
-static const u64 kAddressSpaceSize = 1ULL << 32;
-#endif
-
-static const uptr kRegionSizeLog = FIRST_32_SECOND_64(20, 24);
-
-template <typename AddressSpaceViewTy>
-struct AP32Compact {
- static const uptr kSpaceBeg = 0;
- static const u64 kSpaceSize = kAddressSpaceSize;
- static const uptr kMetadataSize = 16;
- typedef CompactSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = ::kRegionSizeLog;
- using AddressSpaceView = AddressSpaceViewTy;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
-};
-template <typename AddressSpaceView>
-using Allocator32CompactASVT =
- SizeClassAllocator32<AP32Compact<AddressSpaceView>>;
-using Allocator32Compact = Allocator32CompactASVT<LocalAddressSpaceView>;
-
-template <class SizeClassMap>
-void TestSizeClassMap() {
- typedef SizeClassMap SCMap;
- SCMap::Print();
- SCMap::Validate();
-}
-
-TEST(SanitizerCommon, DefaultSizeClassMap) {
- TestSizeClassMap<DefaultSizeClassMap>();
-}
-
-TEST(SanitizerCommon, CompactSizeClassMap) {
- TestSizeClassMap<CompactSizeClassMap>();
-}
-
-TEST(SanitizerCommon, VeryCompactSizeClassMap) {
- TestSizeClassMap<VeryCompactSizeClassMap>();
-}
-
-TEST(SanitizerCommon, InternalSizeClassMap) {
- TestSizeClassMap<InternalSizeClassMap>();
-}
-
-TEST(SanitizerCommon, DenseSizeClassMap) {
- TestSizeClassMap<VeryCompactSizeClassMap>();
-}
-
-template <class Allocator>
-void TestSizeClassAllocator() {
- Allocator *a = new Allocator;
- a->Init(kReleaseToOSIntervalNever);
- typename Allocator::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
-
- static const uptr sizes[] = {
- 1, 16, 30, 40, 100, 1000, 10000,
- 50000, 60000, 100000, 120000, 300000, 500000, 1000000, 2000000
- };
-
- std::vector<void *> allocated;
-
- uptr last_total_allocated = 0;
- for (int i = 0; i < 3; i++) {
- // Allocate a bunch of chunks.
- for (uptr s = 0; s < ARRAY_SIZE(sizes); s++) {
- uptr size = sizes[s];
- if (!a->CanAllocate(size, 1)) continue;
- // printf("s = %ld\n", size);
- uptr n_iter = std::max((uptr)6, 4000000 / size);
- // fprintf(stderr, "size: %ld iter: %ld\n", size, n_iter);
- for (uptr i = 0; i < n_iter; i++) {
- uptr class_id0 = Allocator::SizeClassMapT::ClassID(size);
- char *x = (char*)cache.Allocate(a, class_id0);
- x[0] = 0;
- x[size - 1] = 0;
- x[size / 2] = 0;
- allocated.push_back(x);
- CHECK_EQ(x, a->GetBlockBegin(x));
- CHECK_EQ(x, a->GetBlockBegin(x + size - 1));
- CHECK(a->PointerIsMine(x));
- CHECK(a->PointerIsMine(x + size - 1));
- CHECK(a->PointerIsMine(x + size / 2));
- CHECK_GE(a->GetActuallyAllocatedSize(x), size);
- uptr class_id = a->GetSizeClass(x);
- CHECK_EQ(class_id, Allocator::SizeClassMapT::ClassID(size));
- uptr *metadata = reinterpret_cast<uptr*>(a->GetMetaData(x));
- metadata[0] = reinterpret_cast<uptr>(x) + 1;
- metadata[1] = 0xABCD;
- }
- }
- // Deallocate all.
- for (uptr i = 0; i < allocated.size(); i++) {
- void *x = allocated[i];
- uptr *metadata = reinterpret_cast<uptr*>(a->GetMetaData(x));
- CHECK_EQ(metadata[0], reinterpret_cast<uptr>(x) + 1);
- CHECK_EQ(metadata[1], 0xABCD);
- cache.Deallocate(a, a->GetSizeClass(x), x);
- }
- allocated.clear();
- uptr total_allocated = a->TotalMemoryUsed();
- if (last_total_allocated == 0)
- last_total_allocated = total_allocated;
- CHECK_EQ(last_total_allocated, total_allocated);
- }
-
- // Check that GetBlockBegin never crashes.
- for (uptr x = 0, step = kAddressSpaceSize / 100000;
- x < kAddressSpaceSize - step; x += step)
- if (a->PointerIsMine(reinterpret_cast<void *>(x)))
- Ident(a->GetBlockBegin(reinterpret_cast<void *>(x)));
-
- a->TestOnlyUnmap();
- delete a;
-}
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-// These tests can fail on Windows if memory is somewhat full and lit happens
-// to run them all at the same time. FIXME: Make them not flaky and reenable.
-#if !SANITIZER_WINDOWS
-TEST(SanitizerCommon, SizeClassAllocator64) {
- TestSizeClassAllocator<Allocator64>();
-}
-
-TEST(SanitizerCommon, SizeClassAllocator64Dynamic) {
- TestSizeClassAllocator<Allocator64Dynamic>();
-}
-
-#if !SANITIZER_ANDROID
-//FIXME(kostyak): find values so that those work on Android as well.
-TEST(SanitizerCommon, SizeClassAllocator64Compact) {
- TestSizeClassAllocator<Allocator64Compact>();
-}
-
-TEST(SanitizerCommon, SizeClassAllocator64Dense) {
- TestSizeClassAllocator<Allocator64Dense>();
-}
-#endif
-
-TEST(SanitizerCommon, SizeClassAllocator64VeryCompact) {
- TestSizeClassAllocator<Allocator64VeryCompact>();
-}
-#endif
-#endif
-
-TEST(SanitizerCommon, SizeClassAllocator32Compact) {
- TestSizeClassAllocator<Allocator32Compact>();
-}
-
-template <typename AddressSpaceViewTy>
-struct AP32SeparateBatches {
- static const uptr kSpaceBeg = 0;
- static const u64 kSpaceSize = kAddressSpaceSize;
- static const uptr kMetadataSize = 16;
- typedef DefaultSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = ::kRegionSizeLog;
- using AddressSpaceView = AddressSpaceViewTy;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags =
- SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch;
-};
-template <typename AddressSpaceView>
-using Allocator32SeparateBatchesASVT =
- SizeClassAllocator32<AP32SeparateBatches<AddressSpaceView>>;
-using Allocator32SeparateBatches =
- Allocator32SeparateBatchesASVT<LocalAddressSpaceView>;
-
-TEST(SanitizerCommon, SizeClassAllocator32SeparateBatches) {
- TestSizeClassAllocator<Allocator32SeparateBatches>();
-}
-
-template <class Allocator>
-void SizeClassAllocatorMetadataStress() {
- Allocator *a = new Allocator;
- a->Init(kReleaseToOSIntervalNever);
- typename Allocator::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
-
- const uptr kNumAllocs = 1 << 13;
- void *allocated[kNumAllocs];
- void *meta[kNumAllocs];
- for (uptr i = 0; i < kNumAllocs; i++) {
- void *x = cache.Allocate(a, 1 + i % (Allocator::kNumClasses - 1));
- allocated[i] = x;
- meta[i] = a->GetMetaData(x);
- }
- // Get Metadata kNumAllocs^2 times.
- for (uptr i = 0; i < kNumAllocs * kNumAllocs; i++) {
- uptr idx = i % kNumAllocs;
- void *m = a->GetMetaData(allocated[idx]);
- EXPECT_EQ(m, meta[idx]);
- }
- for (uptr i = 0; i < kNumAllocs; i++) {
- cache.Deallocate(a, 1 + i % (Allocator::kNumClasses - 1), allocated[i]);
- }
-
- a->TestOnlyUnmap();
- delete a;
-}
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-// These tests can fail on Windows if memory is somewhat full and lit happens
-// to run them all at the same time. FIXME: Make them not flaky and reenable.
-#if !SANITIZER_WINDOWS
-TEST(SanitizerCommon, SizeClassAllocator64MetadataStress) {
- SizeClassAllocatorMetadataStress<Allocator64>();
-}
-
-TEST(SanitizerCommon, SizeClassAllocator64DynamicMetadataStress) {
- SizeClassAllocatorMetadataStress<Allocator64Dynamic>();
-}
-
-#if !SANITIZER_ANDROID
-TEST(SanitizerCommon, SizeClassAllocator64CompactMetadataStress) {
- SizeClassAllocatorMetadataStress<Allocator64Compact>();
-}
-#endif
-
-#endif
-#endif // SANITIZER_CAN_USE_ALLOCATOR64
-TEST(SanitizerCommon, SizeClassAllocator32CompactMetadataStress) {
- SizeClassAllocatorMetadataStress<Allocator32Compact>();
-}
-
-template <class Allocator>
-void SizeClassAllocatorGetBlockBeginStress(u64 TotalSize) {
- Allocator *a = new Allocator;
- a->Init(kReleaseToOSIntervalNever);
- typename Allocator::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
-
- uptr max_size_class = Allocator::SizeClassMapT::kLargestClassID;
- uptr size = Allocator::SizeClassMapT::Size(max_size_class);
- // Make sure we correctly compute GetBlockBegin() w/o overflow.
- for (size_t i = 0; i <= TotalSize / size; i++) {
- void *x = cache.Allocate(a, max_size_class);
- void *beg = a->GetBlockBegin(x);
- // if ((i & (i - 1)) == 0)
- // fprintf(stderr, "[%zd] %p %p\n", i, x, beg);
- EXPECT_EQ(x, beg);
- }
-
- a->TestOnlyUnmap();
- delete a;
-}
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-// These tests can fail on Windows if memory is somewhat full and lit happens
-// to run them all at the same time. FIXME: Make them not flaky and reenable.
-#if !SANITIZER_WINDOWS
-TEST(SanitizerCommon, SizeClassAllocator64GetBlockBegin) {
- SizeClassAllocatorGetBlockBeginStress<Allocator64>(
- 1ULL << (SANITIZER_ANDROID ? 31 : 33));
-}
-TEST(SanitizerCommon, SizeClassAllocator64DynamicGetBlockBegin) {
- SizeClassAllocatorGetBlockBeginStress<Allocator64Dynamic>(
- 1ULL << (SANITIZER_ANDROID ? 31 : 33));
-}
-#if !SANITIZER_ANDROID
-TEST(SanitizerCommon, SizeClassAllocator64CompactGetBlockBegin) {
- SizeClassAllocatorGetBlockBeginStress<Allocator64Compact>(1ULL << 33);
-}
-#endif
-TEST(SanitizerCommon, SizeClassAllocator64VeryCompactGetBlockBegin) {
- // Does not have > 4Gb for each class.
- SizeClassAllocatorGetBlockBeginStress<Allocator64VeryCompact>(1ULL << 31);
-}
-TEST(SanitizerCommon, SizeClassAllocator32CompactGetBlockBegin) {
- SizeClassAllocatorGetBlockBeginStress<Allocator32Compact>(1ULL << 33);
-}
-#endif
-#endif // SANITIZER_CAN_USE_ALLOCATOR64
-
-struct TestMapUnmapCallback {
- static int map_count, unmap_count;
- void OnMap(uptr p, uptr size) const { map_count++; }
- void OnUnmap(uptr p, uptr size) const { unmap_count++; }
-};
-int TestMapUnmapCallback::map_count;
-int TestMapUnmapCallback::unmap_count;
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-// These tests can fail on Windows if memory is somewhat full and lit happens
-// to run them all at the same time. FIXME: Make them not flaky and reenable.
-#if !SANITIZER_WINDOWS
-
-template <typename AddressSpaceViewTy = LocalAddressSpaceView>
-struct AP64WithCallback {
- static const uptr kSpaceBeg = kAllocatorSpace;
- static const uptr kSpaceSize = kAllocatorSize;
- static const uptr kMetadataSize = 16;
- typedef ::SizeClassMap SizeClassMap;
- typedef TestMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
- using AddressSpaceView = AddressSpaceViewTy;
-};
-
-TEST(SanitizerCommon, SizeClassAllocator64MapUnmapCallback) {
- TestMapUnmapCallback::map_count = 0;
- TestMapUnmapCallback::unmap_count = 0;
- typedef SizeClassAllocator64<AP64WithCallback<>> Allocator64WithCallBack;
- Allocator64WithCallBack *a = new Allocator64WithCallBack;
- a->Init(kReleaseToOSIntervalNever);
- EXPECT_EQ(TestMapUnmapCallback::map_count, 1); // Allocator state.
- typename Allocator64WithCallBack::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
- AllocatorStats stats;
- stats.Init();
- const size_t kNumChunks = 128;
- uint32_t chunks[kNumChunks];
- a->GetFromAllocator(&stats, 30, chunks, kNumChunks);
- // State + alloc + metadata + freearray.
- EXPECT_EQ(TestMapUnmapCallback::map_count, 4);
- a->TestOnlyUnmap();
- EXPECT_EQ(TestMapUnmapCallback::unmap_count, 1); // The whole thing.
- delete a;
-}
-#endif
-#endif
-
-template <typename AddressSpaceViewTy = LocalAddressSpaceView>
-struct AP32WithCallback {
- static const uptr kSpaceBeg = 0;
- static const u64 kSpaceSize = kAddressSpaceSize;
- static const uptr kMetadataSize = 16;
- typedef CompactSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = ::kRegionSizeLog;
- using AddressSpaceView = AddressSpaceViewTy;
- typedef TestMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
-};
-
-TEST(SanitizerCommon, SizeClassAllocator32MapUnmapCallback) {
- TestMapUnmapCallback::map_count = 0;
- TestMapUnmapCallback::unmap_count = 0;
- typedef SizeClassAllocator32<AP32WithCallback<>> Allocator32WithCallBack;
- Allocator32WithCallBack *a = new Allocator32WithCallBack;
- a->Init(kReleaseToOSIntervalNever);
- EXPECT_EQ(TestMapUnmapCallback::map_count, 0);
- Allocator32WithCallBack::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
- AllocatorStats stats;
- stats.Init();
- a->AllocateBatch(&stats, &cache, 32);
- EXPECT_EQ(TestMapUnmapCallback::map_count, 1);
- a->TestOnlyUnmap();
- EXPECT_EQ(TestMapUnmapCallback::unmap_count, 1);
- delete a;
- // fprintf(stderr, "Map: %d Unmap: %d\n",
- // TestMapUnmapCallback::map_count,
- // TestMapUnmapCallback::unmap_count);
-}
-
-TEST(SanitizerCommon, LargeMmapAllocatorMapUnmapCallback) {
- TestMapUnmapCallback::map_count = 0;
- TestMapUnmapCallback::unmap_count = 0;
- LargeMmapAllocator<TestMapUnmapCallback> a;
- a.Init();
- AllocatorStats stats;
- stats.Init();
- void *x = a.Allocate(&stats, 1 << 20, 1);
- EXPECT_EQ(TestMapUnmapCallback::map_count, 1);
- a.Deallocate(&stats, x);
- EXPECT_EQ(TestMapUnmapCallback::unmap_count, 1);
-}
-
-// Don't test OOM conditions on Win64 because it causes other tests on the same
-// machine to OOM.
-#if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64 && !SANITIZER_ANDROID
-TEST(SanitizerCommon, SizeClassAllocator64Overflow) {
- Allocator64 a;
- a.Init(kReleaseToOSIntervalNever);
- Allocator64::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
- AllocatorStats stats;
- stats.Init();
-
- const size_t kNumChunks = 128;
- uint32_t chunks[kNumChunks];
- bool allocation_failed = false;
- for (int i = 0; i < 1000000; i++) {
- if (!a.GetFromAllocator(&stats, 52, chunks, kNumChunks)) {
- allocation_failed = true;
- break;
- }
- }
- EXPECT_EQ(allocation_failed, true);
-
- a.TestOnlyUnmap();
-}
-#endif
-
-TEST(SanitizerCommon, LargeMmapAllocator) {
- LargeMmapAllocator<NoOpMapUnmapCallback> a;
- a.Init();
- AllocatorStats stats;
- stats.Init();
-
- static const int kNumAllocs = 1000;
- char *allocated[kNumAllocs];
- static const uptr size = 4000;
- // Allocate some.
- for (int i = 0; i < kNumAllocs; i++) {
- allocated[i] = (char *)a.Allocate(&stats, size, 1);
- CHECK(a.PointerIsMine(allocated[i]));
- }
- // Deallocate all.
- CHECK_GT(a.TotalMemoryUsed(), size * kNumAllocs);
- for (int i = 0; i < kNumAllocs; i++) {
- char *p = allocated[i];
- CHECK(a.PointerIsMine(p));
- a.Deallocate(&stats, p);
- }
- // Check that non left.
- CHECK_EQ(a.TotalMemoryUsed(), 0);
-
- // Allocate some more, also add metadata.
- for (int i = 0; i < kNumAllocs; i++) {
- char *x = (char *)a.Allocate(&stats, size, 1);
- CHECK_GE(a.GetActuallyAllocatedSize(x), size);
- uptr *meta = reinterpret_cast<uptr*>(a.GetMetaData(x));
- *meta = i;
- allocated[i] = x;
- }
- for (int i = 0; i < kNumAllocs * kNumAllocs; i++) {
- char *p = allocated[i % kNumAllocs];
- CHECK(a.PointerIsMine(p));
- CHECK(a.PointerIsMine(p + 2000));
- }
- CHECK_GT(a.TotalMemoryUsed(), size * kNumAllocs);
- // Deallocate all in reverse order.
- for (int i = 0; i < kNumAllocs; i++) {
- int idx = kNumAllocs - i - 1;
- char *p = allocated[idx];
- uptr *meta = reinterpret_cast<uptr*>(a.GetMetaData(p));
- CHECK_EQ(*meta, idx);
- CHECK(a.PointerIsMine(p));
- a.Deallocate(&stats, p);
- }
- CHECK_EQ(a.TotalMemoryUsed(), 0);
-
- // Test alignments. Test with 512MB alignment on x64 non-Windows machines.
- // Windows doesn't overcommit, and many machines do not have 51.2GB of swap.
- uptr max_alignment =
- (SANITIZER_WORDSIZE == 64 && !SANITIZER_WINDOWS) ? (1 << 28) : (1 << 24);
- for (uptr alignment = 8; alignment <= max_alignment; alignment *= 2) {
- const uptr kNumAlignedAllocs = 100;
- for (uptr i = 0; i < kNumAlignedAllocs; i++) {
- uptr size = ((i % 10) + 1) * 4096;
- char *p = allocated[i] = (char *)a.Allocate(&stats, size, alignment);
- CHECK_EQ(p, a.GetBlockBegin(p));
- CHECK_EQ(p, a.GetBlockBegin(p + size - 1));
- CHECK_EQ(p, a.GetBlockBegin(p + size / 2));
- CHECK_EQ(0, (uptr)allocated[i] % alignment);
- p[0] = p[size - 1] = 0;
- }
- for (uptr i = 0; i < kNumAlignedAllocs; i++) {
- a.Deallocate(&stats, allocated[i]);
- }
- }
-
- // Regression test for boundary condition in GetBlockBegin().
- uptr page_size = GetPageSizeCached();
- char *p = (char *)a.Allocate(&stats, page_size, 1);
- CHECK_EQ(p, a.GetBlockBegin(p));
- CHECK_EQ(p, (char *)a.GetBlockBegin(p + page_size - 1));
- CHECK_NE(p, (char *)a.GetBlockBegin(p + page_size));
- a.Deallocate(&stats, p);
-}
-
-template <class PrimaryAllocator>
-void TestCombinedAllocator() {
- typedef CombinedAllocator<PrimaryAllocator> Allocator;
- Allocator *a = new Allocator;
- a->Init(kReleaseToOSIntervalNever);
- std::mt19937 r;
-
- typename Allocator::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- a->InitCache(&cache);
-
- EXPECT_EQ(a->Allocate(&cache, -1, 1), (void*)0);
- EXPECT_EQ(a->Allocate(&cache, -1, 1024), (void*)0);
- EXPECT_EQ(a->Allocate(&cache, (uptr)-1 - 1024, 1), (void*)0);
- EXPECT_EQ(a->Allocate(&cache, (uptr)-1 - 1024, 1024), (void*)0);
- EXPECT_EQ(a->Allocate(&cache, (uptr)-1 - 1023, 1024), (void*)0);
- EXPECT_EQ(a->Allocate(&cache, -1, 1), (void*)0);
-
- const uptr kNumAllocs = 100000;
- const uptr kNumIter = 10;
- for (uptr iter = 0; iter < kNumIter; iter++) {
- std::vector<void*> allocated;
- for (uptr i = 0; i < kNumAllocs; i++) {
- uptr size = (i % (1 << 14)) + 1;
- if ((i % 1024) == 0)
- size = 1 << (10 + (i % 14));
- void *x = a->Allocate(&cache, size, 1);
- uptr *meta = reinterpret_cast<uptr*>(a->GetMetaData(x));
- CHECK_EQ(*meta, 0);
- *meta = size;
- allocated.push_back(x);
- }
-
- std::shuffle(allocated.begin(), allocated.end(), r);
-
- // Test ForEachChunk(...)
- {
- std::set<void *> reported_chunks;
- auto cb = [](uptr chunk, void *arg) {
- auto reported_chunks_ptr = reinterpret_cast<std::set<void *> *>(arg);
- auto pair =
- reported_chunks_ptr->insert(reinterpret_cast<void *>(chunk));
- // Check chunk is never reported more than once.
- ASSERT_TRUE(pair.second);
- };
- a->ForEachChunk(cb, reinterpret_cast<void *>(&reported_chunks));
- for (const auto &allocated_ptr : allocated) {
- ASSERT_NE(reported_chunks.find(allocated_ptr), reported_chunks.end());
- }
- }
-
- for (uptr i = 0; i < kNumAllocs; i++) {
- void *x = allocated[i];
- uptr *meta = reinterpret_cast<uptr*>(a->GetMetaData(x));
- CHECK_NE(*meta, 0);
- CHECK(a->PointerIsMine(x));
- *meta = 0;
- a->Deallocate(&cache, x);
- }
- allocated.clear();
- a->SwallowCache(&cache);
- }
- a->DestroyCache(&cache);
- a->TestOnlyUnmap();
-}
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-TEST(SanitizerCommon, CombinedAllocator64) {
- TestCombinedAllocator<Allocator64>();
-}
-
-TEST(SanitizerCommon, CombinedAllocator64Dynamic) {
- TestCombinedAllocator<Allocator64Dynamic>();
-}
-
-#if !SANITIZER_ANDROID
-TEST(SanitizerCommon, CombinedAllocator64Compact) {
- TestCombinedAllocator<Allocator64Compact>();
-}
-#endif
-
-TEST(SanitizerCommon, CombinedAllocator64VeryCompact) {
- TestCombinedAllocator<Allocator64VeryCompact>();
-}
-#endif
-
-TEST(SanitizerCommon, CombinedAllocator32Compact) {
- TestCombinedAllocator<Allocator32Compact>();
-}
-
-template <class Allocator>
-void TestSizeClassAllocatorLocalCache() {
- using AllocatorCache = typename Allocator::AllocatorCache;
- AllocatorCache cache;
- Allocator *a = new Allocator();
-
- a->Init(kReleaseToOSIntervalNever);
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
-
- const uptr kNumAllocs = 10000;
- const int kNumIter = 100;
- uptr saved_total = 0;
- for (int class_id = 1; class_id <= 5; class_id++) {
- for (int it = 0; it < kNumIter; it++) {
- void *allocated[kNumAllocs];
- for (uptr i = 0; i < kNumAllocs; i++) {
- allocated[i] = cache.Allocate(a, class_id);
- }
- for (uptr i = 0; i < kNumAllocs; i++) {
- cache.Deallocate(a, class_id, allocated[i]);
- }
- cache.Drain(a);
- uptr total_allocated = a->TotalMemoryUsed();
- if (it)
- CHECK_EQ(saved_total, total_allocated);
- saved_total = total_allocated;
- }
- }
-
- a->TestOnlyUnmap();
- delete a;
-}
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-// These tests can fail on Windows if memory is somewhat full and lit happens
-// to run them all at the same time. FIXME: Make them not flaky and reenable.
-#if !SANITIZER_WINDOWS
-TEST(SanitizerCommon, SizeClassAllocator64LocalCache) {
- TestSizeClassAllocatorLocalCache<Allocator64>();
-}
-
-TEST(SanitizerCommon, SizeClassAllocator64DynamicLocalCache) {
- TestSizeClassAllocatorLocalCache<Allocator64Dynamic>();
-}
-
-#if !SANITIZER_ANDROID
-TEST(SanitizerCommon, SizeClassAllocator64CompactLocalCache) {
- TestSizeClassAllocatorLocalCache<Allocator64Compact>();
-}
-#endif
-TEST(SanitizerCommon, SizeClassAllocator64VeryCompactLocalCache) {
- TestSizeClassAllocatorLocalCache<Allocator64VeryCompact>();
-}
-#endif
-#endif
-
-TEST(SanitizerCommon, SizeClassAllocator32CompactLocalCache) {
- TestSizeClassAllocatorLocalCache<Allocator32Compact>();
-}
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-typedef Allocator64::AllocatorCache AllocatorCache;
-static AllocatorCache static_allocator_cache;
-
-void *AllocatorLeakTestWorker(void *arg) {
- typedef AllocatorCache::Allocator Allocator;
- Allocator *a = (Allocator*)(arg);
- static_allocator_cache.Allocate(a, 10);
- static_allocator_cache.Drain(a);
- return 0;
-}
-
-TEST(SanitizerCommon, AllocatorLeakTest) {
- typedef AllocatorCache::Allocator Allocator;
- Allocator a;
- a.Init(kReleaseToOSIntervalNever);
- uptr total_used_memory = 0;
- for (int i = 0; i < 100; i++) {
- pthread_t t;
- PTHREAD_CREATE(&t, 0, AllocatorLeakTestWorker, &a);
- PTHREAD_JOIN(t, 0);
- if (i == 0)
- total_used_memory = a.TotalMemoryUsed();
- EXPECT_EQ(a.TotalMemoryUsed(), total_used_memory);
- }
-
- a.TestOnlyUnmap();
-}
-
-// Struct which is allocated to pass info to new threads. The new thread frees
-// it.
-struct NewThreadParams {
- AllocatorCache *thread_cache;
- AllocatorCache::Allocator *allocator;
- uptr class_id;
-};
-
-// Called in a new thread. Just frees its argument.
-static void *DeallocNewThreadWorker(void *arg) {
- NewThreadParams *params = reinterpret_cast<NewThreadParams*>(arg);
- params->thread_cache->Deallocate(params->allocator, params->class_id, params);
- return NULL;
-}
-
-// The allocator cache is supposed to be POD and zero initialized. We should be
-// able to call Deallocate on a zeroed cache, and it will self-initialize.
-TEST(Allocator, AllocatorCacheDeallocNewThread) {
- AllocatorCache::Allocator allocator;
- allocator.Init(kReleaseToOSIntervalNever);
- AllocatorCache main_cache;
- AllocatorCache child_cache;
- memset(&main_cache, 0, sizeof(main_cache));
- memset(&child_cache, 0, sizeof(child_cache));
-
- uptr class_id = DefaultSizeClassMap::ClassID(sizeof(NewThreadParams));
- NewThreadParams *params = reinterpret_cast<NewThreadParams*>(
- main_cache.Allocate(&allocator, class_id));
- params->thread_cache = &child_cache;
- params->allocator = &allocator;
- params->class_id = class_id;
- pthread_t t;
- PTHREAD_CREATE(&t, 0, DeallocNewThreadWorker, params);
- PTHREAD_JOIN(t, 0);
-
- allocator.TestOnlyUnmap();
-}
-#endif
-
-TEST(Allocator, Basic) {
- char *p = (char*)InternalAlloc(10);
- EXPECT_NE(p, (char*)0);
- char *p2 = (char*)InternalAlloc(20);
- EXPECT_NE(p2, (char*)0);
- EXPECT_NE(p2, p);
- InternalFree(p);
- InternalFree(p2);
-}
-
-TEST(Allocator, Stress) {
- const int kCount = 1000;
- char *ptrs[kCount];
- unsigned rnd = 42;
- for (int i = 0; i < kCount; i++) {
- uptr sz = my_rand_r(&rnd) % 1000;
- char *p = (char*)InternalAlloc(sz);
- EXPECT_NE(p, (char*)0);
- ptrs[i] = p;
- }
- for (int i = 0; i < kCount; i++) {
- InternalFree(ptrs[i]);
- }
-}
-
-TEST(Allocator, LargeAlloc) {
- void *p = InternalAlloc(10 << 20);
- InternalFree(p);
-}
-
-TEST(Allocator, ScopedBuffer) {
- const int kSize = 512;
- {
- InternalMmapVector<int> int_buf(kSize);
- EXPECT_EQ((uptr)kSize, int_buf.size()); // NOLINT
- }
- InternalMmapVector<char> char_buf(kSize);
- EXPECT_EQ((uptr)kSize, char_buf.size()); // NOLINT
- internal_memset(char_buf.data(), 'c', kSize);
- for (int i = 0; i < kSize; i++) {
- EXPECT_EQ('c', char_buf[i]);
- }
-}
-
-void IterationTestCallback(uptr chunk, void *arg) {
- reinterpret_cast<std::set<uptr> *>(arg)->insert(chunk);
-}
-
-template <class Allocator>
-void TestSizeClassAllocatorIteration() {
- Allocator *a = new Allocator;
- a->Init(kReleaseToOSIntervalNever);
- typename Allocator::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
-
- static const uptr sizes[] = {1, 16, 30, 40, 100, 1000, 10000,
- 50000, 60000, 100000, 120000, 300000, 500000, 1000000, 2000000};
-
- std::vector<void *> allocated;
-
- // Allocate a bunch of chunks.
- for (uptr s = 0; s < ARRAY_SIZE(sizes); s++) {
- uptr size = sizes[s];
- if (!a->CanAllocate(size, 1)) continue;
- // printf("s = %ld\n", size);
- uptr n_iter = std::max((uptr)6, 80000 / size);
- // fprintf(stderr, "size: %ld iter: %ld\n", size, n_iter);
- for (uptr j = 0; j < n_iter; j++) {
- uptr class_id0 = Allocator::SizeClassMapT::ClassID(size);
- void *x = cache.Allocate(a, class_id0);
- allocated.push_back(x);
- }
- }
-
- std::set<uptr> reported_chunks;
- a->ForceLock();
- a->ForEachChunk(IterationTestCallback, &reported_chunks);
- a->ForceUnlock();
-
- for (uptr i = 0; i < allocated.size(); i++) {
- // Don't use EXPECT_NE. Reporting the first mismatch is enough.
- ASSERT_NE(reported_chunks.find(reinterpret_cast<uptr>(allocated[i])),
- reported_chunks.end());
- }
-
- a->TestOnlyUnmap();
- delete a;
-}
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-// These tests can fail on Windows if memory is somewhat full and lit happens
-// to run them all at the same time. FIXME: Make them not flaky and reenable.
-#if !SANITIZER_WINDOWS
-TEST(SanitizerCommon, SizeClassAllocator64Iteration) {
- TestSizeClassAllocatorIteration<Allocator64>();
-}
-TEST(SanitizerCommon, SizeClassAllocator64DynamicIteration) {
- TestSizeClassAllocatorIteration<Allocator64Dynamic>();
-}
-#endif
-#endif
-
-TEST(SanitizerCommon, SizeClassAllocator32Iteration) {
- TestSizeClassAllocatorIteration<Allocator32Compact>();
-}
-
-TEST(SanitizerCommon, LargeMmapAllocatorIteration) {
- LargeMmapAllocator<NoOpMapUnmapCallback> a;
- a.Init();
- AllocatorStats stats;
- stats.Init();
-
- static const uptr kNumAllocs = 1000;
- char *allocated[kNumAllocs];
- static const uptr size = 40;
- // Allocate some.
- for (uptr i = 0; i < kNumAllocs; i++)
- allocated[i] = (char *)a.Allocate(&stats, size, 1);
-
- std::set<uptr> reported_chunks;
- a.ForceLock();
- a.ForEachChunk(IterationTestCallback, &reported_chunks);
- a.ForceUnlock();
-
- for (uptr i = 0; i < kNumAllocs; i++) {
- // Don't use EXPECT_NE. Reporting the first mismatch is enough.
- ASSERT_NE(reported_chunks.find(reinterpret_cast<uptr>(allocated[i])),
- reported_chunks.end());
- }
- for (uptr i = 0; i < kNumAllocs; i++)
- a.Deallocate(&stats, allocated[i]);
-}
-
-TEST(SanitizerCommon, LargeMmapAllocatorBlockBegin) {
- LargeMmapAllocator<NoOpMapUnmapCallback> a;
- a.Init();
- AllocatorStats stats;
- stats.Init();
-
- static const uptr kNumAllocs = 1024;
- static const uptr kNumExpectedFalseLookups = 10000000;
- char *allocated[kNumAllocs];
- static const uptr size = 4096;
- // Allocate some.
- for (uptr i = 0; i < kNumAllocs; i++) {
- allocated[i] = (char *)a.Allocate(&stats, size, 1);
- }
-
- a.ForceLock();
- for (uptr i = 0; i < kNumAllocs * kNumAllocs; i++) {
- // if ((i & (i - 1)) == 0) fprintf(stderr, "[%zd]\n", i);
- char *p1 = allocated[i % kNumAllocs];
- EXPECT_EQ(p1, a.GetBlockBeginFastLocked(p1));
- EXPECT_EQ(p1, a.GetBlockBeginFastLocked(p1 + size / 2));
- EXPECT_EQ(p1, a.GetBlockBeginFastLocked(p1 + size - 1));
- EXPECT_EQ(p1, a.GetBlockBeginFastLocked(p1 - 100));
- }
-
- for (uptr i = 0; i < kNumExpectedFalseLookups; i++) {
- void *p = reinterpret_cast<void *>(i % 1024);
- EXPECT_EQ((void *)0, a.GetBlockBeginFastLocked(p));
- p = reinterpret_cast<void *>(~0L - (i % 1024));
- EXPECT_EQ((void *)0, a.GetBlockBeginFastLocked(p));
- }
- a.ForceUnlock();
-
- for (uptr i = 0; i < kNumAllocs; i++)
- a.Deallocate(&stats, allocated[i]);
-}
-
-
-// Don't test OOM conditions on Win64 because it causes other tests on the same
-// machine to OOM.
-#if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64 && !SANITIZER_ANDROID
-typedef __sanitizer::SizeClassMap<3, 4, 8, 63, 128, 16> SpecialSizeClassMap;
-template <typename AddressSpaceViewTy = LocalAddressSpaceView>
-struct AP64_SpecialSizeClassMap {
- static const uptr kSpaceBeg = kAllocatorSpace;
- static const uptr kSpaceSize = kAllocatorSize;
- static const uptr kMetadataSize = 0;
- typedef SpecialSizeClassMap SizeClassMap;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = 0;
- using AddressSpaceView = AddressSpaceViewTy;
-};
-
-// Regression test for out-of-memory condition in PopulateFreeList().
-TEST(SanitizerCommon, SizeClassAllocator64PopulateFreeListOOM) {
- // In a world where regions are small and chunks are huge...
- typedef SizeClassAllocator64<AP64_SpecialSizeClassMap<>> SpecialAllocator64;
- const uptr kRegionSize =
- kAllocatorSize / SpecialSizeClassMap::kNumClassesRounded;
- SpecialAllocator64 *a = new SpecialAllocator64;
- a->Init(kReleaseToOSIntervalNever);
- SpecialAllocator64::AllocatorCache cache;
- memset(&cache, 0, sizeof(cache));
- cache.Init(0);
-
- // ...one man is on a mission to overflow a region with a series of
- // successive allocations.
-
- const uptr kClassID = 107;
- const uptr kAllocationSize = SpecialSizeClassMap::Size(kClassID);
- ASSERT_LT(2 * kAllocationSize, kRegionSize);
- ASSERT_GT(3 * kAllocationSize, kRegionSize);
- EXPECT_NE(cache.Allocate(a, kClassID), nullptr);
- EXPECT_NE(cache.Allocate(a, kClassID), nullptr);
- EXPECT_EQ(cache.Allocate(a, kClassID), nullptr);
-
- const uptr Class2 = 100;
- const uptr Size2 = SpecialSizeClassMap::Size(Class2);
- ASSERT_EQ(Size2 * 8, kRegionSize);
- char *p[7];
- for (int i = 0; i < 7; i++) {
- p[i] = (char*)cache.Allocate(a, Class2);
- EXPECT_NE(p[i], nullptr);
- fprintf(stderr, "p[%d] %p s = %lx\n", i, (void*)p[i], Size2);
- p[i][Size2 - 1] = 42;
- if (i) ASSERT_LT(p[i - 1], p[i]);
- }
- EXPECT_EQ(cache.Allocate(a, Class2), nullptr);
- cache.Deallocate(a, Class2, p[0]);
- cache.Drain(a);
- ASSERT_EQ(p[6][Size2 - 1], 42);
- a->TestOnlyUnmap();
- delete a;
-}
-
-#endif
-
-#if SANITIZER_CAN_USE_ALLOCATOR64
-
-class NoMemoryMapper {
- public:
- uptr last_request_buffer_size;
-
- NoMemoryMapper() : last_request_buffer_size(0) {}
-
- uptr MapPackedCounterArrayBuffer(uptr buffer_size) {
- last_request_buffer_size = buffer_size;
- return 0;
- }
- void UnmapPackedCounterArrayBuffer(uptr buffer, uptr buffer_size) {}
-};
-
-class RedZoneMemoryMapper {
- public:
- RedZoneMemoryMapper() {
- const auto page_size = GetPageSize();
- buffer = MmapOrDie(3ULL * page_size, "");
- MprotectNoAccess(reinterpret_cast<uptr>(buffer), page_size);
- MprotectNoAccess(reinterpret_cast<uptr>(buffer) + page_size * 2, page_size);
- }
- ~RedZoneMemoryMapper() {
- UnmapOrDie(buffer, 3 * GetPageSize());
- }
-
- uptr MapPackedCounterArrayBuffer(uptr buffer_size) {
- const auto page_size = GetPageSize();
- CHECK_EQ(buffer_size, page_size);
- memset(reinterpret_cast<void*>(reinterpret_cast<uptr>(buffer) + page_size),
- 0, page_size);
- return reinterpret_cast<uptr>(buffer) + page_size;
- }
- void UnmapPackedCounterArrayBuffer(uptr buffer, uptr buffer_size) {}
-
- private:
- void *buffer;
-};
-
-TEST(SanitizerCommon, SizeClassAllocator64PackedCounterArray) {
- NoMemoryMapper no_memory_mapper;
- typedef Allocator64::PackedCounterArray<NoMemoryMapper>
- NoMemoryPackedCounterArray;
-
- for (int i = 0; i < 64; i++) {
- // Various valid counter's max values packed into one word.
- NoMemoryPackedCounterArray counters_2n(1, 1ULL << i, &no_memory_mapper);
- EXPECT_EQ(8ULL, no_memory_mapper.last_request_buffer_size);
-
- // Check the "all bit set" values too.
- NoMemoryPackedCounterArray counters_2n1_1(1, ~0ULL >> i, &no_memory_mapper);
- EXPECT_EQ(8ULL, no_memory_mapper.last_request_buffer_size);
-
- // Verify the packing ratio, the counter is expected to be packed into the
- // closest power of 2 bits.
- NoMemoryPackedCounterArray counters(64, 1ULL << i, &no_memory_mapper);
- EXPECT_EQ(8ULL * RoundUpToPowerOfTwo(i + 1),
- no_memory_mapper.last_request_buffer_size);
- }
-
- RedZoneMemoryMapper memory_mapper;
- typedef Allocator64::PackedCounterArray<RedZoneMemoryMapper>
- RedZonePackedCounterArray;
- // Go through 1, 2, 4, 8, .. 64 bits per counter.
- for (int i = 0; i < 7; i++) {
- // Make sure counters request one memory page for the buffer.
- const u64 kNumCounters = (GetPageSize() / 8) * (64 >> i);
- RedZonePackedCounterArray counters(kNumCounters,
- 1ULL << ((1 << i) - 1),
- &memory_mapper);
- counters.Inc(0);
- for (u64 c = 1; c < kNumCounters - 1; c++) {
- ASSERT_EQ(0ULL, counters.Get(c));
- counters.Inc(c);
- ASSERT_EQ(1ULL, counters.Get(c - 1));
- }
- ASSERT_EQ(0ULL, counters.Get(kNumCounters - 1));
- counters.Inc(kNumCounters - 1);
-
- if (i > 0) {
- counters.IncRange(0, kNumCounters - 1);
- for (u64 c = 0; c < kNumCounters; c++)
- ASSERT_EQ(2ULL, counters.Get(c));
- }
- }
-}
-
-class RangeRecorder {
- public:
- std::string reported_pages;
-
- RangeRecorder()
- : page_size_scaled_log(
- Log2(GetPageSizeCached() >> Allocator64::kCompactPtrScale)),
- last_page_reported(0) {}
-
- void ReleasePageRangeToOS(u32 from, u32 to) {
- from >>= page_size_scaled_log;
- to >>= page_size_scaled_log;
- ASSERT_LT(from, to);
- if (!reported_pages.empty())
- ASSERT_LT(last_page_reported, from);
- reported_pages.append(from - last_page_reported, '.');
- reported_pages.append(to - from, 'x');
- last_page_reported = to;
- }
- private:
- const uptr page_size_scaled_log;
- u32 last_page_reported;
-};
-
-TEST(SanitizerCommon, SizeClassAllocator64FreePagesRangeTracker) {
- typedef Allocator64::FreePagesRangeTracker<RangeRecorder> RangeTracker;
-
- // 'x' denotes a page to be released, '.' denotes a page to be kept around.
- const char* test_cases[] = {
- "",
- ".",
- "x",
- "........",
- "xxxxxxxxxxx",
- "..............xxxxx",
- "xxxxxxxxxxxxxxxxxx.....",
- "......xxxxxxxx........",
- "xxx..........xxxxxxxxxxxxxxx",
- "......xxxx....xxxx........",
- "xxx..........xxxxxxxx....xxxxxxx",
- "x.x.x.x.x.x.x.x.x.x.x.x.",
- ".x.x.x.x.x.x.x.x.x.x.x.x",
- ".x.x.x.x.x.x.x.x.x.x.x.x.",
- "x.x.x.x.x.x.x.x.x.x.x.x.x",
- };
-
- for (auto test_case : test_cases) {
- RangeRecorder range_recorder;
- RangeTracker tracker(&range_recorder);
- for (int i = 0; test_case[i] != 0; i++)
- tracker.NextPage(test_case[i] == 'x');
- tracker.Done();
- // Strip trailing '.'-pages before comparing the results as they are not
- // going to be reported to range_recorder anyway.
- const char* last_x = strrchr(test_case, 'x');
- std::string expected(
- test_case,
- last_x == nullptr ? 0 : (last_x - test_case + 1));
- EXPECT_STREQ(expected.c_str(), range_recorder.reported_pages.c_str());
- }
-}
-
-class ReleasedPagesTrackingMemoryMapper {
- public:
- std::set<u32> reported_pages;
-
- uptr MapPackedCounterArrayBuffer(uptr buffer_size) {
- reported_pages.clear();
- return reinterpret_cast<uptr>(calloc(1, buffer_size));
- }
- void UnmapPackedCounterArrayBuffer(uptr buffer, uptr buffer_size) {
- free(reinterpret_cast<void*>(buffer));
- }
-
- void ReleasePageRangeToOS(u32 from, u32 to) {
- uptr page_size_scaled =
- GetPageSizeCached() >> Allocator64::kCompactPtrScale;
- for (u32 i = from; i < to; i += page_size_scaled)
- reported_pages.insert(i);
- }
-};
-
-template <class Allocator>
-void TestReleaseFreeMemoryToOS() {
- ReleasedPagesTrackingMemoryMapper memory_mapper;
- const uptr kAllocatedPagesCount = 1024;
- const uptr page_size = GetPageSizeCached();
- const uptr page_size_scaled = page_size >> Allocator::kCompactPtrScale;
- std::mt19937 r;
- uint32_t rnd_state = 42;
-
- for (uptr class_id = 1; class_id <= Allocator::SizeClassMapT::kLargestClassID;
- class_id++) {
- const uptr chunk_size = Allocator::SizeClassMapT::Size(class_id);
- const uptr chunk_size_scaled = chunk_size >> Allocator::kCompactPtrScale;
- const uptr max_chunks =
- kAllocatedPagesCount * GetPageSizeCached() / chunk_size;
-
- // Generate the random free list.
- std::vector<u32> free_array;
- bool in_free_range = false;
- uptr current_range_end = 0;
- for (uptr i = 0; i < max_chunks; i++) {
- if (i == current_range_end) {
- in_free_range = (my_rand_r(&rnd_state) & 1U) == 1;
- current_range_end += my_rand_r(&rnd_state) % 100 + 1;
- }
- if (in_free_range)
- free_array.push_back(i * chunk_size_scaled);
- }
- if (free_array.empty())
- continue;
- // Shuffle free_list to verify that ReleaseFreeMemoryToOS does not depend on
- // the list ordering.
- std::shuffle(free_array.begin(), free_array.end(), r);
-
- Allocator::ReleaseFreeMemoryToOS(&free_array[0], free_array.size(),
- chunk_size, kAllocatedPagesCount,
- &memory_mapper);
-
- // Verify that there are no released pages touched by used chunks and all
- // ranges of free chunks big enough to contain the entire memory pages had
- // these pages released.
- uptr verified_released_pages = 0;
- std::set<u32> free_chunks(free_array.begin(), free_array.end());
-
- u32 current_chunk = 0;
- in_free_range = false;
- u32 current_free_range_start = 0;
- for (uptr i = 0; i <= max_chunks; i++) {
- bool is_free_chunk = free_chunks.find(current_chunk) != free_chunks.end();
-
- if (is_free_chunk) {
- if (!in_free_range) {
- in_free_range = true;
- current_free_range_start = current_chunk;
- }
- } else {
- // Verify that this used chunk does not touch any released page.
- for (uptr i_page = current_chunk / page_size_scaled;
- i_page <= (current_chunk + chunk_size_scaled - 1) /
- page_size_scaled;
- i_page++) {
- bool page_released =
- memory_mapper.reported_pages.find(i_page * page_size_scaled) !=
- memory_mapper.reported_pages.end();
- ASSERT_EQ(false, page_released);
- }
-
- if (in_free_range) {
- in_free_range = false;
- // Verify that all entire memory pages covered by this range of free
- // chunks were released.
- u32 page = RoundUpTo(current_free_range_start, page_size_scaled);
- while (page + page_size_scaled <= current_chunk) {
- bool page_released =
- memory_mapper.reported_pages.find(page) !=
- memory_mapper.reported_pages.end();
- ASSERT_EQ(true, page_released);
- verified_released_pages++;
- page += page_size_scaled;
- }
- }
- }
-
- current_chunk += chunk_size_scaled;
- }
-
- ASSERT_EQ(memory_mapper.reported_pages.size(), verified_released_pages);
- }
-}
-
-TEST(SanitizerCommon, SizeClassAllocator64ReleaseFreeMemoryToOS) {
- TestReleaseFreeMemoryToOS<Allocator64>();
-}
-
-#if !SANITIZER_ANDROID
-TEST(SanitizerCommon, SizeClassAllocator64CompactReleaseFreeMemoryToOS) {
- TestReleaseFreeMemoryToOS<Allocator64Compact>();
-}
-
-TEST(SanitizerCommon, SizeClassAllocator64VeryCompactReleaseFreeMemoryToOS) {
- TestReleaseFreeMemoryToOS<Allocator64VeryCompact>();
-}
-#endif // !SANITIZER_ANDROID
-
-#endif // SANITIZER_CAN_USE_ALLOCATOR64
-
-TEST(SanitizerCommon, TwoLevelByteMap) {
- const u64 kSize1 = 1 << 6, kSize2 = 1 << 12;
- const u64 n = kSize1 * kSize2;
- TwoLevelByteMap<kSize1, kSize2> m;
- m.Init();
- for (u64 i = 0; i < n; i += 7) {
- m.set(i, (i % 100) + 1);
- }
- for (u64 j = 0; j < n; j++) {
- if (j % 7)
- EXPECT_EQ(m[j], 0);
- else
- EXPECT_EQ(m[j], (j % 100) + 1);
- }
-
- m.TestOnlyUnmap();
-}
-
-template <typename AddressSpaceView>
-using TestByteMapASVT =
- TwoLevelByteMap<1 << 12, 1 << 13, AddressSpaceView, TestMapUnmapCallback>;
-using TestByteMap = TestByteMapASVT<LocalAddressSpaceView>;
-
-struct TestByteMapParam {
- TestByteMap *m;
- size_t shard;
- size_t num_shards;
-};
-
-void *TwoLevelByteMapUserThread(void *param) {
- TestByteMapParam *p = (TestByteMapParam*)param;
- for (size_t i = p->shard; i < p->m->size(); i += p->num_shards) {
- size_t val = (i % 100) + 1;
- p->m->set(i, val);
- EXPECT_EQ((*p->m)[i], val);
- }
- return 0;
-}
-
-TEST(SanitizerCommon, ThreadedTwoLevelByteMap) {
- TestByteMap m;
- m.Init();
- TestMapUnmapCallback::map_count = 0;
- TestMapUnmapCallback::unmap_count = 0;
- static const int kNumThreads = 4;
- pthread_t t[kNumThreads];
- TestByteMapParam p[kNumThreads];
- for (int i = 0; i < kNumThreads; i++) {
- p[i].m = &m;
- p[i].shard = i;
- p[i].num_shards = kNumThreads;
- PTHREAD_CREATE(&t[i], 0, TwoLevelByteMapUserThread, &p[i]);
- }
- for (int i = 0; i < kNumThreads; i++) {
- PTHREAD_JOIN(t[i], 0);
- }
- EXPECT_EQ((uptr)TestMapUnmapCallback::map_count, m.size1());
- EXPECT_EQ((uptr)TestMapUnmapCallback::unmap_count, 0UL);
- m.TestOnlyUnmap();
- EXPECT_EQ((uptr)TestMapUnmapCallback::map_count, m.size1());
- EXPECT_EQ((uptr)TestMapUnmapCallback::unmap_count, m.size1());
-}
-
-#endif // #if !SANITIZER_DEBUG
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_allocator_test.cc ---------------------------------------===//
+//===-- sanitizer_allocator_test.cpp --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc (removed)
@@ -1,200 +0,0 @@
-//===-- sanitizer_allocator_testlib.cc ------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-// Malloc replacement library based on CombinedAllocator.
-// The primary purpose of this file is an end-to-end integration test
-// for CombinedAllocator.
-//===----------------------------------------------------------------------===//
-/* Usage:
-clang++ -std=c++11 -fno-exceptions -g -fPIC -I. -I../include -Isanitizer \
- sanitizer_common/tests/sanitizer_allocator_testlib.cc \
- $(\ls sanitizer_common/sanitizer_*.cpp | grep -v sanitizer_common_nolibc.cpp) \
- sanitizer_common/sanitizer_linux_x86_64.S \
- -shared -lpthread -o testmalloc.so
-LD_PRELOAD=`pwd`/testmalloc.so /your/app
-*/
-#include "sanitizer_common/sanitizer_allocator.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include <stddef.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <pthread.h>
-
-#ifndef SANITIZER_MALLOC_HOOK
-# define SANITIZER_MALLOC_HOOK(p, s)
-#endif
-
-#ifndef SANITIZER_FREE_HOOK
-# define SANITIZER_FREE_HOOK(p)
-#endif
-
-static const uptr kAllocatorSpace = 0x600000000000ULL;
-static const uptr kAllocatorSize = 0x10000000000ULL; // 1T.
-
-struct __AP64 {
- static const uptr kSpaceBeg = ~(uptr)0;
- static const uptr kSpaceSize = kAllocatorSize;
- static const uptr kMetadataSize = 0;
- typedef CompactSizeClassMap SizeClassMap;
- typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags =
- SizeClassAllocator64FlagMasks::kRandomShuffleChunks;
-};
-
-namespace {
-
-typedef SizeClassAllocator64<__AP64> PrimaryAllocator;
-typedef CombinedAllocator<PrimaryAllocator> Allocator;
-typedef Allocator::AllocatorCache AllocatorCache;
-
-static Allocator allocator;
-static bool global_inited;
-static THREADLOCAL AllocatorCache cache;
-static THREADLOCAL bool thread_inited;
-static pthread_key_t pkey;
-
-static void thread_dtor(void *v) {
- if ((uptr)v != 3) {
- pthread_setspecific(pkey, (void*)((uptr)v + 1));
- return;
- }
- allocator.SwallowCache(&cache);
-}
-
-static size_t GetRss() {
- if (FILE *f = fopen("/proc/self/statm", "r")) {
- size_t size = 0, rss = 0;
- fscanf(f, "%zd %zd", &size, &rss);
- fclose(f);
- return rss << 12; // rss is in pages.
- }
- return 0;
-}
-
-struct AtExit {
- ~AtExit() {
- allocator.PrintStats();
- Printf("RSS: %zdM\n", GetRss() >> 20);
- }
-};
-
-static AtExit at_exit;
-
-static void NOINLINE thread_init() {
- if (!global_inited) {
- global_inited = true;
- allocator.Init(false /*may_return_null*/);
- pthread_key_create(&pkey, thread_dtor);
- }
- thread_inited = true;
- pthread_setspecific(pkey, (void*)1);
- cache.Init(nullptr);
-}
-} // namespace
-
-extern "C" {
-void *malloc(size_t size) {
- if (UNLIKELY(!thread_inited))
- thread_init();
- void *p = allocator.Allocate(&cache, size, 8);
- SANITIZER_MALLOC_HOOK(p, size);
- return p;
-}
-
-void free(void *p) {
- if (UNLIKELY(!thread_inited))
- thread_init();
- SANITIZER_FREE_HOOK(p);
- allocator.Deallocate(&cache, p);
-}
-
-void *calloc(size_t nmemb, size_t size) {
- if (UNLIKELY(!thread_inited))
- thread_init();
- size *= nmemb;
- void *p = allocator.Allocate(&cache, size, 8, false);
- memset(p, 0, size);
- SANITIZER_MALLOC_HOOK(p, size);
- return p;
-}
-
-void *realloc(void *p, size_t size) {
- if (UNLIKELY(!thread_inited))
- thread_init();
- if (p) {
- SANITIZER_FREE_HOOK(p);
- }
- p = allocator.Reallocate(&cache, p, size, 8);
- if (p) {
- SANITIZER_MALLOC_HOOK(p, size);
- }
- return p;
-}
-
-#if SANITIZER_INTERCEPT_MEMALIGN
-void *memalign(size_t alignment, size_t size) {
- if (UNLIKELY(!thread_inited))
- thread_init();
- void *p = allocator.Allocate(&cache, size, alignment);
- SANITIZER_MALLOC_HOOK(p, size);
- return p;
-}
-#endif // SANITIZER_INTERCEPT_MEMALIGN
-
-int posix_memalign(void **memptr, size_t alignment, size_t size) {
- if (UNLIKELY(!thread_inited))
- thread_init();
- *memptr = allocator.Allocate(&cache, size, alignment);
- SANITIZER_MALLOC_HOOK(*memptr, size);
- return 0;
-}
-
-void *valloc(size_t size) {
- if (UNLIKELY(!thread_inited))
- thread_init();
- if (size == 0)
- size = GetPageSizeCached();
- void *p = allocator.Allocate(&cache, size, GetPageSizeCached());
- SANITIZER_MALLOC_HOOK(p, size);
- return p;
-}
-
-#if SANITIZER_INTERCEPT_CFREE
-void cfree(void *p) ALIAS("free");
-#endif // SANITIZER_INTERCEPT_CFREE
-#if SANITIZER_INTERCEPT_PVALLOC
-void *pvalloc(size_t size) ALIAS("valloc");
-#endif // SANITIZER_INTERCEPT_PVALLOC
-#if SANITIZER_INTERCEPT_MEMALIGN
-void *__libc_memalign(size_t alignment, size_t size) ALIAS("memalign");
-#endif // SANITIZER_INTERCEPT_MEMALIGN
-
-void malloc_usable_size() {
-}
-
-#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
-void mallinfo() {
-}
-
-void mallopt() {
-}
-#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
-} // extern "C"
-
-namespace std {
- struct nothrow_t;
-}
-
-void *operator new(size_t size) ALIAS("malloc");
-void *operator new[](size_t size) ALIAS("malloc");
-void *operator new(size_t size, std::nothrow_t const&) ALIAS("malloc");
-void *operator new[](size_t size, std::nothrow_t const&) ALIAS("malloc");
-void operator delete(void *ptr) throw() ALIAS("free");
-void operator delete[](void *ptr) throw() ALIAS("free");
-void operator delete(void *ptr, std::nothrow_t const&) ALIAS("free");
-void operator delete[](void *ptr, std::nothrow_t const&) ALIAS("free");
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_allocator_testlib.cc ------------------------------------===//
+//===-- sanitizer_allocator_testlib.cpp -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
/* Usage:
clang++ -std=c++11 -fno-exceptions -g -fPIC -I. -I../include -Isanitizer \
- sanitizer_common/tests/sanitizer_allocator_testlib.cc \
+ sanitizer_common/tests/sanitizer_allocator_testlib.cpp \
$(\ls sanitizer_common/sanitizer_*.cpp | grep -v sanitizer_common_nolibc.cpp) \
sanitizer_common/sanitizer_linux_x86_64.S \
-shared -lpthread -o testmalloc.so
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc (removed)
@@ -1,127 +0,0 @@
-//===-- sanitizer_atomic_test.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_atomic.h"
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-template<typename T>
-struct ValAndMagic {
- typename T::Type magic0;
- T a;
- typename T::Type magic1;
-
- static ValAndMagic<T> *sink;
-};
-
-template<typename T>
-ValAndMagic<T> *ValAndMagic<T>::sink;
-
-template<typename T, memory_order load_mo, memory_order store_mo>
-void CheckStoreLoad() {
- typedef typename T::Type Type;
- ValAndMagic<T> val;
- // Prevent the compiler from scalarizing the struct.
- ValAndMagic<T>::sink = &val;
- // Ensure that surrounding memory is not overwritten.
- val.magic0 = val.magic1 = (Type)-3;
- for (u64 i = 0; i < 100; i++) {
- // Generate a value that occupies all bytes of the variable.
- u64 v = i;
- v |= v << 8;
- v |= v << 16;
- v |= v << 32;
- val.a.val_dont_use = (Type)v;
- EXPECT_EQ(atomic_load(&val.a, load_mo), (Type)v);
- val.a.val_dont_use = (Type)-1;
- atomic_store(&val.a, (Type)v, store_mo);
- EXPECT_EQ(val.a.val_dont_use, (Type)v);
- }
- EXPECT_EQ(val.magic0, (Type)-3);
- EXPECT_EQ(val.magic1, (Type)-3);
-}
-
-TEST(SanitizerCommon, AtomicStoreLoad) {
- CheckStoreLoad<atomic_uint8_t, memory_order_relaxed, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint8_t, memory_order_consume, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint8_t, memory_order_acquire, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint8_t, memory_order_relaxed, memory_order_release>();
- CheckStoreLoad<atomic_uint8_t, memory_order_seq_cst, memory_order_seq_cst>();
-
- CheckStoreLoad<atomic_uint16_t, memory_order_relaxed, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint16_t, memory_order_consume, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint16_t, memory_order_acquire, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint16_t, memory_order_relaxed, memory_order_release>();
- CheckStoreLoad<atomic_uint16_t, memory_order_seq_cst, memory_order_seq_cst>();
-
- CheckStoreLoad<atomic_uint32_t, memory_order_relaxed, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint32_t, memory_order_consume, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint32_t, memory_order_acquire, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint32_t, memory_order_relaxed, memory_order_release>();
- CheckStoreLoad<atomic_uint32_t, memory_order_seq_cst, memory_order_seq_cst>();
-
- CheckStoreLoad<atomic_uint64_t, memory_order_relaxed, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint64_t, memory_order_consume, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint64_t, memory_order_acquire, memory_order_relaxed>();
- CheckStoreLoad<atomic_uint64_t, memory_order_relaxed, memory_order_release>();
- CheckStoreLoad<atomic_uint64_t, memory_order_seq_cst, memory_order_seq_cst>();
-
- CheckStoreLoad<atomic_uintptr_t, memory_order_relaxed, memory_order_relaxed>
- ();
- CheckStoreLoad<atomic_uintptr_t, memory_order_consume, memory_order_relaxed>
- ();
- CheckStoreLoad<atomic_uintptr_t, memory_order_acquire, memory_order_relaxed>
- ();
- CheckStoreLoad<atomic_uintptr_t, memory_order_relaxed, memory_order_release>
- ();
- CheckStoreLoad<atomic_uintptr_t, memory_order_seq_cst, memory_order_seq_cst>
- ();
-}
-
-// Clang crashes while compiling this test for Android:
-// http://llvm.org/bugs/show_bug.cgi?id=15587
-#if !SANITIZER_ANDROID
-template<typename T>
-void CheckAtomicCompareExchange() {
- typedef typename T::Type Type;
- {
- Type old_val = 42;
- Type new_val = 24;
- Type var = old_val;
- EXPECT_TRUE(atomic_compare_exchange_strong((T*)&var, &old_val, new_val,
- memory_order_relaxed));
- EXPECT_FALSE(atomic_compare_exchange_strong((T*)&var, &old_val, new_val,
- memory_order_relaxed));
- EXPECT_EQ(new_val, old_val);
- }
- {
- Type old_val = 42;
- Type new_val = 24;
- Type var = old_val;
- EXPECT_TRUE(atomic_compare_exchange_weak((T*)&var, &old_val, new_val,
- memory_order_relaxed));
- EXPECT_FALSE(atomic_compare_exchange_weak((T*)&var, &old_val, new_val,
- memory_order_relaxed));
- EXPECT_EQ(new_val, old_val);
- }
-}
-
-TEST(SanitizerCommon, AtomicCompareExchangeTest) {
- CheckAtomicCompareExchange<atomic_uint8_t>();
- CheckAtomicCompareExchange<atomic_uint16_t>();
- CheckAtomicCompareExchange<atomic_uint32_t>();
- CheckAtomicCompareExchange<atomic_uint64_t>();
- CheckAtomicCompareExchange<atomic_uintptr_t>();
-}
-#endif //!SANITIZER_ANDROID
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_atomic_test.cc ------------------------------------------===//
+//===-- sanitizer_atomic_test.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc (removed)
@@ -1,177 +0,0 @@
-//===-- sanitizer_bitvector_test.cc ---------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of Sanitizer runtime.
-// Tests for sanitizer_bitvector.h.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_bitvector.h"
-
-#include "sanitizer_test_utils.h"
-
-#include "gtest/gtest.h"
-
-#include <algorithm>
-#include <vector>
-#include <random>
-#include <set>
-
-using namespace __sanitizer;
-using namespace std;
-
-
-// Check the 'bv' == 's' and that the indexes go in increasing order.
-// Also check the BV::Iterator
-template <class BV>
-static void CheckBV(const BV &bv, const set<uptr> &s) {
- BV t;
- t.copyFrom(bv);
- set<uptr> t_s(s);
- uptr last_idx = bv.size();
- uptr count = 0;
- for (typename BV::Iterator it(bv); it.hasNext();) {
- uptr idx = it.next();
- count++;
- if (last_idx != bv.size())
- EXPECT_LT(last_idx, idx);
- last_idx = idx;
- EXPECT_TRUE(s.count(idx));
- }
- EXPECT_EQ(count, s.size());
-
- last_idx = bv.size();
- while (!t.empty()) {
- uptr idx = t.getAndClearFirstOne();
- if (last_idx != bv.size())
- EXPECT_LT(last_idx, idx);
- last_idx = idx;
- EXPECT_TRUE(t_s.erase(idx));
- }
- EXPECT_TRUE(t_s.empty());
-}
-
-template <class BV>
-void Print(const BV &bv) {
- BV t;
- t.copyFrom(bv);
- while (!t.empty()) {
- uptr idx = t.getAndClearFirstOne();
- fprintf(stderr, "%lu ", idx);
- }
- fprintf(stderr, "\n");
-}
-
-void Print(const set<uptr> &s) {
- for (set<uptr>::iterator it = s.begin(); it != s.end(); ++it) {
- fprintf(stderr, "%lu ", *it);
- }
- fprintf(stderr, "\n");
-}
-
-template <class BV>
-void TestBitVector(uptr expected_size) {
- std::mt19937 r;
- BV bv, bv1, t_bv;
- EXPECT_EQ(expected_size, BV::kSize);
- bv.clear();
- EXPECT_TRUE(bv.empty());
- bv.setBit(5);
- EXPECT_FALSE(bv.empty());
- EXPECT_FALSE(bv.getBit(4));
- EXPECT_FALSE(bv.getBit(6));
- EXPECT_TRUE(bv.getBit(5));
- bv.clearBit(5);
- EXPECT_FALSE(bv.getBit(5));
-
- // test random bits
- bv.clear();
- set<uptr> s;
- for (uptr it = 0; it < 1000; it++) {
- uptr bit = ((uptr)my_rand() % bv.size());
- EXPECT_EQ(bv.getBit(bit), s.count(bit) == 1);
- switch (my_rand() % 2) {
- case 0:
- EXPECT_EQ(bv.setBit(bit), s.insert(bit).second);
- break;
- case 1:
- size_t old_size = s.size();
- s.erase(bit);
- EXPECT_EQ(bv.clearBit(bit), old_size > s.size());
- break;
- }
- EXPECT_EQ(bv.getBit(bit), s.count(bit) == 1);
- }
-
- vector<uptr>bits(bv.size());
- // Test setUnion, setIntersection, setDifference,
- // intersectsWith, and getAndClearFirstOne.
- for (uptr it = 0; it < 30; it++) {
- // iota
- for (size_t j = 0; j < bits.size(); j++) bits[j] = j;
- std::shuffle(bits.begin(), bits.end(), r);
- set<uptr> s, s1, t_s;
- bv.clear();
- bv1.clear();
- uptr n_bits = ((uptr)my_rand() % bv.size()) + 1;
- uptr n_bits1 = (uptr)my_rand() % (bv.size() / 2);
- EXPECT_TRUE(n_bits > 0 && n_bits <= bv.size());
- EXPECT_TRUE(n_bits1 < bv.size() / 2);
- for (uptr i = 0; i < n_bits; i++) {
- bv.setBit(bits[i]);
- s.insert(bits[i]);
- }
- CheckBV(bv, s);
- for (uptr i = 0; i < n_bits1; i++) {
- bv1.setBit(bits[bv.size() / 2 + i]);
- s1.insert(bits[bv.size() / 2 + i]);
- }
- CheckBV(bv1, s1);
-
- vector<uptr> vec;
- set_intersection(s.begin(), s.end(), s1.begin(), s1.end(),
- back_insert_iterator<vector<uptr> >(vec));
- EXPECT_EQ(bv.intersectsWith(bv1), !vec.empty());
-
- // setUnion
- t_s = s;
- t_bv.copyFrom(bv);
- t_s.insert(s1.begin(), s1.end());
- EXPECT_EQ(t_bv.setUnion(bv1), s.size() != t_s.size());
- CheckBV(t_bv, t_s);
-
- // setIntersection
- t_s = set<uptr>(vec.begin(), vec.end());
- t_bv.copyFrom(bv);
- EXPECT_EQ(t_bv.setIntersection(bv1), s.size() != t_s.size());
- CheckBV(t_bv, t_s);
-
- // setDifference
- vec.clear();
- set_difference(s.begin(), s.end(), s1.begin(), s1.end(),
- back_insert_iterator<vector<uptr> >(vec));
- t_s = set<uptr>(vec.begin(), vec.end());
- t_bv.copyFrom(bv);
- EXPECT_EQ(t_bv.setDifference(bv1), s.size() != t_s.size());
- CheckBV(t_bv, t_s);
- }
-}
-
-TEST(SanitizerCommon, BasicBitVector) {
- TestBitVector<BasicBitVector<u8> >(8);
- TestBitVector<BasicBitVector<u16> >(16);
- TestBitVector<BasicBitVector<> >(SANITIZER_WORDSIZE);
-}
-
-TEST(SanitizerCommon, TwoLevelBitVector) {
- uptr ws = SANITIZER_WORDSIZE;
- TestBitVector<TwoLevelBitVector<1, BasicBitVector<u8> > >(8 * 8);
- TestBitVector<TwoLevelBitVector<> >(ws * ws);
- TestBitVector<TwoLevelBitVector<2> >(ws * ws * 2);
- TestBitVector<TwoLevelBitVector<3> >(ws * ws * 3);
- TestBitVector<TwoLevelBitVector<3, BasicBitVector<u16> > >(16 * 16 * 3);
-}
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bitvector_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_bitvector_test.cc ---------------------------------------===//
+//===-- sanitizer_bitvector_test.cpp --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc (removed)
@@ -1,338 +0,0 @@
-//===-- sanitizer_bvgraph_test.cc -----------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of Sanitizer runtime.
-// Tests for sanitizer_bvgraph.h.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_bvgraph.h"
-
-#include "sanitizer_test_utils.h"
-
-#include "gtest/gtest.h"
-
-#include <algorithm>
-#include <vector>
-#include <set>
-
-using namespace __sanitizer;
-using namespace std;
-
-typedef BasicBitVector<u8> BV1;
-typedef BasicBitVector<> BV2;
-typedef TwoLevelBitVector<> BV3;
-typedef TwoLevelBitVector<3, BasicBitVector<u8> > BV4;
-
-template<class G>
-void PrintGraph(const G &g) {
- for (uptr i = 0; i < g.size(); i++) {
- for (uptr j = 0; j < g.size(); j++) {
- fprintf(stderr, "%d", g.hasEdge(i, j));
- }
- fprintf(stderr, "\n");
- }
-}
-
-
-class SimpleGraph {
- public:
- void clear() { s_.clear(); }
- bool addEdge(uptr from, uptr to) {
- return s_.insert(idx(from, to)).second;
- }
- bool removeEdge(uptr from, uptr to) {
- return s_.erase(idx(from, to));
- }
- template <class G>
- void checkSameAs(G *g) {
- for (set<uptr>::iterator it = s_.begin(); it != s_.end(); ++it) {
- uptr from = *it >> 16;
- uptr to = *it & ((1 << 16) - 1);
- EXPECT_TRUE(g->removeEdge(from, to));
- }
- EXPECT_TRUE(g->empty());
- }
- private:
- uptr idx(uptr from, uptr to) {
- CHECK_LE(from|to, 1 << 16);
- return (from << 16) + to;
- }
- set<uptr> s_;
-};
-
-template <class BV>
-void BasicTest() {
- BVGraph<BV> g;
- g.clear();
- BV target;
- SimpleGraph s_g;
- set<uptr> s;
- set<uptr> s_target;
- int num_reachable = 0;
- for (int it = 0; it < 1000; it++) {
- target.clear();
- s_target.clear();
- for (int t = 0; t < 4; t++) {
- uptr idx = (uptr)my_rand() % g.size();
- EXPECT_EQ(target.setBit(idx), s_target.insert(idx).second);
- }
- uptr from = my_rand() % g.size();
- uptr to = my_rand() % g.size();
- EXPECT_EQ(g.addEdge(from, to), s_g.addEdge(from, to));
- EXPECT_TRUE(g.hasEdge(from, to));
- for (int i = 0; i < 10; i++) {
- from = my_rand() % g.size();
- bool is_reachable = g.isReachable(from, target);
- if (is_reachable) {
- uptr path[BV::kSize];
- uptr len;
- for (len = 1; len < BV::kSize; len++) {
- if (g.findPath(from, target, path, len) == len)
- break;
- }
- EXPECT_LT(len, BV::kSize);
- EXPECT_TRUE(target.getBit(path[len - 1]));
- // fprintf(stderr, "reachable: %zd; path %zd {%zd %zd %zd}\n",
- // from, len, path[0], path[1], path[2]);
- num_reachable++;
- }
- }
- }
- EXPECT_GT(num_reachable, 0);
-}
-
-TEST(BVGraph, BasicTest) {
- BasicTest<BV1>();
- BasicTest<BV2>();
- BasicTest<BV3>();
- BasicTest<BV4>();
-}
-
-template <class BV>
-void RemoveEdges() {
- SimpleGraph s_g;
- BVGraph<BV> g;
- g.clear();
- BV bv;
- set<uptr> s;
- for (int it = 0; it < 100; it++) {
- s.clear();
- bv.clear();
- s_g.clear();
- g.clear();
- for (uptr j = 0; j < g.size() * 2; j++) {
- uptr from = my_rand() % g.size();
- uptr to = my_rand() % g.size();
- EXPECT_EQ(g.addEdge(from, to), s_g.addEdge(from, to));
- }
- for (uptr j = 0; j < 5; j++) {
- uptr idx = my_rand() % g.size();
- s.insert(idx);
- bv.setBit(idx);
- }
-
- if (it % 2) {
- g.removeEdgesFrom(bv);
- for (set<uptr>::iterator from = s.begin(); from != s.end(); ++from) {
- for (uptr to = 0; to < g.size(); to++)
- s_g.removeEdge(*from, to);
- }
- } else {
- g.removeEdgesTo(bv);
- for (set<uptr>::iterator to = s.begin(); to != s.end(); ++to) {
- for (uptr from = 0; from < g.size(); from++)
- s_g.removeEdge(from, *to);
- }
- }
- s_g.checkSameAs(&g);
- }
-}
-
-TEST(BVGraph, RemoveEdges) {
- RemoveEdges<BV1>();
- RemoveEdges<BV2>();
- RemoveEdges<BV3>();
- RemoveEdges<BV4>();
-}
-
-template <class BV>
-void Test_isReachable() {
- uptr path[5];
- BVGraph<BV> g;
- g.clear();
- BV target;
- target.clear();
- uptr t0 = 0;
- uptr t1 = g.size() - 1;
- target.setBit(t0);
- target.setBit(t1);
-
- uptr f0 = 1;
- uptr f1 = 2;
- uptr f2 = g.size() / 2;
- uptr f3 = g.size() - 2;
-
- EXPECT_FALSE(g.isReachable(f0, target));
- EXPECT_FALSE(g.isReachable(f1, target));
- EXPECT_FALSE(g.isReachable(f2, target));
- EXPECT_FALSE(g.isReachable(f3, target));
-
- g.addEdge(f0, f1);
- g.addEdge(f1, f2);
- g.addEdge(f2, f3);
- EXPECT_FALSE(g.isReachable(f0, target));
- EXPECT_FALSE(g.isReachable(f1, target));
- EXPECT_FALSE(g.isReachable(f2, target));
- EXPECT_FALSE(g.isReachable(f3, target));
-
- g.addEdge(f1, t0);
- EXPECT_TRUE(g.isReachable(f0, target));
- EXPECT_TRUE(g.isReachable(f1, target));
- EXPECT_FALSE(g.isReachable(f2, target));
- EXPECT_FALSE(g.isReachable(f3, target));
- EXPECT_EQ(g.findPath(f0, target, path, ARRAY_SIZE(path)), 3U);
- EXPECT_EQ(path[0], f0);
- EXPECT_EQ(path[1], f1);
- EXPECT_EQ(path[2], t0);
- EXPECT_EQ(g.findPath(f1, target, path, ARRAY_SIZE(path)), 2U);
- EXPECT_EQ(path[0], f1);
- EXPECT_EQ(path[1], t0);
-
- g.addEdge(f3, t1);
- EXPECT_TRUE(g.isReachable(f0, target));
- EXPECT_TRUE(g.isReachable(f1, target));
- EXPECT_TRUE(g.isReachable(f2, target));
- EXPECT_TRUE(g.isReachable(f3, target));
-}
-
-TEST(BVGraph, isReachable) {
- Test_isReachable<BV1>();
- Test_isReachable<BV2>();
- Test_isReachable<BV3>();
- Test_isReachable<BV4>();
-}
-
-template <class BV>
-void LongCycle() {
- BVGraph<BV> g;
- g.clear();
- vector<uptr> path_vec(g.size());
- uptr *path = path_vec.data();
- uptr start = 5;
- for (uptr i = start; i < g.size() - 1; i++) {
- g.addEdge(i, i + 1);
- for (uptr j = 0; j < start; j++)
- g.addEdge(i, j);
- }
- // Bad graph that looks like this:
- // 00000000000000
- // 00000000000000
- // 00000000000000
- // 00000000000000
- // 00000000000000
- // 11111010000000
- // 11111001000000
- // 11111000100000
- // 11111000010000
- // 11111000001000
- // 11111000000100
- // 11111000000010
- // 11111000000001
- // if (g.size() <= 64) PrintGraph(g);
- BV target;
- for (uptr i = start + 1; i < g.size(); i += 11) {
- // if ((i & (i - 1)) == 0) fprintf(stderr, "Path: : %zd\n", i);
- target.clear();
- target.setBit(i);
- EXPECT_TRUE(g.isReachable(start, target));
- EXPECT_EQ(g.findPath(start, target, path, g.size()), i - start + 1);
- }
-}
-
-TEST(BVGraph, LongCycle) {
- LongCycle<BV1>();
- LongCycle<BV2>();
- LongCycle<BV3>();
- LongCycle<BV4>();
-}
-
-template <class BV>
-void ShortestPath() {
- uptr path[8];
- BVGraph<BV> g;
- g.clear();
- BV t7;
- t7.clear();
- t7.setBit(7);
- // 1=>2=>3=>4=>5=>6=>7
- // 1=>7
- g.addEdge(1, 2);
- g.addEdge(2, 3);
- g.addEdge(3, 4);
- g.addEdge(4, 5);
- g.addEdge(5, 6);
- g.addEdge(6, 7);
- g.addEdge(1, 7);
- EXPECT_TRUE(g.isReachable(1, t7));
- // No path of length 1.
- EXPECT_EQ(0U, g.findPath(1, t7, path, 1));
- // Trying to find a path of len 2..6 gives path of len 2.
- EXPECT_EQ(2U, g.findPath(1, t7, path, 2));
- EXPECT_EQ(2U, g.findPath(1, t7, path, 3));
- EXPECT_EQ(2U, g.findPath(1, t7, path, 4));
- EXPECT_EQ(2U, g.findPath(1, t7, path, 5));
- EXPECT_EQ(2U, g.findPath(1, t7, path, 6));
- // Trying to find a path of len 7 gives path of len 7, because this is DFS.
- EXPECT_EQ(7U, g.findPath(1, t7, path, 7));
- // But findShortestPath will find the shortest path.
- EXPECT_EQ(2U, g.findShortestPath(1, t7, path, 2));
- EXPECT_EQ(2U, g.findShortestPath(1, t7, path, 7));
-}
-
-TEST(BVGraph, ShortestPath) {
- ShortestPath<BV1>();
- ShortestPath<BV2>();
- ShortestPath<BV3>();
- ShortestPath<BV4>();
-}
-
-template <class BV>
-void RunAddEdgesTest() {
- BVGraph<BV> g;
- BV from;
- const int kMaxEdges = 10;
- uptr added_edges[kMaxEdges];
- g.clear();
- from.clear();
- EXPECT_EQ(0U, g.addEdges(from, 0, added_edges, kMaxEdges));
- EXPECT_EQ(0U, g.addEdges(from, 1, added_edges, kMaxEdges));
- from.setBit(0);
- EXPECT_EQ(1U, g.addEdges(from, 1, added_edges, kMaxEdges));
- EXPECT_EQ(0U, added_edges[0]);
- EXPECT_EQ(0U, g.addEdges(from, 1, added_edges, kMaxEdges));
-
- from.clear();
- from.setBit(1);
- EXPECT_EQ(1U, g.addEdges(from, 4, added_edges, kMaxEdges));
- EXPECT_TRUE(g.hasEdge(1, 4));
- EXPECT_FALSE(g.hasEdge(1, 5));
- EXPECT_EQ(1U, added_edges[0]);
- from.setBit(2);
- from.setBit(3);
- EXPECT_EQ(2U, g.addEdges(from, 4, added_edges, kMaxEdges));
- EXPECT_TRUE(g.hasEdge(2, 4));
- EXPECT_FALSE(g.hasEdge(2, 5));
- EXPECT_TRUE(g.hasEdge(3, 4));
- EXPECT_FALSE(g.hasEdge(3, 5));
- EXPECT_EQ(2U, added_edges[0]);
- EXPECT_EQ(3U, added_edges[1]);
-}
-
-TEST(BVGraph, AddEdgesTest) {
- RunAddEdgesTest<BV2>();
-}
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_bvgraph_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_bvgraph_test.cc -----------------------------------------===//
+//===-- sanitizer_bvgraph_test.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (removed)
@@ -1,449 +0,0 @@
-//===-- sanitizer_common_test.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include <algorithm>
-
-#include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_file.h"
-#include "sanitizer_common/sanitizer_flags.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_platform.h"
-
-#include "sanitizer_pthread_wrappers.h"
-
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-static bool IsSorted(const uptr *array, uptr n) {
- for (uptr i = 1; i < n; i++) {
- if (array[i] < array[i - 1]) return false;
- }
- return true;
-}
-
-TEST(SanitizerCommon, SortTest) {
- uptr array[100];
- uptr n = 100;
- // Already sorted.
- for (uptr i = 0; i < n; i++) {
- array[i] = i;
- }
- Sort(array, n);
- EXPECT_TRUE(IsSorted(array, n));
- // Reverse order.
- for (uptr i = 0; i < n; i++) {
- array[i] = n - 1 - i;
- }
- Sort(array, n);
- EXPECT_TRUE(IsSorted(array, n));
- // Mixed order.
- for (uptr i = 0; i < n; i++) {
- array[i] = (i % 2 == 0) ? i : n - 1 - i;
- }
- Sort(array, n);
- EXPECT_TRUE(IsSorted(array, n));
- // All equal.
- for (uptr i = 0; i < n; i++) {
- array[i] = 42;
- }
- Sort(array, n);
- EXPECT_TRUE(IsSorted(array, n));
- // All but one sorted.
- for (uptr i = 0; i < n - 1; i++) {
- array[i] = i;
- }
- array[n - 1] = 42;
- Sort(array, n);
- EXPECT_TRUE(IsSorted(array, n));
- // Minimal case - sort three elements.
- array[0] = 1;
- array[1] = 0;
- Sort(array, 2);
- EXPECT_TRUE(IsSorted(array, 2));
-}
-
-TEST(SanitizerCommon, MmapAlignedOrDieOnFatalError) {
- uptr PageSize = GetPageSizeCached();
- for (uptr size = 1; size <= 32; size *= 2) {
- for (uptr alignment = 1; alignment <= 32; alignment *= 2) {
- for (int iter = 0; iter < 100; iter++) {
- uptr res = (uptr)MmapAlignedOrDieOnFatalError(
- size * PageSize, alignment * PageSize, "MmapAlignedOrDieTest");
- EXPECT_EQ(0U, res % (alignment * PageSize));
- internal_memset((void*)res, 1, size * PageSize);
- UnmapOrDie((void*)res, size * PageSize);
- }
- }
- }
-}
-
-TEST(SanitizerCommon, InternalMmapVectorRoundUpCapacity) {
- InternalMmapVector<uptr> v;
- v.reserve(1);
- CHECK_EQ(v.capacity(), GetPageSizeCached() / sizeof(uptr));
-}
-
-TEST(SanitizerCommon, InternalMmapVectorReize) {
- InternalMmapVector<uptr> v;
- CHECK_EQ(0U, v.size());
- CHECK_GE(v.capacity(), v.size());
-
- v.reserve(1000);
- CHECK_EQ(0U, v.size());
- CHECK_GE(v.capacity(), 1000U);
-
- v.resize(10000);
- CHECK_EQ(10000U, v.size());
- CHECK_GE(v.capacity(), v.size());
- uptr cap = v.capacity();
-
- v.resize(100);
- CHECK_EQ(100U, v.size());
- CHECK_EQ(v.capacity(), cap);
-
- v.reserve(10);
- CHECK_EQ(100U, v.size());
- CHECK_EQ(v.capacity(), cap);
-}
-
-TEST(SanitizerCommon, InternalMmapVector) {
- InternalMmapVector<uptr> vector;
- for (uptr i = 0; i < 100; i++) {
- EXPECT_EQ(i, vector.size());
- vector.push_back(i);
- }
- for (uptr i = 0; i < 100; i++) {
- EXPECT_EQ(i, vector[i]);
- }
- for (int i = 99; i >= 0; i--) {
- EXPECT_EQ((uptr)i, vector.back());
- vector.pop_back();
- EXPECT_EQ((uptr)i, vector.size());
- }
- InternalMmapVector<uptr> empty_vector;
- CHECK_GT(empty_vector.capacity(), 0U);
- CHECK_EQ(0U, empty_vector.size());
-}
-
-TEST(SanitizerCommon, InternalMmapVectorEq) {
- InternalMmapVector<uptr> vector1;
- InternalMmapVector<uptr> vector2;
- for (uptr i = 0; i < 100; i++) {
- vector1.push_back(i);
- vector2.push_back(i);
- }
- EXPECT_TRUE(vector1 == vector2);
- EXPECT_FALSE(vector1 != vector2);
-
- vector1.push_back(1);
- EXPECT_FALSE(vector1 == vector2);
- EXPECT_TRUE(vector1 != vector2);
-
- vector2.push_back(1);
- EXPECT_TRUE(vector1 == vector2);
- EXPECT_FALSE(vector1 != vector2);
-
- vector1[55] = 1;
- EXPECT_FALSE(vector1 == vector2);
- EXPECT_TRUE(vector1 != vector2);
-}
-
-TEST(SanitizerCommon, InternalMmapVectorSwap) {
- InternalMmapVector<uptr> vector1;
- InternalMmapVector<uptr> vector2;
- InternalMmapVector<uptr> vector3;
- InternalMmapVector<uptr> vector4;
- for (uptr i = 0; i < 100; i++) {
- vector1.push_back(i);
- vector2.push_back(i);
- vector3.push_back(-i);
- vector4.push_back(-i);
- }
- EXPECT_NE(vector2, vector3);
- EXPECT_NE(vector1, vector4);
- vector1.swap(vector3);
- EXPECT_EQ(vector2, vector3);
- EXPECT_EQ(vector1, vector4);
-}
-
-void TestThreadInfo(bool main) {
- uptr stk_addr = 0;
- uptr stk_size = 0;
- uptr tls_addr = 0;
- uptr tls_size = 0;
- GetThreadStackAndTls(main, &stk_addr, &stk_size, &tls_addr, &tls_size);
-
- int stack_var;
- EXPECT_NE(stk_addr, (uptr)0);
- EXPECT_NE(stk_size, (uptr)0);
- EXPECT_GT((uptr)&stack_var, stk_addr);
- EXPECT_LT((uptr)&stack_var, stk_addr + stk_size);
-
-#if SANITIZER_LINUX && defined(__x86_64__)
- static __thread int thread_var;
- EXPECT_NE(tls_addr, (uptr)0);
- EXPECT_NE(tls_size, (uptr)0);
- EXPECT_GT((uptr)&thread_var, tls_addr);
- EXPECT_LT((uptr)&thread_var, tls_addr + tls_size);
-
- // Ensure that tls and stack do not intersect.
- uptr tls_end = tls_addr + tls_size;
- EXPECT_TRUE(tls_addr < stk_addr || tls_addr >= stk_addr + stk_size);
- EXPECT_TRUE(tls_end < stk_addr || tls_end >= stk_addr + stk_size);
- EXPECT_TRUE((tls_addr < stk_addr) == (tls_end < stk_addr));
-#endif
-}
-
-static void *WorkerThread(void *arg) {
- TestThreadInfo(false);
- return 0;
-}
-
-TEST(SanitizerCommon, ThreadStackTlsMain) {
- InitTlsSize();
- TestThreadInfo(true);
-}
-
-TEST(SanitizerCommon, ThreadStackTlsWorker) {
- InitTlsSize();
- pthread_t t;
- PTHREAD_CREATE(&t, 0, WorkerThread, 0);
- PTHREAD_JOIN(t, 0);
-}
-
-bool UptrLess(uptr a, uptr b) {
- return a < b;
-}
-
-TEST(SanitizerCommon, InternalLowerBound) {
- static const uptr kSize = 5;
- int arr[kSize];
- arr[0] = 1;
- arr[1] = 3;
- arr[2] = 5;
- arr[3] = 7;
- arr[4] = 11;
-
- EXPECT_EQ(0u, InternalLowerBound(arr, 0, kSize, 0, UptrLess));
- EXPECT_EQ(0u, InternalLowerBound(arr, 0, kSize, 1, UptrLess));
- EXPECT_EQ(1u, InternalLowerBound(arr, 0, kSize, 2, UptrLess));
- EXPECT_EQ(1u, InternalLowerBound(arr, 0, kSize, 3, UptrLess));
- EXPECT_EQ(2u, InternalLowerBound(arr, 0, kSize, 4, UptrLess));
- EXPECT_EQ(2u, InternalLowerBound(arr, 0, kSize, 5, UptrLess));
- EXPECT_EQ(3u, InternalLowerBound(arr, 0, kSize, 6, UptrLess));
- EXPECT_EQ(3u, InternalLowerBound(arr, 0, kSize, 7, UptrLess));
- EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 8, UptrLess));
- EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 9, UptrLess));
- EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 10, UptrLess));
- EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 11, UptrLess));
- EXPECT_EQ(5u, InternalLowerBound(arr, 0, kSize, 12, UptrLess));
-}
-
-TEST(SanitizerCommon, InternalLowerBoundVsStdLowerBound) {
- std::vector<int> data;
- auto create_item = [] (size_t i, size_t j) {
- auto v = i * 10000 + j;
- return ((v << 6) + (v >> 6) + 0x9e3779b9) % 100;
- };
- for (size_t i = 0; i < 1000; ++i) {
- data.resize(i);
- for (size_t j = 0; j < i; ++j) {
- data[j] = create_item(i, j);
- }
-
- std::sort(data.begin(), data.end());
-
- for (size_t j = 0; j < i; ++j) {
- int val = create_item(i, j);
- for (auto to_find : {val - 1, val, val + 1}) {
- uptr expected =
- std::lower_bound(data.begin(), data.end(), to_find) - data.begin();
- EXPECT_EQ(expected, InternalLowerBound(data.data(), 0, data.size(),
- to_find, std::less<int>()));
- }
- }
- }
-}
-
-#if SANITIZER_LINUX && !SANITIZER_ANDROID
-TEST(SanitizerCommon, FindPathToBinary) {
- char *true_path = FindPathToBinary("true");
- EXPECT_NE((char*)0, internal_strstr(true_path, "/bin/true"));
- InternalFree(true_path);
- EXPECT_EQ(0, FindPathToBinary("unexisting_binary.ergjeorj"));
-}
-#elif SANITIZER_WINDOWS
-TEST(SanitizerCommon, FindPathToBinary) {
- // ntdll.dll should be on PATH in all supported test environments on all
- // supported Windows versions.
- char *ntdll_path = FindPathToBinary("ntdll.dll");
- EXPECT_NE((char*)0, internal_strstr(ntdll_path, "ntdll.dll"));
- InternalFree(ntdll_path);
- EXPECT_EQ(0, FindPathToBinary("unexisting_binary.ergjeorj"));
-}
-#endif
-
-TEST(SanitizerCommon, StripPathPrefix) {
- EXPECT_EQ(0, StripPathPrefix(0, "prefix"));
- EXPECT_STREQ("foo", StripPathPrefix("foo", 0));
- EXPECT_STREQ("dir/file.cc",
- StripPathPrefix("/usr/lib/dir/file.cc", "/usr/lib/"));
- EXPECT_STREQ("/file.cc", StripPathPrefix("/usr/myroot/file.cc", "/myroot"));
- EXPECT_STREQ("file.h", StripPathPrefix("/usr/lib/./file.h", "/usr/lib/"));
-}
-
-TEST(SanitizerCommon, RemoveANSIEscapeSequencesFromString) {
- RemoveANSIEscapeSequencesFromString(nullptr);
- const char *buffs[22] = {
- "Default", "Default",
- "\033[95mLight magenta", "Light magenta",
- "\033[30mBlack\033[32mGreen\033[90mGray", "BlackGreenGray",
- "\033[106mLight cyan \033[107mWhite ", "Light cyan White ",
- "\033[31mHello\033[0m World", "Hello World",
- "\033[38;5;82mHello \033[38;5;198mWorld", "Hello World",
- "123[653456789012", "123[653456789012",
- "Normal \033[5mBlink \033[25mNormal", "Normal Blink Normal",
- "\033[106m\033[107m", "",
- "", "",
- " ", " ",
- };
-
- for (size_t i = 0; i < ARRAY_SIZE(buffs); i+=2) {
- char *buffer_copy = internal_strdup(buffs[i]);
- RemoveANSIEscapeSequencesFromString(buffer_copy);
- EXPECT_STREQ(buffer_copy, buffs[i+1]);
- InternalFree(buffer_copy);
- }
-}
-
-TEST(SanitizerCommon, InternalScopedString) {
- InternalScopedString str(10);
- EXPECT_EQ(0U, str.length());
- EXPECT_STREQ("", str.data());
-
- str.append("foo");
- EXPECT_EQ(3U, str.length());
- EXPECT_STREQ("foo", str.data());
-
- int x = 1234;
- str.append("%d", x);
- EXPECT_EQ(7U, str.length());
- EXPECT_STREQ("foo1234", str.data());
-
- str.append("%d", x);
- EXPECT_EQ(9U, str.length());
- EXPECT_STREQ("foo123412", str.data());
-
- str.clear();
- EXPECT_EQ(0U, str.length());
- EXPECT_STREQ("", str.data());
-
- str.append("0123456789");
- EXPECT_EQ(9U, str.length());
- EXPECT_STREQ("012345678", str.data());
-}
-
-#if SANITIZER_LINUX || SANITIZER_FREEBSD || \
- SANITIZER_OPENBSD || SANITIZER_MAC || SANITIZER_IOS
-TEST(SanitizerCommon, GetRandom) {
- u8 buffer_1[32], buffer_2[32];
- for (bool blocking : { false, true }) {
- EXPECT_FALSE(GetRandom(nullptr, 32, blocking));
- EXPECT_FALSE(GetRandom(buffer_1, 0, blocking));
- EXPECT_FALSE(GetRandom(buffer_1, 512, blocking));
- EXPECT_EQ(ARRAY_SIZE(buffer_1), ARRAY_SIZE(buffer_2));
- for (uptr size = 4; size <= ARRAY_SIZE(buffer_1); size += 4) {
- for (uptr i = 0; i < 100; i++) {
- EXPECT_TRUE(GetRandom(buffer_1, size, blocking));
- EXPECT_TRUE(GetRandom(buffer_2, size, blocking));
- EXPECT_NE(internal_memcmp(buffer_1, buffer_2, size), 0);
- }
- }
- }
-}
-#endif
-
-TEST(SanitizerCommon, ReservedAddressRangeInit) {
- uptr init_size = 0xffff;
- ReservedAddressRange address_range;
- uptr res = address_range.Init(init_size);
- CHECK_NE(res, (void*)-1);
- UnmapOrDie((void*)res, init_size);
- // Should be able to map into the same space now.
- ReservedAddressRange address_range2;
- uptr res2 = address_range2.Init(init_size, nullptr, res);
- CHECK_EQ(res, res2);
-
- // TODO(flowerhack): Once this is switched to the "real" implementation
- // (rather than passing through to MmapNoAccess*), enforce and test "no
- // double initializations allowed"
-}
-
-TEST(SanitizerCommon, ReservedAddressRangeMap) {
- constexpr uptr init_size = 0xffff;
- ReservedAddressRange address_range;
- uptr res = address_range.Init(init_size);
- CHECK_NE(res, (void*) -1);
-
- // Valid mappings should succeed.
- CHECK_EQ(res, address_range.Map(res, init_size));
-
- // Valid mappings should be readable.
- unsigned char buffer[init_size];
- memcpy(buffer, reinterpret_cast<void *>(res), init_size);
-
- // TODO(flowerhack): Once this is switched to the "real" implementation, make
- // sure you can only mmap into offsets in the Init range.
-}
-
-TEST(SanitizerCommon, ReservedAddressRangeUnmap) {
- uptr PageSize = GetPageSizeCached();
- uptr init_size = PageSize * 8;
- ReservedAddressRange address_range;
- uptr base_addr = address_range.Init(init_size);
- CHECK_NE(base_addr, (void*)-1);
- CHECK_EQ(base_addr, address_range.Map(base_addr, init_size));
-
- // Unmapping the entire range should succeed.
- address_range.Unmap(base_addr, init_size);
-
- // Map a new range.
- base_addr = address_range.Init(init_size);
- CHECK_EQ(base_addr, address_range.Map(base_addr, init_size));
-
- // Windows doesn't allow partial unmappings.
- #if !SANITIZER_WINDOWS
-
- // Unmapping at the beginning should succeed.
- address_range.Unmap(base_addr, PageSize);
-
- // Unmapping at the end should succeed.
- uptr new_start = reinterpret_cast<uptr>(address_range.base()) +
- address_range.size() - PageSize;
- address_range.Unmap(new_start, PageSize);
-
- #endif
-
- // Unmapping in the middle of the ReservedAddressRange should fail.
- EXPECT_DEATH(address_range.Unmap(base_addr + (PageSize * 2), PageSize), ".*");
-}
-
-// Windows has no working ReadBinaryName.
-#if !SANITIZER_WINDOWS
-TEST(SanitizerCommon, ReadBinaryNameCached) {
- char buf[256];
- EXPECT_NE((uptr)0, ReadBinaryNameCached(buf, sizeof(buf)));
-}
-#endif
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_common_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_common_test.cc ------------------------------------------===//
+//===-- sanitizer_common_test.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc (removed)
@@ -1,495 +0,0 @@
-//===-- sanitizer_deadlock_detector_test.cc -------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of Sanitizer runtime.
-// Tests for sanitizer_deadlock_detector.h
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_deadlock_detector.h"
-
-#include "sanitizer_test_utils.h"
-
-#include "gtest/gtest.h"
-
-#include <algorithm>
-#include <vector>
-#include <set>
-
-using namespace __sanitizer;
-using namespace std;
-
-typedef BasicBitVector<u8> BV1;
-typedef BasicBitVector<> BV2;
-typedef TwoLevelBitVector<> BV3;
-typedef TwoLevelBitVector<3, BasicBitVector<u8> > BV4;
-
-// Poor man's unique_ptr.
-template<class BV>
-struct ScopedDD {
- ScopedDD() {
- dp = new DeadlockDetector<BV>;
- dp->clear();
- dtls.clear();
- }
- ~ScopedDD() { delete dp; }
- DeadlockDetector<BV> *dp;
- DeadlockDetectorTLS<BV> dtls;
-};
-
-template <class BV>
-void RunBasicTest() {
- uptr path[10];
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
- set<uptr> s;
- for (size_t i = 0; i < d.size() * 3; i++) {
- uptr node = d.newNode(0);
- EXPECT_TRUE(s.insert(node).second);
- }
-
- d.clear();
- s.clear();
- // Add size() nodes.
- for (size_t i = 0; i < d.size(); i++) {
- uptr node = d.newNode(0);
- EXPECT_TRUE(s.insert(node).second);
- }
- // Remove all nodes.
- for (set<uptr>::iterator it = s.begin(); it != s.end(); ++it)
- d.removeNode(*it);
- // The nodes should be reused.
- for (size_t i = 0; i < d.size(); i++) {
- uptr node = d.newNode(0);
- EXPECT_FALSE(s.insert(node).second);
- }
-
- // Cycle: n1->n2->n1
- {
- d.clear();
- dtls.clear();
- uptr n1 = d.newNode(1);
- uptr n2 = d.newNode(2);
- EXPECT_FALSE(d.onLock(&dtls, n1));
- EXPECT_FALSE(d.onLock(&dtls, n2));
- d.onUnlock(&dtls, n2);
- d.onUnlock(&dtls, n1);
-
- EXPECT_FALSE(d.onLock(&dtls, n2));
- EXPECT_EQ(0U, d.findPathToLock(&dtls, n1, path, 1));
- EXPECT_EQ(2U, d.findPathToLock(&dtls, n1, path, 10));
- EXPECT_EQ(2U, d.findPathToLock(&dtls, n1, path, 2));
- EXPECT_TRUE(d.onLock(&dtls, n1));
- EXPECT_EQ(path[0], n1);
- EXPECT_EQ(path[1], n2);
- EXPECT_EQ(d.getData(n1), 1U);
- EXPECT_EQ(d.getData(n2), 2U);
- d.onUnlock(&dtls, n1);
- d.onUnlock(&dtls, n2);
- }
-
- // Cycle: n1->n2->n3->n1
- {
- d.clear();
- dtls.clear();
- uptr n1 = d.newNode(1);
- uptr n2 = d.newNode(2);
- uptr n3 = d.newNode(3);
-
- EXPECT_FALSE(d.onLock(&dtls, n1));
- EXPECT_FALSE(d.onLock(&dtls, n2));
- d.onUnlock(&dtls, n2);
- d.onUnlock(&dtls, n1);
-
- EXPECT_FALSE(d.onLock(&dtls, n2));
- EXPECT_FALSE(d.onLock(&dtls, n3));
- d.onUnlock(&dtls, n3);
- d.onUnlock(&dtls, n2);
-
- EXPECT_FALSE(d.onLock(&dtls, n3));
- EXPECT_EQ(0U, d.findPathToLock(&dtls, n1, path, 2));
- EXPECT_EQ(3U, d.findPathToLock(&dtls, n1, path, 10));
- EXPECT_TRUE(d.onLock(&dtls, n1));
- EXPECT_EQ(path[0], n1);
- EXPECT_EQ(path[1], n2);
- EXPECT_EQ(path[2], n3);
- EXPECT_EQ(d.getData(n1), 1U);
- EXPECT_EQ(d.getData(n2), 2U);
- EXPECT_EQ(d.getData(n3), 3U);
- d.onUnlock(&dtls, n1);
- d.onUnlock(&dtls, n3);
- }
-}
-
-TEST(DeadlockDetector, BasicTest) {
- RunBasicTest<BV1>();
- RunBasicTest<BV2>();
- RunBasicTest<BV3>();
- RunBasicTest<BV4>();
-}
-
-template <class BV>
-void RunRemoveNodeTest() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
-
- uptr l0 = d.newNode(0);
- uptr l1 = d.newNode(1);
- uptr l2 = d.newNode(2);
- uptr l3 = d.newNode(3);
- uptr l4 = d.newNode(4);
- uptr l5 = d.newNode(5);
-
- // l0=>l1=>l2
- d.onLock(&dtls, l0);
- d.onLock(&dtls, l1);
- d.onLock(&dtls, l2);
- d.onUnlock(&dtls, l1);
- d.onUnlock(&dtls, l0);
- d.onUnlock(&dtls, l2);
- // l3=>l4=>l5
- d.onLock(&dtls, l3);
- d.onLock(&dtls, l4);
- d.onLock(&dtls, l5);
- d.onUnlock(&dtls, l4);
- d.onUnlock(&dtls, l3);
- d.onUnlock(&dtls, l5);
-
- set<uptr> locks;
- locks.insert(l0);
- locks.insert(l1);
- locks.insert(l2);
- locks.insert(l3);
- locks.insert(l4);
- locks.insert(l5);
- for (uptr i = 6; i < d.size(); i++) {
- uptr lt = d.newNode(i);
- locks.insert(lt);
- d.onLock(&dtls, lt);
- d.onUnlock(&dtls, lt);
- d.removeNode(lt);
- }
- EXPECT_EQ(locks.size(), d.size());
- // l2=>l0
- EXPECT_FALSE(d.onLock(&dtls, l2));
- EXPECT_TRUE(d.onLock(&dtls, l0));
- d.onUnlock(&dtls, l2);
- d.onUnlock(&dtls, l0);
- // l4=>l3
- EXPECT_FALSE(d.onLock(&dtls, l4));
- EXPECT_TRUE(d.onLock(&dtls, l3));
- d.onUnlock(&dtls, l4);
- d.onUnlock(&dtls, l3);
-
- EXPECT_EQ(d.size(), d.testOnlyGetEpoch());
-
- d.removeNode(l2);
- d.removeNode(l3);
- locks.clear();
- // make sure no edges from or to l0,l1,l4,l5 left.
- for (uptr i = 4; i < d.size(); i++) {
- uptr lt = d.newNode(i);
- locks.insert(lt);
- uptr a, b;
- // l0 => lt?
- a = l0; b = lt;
- EXPECT_FALSE(d.onLock(&dtls, a));
- EXPECT_FALSE(d.onLock(&dtls, b));
- d.onUnlock(&dtls, a);
- d.onUnlock(&dtls, b);
- // l1 => lt?
- a = l1; b = lt;
- EXPECT_FALSE(d.onLock(&dtls, a));
- EXPECT_FALSE(d.onLock(&dtls, b));
- d.onUnlock(&dtls, a);
- d.onUnlock(&dtls, b);
- // lt => l4?
- a = lt; b = l4;
- EXPECT_FALSE(d.onLock(&dtls, a));
- EXPECT_FALSE(d.onLock(&dtls, b));
- d.onUnlock(&dtls, a);
- d.onUnlock(&dtls, b);
- // lt => l5?
- a = lt; b = l5;
- EXPECT_FALSE(d.onLock(&dtls, a));
- EXPECT_FALSE(d.onLock(&dtls, b));
- d.onUnlock(&dtls, a);
- d.onUnlock(&dtls, b);
-
- d.removeNode(lt);
- }
- // Still the same epoch.
- EXPECT_EQ(d.size(), d.testOnlyGetEpoch());
- EXPECT_EQ(locks.size(), d.size() - 4);
- // l2 and l3 should have ben reused.
- EXPECT_EQ(locks.count(l2), 1U);
- EXPECT_EQ(locks.count(l3), 1U);
-}
-
-TEST(DeadlockDetector, RemoveNodeTest) {
- RunRemoveNodeTest<BV1>();
- RunRemoveNodeTest<BV2>();
- RunRemoveNodeTest<BV3>();
- RunRemoveNodeTest<BV4>();
-}
-
-template <class BV>
-void RunMultipleEpochsTest() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
-
- set<uptr> locks;
- for (uptr i = 0; i < d.size(); i++) {
- EXPECT_TRUE(locks.insert(d.newNode(i)).second);
- }
- EXPECT_EQ(d.testOnlyGetEpoch(), d.size());
- for (uptr i = 0; i < d.size(); i++) {
- EXPECT_TRUE(locks.insert(d.newNode(i)).second);
- EXPECT_EQ(d.testOnlyGetEpoch(), d.size() * 2);
- }
- locks.clear();
-
- uptr l0 = d.newNode(0);
- uptr l1 = d.newNode(0);
- d.onLock(&dtls, l0);
- d.onLock(&dtls, l1);
- d.onUnlock(&dtls, l0);
- EXPECT_EQ(d.testOnlyGetEpoch(), 3 * d.size());
- for (uptr i = 0; i < d.size(); i++) {
- EXPECT_TRUE(locks.insert(d.newNode(i)).second);
- }
- EXPECT_EQ(d.testOnlyGetEpoch(), 4 * d.size());
-
-#if !SANITIZER_DEBUG
- // EXPECT_DEATH clones a thread with 4K stack,
- // which is overflown by tsan memory accesses functions in debug mode.
-
- // Can not handle the locks from the previous epoch.
- // The caller should update the lock id.
- EXPECT_DEATH(d.onLock(&dtls, l0), "CHECK failed.*current_epoch_");
-#endif
-}
-
-TEST(DeadlockDetector, MultipleEpochsTest) {
- RunMultipleEpochsTest<BV1>();
- RunMultipleEpochsTest<BV2>();
- RunMultipleEpochsTest<BV3>();
- RunMultipleEpochsTest<BV4>();
-}
-
-template <class BV>
-void RunCorrectEpochFlush() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
- vector<uptr> locks1;
- for (uptr i = 0; i < d.size(); i++)
- locks1.push_back(d.newNode(i));
- EXPECT_EQ(d.testOnlyGetEpoch(), d.size());
- d.onLock(&dtls, locks1[3]);
- d.onLock(&dtls, locks1[4]);
- d.onLock(&dtls, locks1[5]);
-
- // We have a new epoch, old locks in dtls will have to be forgotten.
- uptr l0 = d.newNode(0);
- EXPECT_EQ(d.testOnlyGetEpoch(), d.size() * 2);
- uptr l1 = d.newNode(0);
- EXPECT_EQ(d.testOnlyGetEpoch(), d.size() * 2);
- d.onLock(&dtls, l0);
- d.onLock(&dtls, l1);
- EXPECT_TRUE(d.testOnlyHasEdgeRaw(0, 1));
- EXPECT_FALSE(d.testOnlyHasEdgeRaw(1, 0));
- EXPECT_FALSE(d.testOnlyHasEdgeRaw(3, 0));
- EXPECT_FALSE(d.testOnlyHasEdgeRaw(4, 0));
- EXPECT_FALSE(d.testOnlyHasEdgeRaw(5, 0));
-}
-
-TEST(DeadlockDetector, CorrectEpochFlush) {
- RunCorrectEpochFlush<BV1>();
- RunCorrectEpochFlush<BV2>();
-}
-
-template <class BV>
-void RunTryLockTest() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
-
- uptr l0 = d.newNode(0);
- uptr l1 = d.newNode(0);
- uptr l2 = d.newNode(0);
- EXPECT_FALSE(d.onLock(&dtls, l0));
- EXPECT_FALSE(d.onTryLock(&dtls, l1));
- EXPECT_FALSE(d.onLock(&dtls, l2));
- EXPECT_TRUE(d.isHeld(&dtls, l0));
- EXPECT_TRUE(d.isHeld(&dtls, l1));
- EXPECT_TRUE(d.isHeld(&dtls, l2));
- EXPECT_FALSE(d.testOnlyHasEdge(l0, l1));
- EXPECT_TRUE(d.testOnlyHasEdge(l1, l2));
- d.onUnlock(&dtls, l0);
- d.onUnlock(&dtls, l1);
- d.onUnlock(&dtls, l2);
-}
-
-TEST(DeadlockDetector, TryLockTest) {
- RunTryLockTest<BV1>();
- RunTryLockTest<BV2>();
-}
-
-template <class BV>
-void RunOnFirstLockTest() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
-
- uptr l0 = d.newNode(0);
- uptr l1 = d.newNode(0);
- EXPECT_FALSE(d.onFirstLock(&dtls, l0)); // dtls has old epoch.
- d.onLock(&dtls, l0);
- d.onUnlock(&dtls, l0);
-
- EXPECT_TRUE(d.onFirstLock(&dtls, l0)); // Ok, same ecpoch, first lock.
- EXPECT_FALSE(d.onFirstLock(&dtls, l1)); // Second lock.
- d.onLock(&dtls, l1);
- d.onUnlock(&dtls, l1);
- d.onUnlock(&dtls, l0);
-
- EXPECT_TRUE(d.onFirstLock(&dtls, l0)); // Ok
- d.onUnlock(&dtls, l0);
-
- vector<uptr> locks1;
- for (uptr i = 0; i < d.size(); i++)
- locks1.push_back(d.newNode(i));
-
- EXPECT_TRUE(d.onFirstLock(&dtls, l0)); // Epoch has changed, but not in dtls.
-
- uptr l3 = d.newNode(0);
- d.onLock(&dtls, l3);
- d.onUnlock(&dtls, l3);
-
- EXPECT_FALSE(d.onFirstLock(&dtls, l0)); // Epoch has changed in dtls.
-}
-
-TEST(DeadlockDetector, onFirstLockTest) {
- RunOnFirstLockTest<BV2>();
-}
-
-template <class BV>
-void RunRecusriveLockTest() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
-
- uptr l0 = d.newNode(0);
- uptr l1 = d.newNode(0);
- uptr l2 = d.newNode(0);
- uptr l3 = d.newNode(0);
-
- EXPECT_FALSE(d.onLock(&dtls, l0));
- EXPECT_FALSE(d.onLock(&dtls, l1));
- EXPECT_FALSE(d.onLock(&dtls, l0)); // Recurisve.
- EXPECT_FALSE(d.onLock(&dtls, l2));
- d.onUnlock(&dtls, l0);
- EXPECT_FALSE(d.onLock(&dtls, l3));
- d.onUnlock(&dtls, l0);
- d.onUnlock(&dtls, l1);
- d.onUnlock(&dtls, l2);
- d.onUnlock(&dtls, l3);
- EXPECT_TRUE(d.testOnlyHasEdge(l0, l1));
- EXPECT_TRUE(d.testOnlyHasEdge(l0, l2));
- EXPECT_TRUE(d.testOnlyHasEdge(l0, l3));
-}
-
-TEST(DeadlockDetector, RecusriveLockTest) {
- RunRecusriveLockTest<BV2>();
-}
-
-template <class BV>
-void RunLockContextTest() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
-
- uptr l0 = d.newNode(0);
- uptr l1 = d.newNode(0);
- uptr l2 = d.newNode(0);
- uptr l3 = d.newNode(0);
- uptr l4 = d.newNode(0);
- EXPECT_FALSE(d.onLock(&dtls, l0, 10));
- EXPECT_FALSE(d.onLock(&dtls, l1, 11));
- EXPECT_FALSE(d.onLock(&dtls, l2, 12));
- EXPECT_FALSE(d.onLock(&dtls, l3, 13));
- EXPECT_EQ(10U, d.findLockContext(&dtls, l0));
- EXPECT_EQ(11U, d.findLockContext(&dtls, l1));
- EXPECT_EQ(12U, d.findLockContext(&dtls, l2));
- EXPECT_EQ(13U, d.findLockContext(&dtls, l3));
- d.onUnlock(&dtls, l0);
- EXPECT_EQ(0U, d.findLockContext(&dtls, l0));
- EXPECT_EQ(11U, d.findLockContext(&dtls, l1));
- EXPECT_EQ(12U, d.findLockContext(&dtls, l2));
- EXPECT_EQ(13U, d.findLockContext(&dtls, l3));
- d.onUnlock(&dtls, l2);
- EXPECT_EQ(0U, d.findLockContext(&dtls, l0));
- EXPECT_EQ(11U, d.findLockContext(&dtls, l1));
- EXPECT_EQ(0U, d.findLockContext(&dtls, l2));
- EXPECT_EQ(13U, d.findLockContext(&dtls, l3));
-
- EXPECT_FALSE(d.onLock(&dtls, l4, 14));
- EXPECT_EQ(14U, d.findLockContext(&dtls, l4));
-}
-
-TEST(DeadlockDetector, LockContextTest) {
- RunLockContextTest<BV2>();
-}
-
-template <class BV>
-void RunRemoveEdgesTest() {
- ScopedDD<BV> sdd;
- DeadlockDetector<BV> &d = *sdd.dp;
- DeadlockDetectorTLS<BV> &dtls = sdd.dtls;
- vector<uptr> node(BV::kSize);
- u32 stk_from = 0, stk_to = 0;
- int unique_tid = 0;
- for (size_t i = 0; i < BV::kSize; i++)
- node[i] = d.newNode(0);
-
- for (size_t i = 0; i < BV::kSize; i++)
- EXPECT_FALSE(d.onLock(&dtls, node[i], i + 1));
- for (size_t i = 0; i < BV::kSize; i++) {
- for (uptr j = i + 1; j < BV::kSize; j++) {
- EXPECT_TRUE(
- d.findEdge(node[i], node[j], &stk_from, &stk_to, &unique_tid));
- EXPECT_EQ(stk_from, i + 1);
- EXPECT_EQ(stk_to, j + 1);
- }
- }
- EXPECT_EQ(d.testOnlyGetEpoch(), d.size());
- // Remove and re-create half of the nodes.
- for (uptr i = 1; i < BV::kSize; i += 2)
- d.removeNode(node[i]);
- for (uptr i = 1; i < BV::kSize; i += 2)
- node[i] = d.newNode(0);
- EXPECT_EQ(d.testOnlyGetEpoch(), d.size());
- // The edges from or to the removed nodes should be gone.
- for (size_t i = 0; i < BV::kSize; i++) {
- for (uptr j = i + 1; j < BV::kSize; j++) {
- if ((i % 2) || (j % 2))
- EXPECT_FALSE(
- d.findEdge(node[i], node[j], &stk_from, &stk_to, &unique_tid));
- else
- EXPECT_TRUE(
- d.findEdge(node[i], node[j], &stk_from, &stk_to, &unique_tid));
- }
- }
-}
-
-TEST(DeadlockDetector, RemoveEdgesTest) {
- RunRemoveEdgesTest<BV1>();
-}
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_deadlock_detector_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_deadlock_detector_test.cc -------------------------------===//
+//===-- sanitizer_deadlock_detector_test.cpp ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc (removed)
@@ -1,198 +0,0 @@
-//===-- sanitizer_flags_test.cc -------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_flags.h"
-#include "sanitizer_common/sanitizer_flag_parser.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "gtest/gtest.h"
-
-#include <stdint.h>
-#include <string.h>
-
-namespace __sanitizer {
-
-static const char kFlagName[] = "flag_name";
-static const char kFlagDesc[] = "flag description";
-
-template <typename T>
-static void TestFlag(T start_value, const char *env, T final_value) {
- T flag = start_value;
-
- FlagParser parser;
- RegisterFlag(&parser, kFlagName, kFlagDesc, &flag);
-
- parser.ParseString(env);
-
- EXPECT_EQ(final_value, flag);
-
- // Reporting unrecognized flags is needed to reset them.
- ReportUnrecognizedFlags();
-}
-
-template <>
-void TestFlag(const char *start_value, const char *env,
- const char *final_value) {
- const char *flag = start_value;
-
- FlagParser parser;
- RegisterFlag(&parser, kFlagName, kFlagDesc, &flag);
-
- parser.ParseString(env);
-
- EXPECT_EQ(0, internal_strcmp(final_value, flag));
-
- // Reporting unrecognized flags is needed to reset them.
- ReportUnrecognizedFlags();
-}
-
-TEST(SanitizerCommon, BooleanFlags) {
- TestFlag(false, "flag_name=1", true);
- TestFlag(false, "flag_name=yes", true);
- TestFlag(false, "flag_name=true", true);
- TestFlag(true, "flag_name=0", false);
- TestFlag(true, "flag_name=no", false);
- TestFlag(true, "flag_name=false", false);
-
- EXPECT_DEATH(TestFlag(false, "flag_name", true), "expected '='");
- EXPECT_DEATH(TestFlag(false, "flag_name=", true),
- "Invalid value for bool option: ''");
- EXPECT_DEATH(TestFlag(false, "flag_name=2", true),
- "Invalid value for bool option: '2'");
- EXPECT_DEATH(TestFlag(false, "flag_name=-1", true),
- "Invalid value for bool option: '-1'");
- EXPECT_DEATH(TestFlag(false, "flag_name=on", true),
- "Invalid value for bool option: 'on'");
-}
-
-TEST(SanitizerCommon, HandleSignalMode) {
- TestFlag(kHandleSignalNo, "flag_name=1", kHandleSignalYes);
- TestFlag(kHandleSignalNo, "flag_name=yes", kHandleSignalYes);
- TestFlag(kHandleSignalNo, "flag_name=true", kHandleSignalYes);
- TestFlag(kHandleSignalYes, "flag_name=0", kHandleSignalNo);
- TestFlag(kHandleSignalYes, "flag_name=no", kHandleSignalNo);
- TestFlag(kHandleSignalYes, "flag_name=false", kHandleSignalNo);
- TestFlag(kHandleSignalNo, "flag_name=2", kHandleSignalExclusive);
- TestFlag(kHandleSignalYes, "flag_name=exclusive", kHandleSignalExclusive);
-
- EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name", kHandleSignalNo),
- "expected '='");
- EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=", kHandleSignalNo),
- "Invalid value for signal handler option: ''");
- EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=3", kHandleSignalNo),
- "Invalid value for signal handler option: '3'");
- EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=-1", kHandleSignalNo),
- "Invalid value for signal handler option: '-1'");
- EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=on", kHandleSignalNo),
- "Invalid value for signal handler option: 'on'");
-}
-
-TEST(SanitizerCommon, IntFlags) {
- TestFlag(-11, 0, -11);
- TestFlag(-11, "flag_name=0", 0);
- TestFlag(-11, "flag_name=42", 42);
- TestFlag(-11, "flag_name=-42", -42);
-
- // Unrecognized flags are ignored.
- TestFlag(-11, "--flag_name=42", -11);
- TestFlag(-11, "zzzzzzz=42", -11);
-
- EXPECT_DEATH(TestFlag(-11, "flag_name", 0), "expected '='");
- EXPECT_DEATH(TestFlag(-11, "flag_name=42U", 0),
- "Invalid value for int option");
-}
-
-TEST(SanitizerCommon, LongLongIntFlags) {
- s64 InitValue = -5;
- s64 IntMin = INT64_MIN;
- s64 IntMax = INT64_MAX;
- TestFlag(InitValue, "flag_name=0", 0ll);
- TestFlag(InitValue, "flag_name=42", 42ll);
- TestFlag(InitValue, "flag_name=-42", -42ll);
-
- TestFlag(InitValue, "flag_name=-9223372036854775808", IntMin);
- TestFlag(InitValue, "flag_name=9223372036854775807", IntMax);
-
- TestFlag(InitValue, "flag_name=-92233720368547758080000", IntMin);
- TestFlag(InitValue, "flag_name=92233720368547758070000", IntMax);
-}
-
-TEST(SanitizerCommon, StrFlags) {
- TestFlag("zzz", 0, "zzz");
- TestFlag("zzz", "flag_name=", "");
- TestFlag("zzz", "flag_name=abc", "abc");
- TestFlag("", "flag_name=abc", "abc");
- TestFlag("", "flag_name='abc zxc'", "abc zxc");
- // TestStrFlag("", "flag_name=\"abc qwe\" asd", "abc qwe");
-}
-
-static void TestTwoFlags(const char *env, bool expected_flag1,
- const char *expected_flag2,
- const char *name1 = "flag1",
- const char *name2 = "flag2") {
- bool flag1 = !expected_flag1;
- const char *flag2 = "";
-
- FlagParser parser;
- RegisterFlag(&parser, name1, kFlagDesc, &flag1);
- RegisterFlag(&parser, name2, kFlagDesc, &flag2);
-
- parser.ParseString(env);
-
- EXPECT_EQ(expected_flag1, flag1);
- EXPECT_EQ(0, internal_strcmp(flag2, expected_flag2));
-
- // Reporting unrecognized flags is needed to reset them.
- ReportUnrecognizedFlags();
-}
-
-TEST(SanitizerCommon, MultipleFlags) {
- TestTwoFlags("flag1=1 flag2='zzz'", true, "zzz");
- TestTwoFlags("flag2='qxx' flag1=0", false, "qxx");
- TestTwoFlags("flag1=false:flag2='zzz'", false, "zzz");
- TestTwoFlags("flag2=qxx:flag1=yes", true, "qxx");
- TestTwoFlags("flag2=qxx\nflag1=yes", true, "qxx");
- TestTwoFlags("flag2=qxx\r\nflag1=yes", true, "qxx");
- TestTwoFlags("flag2=qxx\tflag1=yes", true, "qxx");
-}
-
-TEST(SanitizerCommon, CommonSuffixFlags) {
- TestTwoFlags("flag=1 other_flag='zzz'", true, "zzz", "flag", "other_flag");
- TestTwoFlags("other_flag='zzz' flag=1", true, "zzz", "flag", "other_flag");
- TestTwoFlags("other_flag=' flag=0 ' flag=1", true, " flag=0 ", "flag",
- "other_flag");
- TestTwoFlags("flag=1 other_flag=' flag=0 '", true, " flag=0 ", "flag",
- "other_flag");
-}
-
-TEST(SanitizerCommon, CommonFlags) {
- CommonFlags cf;
- FlagParser parser;
- RegisterCommonFlags(&parser, &cf);
-
- cf.SetDefaults();
- EXPECT_TRUE(cf.symbolize);
- EXPECT_STREQ(".", cf.coverage_dir);
-
- cf.symbolize = false;
- cf.coverage = true;
- cf.heap_profile = true;
- cf.log_path = "path/one";
-
- parser.ParseString("symbolize=1:heap_profile=false log_path='path/two'");
- EXPECT_TRUE(cf.symbolize);
- EXPECT_TRUE(cf.coverage);
- EXPECT_FALSE(cf.heap_profile);
- EXPECT_STREQ("path/two", cf.log_path);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_flags_test.cc -------------------------------------------===//
+//===-- sanitizer_flags_test.cpp ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc (removed)
@@ -1,262 +0,0 @@
-//===-- sanitizer_format_interceptor_test.cc ------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Tests for *scanf interceptors implementation in sanitizer_common.
-//
-//===----------------------------------------------------------------------===//
-#include <algorithm>
-#include <vector>
-
-#include "interception/interception.h"
-#include "sanitizer_test_utils.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "gtest/gtest.h"
-
-using namespace __sanitizer;
-
-#define COMMON_INTERCEPTOR_READ_WRITE_RANGE(ctx, ptr, size) \
- do { \
- ((std::vector<unsigned> *)ctx)->push_back(size); \
- ptr = ptr; \
- } while (0)
-
-#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \
- COMMON_INTERCEPTOR_READ_WRITE_RANGE(ctx, ptr, size)
-
-#define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size) \
- COMMON_INTERCEPTOR_READ_WRITE_RANGE(ctx, ptr, size)
-
-#define SANITIZER_INTERCEPT_PRINTF 1
-#include "sanitizer_common/sanitizer_common_interceptors_format.inc"
-
-static const unsigned I = sizeof(int);
-static const unsigned L = sizeof(long);
-static const unsigned LL = sizeof(long long);
-static const unsigned S = sizeof(short);
-static const unsigned C = sizeof(char);
-static const unsigned LC = sizeof(wchar_t);
-static const unsigned D = sizeof(double);
-static const unsigned LD = sizeof(long double);
-static const unsigned F = sizeof(float);
-static const unsigned P = sizeof(char *);
-
-static void verifyFormatResults(const char *format, unsigned n,
- const std::vector<unsigned> &computed_sizes,
- va_list expected_sizes) {
- // "+ 1" because of format string
- ASSERT_EQ(n + 1,
- computed_sizes.size()) << "Unexpected number of format arguments: '"
- << format << "'";
- for (unsigned i = 0; i < n; ++i)
- EXPECT_EQ(va_arg(expected_sizes, unsigned), computed_sizes[i + 1])
- << "Unexpect write size for argument " << i << ", format string '"
- << format << "'";
-}
-
-static const char test_buf[] = "Test string.";
-static const size_t test_buf_size = sizeof(test_buf);
-
-static const unsigned SCANF_ARGS_MAX = 16;
-
-static void testScanf3(void *ctx, int result, bool allowGnuMalloc,
- const char *format, ...) {
- va_list ap;
- va_start(ap, format);
- scanf_common(ctx, result, allowGnuMalloc, format, ap);
- va_end(ap);
-}
-
-static void testScanf2(const char *format, int scanf_result,
- bool allowGnuMalloc, unsigned n,
- va_list expected_sizes) {
- std::vector<unsigned> scanf_sizes;
- // 16 args should be enough.
- testScanf3((void *)&scanf_sizes, scanf_result, allowGnuMalloc, format,
- test_buf, test_buf, test_buf, test_buf, test_buf, test_buf,
- test_buf, test_buf, test_buf, test_buf, test_buf, test_buf,
- test_buf, test_buf, test_buf, test_buf);
- verifyFormatResults(format, n, scanf_sizes, expected_sizes);
-}
-
-static void testScanf(const char *format, unsigned n, ...) {
- va_list ap;
- va_start(ap, n);
- testScanf2(format, SCANF_ARGS_MAX, /* allowGnuMalloc */ true, n, ap);
- va_end(ap);
-}
-
-static void testScanfPartial(const char *format, int scanf_result, unsigned n,
- ...) {
- va_list ap;
- va_start(ap, n);
- testScanf2(format, scanf_result, /* allowGnuMalloc */ true, n, ap);
- va_end(ap);
-}
-
-static void testScanfNoGnuMalloc(const char *format, unsigned n, ...) {
- va_list ap;
- va_start(ap, n);
- testScanf2(format, SCANF_ARGS_MAX, /* allowGnuMalloc */ false, n, ap);
- va_end(ap);
-}
-
-TEST(SanitizerCommonInterceptors, Scanf) {
- testScanf("%d", 1, I);
- testScanf("%d%d%d", 3, I, I, I);
- testScanf("ab%u%dc", 2, I, I);
- testScanf("%ld", 1, L);
- testScanf("%llu", 1, LL);
- testScanf("%qd", 1, LL);
- testScanf("a %hd%hhx", 2, S, C);
- testScanf("%c", 1, C);
- testScanf("%lc", 1, LC);
-
- testScanf("%%", 0);
- testScanf("a%%", 0);
- testScanf("a%%b", 0);
- testScanf("a%%%%b", 0);
- testScanf("a%%b%%", 0);
- testScanf("a%%%%%%b", 0);
- testScanf("a%%%%%b", 0);
- testScanf("a%%%%%f", 1, F);
- testScanf("a%%%lxb", 1, L);
- testScanf("a%lf%%%lxb", 2, D, L);
- testScanf("%nf", 1, I);
-
- testScanf("%10s", 1, 11);
- testScanf("%10c", 1, 10);
- testScanf("%10ls", 1, 11 * LC);
- testScanf("%10lc", 1, 10 * LC);
- testScanf("%%10s", 0);
- testScanf("%*10s", 0);
- testScanf("%*d", 0);
-
- testScanf("%4d%8f%c", 3, I, F, C);
- testScanf("%s%d", 2, test_buf_size, I);
- testScanf("%[abc]", 1, test_buf_size);
- testScanf("%4[bcdef]", 1, 5);
- testScanf("%[]]", 1, test_buf_size);
- testScanf("%8[^]%d0-9-]%c", 2, 9, C);
-
- testScanf("%*[^:]%n:%d:%1[ ]%n", 4, I, I, 2, I);
-
- testScanf("%*d%u", 1, I);
-
- testScanf("%c%d", 2, C, I);
- testScanf("%A%lf", 2, F, D);
-
- testScanf("%ms %Lf", 2, P, LD);
- testScanf("s%Las", 1, LD);
- testScanf("%ar", 1, F);
-
- // In the cases with std::min below the format spec can be interpreted as
- // either floating-something, or (GNU extension) callee-allocated string.
- // Our conservative implementation reports one of the two possibilities with
- // the least store range.
- testScanf("%a[", 0);
- testScanf("%a[]", 0);
- testScanf("%a[]]", 1, std::min(F, P));
- testScanf("%a[abc]", 1, std::min(F, P));
- testScanf("%a[^abc]", 1, std::min(F, P));
- testScanf("%a[ab%c] %d", 0);
- testScanf("%a[^ab%c] %d", 0);
- testScanf("%as", 1, std::min(F, P));
- testScanf("%aS", 1, std::min(F, P));
- testScanf("%a13S", 1, std::min(F, P));
- testScanf("%alS", 1, std::min(F, P));
-
- testScanfNoGnuMalloc("s%Las", 1, LD);
- testScanfNoGnuMalloc("%ar", 1, F);
- testScanfNoGnuMalloc("%a[", 1, F);
- testScanfNoGnuMalloc("%a[]", 1, F);
- testScanfNoGnuMalloc("%a[]]", 1, F);
- testScanfNoGnuMalloc("%a[abc]", 1, F);
- testScanfNoGnuMalloc("%a[^abc]", 1, F);
- testScanfNoGnuMalloc("%a[ab%c] %d", 3, F, C, I);
- testScanfNoGnuMalloc("%a[^ab%c] %d", 3, F, C, I);
- testScanfNoGnuMalloc("%as", 1, F);
- testScanfNoGnuMalloc("%aS", 1, F);
- testScanfNoGnuMalloc("%a13S", 1, F);
- testScanfNoGnuMalloc("%alS", 1, F);
-
- testScanf("%5$d", 0);
- testScanf("%md", 0);
- testScanf("%m10s", 0);
-
- testScanfPartial("%d%d%d%d //1\n", 1, 1, I);
- testScanfPartial("%d%d%d%d //2\n", 2, 2, I, I);
- testScanfPartial("%d%d%d%d //3\n", 3, 3, I, I, I);
- testScanfPartial("%d%d%d%d //4\n", 4, 4, I, I, I, I);
-
- testScanfPartial("%d%n%n%d //1\n", 1, 3, I, I, I);
- testScanfPartial("%d%n%n%d //2\n", 2, 4, I, I, I, I);
-
- testScanfPartial("%d%n%n%d %s %s", 3, 5, I, I, I, I, test_buf_size);
- testScanfPartial("%d%n%n%d %s %s", 4, 6, I, I, I, I, test_buf_size,
- test_buf_size);
-}
-
-static void testPrintf3(void *ctx, const char *format, ...) {
- va_list ap;
- va_start(ap, format);
- printf_common(ctx, format, ap);
- va_end(ap);
-}
-
-static void testPrintf2(const char *format, unsigned n,
- va_list expected_sizes) {
- std::vector<unsigned> printf_sizes;
- // 16 args should be enough.
- testPrintf3((void *)&printf_sizes, format,
- test_buf, test_buf, test_buf, test_buf, test_buf, test_buf,
- test_buf, test_buf, test_buf, test_buf, test_buf, test_buf,
- test_buf, test_buf, test_buf, test_buf);
- verifyFormatResults(format, n, printf_sizes, expected_sizes);
-}
-
-static void testPrintf(const char *format, unsigned n, ...) {
- va_list ap;
- va_start(ap, n);
- testPrintf2(format, n, ap);
- va_end(ap);
-}
-
-TEST(SanitizerCommonInterceptors, Printf) {
- // Only test functionality which differs from scanf
-
- // Indexed arguments
- testPrintf("%5$d", 0);
- testPrintf("%.*5$d", 0);
-
- // errno
- testPrintf("%0-m", 0);
-
- // Dynamic width
- testPrintf("%*n", 1, I);
- testPrintf("%*.10n", 1, I);
-
- // Precision
- testPrintf("%10.10n", 1, I);
- testPrintf("%.3s", 1, 3);
- testPrintf("%.20s", 1, test_buf_size);
-
- // Dynamic precision
- testPrintf("%.*n", 1, I);
- testPrintf("%10.*n", 1, I);
-
- // Dynamic precision for strings is not implemented yet.
- testPrintf("%.*s", 1, 0);
-
- // Checks for wide-character strings are not implemented yet.
- testPrintf("%ls", 1, 0);
-
- testPrintf("%m", 0);
- testPrintf("%m%s", 1, test_buf_size);
- testPrintf("%s%m%s", 2, test_buf_size, test_buf_size);
-}
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_format_interceptor_test.cc ------------------------------===//
+//===-- sanitizer_format_interceptor_test.cpp -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc (removed)
@@ -1,104 +0,0 @@
-//===-- sanitizer_ioctl_test.cc -------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Tests for ioctl interceptor implementation in sanitizer_common.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_LINUX
-
-#include <linux/input.h>
-#include <vector>
-
-#include "interception/interception.h"
-#include "sanitizer_test_utils.h"
-#include "sanitizer_common/sanitizer_platform_limits_posix.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "gtest/gtest.h"
-
-
-using namespace __sanitizer;
-
-#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, sz) \
- do { \
- (void) ctx; \
- (void) ptr; \
- (void) sz; \
- } while (0)
-#define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, sz) \
- do { \
- (void) ctx; \
- (void) ptr; \
- (void) sz; \
- } while (0)
-
-#include "sanitizer_common/sanitizer_common_interceptors_ioctl.inc"
-
-static struct IoctlInit {
- IoctlInit() {
- ioctl_init();
- // Avoid unused function warnings.
- (void)&ioctl_common_pre;
- (void)&ioctl_common_post;
- (void)&ioctl_decode;
- }
-} ioctl_static_initializer;
-
-TEST(SanitizerIoctl, Fixup) {
- EXPECT_EQ((unsigned)FIONBIO, ioctl_request_fixup(FIONBIO));
-
- EXPECT_EQ(EVIOCGBIT(0, 0), ioctl_request_fixup(EVIOCGBIT(0, 16)));
- EXPECT_EQ(EVIOCGBIT(0, 0), ioctl_request_fixup(EVIOCGBIT(1, 16)));
- EXPECT_EQ(EVIOCGBIT(0, 0), ioctl_request_fixup(EVIOCGBIT(1, 17)));
- EXPECT_EQ(EVIOCGBIT(0, 0), ioctl_request_fixup(EVIOCGBIT(31, 16)));
- EXPECT_NE(EVIOCGBIT(0, 0), ioctl_request_fixup(EVIOCGBIT(32, 16)));
-
- EXPECT_EQ(EVIOCGABS(0), ioctl_request_fixup(EVIOCGABS(0)));
- EXPECT_EQ(EVIOCGABS(0), ioctl_request_fixup(EVIOCGABS(5)));
- EXPECT_EQ(EVIOCGABS(0), ioctl_request_fixup(EVIOCGABS(63)));
- EXPECT_NE(EVIOCGABS(0), ioctl_request_fixup(EVIOCGABS(64)));
-
- EXPECT_EQ(EVIOCSABS(0), ioctl_request_fixup(EVIOCSABS(0)));
- EXPECT_EQ(EVIOCSABS(0), ioctl_request_fixup(EVIOCSABS(5)));
- EXPECT_EQ(EVIOCSABS(0), ioctl_request_fixup(EVIOCSABS(63)));
- EXPECT_NE(EVIOCSABS(0), ioctl_request_fixup(EVIOCSABS(64)));
-
- const ioctl_desc *desc = ioctl_lookup(EVIOCGKEY(16));
- EXPECT_NE((void *)0, desc);
- EXPECT_EQ(EVIOCGKEY(0), desc->req);
-}
-
-// Test decoding KVM ioctl numbers.
-TEST(SanitizerIoctl, KVM_GET_MP_STATE) {
- ioctl_desc desc;
- unsigned int desc_value = SANITIZER_MIPS ? 0x4004ae98U : 0x8004ae98U;
- bool res = ioctl_decode(desc_value, &desc);
- EXPECT_TRUE(res);
- EXPECT_EQ(ioctl_desc::WRITE, desc.type);
- EXPECT_EQ(4U, desc.size);
-}
-
-TEST(SanitizerIoctl, KVM_GET_LAPIC) {
- ioctl_desc desc;
- unsigned int desc_value = SANITIZER_MIPS ? 0x4400ae8eU : 0x8400ae8eU;
- bool res = ioctl_decode(desc_value, &desc);
- EXPECT_TRUE(res);
- EXPECT_EQ(ioctl_desc::WRITE, desc.type);
- EXPECT_EQ(1024U, desc.size);
-}
-
-TEST(SanitizerIoctl, KVM_GET_MSR_INDEX_LIST) {
- ioctl_desc desc;
- bool res = ioctl_decode(0xc004ae02U, &desc);
- EXPECT_TRUE(res);
- EXPECT_EQ(ioctl_desc::READWRITE, desc.type);
- EXPECT_EQ(4U, desc.size);
-}
-
-#endif // SANITIZER_LINUX
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ioctl_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_ioctl_test.cc -------------------------------------------===//
+//===-- sanitizer_ioctl_test.cpp ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (removed)
@@ -1,314 +0,0 @@
-//===-- sanitizer_libc_test.cc --------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-// Tests for sanitizer_libc.h.
-//===----------------------------------------------------------------------===//
-#include <algorithm>
-#include <fstream>
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_file.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_platform.h"
-#include "gtest/gtest.h"
-
-#if SANITIZER_WINDOWS
-#define NOMINMAX
-#include <windows.h>
-#undef NOMINMAX
-#endif
-#if SANITIZER_POSIX
-# include <sys/stat.h>
-# include "sanitizer_common/sanitizer_posix.h"
-#endif
-
-using namespace __sanitizer;
-
-// A regression test for internal_memmove() implementation.
-TEST(SanitizerCommon, InternalMemmoveRegression) {
- char src[] = "Hello World";
- char *dest = src + 6;
- __sanitizer::internal_memmove(dest, src, 5);
- EXPECT_EQ(dest[0], src[0]);
- EXPECT_EQ(dest[4], src[4]);
-}
-
-TEST(SanitizerCommon, mem_is_zero) {
- size_t size = 128;
- char *x = new char[size];
- memset(x, 0, size);
- for (size_t pos = 0; pos < size; pos++) {
- x[pos] = 1;
- for (size_t beg = 0; beg < size; beg++) {
- for (size_t end = beg; end < size; end++) {
- // fprintf(stderr, "pos %zd beg %zd end %zd \n", pos, beg, end);
- if (beg <= pos && pos < end)
- EXPECT_FALSE(__sanitizer::mem_is_zero(x + beg, end - beg));
- else
- EXPECT_TRUE(__sanitizer::mem_is_zero(x + beg, end - beg));
- }
- }
- x[pos] = 0;
- }
- delete [] x;
-}
-
-struct stat_and_more {
- struct stat st;
- unsigned char z;
-};
-
-static void temp_file_name(char *buf, size_t bufsize, const char *prefix) {
-#if SANITIZER_WINDOWS
- buf[0] = '\0';
- char tmp_dir[MAX_PATH];
- if (!::GetTempPathA(MAX_PATH, tmp_dir))
- return;
- // GetTempFileNameA needs a MAX_PATH buffer.
- char tmp_path[MAX_PATH];
- if (!::GetTempFileNameA(tmp_dir, prefix, 0, tmp_path))
- return;
- internal_strncpy(buf, tmp_path, bufsize);
-#else
- const char *tmpdir = "/tmp";
-#if SANITIZER_ANDROID
- // I don't know a way to query temp directory location on Android without
- // going through Java interfaces. The code below is not ideal, but should
- // work. May require "adb root", but it is needed for almost any use of ASan
- // on Android already.
- tmpdir = GetEnv("EXTERNAL_STORAGE");
-#endif
- internal_snprintf(buf, bufsize, "%s/%sXXXXXX", tmpdir, prefix);
- ASSERT_TRUE(mkstemp(buf));
-#endif
-}
-
-static void Unlink(const char *path) {
-#if SANITIZER_WINDOWS
- // No sanitizer needs to delete a file on Windows yet. If we ever do, we can
- // add a portable wrapper and test it from here.
- ::DeleteFileA(&path[0]);
-#else
- internal_unlink(path);
-#endif
-}
-
-TEST(SanitizerCommon, FileOps) {
- const char *str1 = "qwerty";
- uptr len1 = internal_strlen(str1);
- const char *str2 = "zxcv";
- uptr len2 = internal_strlen(str2);
-
- char tmpfile[128];
- temp_file_name(tmpfile, sizeof(tmpfile), "sanitizer_common.fileops.tmp.");
- fd_t fd = OpenFile(tmpfile, WrOnly);
- ASSERT_NE(fd, kInvalidFd);
- ASSERT_TRUE(WriteToFile(fd, "A", 1));
- CloseFile(fd);
-
- fd = OpenFile(tmpfile, WrOnly);
- ASSERT_NE(fd, kInvalidFd);
-#if SANITIZER_POSIX && !SANITIZER_MAC
- EXPECT_EQ(internal_lseek(fd, 0, SEEK_END), 0u);
-#endif
- uptr bytes_written = 0;
- EXPECT_TRUE(WriteToFile(fd, str1, len1, &bytes_written));
- EXPECT_EQ(len1, bytes_written);
- EXPECT_TRUE(WriteToFile(fd, str2, len2, &bytes_written));
- EXPECT_EQ(len2, bytes_written);
- CloseFile(fd);
-
- EXPECT_TRUE(FileExists(tmpfile));
-
- fd = OpenFile(tmpfile, RdOnly);
- ASSERT_NE(fd, kInvalidFd);
-
-#if SANITIZER_POSIX
- // The stat wrappers are posix-only.
- uptr fsize = internal_filesize(fd);
- EXPECT_EQ(len1 + len2, fsize);
-
- struct stat st1, st2, st3;
- EXPECT_EQ(0u, internal_stat(tmpfile, &st1));
- EXPECT_EQ(0u, internal_lstat(tmpfile, &st2));
- EXPECT_EQ(0u, internal_fstat(fd, &st3));
- EXPECT_EQ(fsize, (uptr)st3.st_size);
-
- // Verify that internal_fstat does not write beyond the end of the supplied
- // buffer.
- struct stat_and_more sam;
- memset(&sam, 0xAB, sizeof(sam));
- EXPECT_EQ(0u, internal_fstat(fd, &sam.st));
- EXPECT_EQ(0xAB, sam.z);
- EXPECT_NE(0xAB, sam.st.st_size);
- EXPECT_NE(0, sam.st.st_size);
-#endif
-
- char buf[64] = {};
- uptr bytes_read = 0;
- EXPECT_TRUE(ReadFromFile(fd, buf, len1, &bytes_read));
- EXPECT_EQ(len1, bytes_read);
- EXPECT_EQ(0, internal_memcmp(buf, str1, len1));
- EXPECT_EQ((char)0, buf[len1 + 1]);
- internal_memset(buf, 0, len1);
- EXPECT_TRUE(ReadFromFile(fd, buf, len2, &bytes_read));
- EXPECT_EQ(len2, bytes_read);
- EXPECT_EQ(0, internal_memcmp(buf, str2, len2));
- CloseFile(fd);
-
- Unlink(tmpfile);
-}
-
-class SanitizerCommonFileTest : public ::testing::TestWithParam<uptr> {
- void SetUp() override {
- data_.resize(GetParam());
- std::generate(data_.begin(), data_.end(), [] {
- return rand() % 256; // NOLINT
- });
-
- temp_file_name(file_name_, sizeof(file_name_),
- "sanitizer_common.ReadFile.tmp.");
-
- std::ofstream f(file_name_, std::ios::out | std::ios::binary);
- if (!data_.empty())
- f.write(data_.data(), data_.size());
- }
-
- void TearDown() override { Unlink(file_name_); }
-
- protected:
- char file_name_[256];
- std::vector<char> data_;
-};
-
-TEST_P(SanitizerCommonFileTest, ReadFileToBuffer) {
- char *buff;
- uptr size;
- uptr len;
- EXPECT_TRUE(ReadFileToBuffer(file_name_, &buff, &len, &size));
- EXPECT_EQ(data_, std::vector<char>(buff, buff + size));
- UnmapOrDie(buff, len);
-}
-
-TEST_P(SanitizerCommonFileTest, ReadFileToBufferHalf) {
- char *buff;
- uptr size;
- uptr len;
- data_.resize(data_.size() / 2);
- EXPECT_TRUE(ReadFileToBuffer(file_name_, &buff, &len, &size, data_.size()));
- EXPECT_EQ(data_, std::vector<char>(buff, buff + size));
- UnmapOrDie(buff, len);
-}
-
-TEST_P(SanitizerCommonFileTest, ReadFileToVector) {
- InternalMmapVector<char> buff;
- EXPECT_TRUE(ReadFileToVector(file_name_, &buff));
- EXPECT_EQ(data_, std::vector<char>(buff.begin(), buff.end()));
-}
-
-TEST_P(SanitizerCommonFileTest, ReadFileToVectorHalf) {
- InternalMmapVector<char> buff;
- data_.resize(data_.size() / 2);
- EXPECT_TRUE(ReadFileToVector(file_name_, &buff, data_.size()));
- EXPECT_EQ(data_, std::vector<char>(buff.begin(), buff.end()));
-}
-
-INSTANTIATE_TEST_CASE_P(FileSizes, SanitizerCommonFileTest,
- ::testing::Values(0, 1, 7, 13, 32, 4096, 4097, 1048575,
- 1048576, 1048577));
-
-static const size_t kStrlcpyBufSize = 8;
-void test_internal_strlcpy(char *dbuf, const char *sbuf) {
- uptr retval = 0;
- retval = internal_strlcpy(dbuf, sbuf, kStrlcpyBufSize);
- EXPECT_EQ(internal_strncmp(dbuf, sbuf, kStrlcpyBufSize - 1), 0);
- EXPECT_EQ(internal_strlen(dbuf),
- std::min(internal_strlen(sbuf), (uptr)(kStrlcpyBufSize - 1)));
- EXPECT_EQ(retval, internal_strlen(sbuf));
-
- // Test with shorter maxlen.
- uptr maxlen = 2;
- if (internal_strlen(sbuf) > maxlen) {
- retval = internal_strlcpy(dbuf, sbuf, maxlen);
- EXPECT_EQ(internal_strncmp(dbuf, sbuf, maxlen - 1), 0);
- EXPECT_EQ(internal_strlen(dbuf), maxlen - 1);
- }
-}
-
-TEST(SanitizerCommon, InternalStrFunctions) {
- const char *haystack = "haystack";
- EXPECT_EQ(haystack + 2, internal_strchr(haystack, 'y'));
- EXPECT_EQ(haystack + 2, internal_strchrnul(haystack, 'y'));
- EXPECT_EQ(0, internal_strchr(haystack, 'z'));
- EXPECT_EQ(haystack + 8, internal_strchrnul(haystack, 'z'));
-
- char dbuf[kStrlcpyBufSize] = {};
- const char *samesizestr = "1234567";
- const char *shortstr = "123";
- const char *longerstr = "123456789";
-
- // Test internal_strlcpy.
- internal_strlcpy(dbuf, shortstr, 0);
- EXPECT_EQ(dbuf[0], 0);
- EXPECT_EQ(dbuf[0], 0);
- test_internal_strlcpy(dbuf, samesizestr);
- test_internal_strlcpy(dbuf, shortstr);
- test_internal_strlcpy(dbuf, longerstr);
-
- // Test internal_strlcat.
- char dcatbuf[kStrlcpyBufSize] = {};
- uptr retval = 0;
- retval = internal_strlcat(dcatbuf, "aaa", 0);
- EXPECT_EQ(internal_strlen(dcatbuf), (uptr)0);
- EXPECT_EQ(retval, (uptr)3);
-
- retval = internal_strlcat(dcatbuf, "123", kStrlcpyBufSize);
- EXPECT_EQ(internal_strcmp(dcatbuf, "123"), 0);
- EXPECT_EQ(internal_strlen(dcatbuf), (uptr)3);
- EXPECT_EQ(retval, (uptr)3);
-
- retval = internal_strlcat(dcatbuf, "123", kStrlcpyBufSize);
- EXPECT_EQ(internal_strcmp(dcatbuf, "123123"), 0);
- EXPECT_EQ(internal_strlen(dcatbuf), (uptr)6);
- EXPECT_EQ(retval, (uptr)6);
-
- retval = internal_strlcat(dcatbuf, "123", kStrlcpyBufSize);
- EXPECT_EQ(internal_strcmp(dcatbuf, "1231231"), 0);
- EXPECT_EQ(internal_strlen(dcatbuf), (uptr)7);
- EXPECT_EQ(retval, (uptr)9);
-}
-
-// FIXME: File manipulations are not yet supported on Windows
-#if SANITIZER_POSIX && !SANITIZER_MAC
-TEST(SanitizerCommon, InternalMmapWithOffset) {
- char tmpfile[128];
- temp_file_name(tmpfile, sizeof(tmpfile),
- "sanitizer_common.internalmmapwithoffset.tmp.");
- fd_t fd = OpenFile(tmpfile, RdWr);
- ASSERT_NE(fd, kInvalidFd);
-
- uptr page_size = GetPageSizeCached();
- uptr res = internal_ftruncate(fd, page_size * 2);
- ASSERT_FALSE(internal_iserror(res));
-
- res = internal_lseek(fd, page_size, SEEK_SET);
- ASSERT_FALSE(internal_iserror(res));
-
- res = internal_write(fd, "AB", 2);
- ASSERT_FALSE(internal_iserror(res));
-
- char *p = (char *)MapWritableFileToMemory(nullptr, page_size, fd, page_size);
- ASSERT_NE(nullptr, p);
-
- ASSERT_EQ('A', p[0]);
- ASSERT_EQ('B', p[1]);
-
- CloseFile(fd);
- UnmapOrDie(p, page_size);
- internal_unlink(tmpfile);
-}
-#endif
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_libc_test.cc --------------------------------------------===//
+//===-- sanitizer_libc_test.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc (removed)
@@ -1,295 +0,0 @@
-//===-- sanitizer_linux_test.cc -------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Tests for sanitizer_linux.h
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_LINUX
-
-#include "sanitizer_common/sanitizer_linux.h"
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_file.h"
-#include "gtest/gtest.h"
-
-#include <pthread.h>
-#include <sched.h>
-#include <stdlib.h>
-
-#include <algorithm>
-#include <vector>
-
-namespace __sanitizer {
-
-struct TidReporterArgument {
- TidReporterArgument() {
- pthread_mutex_init(&terminate_thread_mutex, NULL);
- pthread_mutex_init(&tid_reported_mutex, NULL);
- pthread_cond_init(&terminate_thread_cond, NULL);
- pthread_cond_init(&tid_reported_cond, NULL);
- terminate_thread = false;
- }
-
- ~TidReporterArgument() {
- pthread_mutex_destroy(&terminate_thread_mutex);
- pthread_mutex_destroy(&tid_reported_mutex);
- pthread_cond_destroy(&terminate_thread_cond);
- pthread_cond_destroy(&tid_reported_cond);
- }
-
- tid_t reported_tid;
- // For signaling to spawned threads that they should terminate.
- pthread_cond_t terminate_thread_cond;
- pthread_mutex_t terminate_thread_mutex;
- bool terminate_thread;
- // For signaling to main thread that a child thread has reported its tid.
- pthread_cond_t tid_reported_cond;
- pthread_mutex_t tid_reported_mutex;
-
- private:
- // Disallow evil constructors
- TidReporterArgument(const TidReporterArgument &);
- void operator=(const TidReporterArgument &);
-};
-
-class ThreadListerTest : public ::testing::Test {
- protected:
- virtual void SetUp() {
- pthread_t pthread_id;
- tid_t tid;
- for (uptr i = 0; i < kThreadCount; i++) {
- SpawnTidReporter(&pthread_id, &tid);
- pthread_ids_.push_back(pthread_id);
- tids_.push_back(tid);
- }
- }
-
- virtual void TearDown() {
- pthread_mutex_lock(&thread_arg.terminate_thread_mutex);
- thread_arg.terminate_thread = true;
- pthread_cond_broadcast(&thread_arg.terminate_thread_cond);
- pthread_mutex_unlock(&thread_arg.terminate_thread_mutex);
- for (uptr i = 0; i < pthread_ids_.size(); i++)
- pthread_join(pthread_ids_[i], NULL);
- }
-
- void SpawnTidReporter(pthread_t *pthread_id, tid_t *tid);
-
- static const uptr kThreadCount = 20;
-
- std::vector<pthread_t> pthread_ids_;
- std::vector<tid_t> tids_;
-
- TidReporterArgument thread_arg;
-};
-
-// Writes its TID once to reported_tid and waits until signaled to terminate.
-void *TidReporterThread(void *argument) {
- TidReporterArgument *arg = reinterpret_cast<TidReporterArgument *>(argument);
- pthread_mutex_lock(&arg->tid_reported_mutex);
- arg->reported_tid = GetTid();
- pthread_cond_broadcast(&arg->tid_reported_cond);
- pthread_mutex_unlock(&arg->tid_reported_mutex);
-
- pthread_mutex_lock(&arg->terminate_thread_mutex);
- while (!arg->terminate_thread)
- pthread_cond_wait(&arg->terminate_thread_cond,
- &arg->terminate_thread_mutex);
- pthread_mutex_unlock(&arg->terminate_thread_mutex);
- return NULL;
-}
-
-void ThreadListerTest::SpawnTidReporter(pthread_t *pthread_id, tid_t *tid) {
- pthread_mutex_lock(&thread_arg.tid_reported_mutex);
- thread_arg.reported_tid = -1;
- ASSERT_EQ(0, pthread_create(pthread_id, NULL,
- TidReporterThread,
- &thread_arg));
- while (thread_arg.reported_tid == (tid_t)(-1))
- pthread_cond_wait(&thread_arg.tid_reported_cond,
- &thread_arg.tid_reported_mutex);
- pthread_mutex_unlock(&thread_arg.tid_reported_mutex);
- *tid = thread_arg.reported_tid;
-}
-
-static std::vector<tid_t> ReadTidsToVector(ThreadLister *thread_lister) {
- std::vector<tid_t> listed_tids;
- InternalMmapVector<tid_t> threads(128);
- EXPECT_TRUE(thread_lister->ListThreads(&threads));
- return std::vector<tid_t>(threads.begin(), threads.end());
-}
-
-static bool Includes(std::vector<tid_t> first, std::vector<tid_t> second) {
- std::sort(first.begin(), first.end());
- std::sort(second.begin(), second.end());
- return std::includes(first.begin(), first.end(),
- second.begin(), second.end());
-}
-
-static bool HasElement(const std::vector<tid_t> &vector, tid_t element) {
- return std::find(vector.begin(), vector.end(), element) != vector.end();
-}
-
-// ThreadLister's output should include the current thread's TID and the TID of
-// every thread we spawned.
-TEST_F(ThreadListerTest, ThreadListerSeesAllSpawnedThreads) {
- tid_t self_tid = GetTid();
- ThreadLister thread_lister(getpid());
- std::vector<tid_t> listed_tids = ReadTidsToVector(&thread_lister);
- ASSERT_TRUE(HasElement(listed_tids, self_tid));
- ASSERT_TRUE(Includes(listed_tids, tids_));
-}
-
-TEST_F(ThreadListerTest, DoNotForgetThreads) {
- ThreadLister thread_lister(getpid());
-
- // Run the loop body twice, because ThreadLister might behave differently if
- // called on a freshly created object.
- for (uptr i = 0; i < 2; i++) {
- std::vector<tid_t> listed_tids = ReadTidsToVector(&thread_lister);
- ASSERT_TRUE(Includes(listed_tids, tids_));
- }
-}
-
-// If new threads have spawned during ThreadLister object's lifetime, calling
-// relisting should cause ThreadLister to recognize their existence.
-TEST_F(ThreadListerTest, NewThreads) {
- ThreadLister thread_lister(getpid());
- std::vector<tid_t> threads_before_extra = ReadTidsToVector(&thread_lister);
-
- pthread_t extra_pthread_id;
- tid_t extra_tid;
- SpawnTidReporter(&extra_pthread_id, &extra_tid);
- // Register the new thread so it gets terminated in TearDown().
- pthread_ids_.push_back(extra_pthread_id);
-
- // It would be very bizarre if the new TID had been listed before we even
- // spawned that thread, but it would also cause a false success in this test,
- // so better check for that.
- ASSERT_FALSE(HasElement(threads_before_extra, extra_tid));
-
- std::vector<tid_t> threads_after_extra = ReadTidsToVector(&thread_lister);
- ASSERT_TRUE(HasElement(threads_after_extra, extra_tid));
-}
-
-TEST(SanitizerCommon, SetEnvTest) {
- const char kEnvName[] = "ENV_FOO";
- SetEnv(kEnvName, "value");
- EXPECT_STREQ("value", getenv(kEnvName));
- unsetenv(kEnvName);
- EXPECT_EQ(0, getenv(kEnvName));
-}
-
-#if (defined(__x86_64__) || defined(__i386__)) && !SANITIZER_ANDROID
-void *thread_self_offset_test_func(void *arg) {
- bool result =
- *(uptr *)((char *)ThreadSelf() + ThreadSelfOffset()) == ThreadSelf();
- return (void *)result;
-}
-
-TEST(SanitizerLinux, ThreadSelfOffset) {
- EXPECT_TRUE((bool)thread_self_offset_test_func(0));
- pthread_t tid;
- void *result;
- ASSERT_EQ(0, pthread_create(&tid, 0, thread_self_offset_test_func, 0));
- ASSERT_EQ(0, pthread_join(tid, &result));
- EXPECT_TRUE((bool)result);
-}
-
-// libpthread puts the thread descriptor at the end of stack space.
-void *thread_descriptor_size_test_func(void *arg) {
- uptr descr_addr = ThreadSelf();
- pthread_attr_t attr;
- pthread_getattr_np(pthread_self(), &attr);
- void *stackaddr;
- size_t stacksize;
- pthread_attr_getstack(&attr, &stackaddr, &stacksize);
- return (void *)((uptr)stackaddr + stacksize - descr_addr);
-}
-
-TEST(SanitizerLinux, ThreadDescriptorSize) {
- pthread_t tid;
- void *result;
- ASSERT_EQ(0, pthread_create(&tid, 0, thread_descriptor_size_test_func, 0));
- ASSERT_EQ(0, pthread_join(tid, &result));
- EXPECT_EQ((uptr)result, ThreadDescriptorSize());
-}
-#endif
-
-TEST(SanitizerCommon, LibraryNameIs) {
- EXPECT_FALSE(LibraryNameIs("", ""));
-
- char full_name[256];
- const char *paths[] = { "", "/", "/path/to/" };
- const char *suffixes[] = { "", "-linux", ".1.2", "-linux.1.2" };
- const char *base_names[] = { "lib", "lib.0", "lib-i386" };
- const char *wrong_names[] = { "", "lib.9", "lib-x86_64" };
- for (uptr i = 0; i < ARRAY_SIZE(paths); i++)
- for (uptr j = 0; j < ARRAY_SIZE(suffixes); j++) {
- for (uptr k = 0; k < ARRAY_SIZE(base_names); k++) {
- internal_snprintf(full_name, ARRAY_SIZE(full_name), "%s%s%s.so",
- paths[i], base_names[k], suffixes[j]);
- EXPECT_TRUE(LibraryNameIs(full_name, base_names[k]))
- << "Full name " << full_name
- << " doesn't match base name " << base_names[k];
- for (uptr m = 0; m < ARRAY_SIZE(wrong_names); m++)
- EXPECT_FALSE(LibraryNameIs(full_name, wrong_names[m]))
- << "Full name " << full_name
- << " matches base name " << wrong_names[m];
- }
- }
-}
-
-#if defined(__mips64)
-// Effectively, this is a test for ThreadDescriptorSize() which is used to
-// compute ThreadSelf().
-TEST(SanitizerLinux, ThreadSelfTest) {
- ASSERT_EQ(pthread_self(), ThreadSelf());
-}
-#endif
-
-TEST(SanitizerCommon, StartSubprocessTest) {
- int pipe_fds[2];
- ASSERT_EQ(0, pipe(pipe_fds));
-#if SANITIZER_ANDROID
- const char *shell = "/system/bin/sh";
-#else
- const char *shell = "/bin/sh";
-#endif
- const char *argv[] = {shell, "-c", "echo -n 'hello'", (char *)NULL};
- int pid = StartSubprocess(shell, argv,
- /* stdin */ kInvalidFd, /* stdout */ pipe_fds[1]);
- ASSERT_GT(pid, 0);
-
- // wait for process to finish.
- while (IsProcessRunning(pid)) {
- }
- ASSERT_FALSE(IsProcessRunning(pid));
-
- char buffer[256];
- {
- char *ptr = buffer;
- uptr bytes_read;
- while (ReadFromFile(pipe_fds[0], ptr, 256, &bytes_read)) {
- if (!bytes_read) {
- break;
- }
- ptr += bytes_read;
- }
- ASSERT_EQ(5, ptr - buffer);
- *ptr = 0;
- }
- ASSERT_EQ(0, strcmp(buffer, "hello")) << "Buffer: " << buffer;
- internal_close(pipe_fds[0]);
-}
-
-} // namespace __sanitizer
-
-#endif // SANITIZER_LINUX
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_linux_test.cc -------------------------------------------===//
+//===-- sanitizer_linux_test.cpp ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc (removed)
@@ -1,188 +0,0 @@
-//===-- sanitizer_list_test.cc --------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_list.h"
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-struct ListItem {
- ListItem *next;
-};
-
-typedef IntrusiveList<ListItem> List;
-
-static List static_list;
-
-static void SetList(List *l, ListItem *x = 0,
- ListItem *y = 0, ListItem *z = 0) {
- l->clear();
- if (x) l->push_back(x);
- if (y) l->push_back(y);
- if (z) l->push_back(z);
-}
-
-static void CheckList(List *l, ListItem *i1, ListItem *i2 = 0, ListItem *i3 = 0,
- ListItem *i4 = 0, ListItem *i5 = 0, ListItem *i6 = 0) {
- if (i1) {
- CHECK_EQ(l->front(), i1);
- l->pop_front();
- }
- if (i2) {
- CHECK_EQ(l->front(), i2);
- l->pop_front();
- }
- if (i3) {
- CHECK_EQ(l->front(), i3);
- l->pop_front();
- }
- if (i4) {
- CHECK_EQ(l->front(), i4);
- l->pop_front();
- }
- if (i5) {
- CHECK_EQ(l->front(), i5);
- l->pop_front();
- }
- if (i6) {
- CHECK_EQ(l->front(), i6);
- l->pop_front();
- }
- CHECK(l->empty());
-}
-
-TEST(SanitizerCommon, IntrusiveList) {
- ListItem items[6];
- CHECK_EQ(static_list.size(), 0);
-
- List l;
- l.clear();
-
- ListItem *x = &items[0];
- ListItem *y = &items[1];
- ListItem *z = &items[2];
- ListItem *a = &items[3];
- ListItem *b = &items[4];
- ListItem *c = &items[5];
-
- CHECK_EQ(l.size(), 0);
- l.push_back(x);
- CHECK_EQ(l.size(), 1);
- CHECK_EQ(l.back(), x);
- CHECK_EQ(l.front(), x);
- l.pop_front();
- CHECK(l.empty());
- l.CheckConsistency();
-
- l.push_front(x);
- CHECK_EQ(l.size(), 1);
- CHECK_EQ(l.back(), x);
- CHECK_EQ(l.front(), x);
- l.pop_front();
- CHECK(l.empty());
- l.CheckConsistency();
-
- l.push_front(x);
- l.push_front(y);
- l.push_front(z);
- CHECK_EQ(l.size(), 3);
- CHECK_EQ(l.front(), z);
- CHECK_EQ(l.back(), x);
- l.CheckConsistency();
-
- l.pop_front();
- CHECK_EQ(l.size(), 2);
- CHECK_EQ(l.front(), y);
- CHECK_EQ(l.back(), x);
- l.pop_front();
- l.pop_front();
- CHECK(l.empty());
- l.CheckConsistency();
-
- l.push_back(x);
- l.push_back(y);
- l.push_back(z);
- CHECK_EQ(l.size(), 3);
- CHECK_EQ(l.front(), x);
- CHECK_EQ(l.back(), z);
- l.CheckConsistency();
-
- l.pop_front();
- CHECK_EQ(l.size(), 2);
- CHECK_EQ(l.front(), y);
- CHECK_EQ(l.back(), z);
- l.pop_front();
- l.pop_front();
- CHECK(l.empty());
- l.CheckConsistency();
-
- l.push_back(x);
- l.push_back(y);
- l.push_back(z);
- l.extract(x, y);
- CHECK_EQ(l.size(), 2);
- CHECK_EQ(l.front(), x);
- CHECK_EQ(l.back(), z);
- l.CheckConsistency();
- l.extract(x, z);
- CHECK_EQ(l.size(), 1);
- CHECK_EQ(l.front(), x);
- CHECK_EQ(l.back(), x);
- l.CheckConsistency();
- l.pop_front();
- CHECK(l.empty());
-
- List l1, l2;
- l1.clear();
- l2.clear();
-
- l1.append_front(&l2);
- CHECK(l1.empty());
- CHECK(l2.empty());
-
- l1.append_back(&l2);
- CHECK(l1.empty());
- CHECK(l2.empty());
-
- SetList(&l1, x);
- CheckList(&l1, x);
-
- SetList(&l1, x, y, z);
- SetList(&l2, a, b, c);
- l1.append_back(&l2);
- CheckList(&l1, x, y, z, a, b, c);
- CHECK(l2.empty());
-
- SetList(&l1, x, y);
- SetList(&l2);
- l1.append_front(&l2);
- CheckList(&l1, x, y);
- CHECK(l2.empty());
-}
-
-TEST(SanitizerCommon, IntrusiveListAppendEmpty) {
- ListItem i;
- List l;
- l.clear();
- l.push_back(&i);
- List l2;
- l2.clear();
- l.append_back(&l2);
- CHECK_EQ(l.back(), &i);
- CHECK_EQ(l.front(), &i);
- CHECK_EQ(l.size(), 1);
- l.append_front(&l2);
- CHECK_EQ(l.back(), &i);
- CHECK_EQ(l.front(), &i);
- CHECK_EQ(l.size(), 1);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_list_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_list_test.cc --------------------------------------------===//
+//===-- sanitizer_list_test.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc (removed)
@@ -1,136 +0,0 @@
-//===-- sanitizer_mutex_test.cc -------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_mutex.h"
-#include "sanitizer_common/sanitizer_common.h"
-
-#include "sanitizer_pthread_wrappers.h"
-
-#include "gtest/gtest.h"
-
-#include <string.h>
-
-namespace __sanitizer {
-
-template<typename MutexType>
-class TestData {
- public:
- explicit TestData(MutexType *mtx)
- : mtx_(mtx) {
- for (int i = 0; i < kSize; i++)
- data_[i] = 0;
- }
-
- void Write() {
- Lock l(mtx_);
- T v0 = data_[0];
- for (int i = 0; i < kSize; i++) {
- CHECK_EQ(data_[i], v0);
- data_[i]++;
- }
- }
-
- void TryWrite() {
- if (!mtx_->TryLock())
- return;
- T v0 = data_[0];
- for (int i = 0; i < kSize; i++) {
- CHECK_EQ(data_[i], v0);
- data_[i]++;
- }
- mtx_->Unlock();
- }
-
- void Backoff() {
- volatile T data[kSize] = {};
- for (int i = 0; i < kSize; i++) {
- data[i]++;
- CHECK_EQ(data[i], 1);
- }
- }
-
- private:
- typedef GenericScopedLock<MutexType> Lock;
- static const int kSize = 64;
- typedef u64 T;
- MutexType *mtx_;
- char pad_[kCacheLineSize];
- T data_[kSize];
-};
-
-const int kThreads = 8;
-#if SANITIZER_DEBUG
-const int kIters = 16*1024;
-#else
-const int kIters = 64*1024;
-#endif
-
-template<typename MutexType>
-static void *lock_thread(void *param) {
- TestData<MutexType> *data = (TestData<MutexType>*)param;
- for (int i = 0; i < kIters; i++) {
- data->Write();
- data->Backoff();
- }
- return 0;
-}
-
-template<typename MutexType>
-static void *try_thread(void *param) {
- TestData<MutexType> *data = (TestData<MutexType>*)param;
- for (int i = 0; i < kIters; i++) {
- data->TryWrite();
- data->Backoff();
- }
- return 0;
-}
-
-template<typename MutexType>
-static void check_locked(MutexType *mtx) {
- GenericScopedLock<MutexType> l(mtx);
- mtx->CheckLocked();
-}
-
-TEST(SanitizerCommon, SpinMutex) {
- SpinMutex mtx;
- mtx.Init();
- TestData<SpinMutex> data(&mtx);
- pthread_t threads[kThreads];
- for (int i = 0; i < kThreads; i++)
- PTHREAD_CREATE(&threads[i], 0, lock_thread<SpinMutex>, &data);
- for (int i = 0; i < kThreads; i++)
- PTHREAD_JOIN(threads[i], 0);
-}
-
-TEST(SanitizerCommon, SpinMutexTry) {
- SpinMutex mtx;
- mtx.Init();
- TestData<SpinMutex> data(&mtx);
- pthread_t threads[kThreads];
- for (int i = 0; i < kThreads; i++)
- PTHREAD_CREATE(&threads[i], 0, try_thread<SpinMutex>, &data);
- for (int i = 0; i < kThreads; i++)
- PTHREAD_JOIN(threads[i], 0);
-}
-
-TEST(SanitizerCommon, BlockingMutex) {
- u64 mtxmem[1024] = {};
- BlockingMutex *mtx = new(mtxmem) BlockingMutex(LINKER_INITIALIZED);
- TestData<BlockingMutex> data(mtx);
- pthread_t threads[kThreads];
- for (int i = 0; i < kThreads; i++)
- PTHREAD_CREATE(&threads[i], 0, lock_thread<BlockingMutex>, &data);
- for (int i = 0; i < kThreads; i++)
- PTHREAD_JOIN(threads[i], 0);
- check_locked(mtx);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_mutex_test.cc -------------------------------------------===//
+//===-- sanitizer_mutex_test.cpp ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: 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=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc (removed)
@@ -1,30 +0,0 @@
-//===-- sanitizer_nolibc_test.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// 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.cpp (from r367466, 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.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_nolibc_test.cc ------------------------------------------===//
+//===-- sanitizer_nolibc_test.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc (removed)
@@ -1,18 +0,0 @@
-//===-- sanitizer_nolibc_test_main.cc -------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-// Tests for libc independence of sanitizer_common.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_libc.h"
-
-extern "C" void _start() {
- __sanitizer::internal__exit(0);
-}
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_nolibc_test_main.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_nolibc_test_main.cc -------------------------------------===//
+//===-- sanitizer_nolibc_test_main.cpp ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc (removed)
@@ -1,80 +0,0 @@
-//===-- sanitizer_posix_test.cc -------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Tests for POSIX-specific code.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_POSIX
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "gtest/gtest.h"
-
-#include <pthread.h>
-#include <sys/mman.h>
-
-namespace __sanitizer {
-
-static pthread_key_t key;
-static bool destructor_executed;
-
-extern "C"
-void destructor(void *arg) {
- uptr iter = reinterpret_cast<uptr>(arg);
- if (iter > 1) {
- ASSERT_EQ(0, pthread_setspecific(key, reinterpret_cast<void *>(iter - 1)));
- return;
- }
- destructor_executed = true;
-}
-
-extern "C"
-void *thread_func(void *arg) {
- return reinterpret_cast<void*>(pthread_setspecific(key, arg));
-}
-
-static void SpawnThread(uptr iteration) {
- destructor_executed = false;
- pthread_t tid;
- ASSERT_EQ(0, pthread_create(&tid, 0, &thread_func,
- reinterpret_cast<void *>(iteration)));
- void *retval;
- ASSERT_EQ(0, pthread_join(tid, &retval));
- ASSERT_EQ(0, retval);
-}
-
-TEST(SanitizerCommon, PthreadDestructorIterations) {
- ASSERT_EQ(0, pthread_key_create(&key, &destructor));
- SpawnThread(GetPthreadDestructorIterations());
- EXPECT_TRUE(destructor_executed);
- SpawnThread(GetPthreadDestructorIterations() + 1);
- EXPECT_FALSE(destructor_executed);
- ASSERT_EQ(0, pthread_key_delete(key));
-}
-
-TEST(SanitizerCommon, IsAccessibleMemoryRange) {
- const int page_size = GetPageSize();
- uptr mem = (uptr)mmap(0, 3 * page_size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON, -1, 0);
- // Protect the middle page.
- mprotect((void *)(mem + page_size), page_size, PROT_NONE);
- EXPECT_TRUE(IsAccessibleMemoryRange(mem, page_size - 1));
- EXPECT_TRUE(IsAccessibleMemoryRange(mem, page_size));
- EXPECT_FALSE(IsAccessibleMemoryRange(mem, page_size + 1));
- EXPECT_TRUE(IsAccessibleMemoryRange(mem + page_size - 1, 1));
- EXPECT_FALSE(IsAccessibleMemoryRange(mem + page_size - 1, 2));
- EXPECT_FALSE(IsAccessibleMemoryRange(mem + 2 * page_size - 1, 1));
- EXPECT_TRUE(IsAccessibleMemoryRange(mem + 2 * page_size, page_size));
- EXPECT_FALSE(IsAccessibleMemoryRange(mem, 3 * page_size));
- EXPECT_FALSE(IsAccessibleMemoryRange(0x0, 2));
-}
-
-} // namespace __sanitizer
-
-#endif // SANITIZER_POSIX
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_posix_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_posix_test.cc -------------------------------------------===//
+//===-- sanitizer_posix_test.cpp ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc (removed)
@@ -1,160 +0,0 @@
-//===-- sanitizer_printf_test.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Tests for sanitizer_printf.cpp
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "gtest/gtest.h"
-
-#include <string.h>
-#include <limits.h>
-
-namespace __sanitizer {
-
-TEST(Printf, Basic) {
- char buf[1024];
- uptr len = internal_snprintf(buf, sizeof(buf),
- "a%db%zdc%ue%zuf%xh%zxq%pe%sr",
- (int)-1, (uptr)-2, // NOLINT
- (unsigned)-4, (uptr)5, // NOLINT
- (unsigned)10, (uptr)11, // NOLINT
- (void*)0x123, "_string_");
- EXPECT_EQ(len, strlen(buf));
-
- std::string expectedString = "a-1b-2c4294967292e5fahbq0x";
- expectedString += std::string(SANITIZER_POINTER_FORMAT_LENGTH - 3, '0');
- expectedString += "123e_string_r";
- EXPECT_STREQ(expectedString.c_str(), buf);
-}
-
-TEST(Printf, OverflowStr) {
- char buf[] = "123456789";
- uptr len = internal_snprintf(buf, 4, "%s", "abcdef"); // NOLINT
- EXPECT_EQ(len, (uptr)6);
- EXPECT_STREQ("abc", buf);
- EXPECT_EQ(buf[3], 0);
- EXPECT_EQ(buf[4], '5');
- EXPECT_EQ(buf[5], '6');
- EXPECT_EQ(buf[6], '7');
- EXPECT_EQ(buf[7], '8');
- EXPECT_EQ(buf[8], '9');
- EXPECT_EQ(buf[9], 0);
-}
-
-TEST(Printf, OverflowInt) {
- char buf[] = "123456789";
- internal_snprintf(buf, 4, "%d", -123456789); // NOLINT
- EXPECT_STREQ("-12", buf);
- EXPECT_EQ(buf[3], 0);
- EXPECT_EQ(buf[4], '5');
- EXPECT_EQ(buf[5], '6');
- EXPECT_EQ(buf[6], '7');
- EXPECT_EQ(buf[7], '8');
- EXPECT_EQ(buf[8], '9');
- EXPECT_EQ(buf[9], 0);
-}
-
-TEST(Printf, OverflowUint) {
- char buf[] = "123456789";
- uptr val;
- if (sizeof(val) == 4) {
- val = (uptr)0x12345678;
- } else {
- val = (uptr)0x123456789ULL;
- }
- internal_snprintf(buf, 4, "a%zx", val); // NOLINT
- EXPECT_STREQ("a12", buf);
- EXPECT_EQ(buf[3], 0);
- EXPECT_EQ(buf[4], '5');
- EXPECT_EQ(buf[5], '6');
- EXPECT_EQ(buf[6], '7');
- EXPECT_EQ(buf[7], '8');
- EXPECT_EQ(buf[8], '9');
- EXPECT_EQ(buf[9], 0);
-}
-
-TEST(Printf, OverflowPtr) {
- char buf[] = "123456789";
- void *p;
- if (sizeof(p) == 4) {
- p = (void*)0x1234567;
- } else {
- p = (void*)0x123456789ULL;
- }
- internal_snprintf(buf, 4, "%p", p); // NOLINT
- EXPECT_STREQ("0x0", buf);
- EXPECT_EQ(buf[3], 0);
- EXPECT_EQ(buf[4], '5');
- EXPECT_EQ(buf[5], '6');
- EXPECT_EQ(buf[6], '7');
- EXPECT_EQ(buf[7], '8');
- EXPECT_EQ(buf[8], '9');
- EXPECT_EQ(buf[9], 0);
-}
-
-#if defined(_WIN32)
-// Oh well, MSVS headers don't define snprintf.
-# define snprintf _snprintf
-#endif
-
-template<typename T>
-static void TestAgainstLibc(const char *fmt, T arg1, T arg2) {
- char buf[1024];
- uptr len = internal_snprintf(buf, sizeof(buf), fmt, arg1, arg2);
- char buf2[1024];
- snprintf(buf2, sizeof(buf2), fmt, arg1, arg2);
- EXPECT_EQ(len, strlen(buf));
- EXPECT_STREQ(buf2, buf);
-}
-
-TEST(Printf, MinMax) {
- TestAgainstLibc<int>("%d-%d", INT_MIN, INT_MAX); // NOLINT
- TestAgainstLibc<unsigned>("%u-%u", 0, UINT_MAX); // NOLINT
- TestAgainstLibc<unsigned>("%x-%x", 0, UINT_MAX); // NOLINT
-#if !defined(_WIN32)
- // %z* format doesn't seem to be supported by MSVS.
- TestAgainstLibc<long>("%zd-%zd", LONG_MIN, LONG_MAX); // NOLINT
- TestAgainstLibc<unsigned long>("%zu-%zu", 0, ULONG_MAX); // NOLINT
- TestAgainstLibc<unsigned long>("%zx-%zx", 0, ULONG_MAX); // NOLINT
-#endif
-}
-
-TEST(Printf, Padding) {
- TestAgainstLibc<int>("%3d - %3d", 1, 0);
- TestAgainstLibc<int>("%3d - %3d", -1, 123);
- TestAgainstLibc<int>("%3d - %3d", -1, -123);
- TestAgainstLibc<int>("%3d - %3d", 12, 1234);
- TestAgainstLibc<int>("%3d - %3d", -12, -1234);
- TestAgainstLibc<int>("%03d - %03d", 1, 0);
- TestAgainstLibc<int>("%03d - %03d", -1, 123);
- TestAgainstLibc<int>("%03d - %03d", -1, -123);
- TestAgainstLibc<int>("%03d - %03d", 12, 1234);
- TestAgainstLibc<int>("%03d - %03d", -12, -1234);
-}
-
-TEST(Printf, Precision) {
- char buf[1024];
- uptr len = internal_snprintf(buf, sizeof(buf), "%.*s", 3, "12345");
- EXPECT_EQ(3U, len);
- EXPECT_STREQ("123", buf);
- len = internal_snprintf(buf, sizeof(buf), "%.*s", 6, "12345");
- EXPECT_EQ(5U, len);
- EXPECT_STREQ("12345", buf);
- len = internal_snprintf(buf, sizeof(buf), "%-6s", "12345");
- EXPECT_EQ(6U, len);
- EXPECT_STREQ("12345 ", buf);
- // Check that width does not overflow the smaller buffer, although
- // 10 chars is requested, it stops at the buffer size, 8.
- len = internal_snprintf(buf, 8, "%-10s", "12345");
- EXPECT_EQ(10U, len); // The required size reported.
- EXPECT_STREQ("12345 ", buf);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_printf_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_printf_test.cc ------------------------------------------===//
+//===-- sanitizer_printf_test.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc (removed)
@@ -1,78 +0,0 @@
-//===-- sanitizer_procmaps_test.cc ----------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#if !defined(_WIN32) // There are no /proc/maps on Windows.
-
-#include "sanitizer_common/sanitizer_procmaps.h"
-#include "gtest/gtest.h"
-
-#include <stdlib.h>
-
-static void noop() {}
-extern const char *argv0;
-
-namespace __sanitizer {
-
-#if SANITIZER_LINUX && !SANITIZER_ANDROID
-TEST(MemoryMappingLayout, CodeRange) {
- uptr start, end;
- bool res = GetCodeRangeForFile("[vdso]", &start, &end);
- EXPECT_EQ(res, true);
- EXPECT_GT(start, 0U);
- EXPECT_LT(start, end);
-}
-#endif
-
-TEST(MemoryMappingLayout, DumpListOfModules) {
- const char *last_slash = strrchr(argv0, '/');
- const char *binary_name = last_slash ? last_slash + 1 : argv0;
- MemoryMappingLayout memory_mapping(false);
- const uptr kMaxModules = 100;
- InternalMmapVector<LoadedModule> modules;
- modules.reserve(kMaxModules);
- memory_mapping.DumpListOfModules(&modules);
- EXPECT_GT(modules.size(), 0U);
- bool found = false;
- for (uptr i = 0; i < modules.size(); ++i) {
- if (modules[i].containsAddress((uptr)&noop)) {
- // Verify that the module name is sane.
- if (strstr(modules[i].full_name(), binary_name) != 0)
- found = true;
- }
- modules[i].clear();
- }
- EXPECT_TRUE(found);
-}
-
-TEST(MemoryMapping, LoadedModuleArchAndUUID) {
- if (SANITIZER_MAC) {
- MemoryMappingLayout memory_mapping(false);
- const uptr kMaxModules = 100;
- InternalMmapVector<LoadedModule> modules;
- modules.reserve(kMaxModules);
- memory_mapping.DumpListOfModules(&modules);
- for (uptr i = 0; i < modules.size(); ++i) {
- ModuleArch arch = modules[i].arch();
- // Darwin unit tests are only run on i386/x86_64/x86_64h.
- if (SANITIZER_WORDSIZE == 32) {
- EXPECT_EQ(arch, kModuleArchI386);
- } else if (SANITIZER_WORDSIZE == 64) {
- EXPECT_TRUE(arch == kModuleArchX86_64 || arch == kModuleArchX86_64H);
- }
- const u8 *uuid = modules[i].uuid();
- u8 null_uuid[kModuleUUIDSize] = {0};
- EXPECT_NE(memcmp(null_uuid, uuid, kModuleUUIDSize), 0);
- }
- }
-}
-
-} // namespace __sanitizer
-#endif // !defined(_WIN32)
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_procmaps_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_procmaps_test.cc ----------------------------------------===//
+//===-- sanitizer_procmaps_test.cpp ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc (removed)
@@ -1,179 +0,0 @@
-//===-- sanitizer_quarantine_test.cc --------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_quarantine.h"
-#include "gtest/gtest.h"
-
-#include <stdlib.h>
-
-namespace __sanitizer {
-
-struct QuarantineCallback {
- void Recycle(void *m) {}
- void *Allocate(uptr size) {
- return malloc(size);
- }
- void Deallocate(void *p) {
- free(p);
- }
-};
-
-typedef QuarantineCache<QuarantineCallback> Cache;
-
-static void* kFakePtr = reinterpret_cast<void*>(0xFA83FA83);
-static const size_t kBlockSize = 8;
-
-static QuarantineCallback cb;
-
-static void DeallocateCache(Cache *cache) {
- while (QuarantineBatch *batch = cache->DequeueBatch())
- cb.Deallocate(batch);
-}
-
-TEST(SanitizerCommon, QuarantineBatchMerge) {
- // Verify the trivial case.
- QuarantineBatch into;
- into.init(kFakePtr, 4UL);
- QuarantineBatch from;
- from.init(kFakePtr, 8UL);
-
- into.merge(&from);
-
- ASSERT_EQ(into.count, 2UL);
- ASSERT_EQ(into.batch[0], kFakePtr);
- ASSERT_EQ(into.batch[1], kFakePtr);
- ASSERT_EQ(into.size, 12UL + sizeof(QuarantineBatch));
- ASSERT_EQ(into.quarantined_size(), 12UL);
-
- ASSERT_EQ(from.count, 0UL);
- ASSERT_EQ(from.size, sizeof(QuarantineBatch));
- ASSERT_EQ(from.quarantined_size(), 0UL);
-
- // Merge the batch to the limit.
- for (uptr i = 2; i < QuarantineBatch::kSize; ++i)
- from.push_back(kFakePtr, 8UL);
- ASSERT_TRUE(into.count + from.count == QuarantineBatch::kSize);
- ASSERT_TRUE(into.can_merge(&from));
-
- into.merge(&from);
- ASSERT_TRUE(into.count == QuarantineBatch::kSize);
-
- // No more space, not even for one element.
- from.init(kFakePtr, 8UL);
-
- ASSERT_FALSE(into.can_merge(&from));
-}
-
-TEST(SanitizerCommon, QuarantineCacheMergeBatchesEmpty) {
- Cache cache;
- Cache to_deallocate;
- cache.MergeBatches(&to_deallocate);
-
- ASSERT_EQ(to_deallocate.Size(), 0UL);
- ASSERT_EQ(to_deallocate.DequeueBatch(), nullptr);
-}
-
-TEST(SanitizerCommon, QuarantineCacheMergeBatchesOneBatch) {
- Cache cache;
- cache.Enqueue(cb, kFakePtr, kBlockSize);
- ASSERT_EQ(kBlockSize + sizeof(QuarantineBatch), cache.Size());
-
- Cache to_deallocate;
- cache.MergeBatches(&to_deallocate);
-
- // Nothing to merge, nothing to deallocate.
- ASSERT_EQ(kBlockSize + sizeof(QuarantineBatch), cache.Size());
-
- ASSERT_EQ(to_deallocate.Size(), 0UL);
- ASSERT_EQ(to_deallocate.DequeueBatch(), nullptr);
-
- DeallocateCache(&cache);
-}
-
-TEST(SanitizerCommon, QuarantineCacheMergeBatchesSmallBatches) {
- // Make a cache with two batches small enough to merge.
- Cache from;
- from.Enqueue(cb, kFakePtr, kBlockSize);
- Cache cache;
- cache.Enqueue(cb, kFakePtr, kBlockSize);
-
- cache.Transfer(&from);
- ASSERT_EQ(kBlockSize * 2 + sizeof(QuarantineBatch) * 2, cache.Size());
-
- Cache to_deallocate;
- cache.MergeBatches(&to_deallocate);
-
- // Batches merged, one batch to deallocate.
- ASSERT_EQ(kBlockSize * 2 + sizeof(QuarantineBatch), cache.Size());
- ASSERT_EQ(to_deallocate.Size(), sizeof(QuarantineBatch));
-
- DeallocateCache(&cache);
- DeallocateCache(&to_deallocate);
-}
-
-TEST(SanitizerCommon, QuarantineCacheMergeBatchesTooBigToMerge) {
- const uptr kNumBlocks = QuarantineBatch::kSize - 1;
-
- // Make a cache with two batches small enough to merge.
- Cache from;
- Cache cache;
- for (uptr i = 0; i < kNumBlocks; ++i) {
- from.Enqueue(cb, kFakePtr, kBlockSize);
- cache.Enqueue(cb, kFakePtr, kBlockSize);
- }
- cache.Transfer(&from);
- ASSERT_EQ(kBlockSize * kNumBlocks * 2 +
- sizeof(QuarantineBatch) * 2, cache.Size());
-
- Cache to_deallocate;
- cache.MergeBatches(&to_deallocate);
-
- // Batches cannot be merged.
- ASSERT_EQ(kBlockSize * kNumBlocks * 2 +
- sizeof(QuarantineBatch) * 2, cache.Size());
- ASSERT_EQ(to_deallocate.Size(), 0UL);
-
- DeallocateCache(&cache);
-}
-
-TEST(SanitizerCommon, QuarantineCacheMergeBatchesALotOfBatches) {
- const uptr kNumBatchesAfterMerge = 3;
- const uptr kNumBlocks = QuarantineBatch::kSize * kNumBatchesAfterMerge;
- const uptr kNumBatchesBeforeMerge = kNumBlocks;
-
- // Make a cache with many small batches.
- Cache cache;
- for (uptr i = 0; i < kNumBlocks; ++i) {
- Cache from;
- from.Enqueue(cb, kFakePtr, kBlockSize);
- cache.Transfer(&from);
- }
-
- ASSERT_EQ(kBlockSize * kNumBlocks +
- sizeof(QuarantineBatch) * kNumBatchesBeforeMerge, cache.Size());
-
- Cache to_deallocate;
- cache.MergeBatches(&to_deallocate);
-
- // All blocks should fit into 3 batches.
- ASSERT_EQ(kBlockSize * kNumBlocks +
- sizeof(QuarantineBatch) * kNumBatchesAfterMerge, cache.Size());
-
- ASSERT_EQ(to_deallocate.Size(),
- sizeof(QuarantineBatch) *
- (kNumBatchesBeforeMerge - kNumBatchesAfterMerge));
-
- DeallocateCache(&cache);
- DeallocateCache(&to_deallocate);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_quarantine_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_quarantine_test.cc --------------------------------------===//
+//===-- sanitizer_quarantine_test.cpp -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc (removed)
@@ -1,98 +0,0 @@
-//===-- sanitizer_vector_test.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of *Sanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_ring_buffer.h"
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-struct LargeStruct {
- int64_t v;
- int64_t extra[3];
-
- explicit LargeStruct(int64_t v) : v(v) {}
- operator int64_t() { return v; }
-};
-
-struct Struct10Bytes {
- short t[3];
-};
-
-TEST(RingBuffer, Construct) {
- RingBuffer<int64_t> *RBlong = RingBuffer<int64_t>::New(20);
- EXPECT_EQ(RBlong->size(), 20U);
- RBlong->Delete();
-}
-
-template <class T> void TestRB() {
- RingBuffer<T> *RB;
- const size_t Sizes[] = {1, 2, 3, 5, 8, 16, 20, 40, 10000};
- for (size_t Size : Sizes) {
- RB = RingBuffer<T>::New(Size);
- EXPECT_EQ(RB->size(), Size);
- RB->Delete();
- }
-
- RB = RingBuffer<T>::New(4);
- EXPECT_EQ(RB->size(), 4U);
-#define EXPECT_RING_BUFFER(a0, a1, a2, a3) \
- EXPECT_EQ((int64_t)(*RB)[0], (int64_t)a0); \
- EXPECT_EQ((int64_t)(*RB)[1], (int64_t)a1); \
- EXPECT_EQ((int64_t)(*RB)[2], (int64_t)a2); \
- EXPECT_EQ((int64_t)(*RB)[3], (int64_t)a3);
-
- RB->push(T(1)); EXPECT_RING_BUFFER(1, 0, 0, 0);
- RB->push(T(2)); EXPECT_RING_BUFFER(2, 1, 0, 0);
- RB->push(T(3)); EXPECT_RING_BUFFER(3, 2, 1, 0);
- RB->push(T(4)); EXPECT_RING_BUFFER(4, 3, 2, 1);
- RB->push(T(5)); EXPECT_RING_BUFFER(5, 4, 3, 2);
- RB->push(T(6)); EXPECT_RING_BUFFER(6, 5, 4, 3);
- RB->push(T(7)); EXPECT_RING_BUFFER(7, 6, 5, 4);
- RB->push(T(8)); EXPECT_RING_BUFFER(8, 7, 6, 5);
- RB->push(T(9)); EXPECT_RING_BUFFER(9, 8, 7, 6);
- RB->push(T(10)); EXPECT_RING_BUFFER(10, 9, 8, 7);
- RB->push(T(11)); EXPECT_RING_BUFFER(11, 10, 9, 8);
- RB->push(T(12)); EXPECT_RING_BUFFER(12, 11, 10, 9);
-
-#undef EXPECT_RING_BUFFER
-}
-
-#if SANITIZER_WORDSIZE == 64
-TEST(RingBuffer, int64) {
- TestRB<int64_t>();
-}
-
-TEST(RingBuffer, LargeStruct) {
- TestRB<LargeStruct>();
-}
-
-template<typename T>
-CompactRingBuffer<T> *AllocCompactRingBuffer(size_t count) {
- size_t sz = sizeof(T) * count;
- EXPECT_EQ(0ULL, sz % 4096);
- void *p = MmapAlignedOrDieOnFatalError(sz, sz * 2, "CompactRingBuffer");
- return new CompactRingBuffer<T>(p, sz);
-}
-
-TEST(CompactRingBuffer, int64) {
- const size_t page_sizes[] = {1, 2, 4, 128};
-
- for (size_t pages : page_sizes) {
- size_t count = 4096 * pages / sizeof(int64_t);
- auto R = AllocCompactRingBuffer<int64_t>(count);
- int64_t top = count * 3 + 13;
- for (int64_t i = 0; i < top; ++i) R->push(i);
- for (int64_t i = 0; i < (int64_t)count; ++i)
- EXPECT_EQ(top - i - 1, (*R)[i]);
- }
-}
-#endif
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_ring_buffer_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_vector_test.cc ------------------------------------------===//
+//===-- sanitizer_vector_test.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc (removed)
@@ -1,92 +0,0 @@
-//===-- sanitizer_stackdepot_test.cc --------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_stackdepot.h"
-#include "sanitizer_common/sanitizer_internal_defs.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-TEST(SanitizerCommon, StackDepotBasic) {
- uptr array[] = {1, 2, 3, 4, 5};
- StackTrace s1(array, ARRAY_SIZE(array));
- u32 i1 = StackDepotPut(s1);
- StackTrace stack = StackDepotGet(i1);
- EXPECT_NE(stack.trace, (uptr*)0);
- EXPECT_EQ(ARRAY_SIZE(array), stack.size);
- EXPECT_EQ(0, internal_memcmp(stack.trace, array, sizeof(array)));
-}
-
-TEST(SanitizerCommon, StackDepotAbsent) {
- StackTrace stack = StackDepotGet((1 << 30) - 1);
- EXPECT_EQ((uptr*)0, stack.trace);
-}
-
-TEST(SanitizerCommon, StackDepotEmptyStack) {
- u32 i1 = StackDepotPut(StackTrace());
- StackTrace stack = StackDepotGet(i1);
- EXPECT_EQ((uptr*)0, stack.trace);
-}
-
-TEST(SanitizerCommon, StackDepotZeroId) {
- StackTrace stack = StackDepotGet(0);
- EXPECT_EQ((uptr*)0, stack.trace);
-}
-
-TEST(SanitizerCommon, StackDepotSame) {
- uptr array[] = {1, 2, 3, 4, 6};
- StackTrace s1(array, ARRAY_SIZE(array));
- u32 i1 = StackDepotPut(s1);
- u32 i2 = StackDepotPut(s1);
- EXPECT_EQ(i1, i2);
- StackTrace stack = StackDepotGet(i1);
- EXPECT_NE(stack.trace, (uptr*)0);
- EXPECT_EQ(ARRAY_SIZE(array), stack.size);
- EXPECT_EQ(0, internal_memcmp(stack.trace, array, sizeof(array)));
-}
-
-TEST(SanitizerCommon, StackDepotSeveral) {
- uptr array1[] = {1, 2, 3, 4, 7};
- StackTrace s1(array1, ARRAY_SIZE(array1));
- u32 i1 = StackDepotPut(s1);
- uptr array2[] = {1, 2, 3, 4, 8, 9};
- StackTrace s2(array2, ARRAY_SIZE(array2));
- u32 i2 = StackDepotPut(s2);
- EXPECT_NE(i1, i2);
-}
-
-TEST(SanitizerCommon, StackDepotReverseMap) {
- uptr array1[] = {1, 2, 3, 4, 5};
- uptr array2[] = {7, 1, 3, 0};
- uptr array3[] = {10, 2, 5, 3};
- uptr array4[] = {1, 3, 2, 5};
- u32 ids[4] = {0};
- StackTrace s1(array1, ARRAY_SIZE(array1));
- StackTrace s2(array2, ARRAY_SIZE(array2));
- StackTrace s3(array3, ARRAY_SIZE(array3));
- StackTrace s4(array4, ARRAY_SIZE(array4));
- ids[0] = StackDepotPut(s1);
- ids[1] = StackDepotPut(s2);
- ids[2] = StackDepotPut(s3);
- ids[3] = StackDepotPut(s4);
-
- StackDepotReverseMap map;
-
- for (uptr i = 0; i < 4; i++) {
- StackTrace stack = StackDepotGet(ids[i]);
- StackTrace from_map = map.Get(ids[i]);
- EXPECT_EQ(stack.size, from_map.size);
- EXPECT_EQ(stack.trace, from_map.trace);
- }
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_stackdepot_test.cc --------------------------------------===//
+//===-- sanitizer_stackdepot_test.cpp -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc (removed)
@@ -1,156 +0,0 @@
-//===-- sanitizer_common_printer_test.cc ----------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of sanitizer_common test suite.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_stacktrace_printer.h"
-
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-TEST(SanitizerStacktracePrinter, RenderSourceLocation) {
- InternalScopedString str(128);
- RenderSourceLocation(&str, "/dir/file.cc", 10, 5, false, "");
- EXPECT_STREQ("/dir/file.cc:10:5", str.data());
-
- str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 11, 0, false, "");
- EXPECT_STREQ("/dir/file.cc:11", str.data());
-
- str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 0, 0, false, "");
- EXPECT_STREQ("/dir/file.cc", str.data());
-
- str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 10, 5, false, "/dir/");
- EXPECT_STREQ("file.cc:10:5", str.data());
-
- str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 10, 5, true, "");
- EXPECT_STREQ("/dir/file.cc(10,5)", str.data());
-
- str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 11, 0, true, "");
- EXPECT_STREQ("/dir/file.cc(11)", str.data());
-
- str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 0, 0, true, "");
- EXPECT_STREQ("/dir/file.cc", str.data());
-
- str.clear();
- RenderSourceLocation(&str, "/dir/file.cc", 10, 5, true, "/dir/");
- EXPECT_STREQ("file.cc(10,5)", str.data());
-}
-
-TEST(SanitizerStacktracePrinter, RenderModuleLocation) {
- InternalScopedString str(128);
- RenderModuleLocation(&str, "/dir/exe", 0x123, kModuleArchUnknown, "");
- EXPECT_STREQ("(/dir/exe+0x123)", str.data());
-
- // Check that we strip file prefix if necessary.
- str.clear();
- RenderModuleLocation(&str, "/dir/exe", 0x123, kModuleArchUnknown, "/dir/");
- EXPECT_STREQ("(exe+0x123)", str.data());
-
- // Check that we render the arch.
- str.clear();
- RenderModuleLocation(&str, "/dir/exe", 0x123, kModuleArchX86_64H, "/dir/");
- EXPECT_STREQ("(exe:x86_64h+0x123)", str.data());
-}
-
-TEST(SanitizerStacktracePrinter, RenderFrame) {
- int frame_no = 42;
- AddressInfo info;
- info.address = 0x400000;
- info.module = internal_strdup("/path/to/my/module");
- info.module_offset = 0x200;
- info.function = internal_strdup("function_foo");
- info.function_offset = 0x100;
- info.file = internal_strdup("/path/to/my/source");
- info.line = 10;
- info.column = 5;
- InternalScopedString str(256);
-
- // Dump all the AddressInfo fields.
- RenderFrame(&str, "%% Frame:%n PC:%p Module:%m ModuleOffset:%o "
- "Function:%f FunctionOffset:%q Source:%s Line:%l "
- "Column:%c",
- frame_no, info, false, "/path/to/", "function_");
- EXPECT_STREQ("% Frame:42 PC:0x400000 Module:my/module ModuleOffset:0x200 "
- "Function:foo FunctionOffset:0x100 Source:my/source Line:10 "
- "Column:5",
- str.data());
- info.Clear();
- str.clear();
-
- // Test special format specifiers.
- info.address = 0x400000;
- RenderFrame(&str, "%M", frame_no, info, false);
- EXPECT_NE(nullptr, internal_strstr(str.data(), "400000"));
- str.clear();
-
- RenderFrame(&str, "%L", frame_no, info, false);
- EXPECT_STREQ("(<unknown module>)", str.data());
- str.clear();
-
- info.module = internal_strdup("/path/to/module");
- info.module_offset = 0x200;
- RenderFrame(&str, "%M", frame_no, info, false);
- EXPECT_NE(nullptr, internal_strstr(str.data(), "(module+0x"));
- EXPECT_NE(nullptr, internal_strstr(str.data(), "200"));
- str.clear();
-
- RenderFrame(&str, "%L", frame_no, info, false);
- EXPECT_STREQ("(/path/to/module+0x200)", str.data());
- str.clear();
-
- info.function = internal_strdup("my_function");
- RenderFrame(&str, "%F", frame_no, info, false);
- EXPECT_STREQ("in my_function", str.data());
- str.clear();
-
- info.function_offset = 0x100;
- RenderFrame(&str, "%F %S", frame_no, info, false);
- EXPECT_STREQ("in my_function+0x100 <null>", str.data());
- str.clear();
-
- info.file = internal_strdup("my_file");
- RenderFrame(&str, "%F %S", frame_no, info, false);
- EXPECT_STREQ("in my_function my_file", str.data());
- str.clear();
-
- info.line = 10;
- RenderFrame(&str, "%F %S", frame_no, info, false);
- EXPECT_STREQ("in my_function my_file:10", str.data());
- str.clear();
-
- info.column = 5;
- RenderFrame(&str, "%S %L", frame_no, info, false);
- EXPECT_STREQ("my_file:10:5 my_file:10:5", str.data());
- str.clear();
-
- RenderFrame(&str, "%S %L", frame_no, info, true);
- EXPECT_STREQ("my_file(10,5) my_file(10,5)", str.data());
- str.clear();
-
- info.column = 0;
- RenderFrame(&str, "%F %S", frame_no, info, true);
- EXPECT_STREQ("in my_function my_file(10)", str.data());
- str.clear();
-
- info.line = 0;
- RenderFrame(&str, "%F %S", frame_no, info, true);
- EXPECT_STREQ("in my_function my_file", str.data());
- str.clear();
-
- info.Clear();
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_printer_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_common_printer_test.cc ----------------------------------===//
+//===-- sanitizer_common_printer_test.cpp ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc (removed)
@@ -1,163 +0,0 @@
-//===-- sanitizer_stacktrace_test.cc --------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_stacktrace.h"
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-class FastUnwindTest : public ::testing::Test {
- protected:
- virtual void SetUp();
- virtual void TearDown();
-
- void UnwindFast();
-
- void *mapping;
- uhwptr *fake_stack;
- const uptr fake_stack_size = 10;
- uhwptr start_pc;
-
- uhwptr fake_bp;
- uhwptr fake_top;
- uhwptr fake_bottom;
- BufferedStackTrace trace;
-};
-
-static uptr PC(uptr idx) {
- return (1<<20) + idx;
-}
-
-void FastUnwindTest::SetUp() {
- size_t ps = GetPageSize();
- mapping = MmapOrDie(2 * ps, "FastUnwindTest");
- MprotectNoAccess((uptr)mapping, ps);
-
- // Unwinder may peek 1 word down from the starting FP.
- fake_stack = (uhwptr *)((uptr)mapping + ps + sizeof(uhwptr));
-
- // Fill an array of pointers with fake fp+retaddr pairs. Frame pointers have
- // even indices.
- for (uptr i = 0; i + 1 < fake_stack_size; i += 2) {
- fake_stack[i] = (uptr)&fake_stack[i+2]; // fp
- fake_stack[i+1] = PC(i + 1); // retaddr
- }
- // Mark the last fp point back up to terminate the stack trace.
- fake_stack[RoundDownTo(fake_stack_size - 1, 2)] = (uhwptr)&fake_stack[0];
-
- // Top is two slots past the end because UnwindFast subtracts two.
- fake_top = (uhwptr)&fake_stack[fake_stack_size + 2];
- // Bottom is one slot before the start because UnwindFast uses >.
- fake_bottom = (uhwptr)mapping;
- fake_bp = (uptr)&fake_stack[0];
- start_pc = PC(0);
-}
-
-void FastUnwindTest::TearDown() {
- size_t ps = GetPageSize();
- UnmapOrDie(mapping, 2 * ps);
-}
-
-#if SANITIZER_CAN_FAST_UNWIND
-
-void FastUnwindTest::UnwindFast() {
- trace.UnwindFast(start_pc, fake_bp, fake_top, fake_bottom, kStackTraceMax);
-}
-
-TEST_F(FastUnwindTest, Basic) {
- UnwindFast();
- // Should get all on-stack retaddrs and start_pc.
- EXPECT_EQ(6U, trace.size);
- EXPECT_EQ(start_pc, trace.trace[0]);
- for (uptr i = 1; i <= 5; i++) {
- EXPECT_EQ(PC(i*2 - 1), trace.trace[i]);
- }
-}
-
-// From: https://github.com/google/sanitizers/issues/162
-TEST_F(FastUnwindTest, FramePointerLoop) {
- // Make one fp point to itself.
- fake_stack[4] = (uhwptr)&fake_stack[4];
- UnwindFast();
- // Should get all on-stack retaddrs up to the 4th slot and start_pc.
- EXPECT_EQ(4U, trace.size);
- EXPECT_EQ(start_pc, trace.trace[0]);
- for (uptr i = 1; i <= 3; i++) {
- EXPECT_EQ(PC(i*2 - 1), trace.trace[i]);
- }
-}
-
-TEST_F(FastUnwindTest, MisalignedFramePointer) {
- // Make one fp misaligned.
- fake_stack[4] += 3;
- UnwindFast();
- // Should get all on-stack retaddrs up to the 4th slot and start_pc.
- EXPECT_EQ(4U, trace.size);
- EXPECT_EQ(start_pc, trace.trace[0]);
- for (uptr i = 1; i < 4U; i++) {
- EXPECT_EQ(PC(i*2 - 1), trace.trace[i]);
- }
-}
-
-TEST_F(FastUnwindTest, OneFrameStackTrace) {
- trace.Unwind(start_pc, fake_bp, nullptr, true, 1);
- EXPECT_EQ(1U, trace.size);
- EXPECT_EQ(start_pc, trace.trace[0]);
- EXPECT_EQ((uhwptr)&fake_stack[0], trace.top_frame_bp);
-}
-
-TEST_F(FastUnwindTest, ZeroFramesStackTrace) {
- trace.Unwind(start_pc, fake_bp, nullptr, true, 0);
- EXPECT_EQ(0U, trace.size);
- EXPECT_EQ(0U, trace.top_frame_bp);
-}
-
-TEST_F(FastUnwindTest, FPBelowPrevFP) {
- // The next FP points to unreadable memory inside the stack limits, but below
- // current FP.
- fake_stack[0] = (uhwptr)&fake_stack[-50];
- fake_stack[1] = PC(1);
- UnwindFast();
- EXPECT_EQ(2U, trace.size);
- EXPECT_EQ(PC(0), trace.trace[0]);
- EXPECT_EQ(PC(1), trace.trace[1]);
-}
-
-TEST_F(FastUnwindTest, CloseToZeroFrame) {
- // Make one pc a NULL pointer.
- fake_stack[5] = 0x0;
- UnwindFast();
- // The stack should be truncated at the NULL pointer (and not include it).
- EXPECT_EQ(3U, trace.size);
- EXPECT_EQ(start_pc, trace.trace[0]);
- for (uptr i = 1; i < 3U; i++) {
- EXPECT_EQ(PC(i*2 - 1), trace.trace[i]);
- }
-}
-
-#endif // SANITIZER_CAN_FAST_UNWIND
-
-TEST(SlowUnwindTest, ShortStackTrace) {
- BufferedStackTrace stack;
- uptr pc = StackTrace::GetCurrentPc();
- uptr bp = GET_CURRENT_FRAME();
- stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/0);
- EXPECT_EQ(0U, stack.size);
- EXPECT_EQ(0U, stack.top_frame_bp);
- stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/1);
- EXPECT_EQ(1U, stack.size);
- EXPECT_EQ(pc, stack.trace[0]);
- EXPECT_EQ(bp, stack.top_frame_bp);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_stacktrace_test.cc --------------------------------------===//
+//===-- sanitizer_stacktrace_test.cpp -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc (removed)
@@ -1,203 +0,0 @@
-//===-- sanitizer_stoptheworld_test.cc ------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Tests for sanitizer_stoptheworld.h
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_LINUX && defined(__x86_64__)
-
-#include "sanitizer_common/sanitizer_stoptheworld.h"
-#include "gtest/gtest.h"
-
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_common.h"
-
-#include <pthread.h>
-#include <sched.h>
-
-namespace __sanitizer {
-
-static pthread_mutex_t incrementer_thread_exit_mutex;
-
-struct CallbackArgument {
- volatile int counter;
- volatile bool threads_stopped;
- volatile bool callback_executed;
- CallbackArgument()
- : counter(0),
- threads_stopped(false),
- callback_executed(false) {}
-};
-
-void *IncrementerThread(void *argument) {
- CallbackArgument *callback_argument = (CallbackArgument *)argument;
- while (true) {
- __sync_fetch_and_add(&callback_argument->counter, 1);
- if (pthread_mutex_trylock(&incrementer_thread_exit_mutex) == 0) {
- pthread_mutex_unlock(&incrementer_thread_exit_mutex);
- return NULL;
- } else {
- sched_yield();
- }
- }
-}
-
-// This callback checks that IncrementerThread is suspended at the time of its
-// execution.
-void Callback(const SuspendedThreadsList &suspended_threads_list,
- void *argument) {
- CallbackArgument *callback_argument = (CallbackArgument *)argument;
- callback_argument->callback_executed = true;
- int counter_at_init = __sync_fetch_and_add(&callback_argument->counter, 0);
- for (uptr i = 0; i < 1000; i++) {
- sched_yield();
- if (__sync_fetch_and_add(&callback_argument->counter, 0) !=
- counter_at_init) {
- callback_argument->threads_stopped = false;
- return;
- }
- }
- callback_argument->threads_stopped = true;
-}
-
-TEST(StopTheWorld, SuspendThreadsSimple) {
- pthread_mutex_init(&incrementer_thread_exit_mutex, NULL);
- CallbackArgument argument;
- pthread_t thread_id;
- int pthread_create_result;
- pthread_mutex_lock(&incrementer_thread_exit_mutex);
- pthread_create_result = pthread_create(&thread_id, NULL, IncrementerThread,
- &argument);
- ASSERT_EQ(0, pthread_create_result);
- StopTheWorld(&Callback, &argument);
- pthread_mutex_unlock(&incrementer_thread_exit_mutex);
- EXPECT_TRUE(argument.callback_executed);
- EXPECT_TRUE(argument.threads_stopped);
- // argument is on stack, so we have to wait for the incrementer thread to
- // terminate before we can return from this function.
- ASSERT_EQ(0, pthread_join(thread_id, NULL));
- pthread_mutex_destroy(&incrementer_thread_exit_mutex);
-}
-
-// A more comprehensive test where we spawn a bunch of threads while executing
-// StopTheWorld in parallel.
-static const uptr kThreadCount = 50;
-static const uptr kStopWorldAfter = 10; // let this many threads spawn first
-
-static pthread_mutex_t advanced_incrementer_thread_exit_mutex;
-
-struct AdvancedCallbackArgument {
- volatile uptr thread_index;
- volatile int counters[kThreadCount];
- pthread_t thread_ids[kThreadCount];
- volatile bool threads_stopped;
- volatile bool callback_executed;
- volatile bool fatal_error;
- AdvancedCallbackArgument()
- : thread_index(0),
- threads_stopped(false),
- callback_executed(false),
- fatal_error(false) {}
-};
-
-void *AdvancedIncrementerThread(void *argument) {
- AdvancedCallbackArgument *callback_argument =
- (AdvancedCallbackArgument *)argument;
- uptr this_thread_index = __sync_fetch_and_add(
- &callback_argument->thread_index, 1);
- // Spawn the next thread.
- int pthread_create_result;
- if (this_thread_index + 1 < kThreadCount) {
- pthread_create_result =
- pthread_create(&callback_argument->thread_ids[this_thread_index + 1],
- NULL, AdvancedIncrementerThread, argument);
- // Cannot use ASSERT_EQ in non-void-returning functions. If there's a
- // problem, defer failing to the main thread.
- if (pthread_create_result != 0) {
- callback_argument->fatal_error = true;
- __sync_fetch_and_add(&callback_argument->thread_index,
- kThreadCount - callback_argument->thread_index);
- }
- }
- // Do the actual work.
- while (true) {
- __sync_fetch_and_add(&callback_argument->counters[this_thread_index], 1);
- if (pthread_mutex_trylock(&advanced_incrementer_thread_exit_mutex) == 0) {
- pthread_mutex_unlock(&advanced_incrementer_thread_exit_mutex);
- return NULL;
- } else {
- sched_yield();
- }
- }
-}
-
-void AdvancedCallback(const SuspendedThreadsList &suspended_threads_list,
- void *argument) {
- AdvancedCallbackArgument *callback_argument =
- (AdvancedCallbackArgument *)argument;
- callback_argument->callback_executed = true;
-
- int counters_at_init[kThreadCount];
- for (uptr j = 0; j < kThreadCount; j++)
- counters_at_init[j] = __sync_fetch_and_add(&callback_argument->counters[j],
- 0);
- for (uptr i = 0; i < 10; i++) {
- sched_yield();
- for (uptr j = 0; j < kThreadCount; j++)
- if (__sync_fetch_and_add(&callback_argument->counters[j], 0) !=
- counters_at_init[j]) {
- callback_argument->threads_stopped = false;
- return;
- }
- }
- callback_argument->threads_stopped = true;
-}
-
-TEST(StopTheWorld, SuspendThreadsAdvanced) {
- pthread_mutex_init(&advanced_incrementer_thread_exit_mutex, NULL);
- AdvancedCallbackArgument argument;
-
- pthread_mutex_lock(&advanced_incrementer_thread_exit_mutex);
- int pthread_create_result;
- pthread_create_result = pthread_create(&argument.thread_ids[0], NULL,
- AdvancedIncrementerThread,
- &argument);
- ASSERT_EQ(0, pthread_create_result);
- // Wait for several threads to spawn before proceeding.
- while (__sync_fetch_and_add(&argument.thread_index, 0) < kStopWorldAfter)
- sched_yield();
- StopTheWorld(&AdvancedCallback, &argument);
- EXPECT_TRUE(argument.callback_executed);
- EXPECT_TRUE(argument.threads_stopped);
-
- // Wait for all threads to spawn before we start terminating them.
- while (__sync_fetch_and_add(&argument.thread_index, 0) < kThreadCount)
- sched_yield();
- ASSERT_FALSE(argument.fatal_error); // a pthread_create has failed
- // Signal the threads to terminate.
- pthread_mutex_unlock(&advanced_incrementer_thread_exit_mutex);
- for (uptr i = 0; i < kThreadCount; i++)
- ASSERT_EQ(0, pthread_join(argument.thread_ids[i], NULL));
- pthread_mutex_destroy(&advanced_incrementer_thread_exit_mutex);
-}
-
-static void SegvCallback(const SuspendedThreadsList &suspended_threads_list,
- void *argument) {
- *(volatile int*)0x1234 = 0;
-}
-
-TEST(StopTheWorld, SegvInCallback) {
- // Test that tracer thread catches SIGSEGV.
- StopTheWorld(&SegvCallback, NULL);
-}
-
-} // namespace __sanitizer
-
-#endif // SANITIZER_LINUX && defined(__x86_64__)
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_stoptheworld_test.cc ------------------------------------===//
+//===-- sanitizer_stoptheworld_test.cpp -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc (removed)
@@ -1,52 +0,0 @@
-//===-- sanitizer_stoptheworld_testlib.cc ---------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-// Dynamic library to test StopTheWorld functionality.
-// When loaded with LD_PRELOAD, it will periodically suspend all threads.
-//===----------------------------------------------------------------------===//
-/* Usage:
-clang++ -fno-exceptions -g -fPIC -I. \
- sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc \
- sanitizer_common/sanitizer_*.cc -shared -lpthread -o teststoptheworld.so
-LD_PRELOAD=`pwd`/teststoptheworld.so /your/app
-*/
-
-#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_LINUX
-
-#include <dlfcn.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <pthread.h>
-#include <unistd.h>
-
-#include "sanitizer_common/sanitizer_stoptheworld.h"
-
-namespace {
-const uptr kSuspendDuration = 3;
-const uptr kRunDuration = 3;
-
-void Callback(const SuspendedThreadsList &suspended_threads_list,
- void *argument) {
- sleep(kSuspendDuration);
-}
-
-void *SuspenderThread(void *argument) {
- while (true) {
- sleep(kRunDuration);
- StopTheWorld(Callback, NULL);
- }
- return NULL;
-}
-
-__attribute__((constructor)) void StopTheWorldTestLibConstructor(void) {
- pthread_t thread_id;
- pthread_create(&thread_id, NULL, SuspenderThread, NULL);
-}
-} // namespace
-
-#endif // SANITIZER_LINUX
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stoptheworld_testlib.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_stoptheworld_testlib.cc ---------------------------------===//
+//===-- sanitizer_stoptheworld_testlib.cpp --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,8 +10,8 @@
//===----------------------------------------------------------------------===//
/* Usage:
clang++ -fno-exceptions -g -fPIC -I. \
- sanitizer_common/tests/sanitizer_stoptheworld_testlib.cc \
- sanitizer_common/sanitizer_*.cc -shared -lpthread -o teststoptheworld.so
+ sanitizer_common/tests/sanitizer_stoptheworld_testlib.cpp \
+ sanitizer_common/sanitizer_*.cpp -shared -lpthread -o teststoptheworld.so
LD_PRELOAD=`pwd`/teststoptheworld.so /your/app
*/
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc (removed)
@@ -1,140 +0,0 @@
-//===-- sanitizer_suppressions_test.cc ------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_suppressions.h"
-#include "gtest/gtest.h"
-
-#include <string.h>
-
-namespace __sanitizer {
-
-static bool MyMatch(const char *templ, const char *func) {
- char tmp[1024];
- strcpy(tmp, templ); // NOLINT
- return TemplateMatch(tmp, func);
-}
-
-TEST(Suppressions, Match) {
- EXPECT_TRUE(MyMatch("foobar$", "foobar"));
-
- EXPECT_TRUE(MyMatch("foobar", "foobar"));
- EXPECT_TRUE(MyMatch("*foobar*", "foobar"));
- EXPECT_TRUE(MyMatch("foobar", "prefix_foobar_postfix"));
- EXPECT_TRUE(MyMatch("*foobar*", "prefix_foobar_postfix"));
- EXPECT_TRUE(MyMatch("foo*bar", "foo_middle_bar"));
- EXPECT_TRUE(MyMatch("foo*bar", "foobar"));
- EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_bar_another_baz"));
- EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_barbaz"));
- EXPECT_TRUE(MyMatch("^foobar", "foobar"));
- EXPECT_TRUE(MyMatch("^foobar", "foobar_postfix"));
- EXPECT_TRUE(MyMatch("^*foobar", "foobar"));
- EXPECT_TRUE(MyMatch("^*foobar", "prefix_foobar"));
- EXPECT_TRUE(MyMatch("foobar$", "foobar"));
- EXPECT_TRUE(MyMatch("foobar$", "prefix_foobar"));
- EXPECT_TRUE(MyMatch("*foobar*$", "foobar"));
- EXPECT_TRUE(MyMatch("*foobar*$", "foobar_postfix"));
- EXPECT_TRUE(MyMatch("^foobar$", "foobar"));
-
- EXPECT_FALSE(MyMatch("foo", "baz"));
- EXPECT_FALSE(MyMatch("foobarbaz", "foobar"));
- EXPECT_FALSE(MyMatch("foobarbaz", "barbaz"));
- EXPECT_FALSE(MyMatch("foo*bar", "foobaz"));
- EXPECT_FALSE(MyMatch("foo*bar", "foo_baz"));
- EXPECT_FALSE(MyMatch("^foobar", "prefix_foobar"));
- EXPECT_FALSE(MyMatch("foobar$", "foobar_postfix"));
- EXPECT_FALSE(MyMatch("^foobar$", "prefix_foobar"));
- EXPECT_FALSE(MyMatch("^foobar$", "foobar_postfix"));
- EXPECT_FALSE(MyMatch("foo^bar", "foobar"));
- EXPECT_FALSE(MyMatch("foo$bar", "foobar"));
- EXPECT_FALSE(MyMatch("foo$^bar", "foobar"));
-}
-
-static const char *kTestSuppressionTypes[] = {"race", "thread", "mutex",
- "signal"};
-
-class SuppressionContextTest : public ::testing::Test {
- public:
- SuppressionContextTest()
- : ctx_(kTestSuppressionTypes, ARRAY_SIZE(kTestSuppressionTypes)) {}
-
- protected:
- SuppressionContext ctx_;
-
- void CheckSuppressions(unsigned count, std::vector<const char *> types,
- std::vector<const char *> templs) const {
- EXPECT_EQ(count, ctx_.SuppressionCount());
- for (unsigned i = 0; i < count; i++) {
- const Suppression *s = ctx_.SuppressionAt(i);
- EXPECT_STREQ(types[i], s->type);
- EXPECT_STREQ(templs[i], s->templ);
- }
- }
-};
-
-TEST_F(SuppressionContextTest, Parse) {
- ctx_.Parse("race:foo\n"
- " race:bar\n" // NOLINT
- "race:baz \n" // NOLINT
- "# a comment\n"
- "race:quz\n"); // NOLINT
- CheckSuppressions(4, {"race", "race", "race", "race"},
- {"foo", "bar", "baz", "quz"});
-}
-
-TEST_F(SuppressionContextTest, Parse2) {
- ctx_.Parse(
- " # first line comment\n" // NOLINT
- " race:bar \n" // NOLINT
- "race:baz* *baz\n"
- "# a comment\n"
- "# last line comment\n"
- ); // NOLINT
- CheckSuppressions(2, {"race", "race"}, {"bar", "baz* *baz"});
-}
-
-TEST_F(SuppressionContextTest, Parse3) {
- ctx_.Parse(
- "# last suppression w/o line-feed\n"
- "race:foo\n"
- "race:bar\r\n"
- "race:baz"
- ); // NOLINT
- CheckSuppressions(3, {"race", "race", "race"}, {"foo", "bar", "baz"});
-}
-
-TEST_F(SuppressionContextTest, ParseType) {
- ctx_.Parse(
- "race:foo\n"
- "thread:bar\n"
- "mutex:baz\n"
- "signal:quz\n"
- ); // NOLINT
- CheckSuppressions(4, {"race", "thread", "mutex", "signal"},
- {"foo", "bar", "baz", "quz"});
-}
-
-TEST_F(SuppressionContextTest, HasSuppressionType) {
- ctx_.Parse(
- "race:foo\n"
- "thread:bar\n");
- EXPECT_TRUE(ctx_.HasSuppressionType("race"));
- EXPECT_TRUE(ctx_.HasSuppressionType("thread"));
- EXPECT_FALSE(ctx_.HasSuppressionType("mutex"));
- EXPECT_FALSE(ctx_.HasSuppressionType("signal"));
-}
-
-TEST_F(SuppressionContextTest, RegressionTestForBufferOverflowInSuppressions) {
- EXPECT_DEATH(ctx_.Parse("race"), "failed to parse suppressions");
- EXPECT_DEATH(ctx_.Parse("foo"), "failed to parse suppressions");
-}
-
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_suppressions_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_suppressions_test.cc ------------------------------------===//
+//===-- sanitizer_suppressions_test.cpp -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc (removed)
@@ -1,71 +0,0 @@
-//===-- sanitizer_symbolizer_test.cc --------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Tests for sanitizer_symbolizer.h and sanitizer_symbolizer_internal.h
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "sanitizer_common/sanitizer_symbolizer_internal.h"
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-TEST(Symbolizer, ExtractToken) {
- char *token;
- const char *rest;
-
- rest = ExtractToken("a;b;c", ";", &token);
- EXPECT_STREQ("a", token);
- EXPECT_STREQ("b;c", rest);
- InternalFree(token);
-
- rest = ExtractToken("aaa-bbb.ccc", ";.-*", &token);
- EXPECT_STREQ("aaa", token);
- EXPECT_STREQ("bbb.ccc", rest);
- InternalFree(token);
-}
-
-TEST(Symbolizer, ExtractInt) {
- int token;
- const char *rest = ExtractInt("123,456;789", ";,", &token);
- EXPECT_EQ(123, token);
- EXPECT_STREQ("456;789", rest);
-}
-
-TEST(Symbolizer, ExtractUptr) {
- uptr token;
- const char *rest = ExtractUptr("123,456;789", ";,", &token);
- EXPECT_EQ(123U, token);
- EXPECT_STREQ("456;789", rest);
-}
-
-TEST(Symbolizer, ExtractTokenUpToDelimiter) {
- char *token;
- const char *rest =
- ExtractTokenUpToDelimiter("aaa-+-bbb-+-ccc", "-+-", &token);
- EXPECT_STREQ("aaa", token);
- EXPECT_STREQ("bbb-+-ccc", rest);
- InternalFree(token);
-}
-
-#if !SANITIZER_WINDOWS
-TEST(Symbolizer, DemangleSwiftAndCXX) {
- // Swift names are not demangled in default llvm build because Swift
- // runtime is not linked in.
- EXPECT_STREQ("_TtSd", DemangleSwiftAndCXX("_TtSd"));
- // Check that the rest demangles properly.
- EXPECT_STREQ("f1(char*, int)", DemangleSwiftAndCXX("_Z2f1Pci"));
-#if !SANITIZER_FREEBSD // QoI issue with libcxxrt on FreeBSD
- EXPECT_STREQ("foo", DemangleSwiftAndCXX("foo"));
-#endif
- EXPECT_STREQ("", DemangleSwiftAndCXX(""));
-}
-#endif
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_symbolizer_test.cc --------------------------------------===//
+//===-- sanitizer_symbolizer_test.cpp -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: 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=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc (removed)
@@ -1,23 +0,0 @@
-//===-- sanitizer_test_main.cc --------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "gtest/gtest.h"
-#include "sanitizer_common/sanitizer_flags.h"
-
-const char *argv0;
-
-int main(int argc, char **argv) {
- argv0 = argv[0];
- testing::GTEST_FLAG(death_test_style) = "threadsafe";
- testing::InitGoogleTest(&argc, argv);
- __sanitizer::SetCommonFlagsDefaults();
- return RUN_ALL_TESTS();
-}
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cpp (from r367466, 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.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_test_main.cc --------------------------------------------===//
+//===-- sanitizer_test_main.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc (removed)
@@ -1,236 +0,0 @@
-//===-- sanitizer_thread_registry_test.cc ---------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of shared sanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_thread_registry.h"
-
-#include "sanitizer_pthread_wrappers.h"
-
-#include "gtest/gtest.h"
-
-#include <vector>
-
-namespace __sanitizer {
-
-static BlockingMutex tctx_allocator_lock(LINKER_INITIALIZED);
-static LowLevelAllocator tctx_allocator;
-
-template<typename TCTX>
-static ThreadContextBase *GetThreadContext(u32 tid) {
- BlockingMutexLock l(&tctx_allocator_lock);
- return new(tctx_allocator) TCTX(tid);
-}
-
-static const u32 kMaxRegistryThreads = 1000;
-static const u32 kRegistryQuarantine = 2;
-
-static void CheckThreadQuantity(ThreadRegistry *registry, uptr exp_total,
- uptr exp_running, uptr exp_alive) {
- uptr total, running, alive;
- registry->GetNumberOfThreads(&total, &running, &alive);
- EXPECT_EQ(exp_total, total);
- EXPECT_EQ(exp_running, running);
- EXPECT_EQ(exp_alive, alive);
-}
-
-static bool is_detached(u32 tid) {
- return (tid % 2 == 0);
-}
-
-static uptr get_uid(u32 tid) {
- return tid * 2;
-}
-
-static bool HasName(ThreadContextBase *tctx, void *arg) {
- char *name = (char*)arg;
- return (0 == internal_strcmp(tctx->name, name));
-}
-
-static bool HasUid(ThreadContextBase *tctx, void *arg) {
- uptr uid = (uptr)arg;
- return (tctx->user_id == uid);
-}
-
-static void MarkUidAsPresent(ThreadContextBase *tctx, void *arg) {
- bool *arr = (bool*)arg;
- arr[tctx->tid] = true;
-}
-
-static void TestRegistry(ThreadRegistry *registry, bool has_quarantine) {
- // Create and start a main thread.
- EXPECT_EQ(0U, registry->CreateThread(get_uid(0), true, -1, 0));
- registry->StartThread(0, 0, ThreadType::Regular, 0);
- // Create a bunch of threads.
- for (u32 i = 1; i <= 10; i++) {
- EXPECT_EQ(i, registry->CreateThread(get_uid(i), is_detached(i), 0, 0));
- }
- CheckThreadQuantity(registry, 11, 1, 11);
- // Start some of them.
- for (u32 i = 1; i <= 5; i++) {
- registry->StartThread(i, 0, ThreadType::Regular, 0);
- }
- CheckThreadQuantity(registry, 11, 6, 11);
- // Finish, create and start more threads.
- for (u32 i = 1; i <= 5; i++) {
- registry->FinishThread(i);
- if (!is_detached(i))
- registry->JoinThread(i, 0);
- }
- for (u32 i = 6; i <= 10; i++) {
- registry->StartThread(i, 0, ThreadType::Regular, 0);
- }
- std::vector<u32> new_tids;
- for (u32 i = 11; i <= 15; i++) {
- new_tids.push_back(
- registry->CreateThread(get_uid(i), is_detached(i), 0, 0));
- }
- ASSERT_LE(kRegistryQuarantine, 5U);
- u32 exp_total = 16 - (has_quarantine ? 5 - kRegistryQuarantine : 0);
- CheckThreadQuantity(registry, exp_total, 6, 11);
- // Test SetThreadName and FindThread.
- registry->SetThreadName(6, "six");
- registry->SetThreadName(7, "seven");
- EXPECT_EQ(7U, registry->FindThread(HasName, (void*)"seven"));
- EXPECT_EQ(ThreadRegistry::kUnknownTid,
- registry->FindThread(HasName, (void*)"none"));
- EXPECT_EQ(0U, registry->FindThread(HasUid, (void*)get_uid(0)));
- EXPECT_EQ(10U, registry->FindThread(HasUid, (void*)get_uid(10)));
- EXPECT_EQ(ThreadRegistry::kUnknownTid,
- registry->FindThread(HasUid, (void*)0x1234));
- // Detach and finish and join remaining threads.
- for (u32 i = 6; i <= 10; i++) {
- registry->DetachThread(i, 0);
- registry->FinishThread(i);
- }
- for (u32 i = 0; i < new_tids.size(); i++) {
- u32 tid = new_tids[i];
- registry->StartThread(tid, 0, ThreadType::Regular, 0);
- registry->DetachThread(tid, 0);
- registry->FinishThread(tid);
- }
- CheckThreadQuantity(registry, exp_total, 1, 1);
- // Test methods that require the caller to hold a ThreadRegistryLock.
- bool has_tid[16];
- internal_memset(&has_tid[0], 0, sizeof(has_tid));
- {
- ThreadRegistryLock l(registry);
- registry->RunCallbackForEachThreadLocked(MarkUidAsPresent, &has_tid[0]);
- }
- for (u32 i = 0; i < exp_total; i++) {
- EXPECT_TRUE(has_tid[i]);
- }
- {
- ThreadRegistryLock l(registry);
- registry->CheckLocked();
- ThreadContextBase *main_thread = registry->GetThreadLocked(0);
- EXPECT_EQ(main_thread, registry->FindThreadContextLocked(
- HasUid, (void*)get_uid(0)));
- }
- EXPECT_EQ(11U, registry->GetMaxAliveThreads());
-}
-
-TEST(SanitizerCommon, ThreadRegistryTest) {
- ThreadRegistry quarantine_registry(GetThreadContext<ThreadContextBase>,
- kMaxRegistryThreads,
- kRegistryQuarantine);
- TestRegistry(&quarantine_registry, true);
-
- ThreadRegistry no_quarantine_registry(GetThreadContext<ThreadContextBase>,
- kMaxRegistryThreads,
- kMaxRegistryThreads);
- TestRegistry(&no_quarantine_registry, false);
-}
-
-static const int kThreadsPerShard = 20;
-static const int kNumShards = 25;
-
-static int num_created[kNumShards + 1];
-static int num_started[kNumShards + 1];
-static int num_joined[kNumShards + 1];
-
-namespace {
-
-struct RunThreadArgs {
- ThreadRegistry *registry;
- uptr shard; // started from 1.
-};
-
-class TestThreadContext : public ThreadContextBase {
- public:
- explicit TestThreadContext(int tid) : ThreadContextBase(tid) {}
- void OnJoined(void *arg) {
- uptr shard = (uptr)arg;
- num_joined[shard]++;
- }
- void OnStarted(void *arg) {
- uptr shard = (uptr)arg;
- num_started[shard]++;
- }
- void OnCreated(void *arg) {
- uptr shard = (uptr)arg;
- num_created[shard]++;
- }
-};
-
-} // namespace
-
-void *RunThread(void *arg) {
- RunThreadArgs *args = static_cast<RunThreadArgs*>(arg);
- std::vector<int> tids;
- for (int i = 0; i < kThreadsPerShard; i++)
- tids.push_back(
- args->registry->CreateThread(0, false, 0, (void*)args->shard));
- for (int i = 0; i < kThreadsPerShard; i++)
- args->registry->StartThread(tids[i], 0, ThreadType::Regular,
- (void*)args->shard);
- for (int i = 0; i < kThreadsPerShard; i++)
- args->registry->FinishThread(tids[i]);
- for (int i = 0; i < kThreadsPerShard; i++)
- args->registry->JoinThread(tids[i], (void*)args->shard);
- return 0;
-}
-
-static void ThreadedTestRegistry(ThreadRegistry *registry) {
- // Create and start a main thread.
- EXPECT_EQ(0U, registry->CreateThread(0, true, -1, 0));
- registry->StartThread(0, 0, ThreadType::Regular, 0);
- pthread_t threads[kNumShards];
- RunThreadArgs args[kNumShards];
- for (int i = 0; i < kNumShards; i++) {
- args[i].registry = registry;
- args[i].shard = i + 1;
- PTHREAD_CREATE(&threads[i], 0, RunThread, &args[i]);
- }
- for (int i = 0; i < kNumShards; i++) {
- PTHREAD_JOIN(threads[i], 0);
- }
- // Check that each thread created/started/joined correct amount
- // of "threads" in thread_registry.
- EXPECT_EQ(1, num_created[0]);
- EXPECT_EQ(1, num_started[0]);
- EXPECT_EQ(0, num_joined[0]);
- for (int i = 1; i <= kNumShards; i++) {
- EXPECT_EQ(kThreadsPerShard, num_created[i]);
- EXPECT_EQ(kThreadsPerShard, num_started[i]);
- EXPECT_EQ(kThreadsPerShard, num_joined[i]);
- }
-}
-
-TEST(SanitizerCommon, ThreadRegistryThreadedTest) {
- memset(&num_created, 0, sizeof(num_created));
- memset(&num_started, 0, sizeof(num_created));
- memset(&num_joined, 0, sizeof(num_created));
-
- ThreadRegistry registry(GetThreadContext<TestThreadContext>,
- kThreadsPerShard * kNumShards + 1, 10);
- ThreadedTestRegistry(®istry);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_thread_registry_test.cc ---------------------------------===//
+//===-- sanitizer_thread_registry_test.cpp --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc (removed)
@@ -1,32 +0,0 @@
-//===-- sanitizer_type_traits_test.cc -------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_type_traits.h"
-#include "gtest/gtest.h"
-#include "sanitizer_common/sanitizer_internal_defs.h"
-
-using namespace __sanitizer;
-
-TEST(SanitizerCommon, IsSame) {
- ASSERT_TRUE((is_same<unsigned, unsigned>::value));
- ASSERT_TRUE((is_same<uptr, uptr>::value));
- ASSERT_TRUE((is_same<sptr, sptr>::value));
- ASSERT_TRUE((is_same<const uptr, const uptr>::value));
-
- ASSERT_FALSE((is_same<unsigned, signed>::value));
- ASSERT_FALSE((is_same<uptr, sptr>::value));
- ASSERT_FALSE((is_same<uptr, const uptr>::value));
-}
-
-TEST(SanitizerCommon, Conditional) {
- ASSERT_TRUE((is_same<int, conditional<true, int, double>::type>::value));
- ASSERT_TRUE((is_same<double, conditional<false, int, double>::type>::value));
-}
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_type_traits_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_type_traits_test.cc -------------------------------------===//
+//===-- sanitizer_type_traits_test.cpp ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc (removed)
@@ -1,50 +0,0 @@
-//===-- sanitizer_vector_test.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of *Sanitizer runtime.
-//
-//===----------------------------------------------------------------------===//
-#include "sanitizer_common/sanitizer_vector.h"
-#include "gtest/gtest.h"
-
-namespace __sanitizer {
-
-TEST(Vector, Basic) {
- Vector<int> v;
- EXPECT_EQ(v.Size(), 0u);
- v.PushBack(42);
- EXPECT_EQ(v.Size(), 1u);
- EXPECT_EQ(v[0], 42);
- v.PushBack(43);
- EXPECT_EQ(v.Size(), 2u);
- EXPECT_EQ(v[0], 42);
- EXPECT_EQ(v[1], 43);
-}
-
-TEST(Vector, Stride) {
- Vector<int> v;
- for (int i = 0; i < 1000; i++) {
- v.PushBack(i);
- EXPECT_EQ(v.Size(), i + 1u);
- EXPECT_EQ(v[i], i);
- }
- for (int i = 0; i < 1000; i++) {
- EXPECT_EQ(v[i], i);
- }
-}
-
-TEST(Vector, ResizeReduction) {
- Vector<int> v;
- v.PushBack(0);
- v.PushBack(0);
- EXPECT_EQ(v.Size(), 2u);
- v.Resize(1);
- EXPECT_EQ(v.Size(), 1u);
-}
-
-} // namespace __sanitizer
Copied: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cpp (from r367466, compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cpp?p2=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cpp&p1=compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc&r1=367466&r2=367467&rev=367467&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cpp Wed Jul 31 12:11:14 2019
@@ -1,4 +1,4 @@
-//===-- sanitizer_vector_test.cc ------------------------------------------===//
+//===-- sanitizer_vector_test.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/sanitizer_common/tests/standalone_malloc_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/standalone_malloc_test.cc?rev=367466&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/standalone_malloc_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/standalone_malloc_test.cc (removed)
@@ -1,87 +0,0 @@
-#include <stdio.h>
-#include <vector>
-#include <pthread.h>
-#include <malloc.h>
-#include <algorithm>
-
-using namespace std;
-
-const size_t kNumThreds = 16;
-const size_t kNumIters = 1 << 23;
-
-inline void break_optimization(void *arg) {
- __asm__ __volatile__("" : : "r" (arg) : "memory");
-}
-
-__attribute__((noinline))
-static void *MallocThread(void *t) {
- size_t total_malloced = 0, total_freed = 0;
- size_t max_in_use = 0;
- size_t tid = reinterpret_cast<size_t>(t);
- vector<pair<char *, size_t> > allocated;
- allocated.reserve(kNumIters);
- for (size_t i = 1; i < kNumIters; i++) {
- if ((i % (kNumIters / 4)) == 0 && tid == 0)
- fprintf(stderr, " T[%ld] iter %ld\n", tid, i);
- bool allocate = (i % 5) <= 2; // 60% malloc, 40% free
- if (i > kNumIters / 4)
- allocate = i % 2; // then switch to 50% malloc, 50% free
- if (allocate) {
- size_t size = 1 + (i % 200);
- if ((i % 10001) == 0)
- size *= 4096;
- total_malloced += size;
- char *x = new char[size];
- x[0] = x[size - 1] = x[size / 2] = 0;
- allocated.push_back(make_pair(x, size));
- max_in_use = max(max_in_use, total_malloced - total_freed);
- } else {
- if (allocated.empty()) continue;
- size_t slot = i % allocated.size();
- char *p = allocated[slot].first;
- p[0] = 0; // emulate last user touch of the block
- size_t size = allocated[slot].second;
- total_freed += size;
- swap(allocated[slot], allocated.back());
- allocated.pop_back();
- delete [] p;
- }
- }
- if (tid == 0)
- fprintf(stderr, " T[%ld] total_malloced: %ldM in use %ldM max %ldM\n",
- tid, total_malloced >> 20, (total_malloced - total_freed) >> 20,
- max_in_use >> 20);
- for (size_t i = 0; i < allocated.size(); i++)
- delete [] allocated[i].first;
- return 0;
-}
-
-template <int depth>
-struct DeepStack {
- __attribute__((noinline))
- static void *run(void *t) {
- break_optimization(0);
- DeepStack<depth - 1>::run(t);
- break_optimization(0);
- return 0;
- }
-};
-
-template<>
-struct DeepStack<0> {
- static void *run(void *t) {
- MallocThread(t);
- return 0;
- }
-};
-
-// Build with -Dstandalone_malloc_test=main to make it a separate program.
-int standalone_malloc_test() {
- pthread_t t[kNumThreds];
- for (size_t i = 0; i < kNumThreds; i++)
- pthread_create(&t[i], 0, DeepStack<200>::run, reinterpret_cast<void *>(i));
- for (size_t i = 0; i < kNumThreds; i++)
- pthread_join(t[i], 0);
- malloc_stats();
- return 0;
-}
More information about the llvm-commits
mailing list