[compiler-rt] r367569 - compiler-rt: Rename .cc file in lib/scudo/standalone/tests to .cpp
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 07:38:49 PDT 2019
Author: nico
Date: Thu Aug 1 07:38:49 2019
New Revision: 367569
URL: http://llvm.org/viewvc/llvm-project?rev=367569&view=rev
Log:
compiler-rt: Rename .cc file in lib/scudo/standalone/tests to .cpp
Like r367463, but for scudo/standalone/tests.
With this, all files in compiler-rt/lib have extension cpp.
Added:
compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc
compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
- copied, changed from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc
Removed:
compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc
compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc
compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc
Modified:
compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt
Modified: compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt?rev=367569&r1=367568&r2=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt Thu Aug 1 07:38:49 2019
@@ -57,41 +57,44 @@ macro(add_scudo_unittest testname)
endmacro()
set(SCUDO_UNIT_TEST_SOURCES
- atomic_test.cc
- bytemap_test.cc
- checksum_test.cc
- chunk_test.cc
- combined_test.cc
- flags_test.cc
- list_test.cc
- map_test.cc
- mutex_test.cc
- primary_test.cc
- quarantine_test.cc
- release_test.cc
- report_test.cc
- secondary_test.cc
- size_class_map_test.cc
- stats_test.cc
- strings_test.cc
- tsd_test.cc
- vector_test.cc
- scudo_unit_test_main.cc)
+ atomic_test.cpp
+ bytemap_test.cpp
+ checksum_test.cpp
+ chunk_test.cpp
+ combined_test.cpp
+ flags_test.cpp
+ list_test.cpp
+ map_test.cpp
+ mutex_test.cpp
+ primary_test.cpp
+ quarantine_test.cpp
+ release_test.cpp
+ report_test.cpp
+ secondary_test.cpp
+ size_class_map_test.cpp
+ stats_test.cpp
+ strings_test.cpp
+ tsd_test.cpp
+ vector_test.cpp
+ scudo_unit_test_main.cpp
+ )
add_scudo_unittest(ScudoUnitTest
SOURCES ${SCUDO_UNIT_TEST_SOURCES})
set(SCUDO_C_UNIT_TEST_SOURCES
- wrappers_c_test.cc
- scudo_unit_test_main.cc)
+ wrappers_c_test.cpp
+ scudo_unit_test_main.cpp
+ )
add_scudo_unittest(ScudoCUnitTest
SOURCES ${SCUDO_C_UNIT_TEST_SOURCES}
ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers)
set(SCUDO_CXX_UNIT_TEST_SOURCES
- wrappers_cpp_test.cc
- scudo_unit_test_main.cc)
+ wrappers_cpp_test.cpp
+ scudo_unit_test_main.cpp
+ )
add_scudo_unittest(ScudoCxxUnitTest
SOURCES ${SCUDO_CXX_UNIT_TEST_SOURCES}
Removed: compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc (removed)
@@ -1,112 +0,0 @@
-//===-- atomic_test.cc ------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "scudo/standalone/atomic_helpers.h"
-#include "gtest/gtest.h"
-
-namespace scudo {
-
-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 LoadMO, memory_order StoreMO>
-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.ValDoNotUse = (Type)V;
- EXPECT_EQ(atomic_load(&Val.A, LoadMO), (Type)V);
- Val.A.ValDoNotUse = (Type)-1;
- atomic_store(&Val.A, (Type)V, StoreMO);
- EXPECT_EQ(Val.A.ValDoNotUse, (Type)V);
- }
- EXPECT_EQ(Val.Magic0, (Type)-3);
- EXPECT_EQ(Val.Magic1, (Type)-3);
-}
-
-TEST(ScudoAtomicTest, AtomicStoreLoad) {
- checkStoreLoad<atomic_u8, memory_order_relaxed, memory_order_relaxed>();
- checkStoreLoad<atomic_u8, memory_order_consume, memory_order_relaxed>();
- checkStoreLoad<atomic_u8, memory_order_acquire, memory_order_relaxed>();
- checkStoreLoad<atomic_u8, memory_order_relaxed, memory_order_release>();
- checkStoreLoad<atomic_u8, memory_order_seq_cst, memory_order_seq_cst>();
-
- checkStoreLoad<atomic_u16, memory_order_relaxed, memory_order_relaxed>();
- checkStoreLoad<atomic_u16, memory_order_consume, memory_order_relaxed>();
- checkStoreLoad<atomic_u16, memory_order_acquire, memory_order_relaxed>();
- checkStoreLoad<atomic_u16, memory_order_relaxed, memory_order_release>();
- checkStoreLoad<atomic_u16, memory_order_seq_cst, memory_order_seq_cst>();
-
- checkStoreLoad<atomic_u32, memory_order_relaxed, memory_order_relaxed>();
- checkStoreLoad<atomic_u32, memory_order_consume, memory_order_relaxed>();
- checkStoreLoad<atomic_u32, memory_order_acquire, memory_order_relaxed>();
- checkStoreLoad<atomic_u32, memory_order_relaxed, memory_order_release>();
- checkStoreLoad<atomic_u32, memory_order_seq_cst, memory_order_seq_cst>();
-
- checkStoreLoad<atomic_u64, memory_order_relaxed, memory_order_relaxed>();
- checkStoreLoad<atomic_u64, memory_order_consume, memory_order_relaxed>();
- checkStoreLoad<atomic_u64, memory_order_acquire, memory_order_relaxed>();
- checkStoreLoad<atomic_u64, memory_order_relaxed, memory_order_release>();
- checkStoreLoad<atomic_u64, memory_order_seq_cst, memory_order_seq_cst>();
-
- checkStoreLoad<atomic_uptr, memory_order_relaxed, memory_order_relaxed>();
- checkStoreLoad<atomic_uptr, memory_order_consume, memory_order_relaxed>();
- checkStoreLoad<atomic_uptr, memory_order_acquire, memory_order_relaxed>();
- checkStoreLoad<atomic_uptr, memory_order_relaxed, memory_order_release>();
- checkStoreLoad<atomic_uptr, memory_order_seq_cst, memory_order_seq_cst>();
-}
-
-template <typename T> void checkAtomicCompareExchange() {
- typedef typename T::Type Type;
- {
- Type OldVal = 42;
- Type NewVal = 24;
- Type V = OldVal;
- EXPECT_TRUE(atomic_compare_exchange_strong(
- reinterpret_cast<T *>(&V), &OldVal, NewVal, memory_order_relaxed));
- EXPECT_FALSE(atomic_compare_exchange_strong(
- reinterpret_cast<T *>(&V), &OldVal, NewVal, memory_order_relaxed));
- EXPECT_EQ(NewVal, OldVal);
- }
- {
- Type OldVal = 42;
- Type NewVal = 24;
- Type V = OldVal;
- EXPECT_TRUE(atomic_compare_exchange_weak(reinterpret_cast<T *>(&V), &OldVal,
- NewVal, memory_order_relaxed));
- EXPECT_FALSE(atomic_compare_exchange_weak(
- reinterpret_cast<T *>(&V), &OldVal, NewVal, memory_order_relaxed));
- EXPECT_EQ(NewVal, OldVal);
- }
-}
-
-TEST(ScudoAtomicTest, AtomicCompareExchangeTest) {
- checkAtomicCompareExchange<atomic_u8>();
- checkAtomicCompareExchange<atomic_u16>();
- checkAtomicCompareExchange<atomic_u32>();
- checkAtomicCompareExchange<atomic_u64>();
- checkAtomicCompareExchange<atomic_uptr>();
-}
-
-} // namespace scudo
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/atomic_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- atomic_test.cc ------------------------------------------*- C++ -*-===//
+//===-- atomic_test.cpp -----------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/bytemap_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc (removed)
@@ -1,74 +0,0 @@
-//===-- bytemap_test.cc -----------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "bytemap.h"
-
-#include "gtest/gtest.h"
-
-#include <string.h>
-
-template <typename T> void testMap(T &Map, scudo::uptr Size) {
- Map.init();
- for (scudo::uptr I = 0; I < Size; I += 7)
- Map.set(I, (I % 100) + 1);
- for (scudo::uptr J = 0; J < Size; J++) {
- if (J % 7)
- EXPECT_EQ(Map[J], 0);
- else
- EXPECT_EQ(Map[J], (J % 100) + 1);
- }
-}
-
-TEST(ScudoByteMapTest, FlatByteMap) {
- const scudo::uptr Size = 1U << 10;
- scudo::FlatByteMap<Size> Map;
- testMap(Map, Size);
- Map.unmapTestOnly();
-}
-
-TEST(ScudoByteMapTest, TwoLevelByteMap) {
- const scudo::uptr Size1 = 1U << 6, Size2 = 1U << 12;
- scudo::TwoLevelByteMap<Size1, Size2> Map;
- testMap(Map, Size1 * Size2);
- Map.unmapTestOnly();
-}
-
-using TestByteMap = scudo::TwoLevelByteMap<1U << 12, 1U << 13>;
-
-struct TestByteMapParam {
- TestByteMap *Map;
- scudo::uptr Shard;
- scudo::uptr NumberOfShards;
-};
-
-void *populateByteMap(void *Param) {
- TestByteMapParam *P = reinterpret_cast<TestByteMapParam *>(Param);
- for (scudo::uptr I = P->Shard; I < P->Map->size(); I += P->NumberOfShards) {
- scudo::u8 V = static_cast<scudo::u8>((I % 100) + 1);
- P->Map->set(I, V);
- EXPECT_EQ((*P->Map)[I], V);
- }
- return 0;
-}
-
-TEST(ScudoByteMapTest, ThreadedTwoLevelByteMap) {
- TestByteMap Map;
- Map.init();
- static const scudo::uptr NumberOfThreads = 16U;
- pthread_t T[NumberOfThreads];
- TestByteMapParam P[NumberOfThreads];
- for (scudo::uptr I = 0; I < NumberOfThreads; I++) {
- P[I].Map = ⤅
- P[I].Shard = I;
- P[I].NumberOfShards = NumberOfThreads;
- pthread_create(&T[I], 0, populateByteMap, &P[I]);
- }
- for (scudo::uptr I = 0; I < NumberOfThreads; I++)
- pthread_join(T[I], 0);
- Map.unmapTestOnly();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/bytemap_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- bytemap_test.cc -----------------------------------------*- C++ -*-===//
+//===-- bytemap_test.cpp ----------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/checksum_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc (removed)
@@ -1,58 +0,0 @@
-//===-- checksum_test.cc ----------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "checksum.h"
-
-#include "gtest/gtest.h"
-
-#include <string.h>
-
-scudo::u16 computeSoftwareChecksum(scudo::u32 Seed, scudo::uptr *Array,
- scudo::uptr ArraySize) {
- scudo::u16 Checksum = static_cast<scudo::u16>(Seed & 0xffff);
- for (scudo::uptr I = 0; I < ArraySize; I++)
- Checksum = scudo::computeBSDChecksum(Checksum, Array[I]);
- return Checksum;
-}
-
-scudo::u16 computeHardwareChecksum(scudo::u32 Seed, scudo::uptr *Array,
- scudo::uptr ArraySize) {
- scudo::u32 Crc = Seed;
- for (scudo::uptr I = 0; I < ArraySize; I++)
- Crc = scudo::computeHardwareCRC32(Crc, Array[I]);
- return static_cast<scudo::u16>((Crc & 0xffff) ^ (Crc >> 16));
-}
-
-typedef scudo::u16 (*ComputeChecksum)(scudo::u32, scudo::uptr *, scudo::uptr);
-
-// This verifies that flipping bits in the data being checksummed produces a
-// different checksum. We do not use random data to avoid flakyness.
-template <ComputeChecksum F> void verifyChecksumFunctionBitFlip() {
- scudo::uptr Array[sizeof(scudo::u64) / sizeof(scudo::uptr)];
- const scudo::uptr ArraySize = ARRAY_SIZE(Array);
- memset(Array, 0xaa, sizeof(Array));
- const scudo::u32 Seed = 0x41424343U;
- const scudo::u16 Reference = F(Seed, Array, ArraySize);
- scudo::u8 IdenticalChecksums = 0;
- for (scudo::uptr I = 0; I < ArraySize; I++) {
- for (scudo::uptr J = 0; J < SCUDO_WORDSIZE; J++) {
- Array[I] ^= 1U << J;
- if (F(Seed, Array, ArraySize) == Reference)
- IdenticalChecksums++;
- Array[I] ^= 1U << J;
- }
- }
- // Allow for a couple of identical checksums over the whole set of flips.
- EXPECT_LE(IdenticalChecksums, 2);
-}
-
-TEST(ScudoChecksumTest, ChecksumFunctions) {
- verifyChecksumFunctionBitFlip<computeSoftwareChecksum>();
- if (&scudo::computeHardwareCRC32 && scudo::hasHardwareCRC32())
- verifyChecksumFunctionBitFlip<computeHardwareChecksum>();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/checksum_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- checksum_test.cc ----------------------------------------*- C++ -*-===//
+//===-- checksum_test.cpp ---------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/chunk_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc (removed)
@@ -1,80 +0,0 @@
-//===-- chunk_test.cc -------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "chunk.h"
-
-#include "gtest/gtest.h"
-
-#include <stdlib.h>
-
-static constexpr scudo::uptr HeaderSize = scudo::Chunk::getHeaderSize();
-static constexpr scudo::u32 Cookie = 0x41424344U;
-static constexpr scudo::u32 InvalidCookie = 0x11223344U;
-
-static void initChecksum(void) {
- if (&scudo::computeHardwareCRC32 && scudo::hasHardwareCRC32())
- scudo::HashAlgorithm = scudo::Checksum::HardwareCRC32;
-}
-
-TEST(ScudoChunkTest, ChunkBasic) {
- initChecksum();
- const scudo::uptr Size = 0x100U;
- scudo::Chunk::UnpackedHeader Header = {};
- void *Block = malloc(HeaderSize + Size);
- void *P = reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(Block) +
- HeaderSize);
- scudo::Chunk::storeHeader(Cookie, P, &Header);
- memset(P, 'A', Size);
- scudo::Chunk::loadHeader(Cookie, P, &Header);
- EXPECT_TRUE(scudo::Chunk::isValid(Cookie, P, &Header));
- EXPECT_FALSE(scudo::Chunk::isValid(InvalidCookie, P, &Header));
- EXPECT_DEATH(scudo::Chunk::loadHeader(InvalidCookie, P, &Header), "");
- free(Block);
-}
-
-TEST(ScudoChunkTest, ChunkCmpXchg) {
- initChecksum();
- const scudo::uptr Size = 0x100U;
- scudo::Chunk::UnpackedHeader OldHeader = {};
- OldHeader.Origin = scudo::Chunk::Origin::Malloc;
- OldHeader.ClassId = 0x42U;
- OldHeader.SizeOrUnusedBytes = Size;
- OldHeader.State = scudo::Chunk::State::Allocated;
- void *Block = malloc(HeaderSize + Size);
- void *P = reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(Block) +
- HeaderSize);
- scudo::Chunk::storeHeader(Cookie, P, &OldHeader);
- memset(P, 'A', Size);
- scudo::Chunk::UnpackedHeader NewHeader = OldHeader;
- NewHeader.State = scudo::Chunk::State::Quarantined;
- scudo::Chunk::compareExchangeHeader(Cookie, P, &NewHeader, &OldHeader);
- NewHeader = {};
- EXPECT_TRUE(scudo::Chunk::isValid(Cookie, P, &NewHeader));
- EXPECT_EQ(NewHeader.State, scudo::Chunk::State::Quarantined);
- EXPECT_FALSE(scudo::Chunk::isValid(InvalidCookie, P, &NewHeader));
- free(Block);
-}
-
-TEST(ScudoChunkTest, CorruptHeader) {
- initChecksum();
- const scudo::uptr Size = 0x100U;
- scudo::Chunk::UnpackedHeader Header = {};
- void *Block = malloc(HeaderSize + Size);
- void *P = reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(Block) +
- HeaderSize);
- scudo::Chunk::storeHeader(Cookie, P, &Header);
- memset(P, 'A', Size);
- scudo::Chunk::loadHeader(Cookie, P, &Header);
- // Simulate a couple of corrupted bits per byte of header data.
- for (scudo::uptr I = 0; I < sizeof(scudo::Chunk::PackedHeader); I++) {
- *(reinterpret_cast<scudo::u8 *>(Block) + I) ^= 0x42U;
- EXPECT_DEATH(scudo::Chunk::loadHeader(Cookie, P, &Header), "");
- *(reinterpret_cast<scudo::u8 *>(Block) + I) ^= 0x42U;
- }
- free(Block);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/chunk_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- chunk_test.cc -------------------------------------------*- C++ -*-===//
+//===-- chunk_test.cpp ------------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/combined_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc (removed)
@@ -1,237 +0,0 @@
-//===-- combined_test.cc ----------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "allocator_config.h"
-#include "combined.h"
-
-#include "gtest/gtest.h"
-
-#include <condition_variable>
-#include <mutex>
-#include <thread>
-
-static std::mutex Mutex;
-static std::condition_variable Cv;
-static bool Ready = false;
-
-static constexpr scudo::Chunk::Origin Origin = scudo::Chunk::Origin::Malloc;
-
-// This allows us to turn on the Quarantine for specific tests. The Quarantine
-// parameters are on the low end, to avoid having to loop excessively in some
-// tests.
-static bool UseQuarantine = false;
-extern "C" const char *__scudo_default_options() {
- if (!UseQuarantine)
- return "";
- return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
- "quarantine_max_chunk_size=1024";
-}
-
-template <class Config> static void testAllocator() {
- using AllocatorT = scudo::Allocator<Config>;
- auto Deleter = [](AllocatorT *A) {
- A->unmapTestOnly();
- delete A;
- };
- std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
- Deleter);
- Allocator->reset();
-
- constexpr scudo::uptr MinAlignLog = FIRST_32_SECOND_64(3U, 4U);
-
- // This allocates and deallocates a bunch of chunks, with a wide range of
- // sizes and alignments, with a focus on sizes that could trigger weird
- // behaviors (plus or minus a small delta of a power of two for example).
- for (scudo::uptr SizeLog = 0U; SizeLog <= 20U; SizeLog++) {
- for (scudo::uptr AlignLog = MinAlignLog; AlignLog <= 16U; AlignLog++) {
- const scudo::uptr Align = 1U << AlignLog;
- for (scudo::sptr Delta = -32; Delta <= 32; Delta++) {
- if (static_cast<scudo::sptr>(1U << SizeLog) + Delta <= 0)
- continue;
- const scudo::uptr Size = (1U << SizeLog) + Delta;
- void *P = Allocator->allocate(Size, Origin, Align);
- EXPECT_NE(P, nullptr);
- EXPECT_TRUE(scudo::isAligned(reinterpret_cast<scudo::uptr>(P), Align));
- EXPECT_LE(Size, Allocator->getUsableSize(P));
- memset(P, 0xaa, Size);
- Allocator->deallocate(P, Origin, Size);
- }
- }
- }
- Allocator->releaseToOS();
-
- // Verify that a chunk will end up being reused, at some point.
- const scudo::uptr NeedleSize = 1024U;
- void *NeedleP = Allocator->allocate(NeedleSize, Origin);
- Allocator->deallocate(NeedleP, Origin);
- bool Found = false;
- for (scudo::uptr I = 0; I < 1024U && !Found; I++) {
- void *P = Allocator->allocate(NeedleSize, Origin);
- if (P == NeedleP)
- Found = true;
- Allocator->deallocate(P, Origin);
- }
- EXPECT_TRUE(Found);
-
- constexpr scudo::uptr MaxSize = Config::Primary::SizeClassMap::MaxSize;
-
- // Reallocate a large chunk all the way down to a byte, verifying that we
- // preserve the data in the process.
- scudo::uptr Size = MaxSize * 2;
- const scudo::uptr DataSize = 2048U;
- void *P = Allocator->allocate(Size, Origin);
- const char Marker = 0xab;
- memset(P, Marker, scudo::Min(Size, DataSize));
- while (Size > 1U) {
- Size /= 2U;
- void *NewP = Allocator->reallocate(P, Size);
- EXPECT_NE(NewP, nullptr);
- for (scudo::uptr J = 0; J < scudo::Min(Size, DataSize); J++)
- EXPECT_EQ((reinterpret_cast<char *>(NewP))[J], Marker);
- P = NewP;
- }
- Allocator->deallocate(P, Origin);
-
- // Allocates a bunch of chunks, then iterate over all the chunks, ensuring
- // they are the ones we allocated. This requires the allocator to not have any
- // other allocated chunk at this point (eg: won't work with the Quarantine).
- if (!UseQuarantine) {
- std::vector<void *> V;
- for (scudo::uptr I = 0; I < 64U; I++)
- V.push_back(Allocator->allocate(rand() % (MaxSize / 2U), Origin));
- Allocator->disable();
- Allocator->iterateOverChunks(
- 0U, static_cast<scudo::uptr>(SCUDO_MMAP_RANGE_SIZE - 1),
- [](uintptr_t Base, size_t Size, void *Arg) {
- std::vector<void *> *V = reinterpret_cast<std::vector<void *> *>(Arg);
- void *P = reinterpret_cast<void *>(Base);
- EXPECT_NE(std::find(V->begin(), V->end(), P), V->end());
- },
- reinterpret_cast<void *>(&V));
- Allocator->enable();
- while (!V.empty()) {
- Allocator->deallocate(V.back(), Origin);
- V.pop_back();
- }
- }
-
- Allocator->releaseToOS();
- Allocator->printStats();
-}
-
-TEST(ScudoCombinedTest, BasicCombined) {
- testAllocator<scudo::DefaultConfig>();
-#if SCUDO_WORDSIZE == 64U
- testAllocator<scudo::FuchsiaConfig>();
-#endif
- // The following configs should work on all platforms.
- UseQuarantine = true;
- testAllocator<scudo::AndroidConfig>();
- UseQuarantine = false;
- testAllocator<scudo::AndroidSvelteConfig>();
-}
-
-template <typename AllocatorT> static void stressAllocator(AllocatorT *A) {
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- while (!Ready)
- Cv.wait(Lock);
- }
- std::vector<std::pair<void *, scudo::uptr>> V;
- for (scudo::uptr I = 0; I < 256U; I++) {
- const scudo::uptr Size = std::rand() % 4096U;
- void *P = A->allocate(Size, Origin);
- // A region could have ran out of memory, resulting in a null P.
- if (P)
- V.push_back(std::make_pair(P, Size));
- }
- while (!V.empty()) {
- auto Pair = V.back();
- A->deallocate(Pair.first, Origin, Pair.second);
- V.pop_back();
- }
-}
-
-template <class Config> static void testAllocatorThreaded() {
- using AllocatorT = scudo::Allocator<Config>;
- auto Deleter = [](AllocatorT *A) {
- A->unmapTestOnly();
- delete A;
- };
- std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
- Deleter);
- Allocator->reset();
- std::thread Threads[32];
- for (scudo::uptr I = 0; I < ARRAY_SIZE(Threads); I++)
- Threads[I] = std::thread(stressAllocator<AllocatorT>, Allocator.get());
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- Ready = true;
- Cv.notify_all();
- }
- for (auto &T : Threads)
- T.join();
- Allocator->releaseToOS();
-}
-
-TEST(ScudoCombinedTest, ThreadedCombined) {
- testAllocatorThreaded<scudo::DefaultConfig>();
-#if SCUDO_WORDSIZE == 64U
- testAllocatorThreaded<scudo::FuchsiaConfig>();
-#endif
- UseQuarantine = true;
- testAllocatorThreaded<scudo::AndroidConfig>();
- UseQuarantine = false;
- testAllocatorThreaded<scudo::AndroidSvelteConfig>();
-}
-
-struct DeathConfig {
- // Tiny allocator, its Primary only serves chunks of 1024 bytes.
- using DeathSizeClassMap = scudo::SizeClassMap<1U, 10U, 10U, 10U, 1U, 10U>;
- typedef scudo::SizeClassAllocator32<DeathSizeClassMap, 18U> Primary;
- template <class A> using TSDRegistryT = scudo::TSDRegistrySharedT<A, 1U>;
-};
-
-TEST(ScudoCombinedTest, DeathCombined) {
- using AllocatorT = scudo::Allocator<DeathConfig>;
- auto Deleter = [](AllocatorT *A) {
- A->unmapTestOnly();
- delete A;
- };
- std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
- Deleter);
- Allocator->reset();
-
- const scudo::uptr Size = 1000U;
- void *P = Allocator->allocate(Size, Origin);
- EXPECT_NE(P, nullptr);
-
- // Invalid sized deallocation.
- EXPECT_DEATH(Allocator->deallocate(P, Origin, Size + 8U), "");
-
- // Misaligned pointer.
- void *MisalignedP =
- reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(P) | 1U);
- EXPECT_DEATH(Allocator->deallocate(MisalignedP, Origin, Size), "");
- EXPECT_DEATH(Allocator->reallocate(MisalignedP, Size * 2U), "");
-
- // Header corruption.
- scudo::u64 *H =
- reinterpret_cast<scudo::u64 *>(scudo::Chunk::getAtomicHeader(P));
- *H ^= 0x42U;
- EXPECT_DEATH(Allocator->deallocate(P, Origin, Size), "");
- *H ^= 0x420042U;
- EXPECT_DEATH(Allocator->deallocate(P, Origin, Size), "");
- *H ^= 0x420000U;
-
- // Invalid chunk state.
- Allocator->deallocate(P, Origin, Size);
- EXPECT_DEATH(Allocator->deallocate(P, Origin, Size), "");
- EXPECT_DEATH(Allocator->reallocate(P, Size * 2U), "");
- EXPECT_DEATH(Allocator->getUsableSize(P), "");
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/combined_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- combined_test.cc ----------------------------------------*- C++ -*-===//
+//===-- combined_test.cpp ---------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/flags_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc (removed)
@@ -1,119 +0,0 @@
-//===-- flags_test.cc -------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "flags.h"
-#include "flags_parser.h"
-
-#include "gtest/gtest.h"
-
-#include <string.h>
-
-static const char FlagName[] = "flag_name";
-static const char FlagDesc[] = "flag description";
-
-template <typename T>
-static void testFlag(scudo::FlagType Type, T StartValue, const char *Env,
- T FinalValue) {
- scudo::FlagParser Parser;
- T Flag = StartValue;
- Parser.registerFlag(FlagName, FlagDesc, Type, &Flag);
- Parser.parseString(Env);
- EXPECT_EQ(FinalValue, Flag);
- // Reporting unrecognized flags is needed to reset them.
- scudo::reportUnrecognizedFlags();
-}
-
-TEST(ScudoFlagsTest, BooleanFlags) {
- testFlag(scudo::FlagType::FT_bool, false, "flag_name=1", true);
- testFlag(scudo::FlagType::FT_bool, false, "flag_name=yes", true);
- testFlag(scudo::FlagType::FT_bool, false, "flag_name='yes'", true);
- testFlag(scudo::FlagType::FT_bool, false, "flag_name=true", true);
- testFlag(scudo::FlagType::FT_bool, true, "flag_name=0", false);
- testFlag(scudo::FlagType::FT_bool, true, "flag_name=\"0\"", false);
- testFlag(scudo::FlagType::FT_bool, true, "flag_name=no", false);
- testFlag(scudo::FlagType::FT_bool, true, "flag_name=false", false);
- testFlag(scudo::FlagType::FT_bool, true, "flag_name='false'", false);
-}
-
-TEST(ScudoFlagsDeathTest, BooleanFlags) {
- EXPECT_DEATH(testFlag(scudo::FlagType::FT_bool, false, "flag_name", true),
- "expected '='");
- EXPECT_DEATH(testFlag(scudo::FlagType::FT_bool, false, "flag_name=", true),
- "invalid value for bool option: ''");
- EXPECT_DEATH(testFlag(scudo::FlagType::FT_bool, false, "flag_name=2", true),
- "invalid value for bool option: '2'");
- EXPECT_DEATH(testFlag(scudo::FlagType::FT_bool, false, "flag_name=-1", true),
- "invalid value for bool option: '-1'");
- EXPECT_DEATH(testFlag(scudo::FlagType::FT_bool, false, "flag_name=on", true),
- "invalid value for bool option: 'on'");
-}
-
-TEST(ScudoFlagsTest, IntFlags) {
- testFlag(scudo::FlagType::FT_int, -11, nullptr, -11);
- testFlag(scudo::FlagType::FT_int, -11, "flag_name=0", 0);
- testFlag(scudo::FlagType::FT_int, -11, "flag_name='0'", 0);
- testFlag(scudo::FlagType::FT_int, -11, "flag_name=42", 42);
- testFlag(scudo::FlagType::FT_int, -11, "flag_name=-42", -42);
- testFlag(scudo::FlagType::FT_int, -11, "flag_name=\"-42\"", -42);
-
- // Unrecognized flags are ignored.
- testFlag(scudo::FlagType::FT_int, -11, "--flag_name=42", -11);
- testFlag(scudo::FlagType::FT_int, -11, "zzzzzzz=42", -11);
-}
-
-TEST(ScudoFlagsDeathTest, IntFlags) {
- EXPECT_DEATH(testFlag(scudo::FlagType::FT_int, -11, "flag_name", 0),
- "expected '='");
- EXPECT_DEATH(testFlag(scudo::FlagType::FT_int, -11, "flag_name=42U", 0),
- "invalid value for int option");
-}
-
-static void testTwoFlags(const char *Env, bool ExpectedFlag1,
- const int ExpectedFlag2, const char *Name1 = "flag1",
- const char *Name2 = "flag2") {
- scudo::FlagParser Parser;
- bool Flag1 = !ExpectedFlag1;
- int Flag2;
- Parser.registerFlag(Name1, FlagDesc, scudo::FlagType::FT_bool, &Flag1);
- Parser.registerFlag(Name2, FlagDesc, scudo::FlagType::FT_int, &Flag2);
- Parser.parseString(Env);
- EXPECT_EQ(ExpectedFlag1, Flag1);
- EXPECT_EQ(Flag2, ExpectedFlag2);
- // Reporting unrecognized flags is needed to reset them.
- scudo::reportUnrecognizedFlags();
-}
-
-TEST(ScudoFlagsTest, MultipleFlags) {
- testTwoFlags("flag1=1 flag2=42", true, 42);
- testTwoFlags("flag2=-1 flag1=0", false, -1);
- testTwoFlags("flag1=false:flag2=1337", false, 1337);
- testTwoFlags("flag2=42:flag1=yes", true, 42);
- testTwoFlags("flag2=42\nflag1=yes", true, 42);
- testTwoFlags("flag2=42\r\nflag1=yes", true, 42);
- testTwoFlags("flag2=42\tflag1=yes", true, 42);
-}
-
-TEST(ScudoFlagsTest, CommonSuffixFlags) {
- testTwoFlags("flag=1 other_flag=42", true, 42, "flag", "other_flag");
- testTwoFlags("other_flag=42 flag=1", true, 42, "flag", "other_flag");
-}
-
-TEST(ScudoFlagsTest, AllocatorFlags) {
- scudo::FlagParser Parser;
- scudo::Flags Flags;
- scudo::registerFlags(&Parser, &Flags);
- Flags.setDefaults();
- Flags.dealloc_type_mismatch = false;
- Flags.delete_size_mismatch = false;
- Flags.quarantine_max_chunk_size = 1024;
- Parser.parseString("dealloc_type_mismatch=true:delete_size_mismatch=true:"
- "quarantine_max_chunk_size=2048");
- EXPECT_TRUE(Flags.dealloc_type_mismatch);
- EXPECT_TRUE(Flags.delete_size_mismatch);
- EXPECT_EQ(2048, Flags.quarantine_max_chunk_size);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/flags_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- flags_test.cc -------------------------------------------*- C++ -*-===//
+//===-- flags_test.cpp ------------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/list_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc (removed)
@@ -1,185 +0,0 @@
-//===-- list_test.cc --------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "scudo/standalone/list.h"
-#include "gtest/gtest.h"
-
-struct ListItem {
- ListItem *Next;
-};
-
-typedef scudo::IntrusiveList<ListItem> List;
-
-static List StaticList;
-
-static void setList(List *L, ListItem *X = nullptr, ListItem *Y = nullptr,
- ListItem *Z = nullptr) {
- 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 = nullptr,
- ListItem *I3 = nullptr, ListItem *I4 = nullptr,
- ListItem *I5 = nullptr, ListItem *I6 = nullptr) {
- if (I1) {
- EXPECT_EQ(L->front(), I1);
- L->pop_front();
- }
- if (I2) {
- EXPECT_EQ(L->front(), I2);
- L->pop_front();
- }
- if (I3) {
- EXPECT_EQ(L->front(), I3);
- L->pop_front();
- }
- if (I4) {
- EXPECT_EQ(L->front(), I4);
- L->pop_front();
- }
- if (I5) {
- EXPECT_EQ(L->front(), I5);
- L->pop_front();
- }
- if (I6) {
- EXPECT_EQ(L->front(), I6);
- L->pop_front();
- }
- EXPECT_TRUE(L->empty());
-}
-
-TEST(ScudoListTest, IntrusiveList) {
- ListItem Items[6];
- EXPECT_EQ(StaticList.size(), 0U);
-
- 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];
-
- EXPECT_EQ(L.size(), 0U);
- L.push_back(X);
- EXPECT_EQ(L.size(), 1U);
- EXPECT_EQ(L.back(), X);
- EXPECT_EQ(L.front(), X);
- L.pop_front();
- EXPECT_TRUE(L.empty());
- L.checkConsistency();
-
- L.push_front(X);
- EXPECT_EQ(L.size(), 1U);
- EXPECT_EQ(L.back(), X);
- EXPECT_EQ(L.front(), X);
- L.pop_front();
- EXPECT_TRUE(L.empty());
- L.checkConsistency();
-
- L.push_front(X);
- L.push_front(Y);
- L.push_front(Z);
- EXPECT_EQ(L.size(), 3U);
- EXPECT_EQ(L.front(), Z);
- EXPECT_EQ(L.back(), X);
- L.checkConsistency();
-
- L.pop_front();
- EXPECT_EQ(L.size(), 2U);
- EXPECT_EQ(L.front(), Y);
- EXPECT_EQ(L.back(), X);
- L.pop_front();
- L.pop_front();
- EXPECT_TRUE(L.empty());
- L.checkConsistency();
-
- L.push_back(X);
- L.push_back(Y);
- L.push_back(Z);
- EXPECT_EQ(L.size(), 3U);
- EXPECT_EQ(L.front(), X);
- EXPECT_EQ(L.back(), Z);
- L.checkConsistency();
-
- L.pop_front();
- EXPECT_EQ(L.size(), 2U);
- EXPECT_EQ(L.front(), Y);
- EXPECT_EQ(L.back(), Z);
- L.pop_front();
- L.pop_front();
- EXPECT_TRUE(L.empty());
- L.checkConsistency();
-
- L.push_back(X);
- L.push_back(Y);
- L.push_back(Z);
- L.extract(X, Y);
- EXPECT_EQ(L.size(), 2U);
- EXPECT_EQ(L.front(), X);
- EXPECT_EQ(L.back(), Z);
- L.checkConsistency();
- L.extract(X, Z);
- EXPECT_EQ(L.size(), 1U);
- EXPECT_EQ(L.front(), X);
- EXPECT_EQ(L.back(), X);
- L.checkConsistency();
- L.pop_front();
- EXPECT_TRUE(L.empty());
-
- List L1, L2;
- L1.clear();
- L2.clear();
-
- L1.append_front(&L2);
- EXPECT_TRUE(L1.empty());
- EXPECT_TRUE(L2.empty());
-
- L1.append_back(&L2);
- EXPECT_TRUE(L1.empty());
- EXPECT_TRUE(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);
- EXPECT_TRUE(L2.empty());
-
- setList(&L1, X, Y);
- setList(&L2);
- L1.append_front(&L2);
- checkList(&L1, X, Y);
- EXPECT_TRUE(L2.empty());
-}
-
-TEST(ScudoListTest, IntrusiveListAppendEmpty) {
- ListItem I;
- List L;
- L.clear();
- L.push_back(&I);
- List L2;
- L2.clear();
- L.append_back(&L2);
- EXPECT_EQ(L.back(), &I);
- EXPECT_EQ(L.front(), &I);
- EXPECT_EQ(L.size(), 1U);
- L.append_front(&L2);
- EXPECT_EQ(L.back(), &I);
- EXPECT_EQ(L.front(), &I);
- EXPECT_EQ(L.size(), 1U);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/list_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- list_test.cc --------------------------------------------*- C++ -*-===//
+//===-- list_test.cpp -------------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/map_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc (removed)
@@ -1,71 +0,0 @@
-//===-- map_test.cc ---------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "common.h"
-
-#include "gtest/gtest.h"
-
-#include <string.h>
-#include <unistd.h>
-
-static const char *MappingName = "scudo:test";
-
-TEST(ScudoMapTest, PageSize) {
- EXPECT_EQ(scudo::getPageSizeCached(),
- static_cast<scudo::uptr>(getpagesize()));
-}
-
-TEST(ScudoMapTest, MapNoAccessUnmap) {
- const scudo::uptr Size = 4 * scudo::getPageSizeCached();
- scudo::MapPlatformData Data = {};
- void *P = scudo::map(nullptr, Size, MappingName, MAP_NOACCESS, &Data);
- EXPECT_NE(P, nullptr);
- EXPECT_DEATH(memset(P, 0xaa, Size), "");
- scudo::unmap(P, Size, UNMAP_ALL, &Data);
-}
-
-TEST(ScudoMapTest, MapUnmap) {
- const scudo::uptr Size = 4 * scudo::getPageSizeCached();
- scudo::MapPlatformData Data = {};
- void *P = scudo::map(nullptr, Size, MappingName, 0, &Data);
- EXPECT_NE(P, nullptr);
- memset(P, 0xaa, Size);
- scudo::unmap(P, Size, 0, &Data);
- EXPECT_DEATH(memset(P, 0xbb, Size), "");
-}
-
-TEST(ScudoMapTest, MapWithGuardUnmap) {
- const scudo::uptr PageSize = scudo::getPageSizeCached();
- const scudo::uptr Size = 4 * PageSize;
- scudo::MapPlatformData Data = {};
- void *P = scudo::map(nullptr, Size + 2 * PageSize, MappingName, MAP_NOACCESS,
- &Data);
- EXPECT_NE(P, nullptr);
- void *Q =
- reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(P) + PageSize);
- EXPECT_EQ(scudo::map(Q, Size, MappingName, 0, &Data), Q);
- memset(Q, 0xaa, Size);
- EXPECT_DEATH(memset(Q, 0xaa, Size + 1), "");
- scudo::unmap(P, Size + 2 * PageSize, UNMAP_ALL, &Data);
-}
-
-TEST(ScudoMapTest, MapGrowUnmap) {
- const scudo::uptr PageSize = scudo::getPageSizeCached();
- const scudo::uptr Size = 4 * PageSize;
- scudo::MapPlatformData Data = {};
- void *P = scudo::map(nullptr, Size, MappingName, MAP_NOACCESS, &Data);
- EXPECT_NE(P, nullptr);
- void *Q =
- reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(P) + PageSize);
- EXPECT_EQ(scudo::map(Q, PageSize, MappingName, 0, &Data), Q);
- memset(Q, 0xaa, PageSize);
- Q = reinterpret_cast<void *>(reinterpret_cast<scudo::uptr>(Q) + PageSize);
- EXPECT_EQ(scudo::map(Q, PageSize, MappingName, 0, &Data), Q);
- memset(Q, 0xbb, PageSize);
- scudo::unmap(P, Size, UNMAP_ALL, &Data);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/map_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- map_test.cc ---------------------------------------------*- C++ -*-===//
+//===-- map_test.cpp --------------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/mutex_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc (removed)
@@ -1,102 +0,0 @@
-//===-- mutex_test.cc -------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "mutex.h"
-
-#include "gtest/gtest.h"
-
-#include <string.h>
-
-class TestData {
-public:
- explicit TestData(scudo::HybridMutex &M) : Mutex(M) {
- for (scudo::u32 I = 0; I < Size; I++)
- Data[I] = 0;
- }
-
- void write() {
- scudo::ScopedLock L(Mutex);
- T V0 = Data[0];
- for (scudo::u32 I = 0; I < Size; I++) {
- EXPECT_EQ(Data[I], V0);
- Data[I]++;
- }
- }
-
- void tryWrite() {
- if (!Mutex.tryLock())
- return;
- T V0 = Data[0];
- for (scudo::u32 I = 0; I < Size; I++) {
- EXPECT_EQ(Data[I], V0);
- Data[I]++;
- }
- Mutex.unlock();
- }
-
- void backoff() {
- volatile T LocalData[Size] = {};
- for (scudo::u32 I = 0; I < Size; I++) {
- LocalData[I]++;
- EXPECT_EQ(LocalData[I], 1U);
- }
- }
-
-private:
- static const scudo::u32 Size = 64U;
- typedef scudo::u64 T;
- scudo::HybridMutex &Mutex;
- ALIGNED(SCUDO_CACHE_LINE_SIZE) T Data[Size];
-};
-
-const scudo::u32 NumberOfThreads = 8;
-#if SCUDO_DEBUG
-const scudo::u32 NumberOfIterations = 4 * 1024;
-#else
-const scudo::u32 NumberOfIterations = 16 * 1024;
-#endif
-
-static void *lockThread(void *Param) {
- TestData *Data = reinterpret_cast<TestData *>(Param);
- for (scudo::u32 I = 0; I < NumberOfIterations; I++) {
- Data->write();
- Data->backoff();
- }
- return 0;
-}
-
-static void *tryThread(void *Param) {
- TestData *Data = reinterpret_cast<TestData *>(Param);
- for (scudo::u32 I = 0; I < NumberOfIterations; I++) {
- Data->tryWrite();
- Data->backoff();
- }
- return 0;
-}
-
-TEST(ScudoMutexTest, Mutex) {
- scudo::HybridMutex M;
- M.init();
- TestData Data(M);
- pthread_t Threads[NumberOfThreads];
- for (scudo::u32 I = 0; I < NumberOfThreads; I++)
- pthread_create(&Threads[I], 0, lockThread, &Data);
- for (scudo::u32 I = 0; I < NumberOfThreads; I++)
- pthread_join(Threads[I], 0);
-}
-
-TEST(ScudoMutexTest, MutexTry) {
- scudo::HybridMutex M;
- M.init();
- TestData Data(M);
- pthread_t Threads[NumberOfThreads];
- for (scudo::u32 I = 0; I < NumberOfThreads; I++)
- pthread_create(&Threads[I], 0, tryThread, &Data);
- for (scudo::u32 I = 0; I < NumberOfThreads; I++)
- pthread_join(Threads[I], 0);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/mutex_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- mutex_test.cc -------------------------------------------*- C++ -*-===//
+//===-- mutex_test.cpp ------------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/primary_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc (removed)
@@ -1,190 +0,0 @@
-//===-- primary_test.cc -----------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "primary32.h"
-#include "primary64.h"
-#include "size_class_map.h"
-
-#include "gtest/gtest.h"
-
-#include <condition_variable>
-#include <mutex>
-#include <thread>
-
-// Note that with small enough regions, the SizeClassAllocator64 also works on
-// 32-bit architectures. It's not something we want to encourage, but we still
-// should ensure the tests pass.
-
-template <typename Primary> static void testPrimary() {
- const scudo::uptr NumberOfAllocations = 32U;
- auto Deleter = [](Primary *P) {
- P->unmapTestOnly();
- delete P;
- };
- std::unique_ptr<Primary, decltype(Deleter)> Allocator(new Primary, Deleter);
- Allocator->init(/*ReleaseToOsInterval=*/-1);
- typename Primary::CacheT Cache;
- Cache.init(nullptr, Allocator.get());
- for (scudo::uptr I = 0; I <= 16U; I++) {
- const scudo::uptr Size = 1UL << I;
- if (!Primary::canAllocate(Size))
- continue;
- const scudo::uptr ClassId = Primary::SizeClassMap::getClassIdBySize(Size);
- void *Pointers[NumberOfAllocations];
- for (scudo::uptr J = 0; J < NumberOfAllocations; J++) {
- void *P = Cache.allocate(ClassId);
- memset(P, 'B', Size);
- Pointers[J] = P;
- }
- for (scudo::uptr J = 0; J < NumberOfAllocations; J++)
- Cache.deallocate(ClassId, Pointers[J]);
- }
- Cache.destroy(nullptr);
- Allocator->releaseToOS();
- Allocator->printStats();
-}
-
-TEST(ScudoPrimaryTest, BasicPrimary) {
- using SizeClassMap = scudo::DefaultSizeClassMap;
- testPrimary<scudo::SizeClassAllocator32<SizeClassMap, 18U>>();
- testPrimary<scudo::SizeClassAllocator64<SizeClassMap, 24U>>();
-}
-
-// The 64-bit SizeClassAllocator can be easily OOM'd with small region sizes.
-// For the 32-bit one, it requires actually exhausting memory, so we skip it.
-TEST(ScudoPrimaryTest, Primary64OOM) {
- using Primary = scudo::SizeClassAllocator64<scudo::DefaultSizeClassMap, 20U>;
- using TransferBatch = Primary::CacheT::TransferBatch;
- Primary Allocator;
- Allocator.init(/*ReleaseToOsInterval=*/-1);
- typename Primary::CacheT Cache;
- scudo::GlobalStats Stats;
- Stats.init();
- Cache.init(&Stats, &Allocator);
- bool AllocationFailed = false;
- std::vector<TransferBatch *> Batches;
- const scudo::uptr ClassId = Primary::SizeClassMap::LargestClassId;
- const scudo::uptr Size = Primary::getSizeByClassId(ClassId);
- for (scudo::uptr I = 0; I < 10000U; I++) {
- TransferBatch *B = Allocator.popBatch(&Cache, ClassId);
- if (!B) {
- AllocationFailed = true;
- break;
- }
- for (scudo::uptr J = 0; J < B->getCount(); J++)
- memset(B->get(J), 'B', Size);
- Batches.push_back(B);
- }
- while (!Batches.empty()) {
- Allocator.pushBatch(ClassId, Batches.back());
- Batches.pop_back();
- }
- Cache.destroy(nullptr);
- Allocator.releaseToOS();
- Allocator.printStats();
- EXPECT_EQ(AllocationFailed, true);
- Allocator.unmapTestOnly();
-}
-
-template <typename Primary> static void testIteratePrimary() {
- auto Deleter = [](Primary *P) {
- P->unmapTestOnly();
- delete P;
- };
- std::unique_ptr<Primary, decltype(Deleter)> Allocator(new Primary, Deleter);
- Allocator->init(/*ReleaseToOsInterval=*/-1);
- typename Primary::CacheT Cache;
- Cache.init(nullptr, Allocator.get());
- std::vector<std::pair<scudo::uptr, void *>> V;
- for (scudo::uptr I = 0; I < 64U; I++) {
- const scudo::uptr Size = std::rand() % Primary::SizeClassMap::MaxSize;
- const scudo::uptr ClassId = Primary::SizeClassMap::getClassIdBySize(Size);
- void *P = Cache.allocate(ClassId);
- V.push_back(std::make_pair(ClassId, P));
- }
- scudo::uptr Found = 0;
- auto Lambda = [V, &Found](scudo::uptr Block) {
- for (const auto &Pair : V) {
- if (Pair.second == reinterpret_cast<void *>(Block))
- Found++;
- }
- };
- Allocator->disable();
- Allocator->iterateOverBlocks(Lambda);
- Allocator->enable();
- EXPECT_EQ(Found, V.size());
- while (!V.empty()) {
- auto Pair = V.back();
- Cache.deallocate(Pair.first, Pair.second);
- V.pop_back();
- }
- Cache.destroy(nullptr);
- Allocator->releaseToOS();
- Allocator->printStats();
-}
-
-TEST(ScudoPrimaryTest, PrimaryIterate) {
- using SizeClassMap = scudo::DefaultSizeClassMap;
- testIteratePrimary<scudo::SizeClassAllocator32<SizeClassMap, 18U>>();
- testIteratePrimary<scudo::SizeClassAllocator64<SizeClassMap, 24U>>();
-}
-
-static std::mutex Mutex;
-static std::condition_variable Cv;
-static bool Ready = false;
-
-template <typename Primary> static void performAllocations(Primary *Allocator) {
- static THREADLOCAL typename Primary::CacheT Cache;
- Cache.init(nullptr, Allocator);
- std::vector<std::pair<scudo::uptr, void *>> V;
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- while (!Ready)
- Cv.wait(Lock);
- }
- for (scudo::uptr I = 0; I < 256U; I++) {
- const scudo::uptr Size = std::rand() % Primary::SizeClassMap::MaxSize / 4;
- const scudo::uptr ClassId = Primary::SizeClassMap::getClassIdBySize(Size);
- void *P = Cache.allocate(ClassId);
- if (P)
- V.push_back(std::make_pair(ClassId, P));
- }
- while (!V.empty()) {
- auto Pair = V.back();
- Cache.deallocate(Pair.first, Pair.second);
- V.pop_back();
- }
- Cache.destroy(nullptr);
-}
-
-template <typename Primary> static void testPrimaryThreaded() {
- auto Deleter = [](Primary *P) {
- P->unmapTestOnly();
- delete P;
- };
- std::unique_ptr<Primary, decltype(Deleter)> Allocator(new Primary, Deleter);
- Allocator->init(/*ReleaseToOsInterval=*/-1);
- std::thread Threads[32];
- for (scudo::uptr I = 0; I < ARRAY_SIZE(Threads); I++)
- Threads[I] = std::thread(performAllocations<Primary>, Allocator.get());
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- Ready = true;
- Cv.notify_all();
- }
- for (auto &T : Threads)
- T.join();
- Allocator->releaseToOS();
- Allocator->printStats();
-}
-
-TEST(ScudoPrimaryTest, PrimaryThreaded) {
- using SizeClassMap = scudo::SvelteSizeClassMap;
- testPrimaryThreaded<scudo::SizeClassAllocator32<SizeClassMap, 18U>>();
- testPrimaryThreaded<scudo::SizeClassAllocator64<SizeClassMap, 24U>>();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/primary_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- primary_test.cc -----------------------------------------*- C++ -*-===//
+//===-- primary_test.cpp ----------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/quarantine_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc (removed)
@@ -1,240 +0,0 @@
-//===-- quarantine_test.cc --------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "quarantine.h"
-
-#include "gtest/gtest.h"
-
-#include <stdlib.h>
-
-static void *FakePtr = reinterpret_cast<void *>(0xFA83FA83);
-static const scudo::uptr BlockSize = 8UL;
-static const scudo::uptr LargeBlockSize = 16384UL;
-
-struct QuarantineCallback {
- void recycle(void *P) { EXPECT_EQ(P, FakePtr); }
- void *allocate(scudo::uptr Size) { return malloc(Size); }
- void deallocate(void *P) { free(P); }
-};
-
-typedef scudo::GlobalQuarantine<QuarantineCallback, void> QuarantineT;
-typedef typename QuarantineT::CacheT CacheT;
-
-static QuarantineCallback Cb;
-
-static void deallocateCache(CacheT *Cache) {
- while (scudo::QuarantineBatch *Batch = Cache->dequeueBatch())
- Cb.deallocate(Batch);
-}
-
-TEST(ScudoQuarantineTest, QuarantineBatchMerge) {
- // Verify the trivial case.
- scudo::QuarantineBatch Into;
- Into.init(FakePtr, 4UL);
- scudo::QuarantineBatch From;
- From.init(FakePtr, 8UL);
-
- Into.merge(&From);
-
- EXPECT_EQ(Into.Count, 2UL);
- EXPECT_EQ(Into.Batch[0], FakePtr);
- EXPECT_EQ(Into.Batch[1], FakePtr);
- EXPECT_EQ(Into.Size, 12UL + sizeof(scudo::QuarantineBatch));
- EXPECT_EQ(Into.getQuarantinedSize(), 12UL);
-
- EXPECT_EQ(From.Count, 0UL);
- EXPECT_EQ(From.Size, sizeof(scudo::QuarantineBatch));
- EXPECT_EQ(From.getQuarantinedSize(), 0UL);
-
- // Merge the batch to the limit.
- for (scudo::uptr I = 2; I < scudo::QuarantineBatch::MaxCount; ++I)
- From.push_back(FakePtr, 8UL);
- EXPECT_TRUE(Into.Count + From.Count == scudo::QuarantineBatch::MaxCount);
- EXPECT_TRUE(Into.canMerge(&From));
-
- Into.merge(&From);
- EXPECT_TRUE(Into.Count == scudo::QuarantineBatch::MaxCount);
-
- // No more space, not even for one element.
- From.init(FakePtr, 8UL);
-
- EXPECT_FALSE(Into.canMerge(&From));
-}
-
-TEST(ScudoQuarantineTest, QuarantineCacheMergeBatchesEmpty) {
- CacheT Cache;
- CacheT ToDeallocate;
- Cache.init();
- ToDeallocate.init();
- Cache.mergeBatches(&ToDeallocate);
-
- EXPECT_EQ(ToDeallocate.getSize(), 0UL);
- EXPECT_EQ(ToDeallocate.dequeueBatch(), nullptr);
-}
-
-TEST(SanitizerCommon, QuarantineCacheMergeBatchesOneBatch) {
- CacheT Cache;
- Cache.init();
- Cache.enqueue(Cb, FakePtr, BlockSize);
- EXPECT_EQ(BlockSize + sizeof(scudo::QuarantineBatch), Cache.getSize());
-
- CacheT ToDeallocate;
- ToDeallocate.init();
- Cache.mergeBatches(&ToDeallocate);
-
- // Nothing to merge, nothing to deallocate.
- EXPECT_EQ(BlockSize + sizeof(scudo::QuarantineBatch), Cache.getSize());
-
- EXPECT_EQ(ToDeallocate.getSize(), 0UL);
- EXPECT_EQ(ToDeallocate.dequeueBatch(), nullptr);
-
- deallocateCache(&Cache);
-}
-
-TEST(ScudoQuarantineTest, QuarantineCacheMergeBatchesSmallBatches) {
- // Make a Cache with two batches small enough to merge.
- CacheT From;
- From.init();
- From.enqueue(Cb, FakePtr, BlockSize);
- CacheT Cache;
- Cache.init();
- Cache.enqueue(Cb, FakePtr, BlockSize);
-
- Cache.transfer(&From);
- EXPECT_EQ(BlockSize * 2 + sizeof(scudo::QuarantineBatch) * 2,
- Cache.getSize());
-
- CacheT ToDeallocate;
- ToDeallocate.init();
- Cache.mergeBatches(&ToDeallocate);
-
- // Batches merged, one batch to deallocate.
- EXPECT_EQ(BlockSize * 2 + sizeof(scudo::QuarantineBatch), Cache.getSize());
- EXPECT_EQ(ToDeallocate.getSize(), sizeof(scudo::QuarantineBatch));
-
- deallocateCache(&Cache);
- deallocateCache(&ToDeallocate);
-}
-
-TEST(ScudoQuarantineTest, QuarantineCacheMergeBatchesTooBigToMerge) {
- const scudo::uptr NumBlocks = scudo::QuarantineBatch::MaxCount - 1;
-
- // Make a Cache with two batches small enough to merge.
- CacheT From;
- CacheT Cache;
- From.init();
- Cache.init();
- for (scudo::uptr I = 0; I < NumBlocks; ++I) {
- From.enqueue(Cb, FakePtr, BlockSize);
- Cache.enqueue(Cb, FakePtr, BlockSize);
- }
- Cache.transfer(&From);
- EXPECT_EQ(BlockSize * NumBlocks * 2 + sizeof(scudo::QuarantineBatch) * 2,
- Cache.getSize());
-
- CacheT ToDeallocate;
- ToDeallocate.init();
- Cache.mergeBatches(&ToDeallocate);
-
- // Batches cannot be merged.
- EXPECT_EQ(BlockSize * NumBlocks * 2 + sizeof(scudo::QuarantineBatch) * 2,
- Cache.getSize());
- EXPECT_EQ(ToDeallocate.getSize(), 0UL);
-
- deallocateCache(&Cache);
-}
-
-TEST(ScudoQuarantineTest, QuarantineCacheMergeBatchesALotOfBatches) {
- const scudo::uptr NumBatchesAfterMerge = 3;
- const scudo::uptr NumBlocks =
- scudo::QuarantineBatch::MaxCount * NumBatchesAfterMerge;
- const scudo::uptr NumBatchesBeforeMerge = NumBlocks;
-
- // Make a Cache with many small batches.
- CacheT Cache;
- Cache.init();
- for (scudo::uptr I = 0; I < NumBlocks; ++I) {
- CacheT From;
- From.init();
- From.enqueue(Cb, FakePtr, BlockSize);
- Cache.transfer(&From);
- }
-
- EXPECT_EQ(BlockSize * NumBlocks +
- sizeof(scudo::QuarantineBatch) * NumBatchesBeforeMerge,
- Cache.getSize());
-
- CacheT ToDeallocate;
- ToDeallocate.init();
- Cache.mergeBatches(&ToDeallocate);
-
- // All blocks should fit Into 3 batches.
- EXPECT_EQ(BlockSize * NumBlocks +
- sizeof(scudo::QuarantineBatch) * NumBatchesAfterMerge,
- Cache.getSize());
-
- EXPECT_EQ(ToDeallocate.getSize(),
- sizeof(scudo::QuarantineBatch) *
- (NumBatchesBeforeMerge - NumBatchesAfterMerge));
-
- deallocateCache(&Cache);
- deallocateCache(&ToDeallocate);
-}
-
-static const scudo::uptr MaxQuarantineSize = 1024UL << 10; // 1MB
-static const scudo::uptr MaxCacheSize = 256UL << 10; // 256KB
-
-TEST(ScudoQuarantineTest, GlobalQuarantine) {
- QuarantineT Quarantine;
- CacheT Cache;
- Cache.init();
- Quarantine.init(MaxQuarantineSize, MaxCacheSize);
- EXPECT_EQ(Quarantine.getMaxSize(), MaxQuarantineSize);
- EXPECT_EQ(Quarantine.getCacheSize(), MaxCacheSize);
-
- bool DrainOccurred = false;
- scudo::uptr CacheSize = Cache.getSize();
- EXPECT_EQ(Cache.getSize(), 0UL);
- // We quarantine enough blocks that a drain has to occur. Verify this by
- // looking for a decrease of the size of the cache.
- for (scudo::uptr I = 0; I < 128UL; I++) {
- Quarantine.put(&Cache, Cb, FakePtr, LargeBlockSize);
- if (!DrainOccurred && Cache.getSize() < CacheSize)
- DrainOccurred = true;
- CacheSize = Cache.getSize();
- }
- EXPECT_TRUE(DrainOccurred);
-
- Quarantine.drainAndRecycle(&Cache, Cb);
- EXPECT_EQ(Cache.getSize(), 0UL);
-
- Quarantine.printStats();
-}
-
-void *populateQuarantine(void *Param) {
- CacheT Cache;
- Cache.init();
- QuarantineT *Quarantine = reinterpret_cast<QuarantineT *>(Param);
- for (scudo::uptr I = 0; I < 128UL; I++)
- Quarantine->put(&Cache, Cb, FakePtr, LargeBlockSize);
- return 0;
-}
-
-TEST(ScudoQuarantineTest, ThreadedGlobalQuarantine) {
- QuarantineT Quarantine;
- Quarantine.init(MaxQuarantineSize, MaxCacheSize);
-
- const scudo::uptr NumberOfThreads = 32U;
- pthread_t T[NumberOfThreads];
- for (scudo::uptr I = 0; I < NumberOfThreads; I++)
- pthread_create(&T[I], 0, populateQuarantine, &Quarantine);
- for (scudo::uptr I = 0; I < NumberOfThreads; I++)
- pthread_join(T[I], 0);
-
- Quarantine.printStats();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/quarantine_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- quarantine_test.cc --------------------------------------*- C++ -*-===//
+//===-- quarantine_test.cpp -------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/release_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc (removed)
@@ -1,260 +0,0 @@
-//===-- release_test.cc -----------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "list.h"
-#include "release.h"
-#include "size_class_map.h"
-
-#include "gtest/gtest.h"
-
-#include <string.h>
-
-#include <algorithm>
-#include <random>
-
-TEST(ScudoReleaseTest, PackedCounterArray) {
- for (scudo::uptr I = 0; I < SCUDO_WORDSIZE; I++) {
- // Various valid counter's max values packed into one word.
- scudo::PackedCounterArray Counters2N(1, 1UL << I);
- EXPECT_EQ(sizeof(scudo::uptr), Counters2N.getBufferSize());
- // Check the "all bit set" values too.
- scudo::PackedCounterArray Counters2N1_1(1, ~0UL >> I);
- EXPECT_EQ(sizeof(scudo::uptr), Counters2N1_1.getBufferSize());
- // Verify the packing ratio, the counter is Expected to be packed into the
- // closest power of 2 bits.
- scudo::PackedCounterArray Counters(SCUDO_WORDSIZE, 1UL << I);
- EXPECT_EQ(sizeof(scudo::uptr) * scudo::roundUpToPowerOfTwo(I + 1),
- Counters.getBufferSize());
- }
-
- // Go through 1, 2, 4, 8, .. {32,64} bits per counter.
- for (scudo::uptr I = 0; (SCUDO_WORDSIZE >> I) != 0; I++) {
- // Make sure counters request one memory page for the buffer.
- const scudo::uptr NumCounters =
- (scudo::getPageSizeCached() / 8) * (SCUDO_WORDSIZE >> I);
- scudo::PackedCounterArray Counters(NumCounters, 1UL << ((1UL << I) - 1));
- Counters.inc(0);
- for (scudo::uptr C = 1; C < NumCounters - 1; C++) {
- EXPECT_EQ(0UL, Counters.get(C));
- Counters.inc(C);
- EXPECT_EQ(1UL, Counters.get(C - 1));
- }
- EXPECT_EQ(0UL, Counters.get(NumCounters - 1));
- Counters.inc(NumCounters - 1);
- if (I > 0) {
- Counters.incRange(0, NumCounters - 1);
- for (scudo::uptr C = 0; C < NumCounters; C++)
- EXPECT_EQ(2UL, Counters.get(C));
- }
- }
-}
-
-class StringRangeRecorder {
-public:
- std::string ReportedPages;
-
- StringRangeRecorder()
- : PageSizeScaledLog(scudo::getLog2(scudo::getPageSizeCached())) {}
-
- void releasePageRangeToOS(scudo::uptr From, scudo::uptr To) {
- From >>= PageSizeScaledLog;
- To >>= PageSizeScaledLog;
- EXPECT_LT(From, To);
- if (!ReportedPages.empty())
- EXPECT_LT(LastPageReported, From);
- ReportedPages.append(From - LastPageReported, '.');
- ReportedPages.append(To - From, 'x');
- LastPageReported = To;
- }
-
-private:
- const scudo::uptr PageSizeScaledLog;
- scudo::uptr LastPageReported = 0;
-};
-
-TEST(ScudoReleaseTest, FreePagesRangeTracker) {
- // 'x' denotes a page to be released, '.' denotes a page to be kept around.
- const char *TestCases[] = {
- "",
- ".",
- "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",
- };
- typedef scudo::FreePagesRangeTracker<StringRangeRecorder> RangeTracker;
-
- for (auto TestCase : TestCases) {
- StringRangeRecorder Recorder;
- RangeTracker Tracker(&Recorder);
- for (scudo::uptr I = 0; TestCase[I] != 0; I++)
- Tracker.processNextPage(TestCase[I] == 'x');
- Tracker.finish();
- // Strip trailing '.'-pages before comparing the results as they are not
- // going to be reported to range_recorder anyway.
- const char *LastX = strrchr(TestCase, 'x');
- std::string Expected(TestCase,
- LastX == nullptr ? 0 : (LastX - TestCase + 1));
- EXPECT_STREQ(Expected.c_str(), Recorder.ReportedPages.c_str());
- }
-}
-
-class ReleasedPagesRecorder {
-public:
- std::set<scudo::uptr> ReportedPages;
-
- void releasePageRangeToOS(scudo::uptr From, scudo::uptr To) {
- const scudo::uptr PageSize = scudo::getPageSizeCached();
- for (scudo::uptr I = From; I < To; I += PageSize)
- ReportedPages.insert(I);
- }
-};
-
-// Simplified version of a TransferBatch.
-template <class SizeClassMap> struct FreeBatch {
- static const scudo::u32 MaxCount = SizeClassMap::MaxNumCachedHint;
- void clear() { Count = 0; }
- void add(scudo::uptr P) {
- DCHECK_LT(Count, MaxCount);
- Batch[Count++] = P;
- }
- scudo::u32 getCount() const { return Count; }
- scudo::uptr get(scudo::u32 I) const {
- DCHECK_LE(I, Count);
- return Batch[I];
- }
- FreeBatch *Next;
-
-private:
- scudo::u32 Count;
- scudo::uptr Batch[MaxCount];
-};
-
-template <class SizeClassMap> void testReleaseFreeMemoryToOS() {
- typedef FreeBatch<SizeClassMap> Batch;
- const scudo::uptr AllocatedPagesCount = 1024;
- const scudo::uptr PageSize = scudo::getPageSizeCached();
- std::mt19937 R;
- scudo::u32 RandState = 42;
-
- for (scudo::uptr I = 1; I <= SizeClassMap::LargestClassId; I++) {
- const scudo::uptr BlockSize = SizeClassMap::getSizeByClassId(I);
- const scudo::uptr MaxBlocks = AllocatedPagesCount * PageSize / BlockSize;
-
- // Generate the random free list.
- std::vector<scudo::uptr> FreeArray;
- bool InFreeRange = false;
- scudo::uptr CurrentRangeEnd = 0;
- for (scudo::uptr I = 0; I < MaxBlocks; I++) {
- if (I == CurrentRangeEnd) {
- InFreeRange = (scudo::getRandomU32(&RandState) & 1U) == 1;
- CurrentRangeEnd += (scudo::getRandomU32(&RandState) & 0x7f) + 1;
- }
- if (InFreeRange)
- FreeArray.push_back(I * BlockSize);
- }
- if (FreeArray.empty())
- continue;
- // Shuffle the array to ensure that the order is irrelevant.
- std::shuffle(FreeArray.begin(), FreeArray.end(), R);
-
- // Build the FreeList from the FreeArray.
- scudo::IntrusiveList<Batch> FreeList;
- FreeList.clear();
- Batch *CurrentBatch = nullptr;
- for (auto const &Block : FreeArray) {
- if (!CurrentBatch) {
- CurrentBatch = new Batch;
- CurrentBatch->clear();
- FreeList.push_back(CurrentBatch);
- }
- CurrentBatch->add(Block);
- if (CurrentBatch->getCount() == Batch::MaxCount)
- CurrentBatch = nullptr;
- }
-
- // Release the memory.
- ReleasedPagesRecorder Recorder;
- releaseFreeMemoryToOS(&FreeList, 0, AllocatedPagesCount, BlockSize,
- &Recorder);
-
- // 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.
- scudo::uptr VerifiedReleasedPages = 0;
- std::set<scudo::uptr> FreeBlocks(FreeArray.begin(), FreeArray.end());
-
- scudo::uptr CurrentBlock = 0;
- InFreeRange = false;
- scudo::uptr CurrentFreeRangeStart = 0;
- for (scudo::uptr I = 0; I <= MaxBlocks; I++) {
- const bool IsFreeBlock =
- FreeBlocks.find(CurrentBlock) != FreeBlocks.end();
- if (IsFreeBlock) {
- if (!InFreeRange) {
- InFreeRange = true;
- CurrentFreeRangeStart = CurrentBlock;
- }
- } else {
- // Verify that this used chunk does not touch any released page.
- const scudo::uptr StartPage = CurrentBlock / PageSize;
- const scudo::uptr EndPage = (CurrentBlock + BlockSize - 1) / PageSize;
- for (scudo::uptr J = StartPage; J <= EndPage; J++) {
- const bool PageReleased = Recorder.ReportedPages.find(J * PageSize) !=
- Recorder.ReportedPages.end();
- EXPECT_EQ(false, PageReleased);
- }
-
- if (InFreeRange) {
- InFreeRange = false;
- // Verify that all entire memory pages covered by this range of free
- // chunks were released.
- scudo::uptr P = scudo::roundUpTo(CurrentFreeRangeStart, PageSize);
- while (P + PageSize <= CurrentBlock) {
- const bool PageReleased =
- Recorder.ReportedPages.find(P) != Recorder.ReportedPages.end();
- EXPECT_EQ(true, PageReleased);
- VerifiedReleasedPages++;
- P += PageSize;
- }
- }
- }
-
- CurrentBlock += BlockSize;
- }
-
- EXPECT_EQ(Recorder.ReportedPages.size(), VerifiedReleasedPages);
-
- while (!FreeList.empty()) {
- CurrentBatch = FreeList.front();
- FreeList.pop_front();
- delete CurrentBatch;
- }
- }
-}
-
-TEST(ScudoReleaseTest, ReleaseFreeMemoryToOSDefault) {
- testReleaseFreeMemoryToOS<scudo::DefaultSizeClassMap>();
-}
-
-TEST(ScudoReleaseTest, ReleaseFreeMemoryToOSAndroid) {
- testReleaseFreeMemoryToOS<scudo::AndroidSizeClassMap>();
-}
-
-TEST(ScudoReleaseTest, ReleaseFreeMemoryToOSSvelte) {
- testReleaseFreeMemoryToOS<scudo::SvelteSizeClassMap>();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/release_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- release_test.cc -----------------------------------------*- C++ -*-===//
+//===-- release_test.cpp ----------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/report_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc (removed)
@@ -1,47 +0,0 @@
-//===-- report_test.cc ------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "scudo/standalone/report.h"
-#include "gtest/gtest.h"
-
-TEST(ScudoReportTest, Generic) {
- void *P = reinterpret_cast<void *>(0x42424242U);
- EXPECT_DEATH(scudo::reportError("TEST123"), "Scudo ERROR.*TEST123");
- EXPECT_DEATH(scudo::reportInvalidFlag("ABC", "DEF"), "Scudo ERROR.*ABC.*DEF");
- EXPECT_DEATH(scudo::reportHeaderCorruption(P), "Scudo ERROR.*42424242");
- EXPECT_DEATH(scudo::reportHeaderRace(P), "Scudo ERROR.*42424242");
- EXPECT_DEATH(scudo::reportSanityCheckError("XYZ"), "Scudo ERROR.*XYZ");
- EXPECT_DEATH(scudo::reportAlignmentTooBig(123, 456), "Scudo ERROR.*123.*456");
- EXPECT_DEATH(scudo::reportAllocationSizeTooBig(123, 456, 789),
- "Scudo ERROR.*123.*456.*789");
- EXPECT_DEATH(scudo::reportOutOfMemory(4242), "Scudo ERROR.*4242");
- EXPECT_DEATH(
- scudo::reportInvalidChunkState(scudo::AllocatorAction::Recycling, P),
- "Scudo ERROR.*recycling.*42424242");
- EXPECT_DEATH(
- scudo::reportInvalidChunkState(scudo::AllocatorAction::Sizing, P),
- "Scudo ERROR.*sizing.*42424242");
- EXPECT_DEATH(
- scudo::reportMisalignedPointer(scudo::AllocatorAction::Deallocating, P),
- "Scudo ERROR.*deallocating.*42424242");
- EXPECT_DEATH(scudo::reportDeallocTypeMismatch(
- scudo::AllocatorAction::Reallocating, P, 0, 1),
- "Scudo ERROR.*reallocating.*42424242");
- EXPECT_DEATH(scudo::reportDeleteSizeMismatch(P, 123, 456),
- "Scudo ERROR.*42424242.*123.*456");
-}
-
-TEST(ScudoReportTest, CSpecific) {
- EXPECT_DEATH(scudo::reportAlignmentNotPowerOfTwo(123), "Scudo ERROR.*123");
- EXPECT_DEATH(scudo::reportCallocOverflow(123, 456), "Scudo ERROR.*123.*456");
- EXPECT_DEATH(scudo::reportInvalidPosixMemalignAlignment(789),
- "Scudo ERROR.*789");
- EXPECT_DEATH(scudo::reportPvallocOverflow(123), "Scudo ERROR.*123");
- EXPECT_DEATH(scudo::reportInvalidAlignedAllocAlignment(123, 456),
- "Scudo ERROR.*123.*456");
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/report_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- report_test.cc ------------------------------------------*- C++ -*-===//
+//===-- report_test.cpp -----------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/scudo_unit_test_main.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc (removed)
@@ -1,14 +0,0 @@
-//===-- scudo_unit_test_main.cc ---------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/scudo_unit_test_main.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- scudo_unit_test_main.cc ---------------------------------*- C++ -*-===//
+//===-- scudo_unit_test_main.cpp --------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/secondary_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc (removed)
@@ -1,137 +0,0 @@
-//===-- secondary_test.cc ---------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "secondary.h"
-
-#include "gtest/gtest.h"
-
-#include <stdio.h>
-
-#include <condition_variable>
-#include <mutex>
-#include <thread>
-
-TEST(ScudoSecondaryTest, SecondaryBasic) {
- scudo::GlobalStats S;
- S.init();
- scudo::MapAllocator *L = new scudo::MapAllocator;
- L->init(&S);
- const scudo::uptr Size = 1U << 16;
- void *P = L->allocate(Size);
- EXPECT_NE(P, nullptr);
- memset(P, 'A', Size);
- EXPECT_GE(scudo::MapAllocator::getBlockSize(P), Size);
- L->deallocate(P);
- EXPECT_DEATH(memset(P, 'A', Size), "");
-
- const scudo::uptr Align = 1U << 16;
- P = L->allocate(Size + Align, Align);
- EXPECT_NE(P, nullptr);
- void *AlignedP = reinterpret_cast<void *>(
- scudo::roundUpTo(reinterpret_cast<scudo::uptr>(P), Align));
- memset(AlignedP, 'A', Size);
- L->deallocate(P);
-
- std::vector<void *> V;
- for (scudo::uptr I = 0; I < 32U; I++)
- V.push_back(L->allocate(Size));
- std::random_shuffle(V.begin(), V.end());
- while (!V.empty()) {
- L->deallocate(V.back());
- V.pop_back();
- }
- L->printStats();
-}
-
-// This exercises a variety of combinations of size and alignment for the
-// MapAllocator. The size computation done here mimic the ones done by the
-// combined allocator.
-TEST(ScudoSecondaryTest, SecondaryCombinations) {
- constexpr scudo::uptr MinAlign = FIRST_32_SECOND_64(8, 16);
- constexpr scudo::uptr HeaderSize = scudo::roundUpTo(8, MinAlign);
- scudo::MapAllocator *L = new scudo::MapAllocator;
- L->init(nullptr);
- for (scudo::uptr SizeLog = 0; SizeLog <= 20; SizeLog++) {
- for (scudo::uptr AlignLog = FIRST_32_SECOND_64(3, 4); AlignLog <= 16;
- AlignLog++) {
- const scudo::uptr Align = 1U << AlignLog;
- for (scudo::sptr Delta = -128; Delta <= 128; Delta += 8) {
- if (static_cast<scudo::sptr>(1U << SizeLog) + Delta <= 0)
- continue;
- const scudo::uptr UserSize =
- scudo::roundUpTo((1U << SizeLog) + Delta, MinAlign);
- const scudo::uptr Size =
- HeaderSize + UserSize + (Align > MinAlign ? Align - HeaderSize : 0);
- void *P = L->allocate(Size, Align);
- EXPECT_NE(P, nullptr);
- void *AlignedP = reinterpret_cast<void *>(
- scudo::roundUpTo(reinterpret_cast<scudo::uptr>(P), Align));
- memset(AlignedP, 0xff, UserSize);
- L->deallocate(P);
- }
- }
- }
- L->printStats();
-}
-
-TEST(ScudoSecondaryTest, SecondaryIterate) {
- scudo::MapAllocator *L = new scudo::MapAllocator;
- L->init(nullptr);
- std::vector<void *> V;
- const scudo::uptr PageSize = scudo::getPageSizeCached();
- for (scudo::uptr I = 0; I < 32U; I++)
- V.push_back(L->allocate((std::rand() % 16) * PageSize));
- auto Lambda = [V](scudo::uptr Block) {
- EXPECT_NE(std::find(V.begin(), V.end(), reinterpret_cast<void *>(Block)),
- V.end());
- };
- L->disable();
- L->iterateOverBlocks(Lambda);
- L->enable();
- while (!V.empty()) {
- L->deallocate(V.back());
- V.pop_back();
- }
- L->printStats();
-}
-
-static std::mutex Mutex;
-static std::condition_variable Cv;
-static bool Ready = false;
-
-static void performAllocations(scudo::MapAllocator *L) {
- std::vector<void *> V;
- const scudo::uptr PageSize = scudo::getPageSizeCached();
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- while (!Ready)
- Cv.wait(Lock);
- }
- for (scudo::uptr I = 0; I < 32U; I++)
- V.push_back(L->allocate((std::rand() % 16) * PageSize));
- while (!V.empty()) {
- L->deallocate(V.back());
- V.pop_back();
- }
-}
-
-TEST(ScudoSecondaryTest, SecondaryThreadsRace) {
- scudo::MapAllocator *L = new scudo::MapAllocator;
- L->init(nullptr);
- std::thread Threads[10];
- for (scudo::uptr I = 0; I < 10U; I++)
- Threads[I] = std::thread(performAllocations, L);
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- Ready = true;
- Cv.notify_all();
- }
- for (auto &T : Threads)
- T.join();
- L->printStats();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/secondary_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- secondary_test.cc ---------------------------------------*- C++ -*-===//
+//===-- secondary_test.cpp --------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/size_class_map_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc (removed)
@@ -1,38 +0,0 @@
-//===-- size_class_map_test.cc ----------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "scudo/standalone/size_class_map.h"
-#include "gtest/gtest.h"
-
-template <class SizeClassMap> void testSizeClassMap() {
- typedef SizeClassMap SCMap;
- SCMap::print();
- SCMap::validate();
-}
-
-TEST(ScudoSizeClassMapTest, DefaultSizeClassMap) {
- testSizeClassMap<scudo::DefaultSizeClassMap>();
-}
-
-TEST(ScudoSizeClassMapTest, SvelteSizeClassMap) {
- testSizeClassMap<scudo::SvelteSizeClassMap>();
-}
-
-TEST(ScudoSizeClassMapTest, AndroidSizeClassMap) {
- testSizeClassMap<scudo::AndroidSizeClassMap>();
-}
-
-TEST(ScudoSizeClassMapTest, OneClassSizeClassMap) {
- testSizeClassMap<scudo::SizeClassMap<1, 5, 5, 5, 0, 0>>();
-}
-
-#if SCUDO_CAN_USE_PRIMARY64
-TEST(ScudoSizeClassMapTest, LargeMaxSizeClassMap) {
- testSizeClassMap<scudo::SizeClassMap<3, 4, 8, 63, 128, 16>>();
-}
-#endif
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/size_class_map_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- size_class_map_test.cc ----------------------------------*- C++ -*-===//
+//===-- size_class_map_test.cpp ---------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/stats_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc (removed)
@@ -1,45 +0,0 @@
-//===-- stats_test.cc -------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "scudo/standalone/stats.h"
-#include "gtest/gtest.h"
-
-TEST(ScudoStatsTest, LocalStats) {
- scudo::LocalStats LStats;
- LStats.init();
- for (scudo::uptr I = 0; I < scudo::StatCount; I++)
- EXPECT_EQ(LStats.get(static_cast<scudo::StatType>(I)), 0U);
- LStats.add(scudo::StatAllocated, 4096U);
- EXPECT_EQ(LStats.get(scudo::StatAllocated), 4096U);
- LStats.sub(scudo::StatAllocated, 4096U);
- EXPECT_EQ(LStats.get(scudo::StatAllocated), 0U);
- LStats.set(scudo::StatAllocated, 4096U);
- EXPECT_EQ(LStats.get(scudo::StatAllocated), 4096U);
-}
-
-TEST(ScudoStatsTest, GlobalStats) {
- scudo::GlobalStats GStats;
- GStats.init();
- scudo::uptr Counters[scudo::StatCount] = {};
- GStats.get(Counters);
- for (scudo::uptr I = 0; I < scudo::StatCount; I++)
- EXPECT_EQ(Counters[I], 0U);
- scudo::LocalStats LStats;
- LStats.init();
- GStats.link(&LStats);
- for (scudo::uptr I = 0; I < scudo::StatCount; I++)
- LStats.add(static_cast<scudo::StatType>(I), 4096U);
- GStats.get(Counters);
- for (scudo::uptr I = 0; I < scudo::StatCount; I++)
- EXPECT_EQ(Counters[I], 4096U);
- // Unlinking the local stats move numbers to the global stats.
- GStats.unlink(&LStats);
- GStats.get(Counters);
- for (scudo::uptr I = 0; I < scudo::StatCount; I++)
- EXPECT_EQ(Counters[I], 4096U);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/stats_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- stats_test.cc -------------------------------------------*- C++ -*-===//
+//===-- stats_test.cpp ------------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/strings_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc (removed)
@@ -1,98 +0,0 @@
-//===-- strings_test.cc -----------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "scudo/standalone/string_utils.h"
-#include "gtest/gtest.h"
-
-#include <limits.h>
-
-TEST(ScudoStringsTest, Basic) {
- scudo::ScopedString Str(128);
- Str.append("a%db%zdc%ue%zuf%xh%zxq%pe%sr", static_cast<int>(-1),
- static_cast<scudo::uptr>(-2), static_cast<unsigned>(-4),
- static_cast<scudo::uptr>(5), static_cast<unsigned>(10),
- static_cast<scudo::uptr>(11), reinterpret_cast<void *>(0x123),
- "_string_");
- EXPECT_EQ(Str.length(), strlen(Str.data()));
-
- std::string expectedString = "a-1b-2c4294967292e5fahbq0x";
- expectedString += std::string(SCUDO_POINTER_FORMAT_LENGTH - 3, '0');
- expectedString += "123e_string_r";
- EXPECT_EQ(Str.length(), strlen(Str.data()));
- EXPECT_STREQ(expectedString.c_str(), Str.data());
-}
-
-TEST(ScudoStringsTest, Precision) {
- scudo::ScopedString Str(128);
- Str.append("%.*s", 3, "12345");
- EXPECT_EQ(Str.length(), strlen(Str.data()));
- EXPECT_STREQ("123", Str.data());
- Str.clear();
- Str.append("%.*s", 6, "12345");
- EXPECT_EQ(Str.length(), strlen(Str.data()));
- EXPECT_STREQ("12345", Str.data());
- Str.clear();
- Str.append("%-6s", "12345");
- EXPECT_EQ(Str.length(), strlen(Str.data()));
- EXPECT_STREQ("12345 ", Str.data());
-}
-
-static void fillString(scudo::ScopedString &Str, scudo::uptr Size) {
- for (scudo::uptr I = 0; I < Size; I++)
- Str.append("A");
-}
-
-TEST(ScudoStringTest, PotentialOverflows) {
- // Use a ScopedString that spans a page, and attempt to write past the end
- // of it with variations of append. The expectation is for nothing to crash.
- const scudo::uptr PageSize = scudo::getPageSizeCached();
- scudo::ScopedString Str(PageSize);
- Str.clear();
- fillString(Str, 2 * PageSize);
- Str.clear();
- fillString(Str, PageSize - 64);
- Str.append("%-128s", "12345");
- Str.clear();
- fillString(Str, PageSize - 16);
- Str.append("%024x", 12345);
- Str.clear();
- fillString(Str, PageSize - 16);
- Str.append("EEEEEEEEEEEEEEEEEEEEEEEE");
-}
-
-template <typename T>
-static void testAgainstLibc(const char *Format, T Arg1, T Arg2) {
- scudo::ScopedString Str(128);
- Str.append(Format, Arg1, Arg2);
- char Buffer[128];
- snprintf(Buffer, sizeof(Buffer), Format, Arg1, Arg2);
- EXPECT_EQ(Str.length(), strlen(Str.data()));
- EXPECT_STREQ(Buffer, Str.data());
-}
-
-TEST(ScudoStringsTest, MinMax) {
- testAgainstLibc<int>("%d-%d", INT_MIN, INT_MAX);
- testAgainstLibc<unsigned>("%u-%u", 0, UINT_MAX);
- testAgainstLibc<unsigned>("%x-%x", 0, UINT_MAX);
- testAgainstLibc<long>("%zd-%zd", LONG_MIN, LONG_MAX);
- testAgainstLibc<unsigned long>("%zu-%zu", 0, ULONG_MAX);
- testAgainstLibc<unsigned long>("%zx-%zx", 0, ULONG_MAX);
-}
-
-TEST(ScudoStringsTest, 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);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/strings_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- strings_test.cc -----------------------------------------*- C++ -*-===//
+//===-- strings_test.cpp ----------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/tsd_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc (removed)
@@ -1,168 +0,0 @@
-//===-- tsd_test.cc ---------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "tsd_exclusive.h"
-#include "tsd_shared.h"
-
-#include "gtest/gtest.h"
-
-#include <condition_variable>
-#include <mutex>
-#include <thread>
-
-// We mock out an allocator with a TSD registry, mostly using empty stubs. The
-// cache contains a single volatile uptr, to be able to test that several
-// concurrent threads will not access or modify the same cache at the same time.
-template <class Config> class MockAllocator {
-public:
- using ThisT = MockAllocator<Config>;
- using TSDRegistryT = typename Config::template TSDRegistryT<ThisT>;
- using CacheT = struct MockCache { volatile scudo::uptr Canary; };
- using QuarantineCacheT = struct MockQuarantine {};
-
- void initLinkerInitialized() {
- // This should only be called once by the registry.
- EXPECT_FALSE(Initialized);
- Initialized = true;
- }
- void reset() { memset(this, 0, sizeof(*this)); }
-
- void unmapTestOnly() { TSDRegistry.unmapTestOnly(); }
- void initCache(CacheT *Cache) { memset(Cache, 0, sizeof(*Cache)); }
- void commitBack(scudo::TSD<MockAllocator> *TSD) {}
- TSDRegistryT *getTSDRegistry() { return &TSDRegistry; }
-
- bool isInitialized() { return Initialized; }
-
-private:
- bool Initialized;
- TSDRegistryT TSDRegistry;
-};
-
-struct OneCache {
- template <class Allocator>
- using TSDRegistryT = scudo::TSDRegistrySharedT<Allocator, 1U>;
-};
-
-struct SharedCaches {
- template <class Allocator>
- using TSDRegistryT = scudo::TSDRegistrySharedT<Allocator, 16U>;
-};
-
-struct ExclusiveCaches {
- template <class Allocator>
- using TSDRegistryT = scudo::TSDRegistryExT<Allocator>;
-};
-
-TEST(ScudoTSDTest, TSDRegistryInit) {
- using AllocatorT = MockAllocator<OneCache>;
- auto Deleter = [](AllocatorT *A) {
- A->unmapTestOnly();
- delete A;
- };
- std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
- Deleter);
- Allocator->reset();
- EXPECT_FALSE(Allocator->isInitialized());
-
- auto Registry = Allocator->getTSDRegistry();
- Registry->initLinkerInitialized(Allocator.get());
- EXPECT_TRUE(Allocator->isInitialized());
-}
-
-template <class AllocatorT> static void testRegistry() {
- auto Deleter = [](AllocatorT *A) {
- A->unmapTestOnly();
- delete A;
- };
- std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
- Deleter);
- Allocator->reset();
- EXPECT_FALSE(Allocator->isInitialized());
-
- auto Registry = Allocator->getTSDRegistry();
- Registry->initThreadMaybe(Allocator.get(), /*MinimalInit=*/true);
- EXPECT_TRUE(Allocator->isInitialized());
-
- bool UnlockRequired;
- auto TSD = Registry->getTSDAndLock(&UnlockRequired);
- EXPECT_NE(TSD, nullptr);
- EXPECT_EQ(TSD->Cache.Canary, 0U);
- if (UnlockRequired)
- TSD->unlock();
-
- Registry->initThreadMaybe(Allocator.get(), /*MinimalInit=*/false);
- TSD = Registry->getTSDAndLock(&UnlockRequired);
- EXPECT_NE(TSD, nullptr);
- EXPECT_EQ(TSD->Cache.Canary, 0U);
- memset(&TSD->Cache, 0x42, sizeof(TSD->Cache));
- if (UnlockRequired)
- TSD->unlock();
-}
-
-TEST(ScudoTSDTest, TSDRegistryBasic) {
- testRegistry<MockAllocator<OneCache>>();
- testRegistry<MockAllocator<SharedCaches>>();
- testRegistry<MockAllocator<ExclusiveCaches>>();
-}
-
-static std::mutex Mutex;
-static std::condition_variable Cv;
-static bool Ready = false;
-
-template <typename AllocatorT> static void stressCache(AllocatorT *Allocator) {
- auto Registry = Allocator->getTSDRegistry();
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- while (!Ready)
- Cv.wait(Lock);
- }
- Registry->initThreadMaybe(Allocator, /*MinimalInit=*/false);
- bool UnlockRequired;
- auto TSD = Registry->getTSDAndLock(&UnlockRequired);
- EXPECT_NE(TSD, nullptr);
- // For an exclusive TSD, the cache should be empty. We cannot guarantee the
- // same for a shared TSD.
- if (!UnlockRequired)
- EXPECT_EQ(TSD->Cache.Canary, 0U);
- // Transform the thread id to a uptr to use it as canary.
- const scudo::uptr Canary = static_cast<scudo::uptr>(
- std::hash<std::thread::id>{}(std::this_thread::get_id()));
- TSD->Cache.Canary = Canary;
- // Loop a few times to make sure that a concurrent thread isn't modifying it.
- for (scudo::uptr I = 0; I < 4096U; I++)
- EXPECT_EQ(TSD->Cache.Canary, Canary);
- if (UnlockRequired)
- TSD->unlock();
-}
-
-template <class AllocatorT> static void testRegistryThreaded() {
- auto Deleter = [](AllocatorT *A) {
- A->unmapTestOnly();
- delete A;
- };
- std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
- Deleter);
- Allocator->reset();
- std::thread Threads[32];
- for (scudo::uptr I = 0; I < ARRAY_SIZE(Threads); I++)
- Threads[I] = std::thread(stressCache<AllocatorT>, Allocator.get());
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- Ready = true;
- Cv.notify_all();
- }
- for (auto &T : Threads)
- T.join();
-}
-
-TEST(ScudoTSDTest, TSDRegistryThreaded) {
- testRegistryThreaded<MockAllocator<OneCache>>();
- testRegistryThreaded<MockAllocator<SharedCaches>>();
- testRegistryThreaded<MockAllocator<ExclusiveCaches>>();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/tsd_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- tsd_test.cc ---------------------------------------------*- C++ -*-===//
+//===-- tsd_test.cpp --------------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/vector_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc (removed)
@@ -1,43 +0,0 @@
-//===-- vector_test.cc ------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "vector.h"
-
-#include "gtest/gtest.h"
-
-TEST(ScudoVectorTest, Basic) {
- scudo::Vector<int> V;
- EXPECT_EQ(V.size(), 0U);
- V.push_back(42);
- EXPECT_EQ(V.size(), 1U);
- EXPECT_EQ(V[0], 42);
- V.push_back(43);
- EXPECT_EQ(V.size(), 2U);
- EXPECT_EQ(V[0], 42);
- EXPECT_EQ(V[1], 43);
-}
-
-TEST(ScudoVectorTest, Stride) {
- scudo::Vector<int> V;
- for (int i = 0; i < 1000; i++) {
- V.push_back(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(ScudoVectorTest, ResizeReduction) {
- scudo::Vector<int> V;
- V.push_back(0);
- V.push_back(0);
- EXPECT_EQ(V.size(), 2U);
- V.resize(1);
- EXPECT_EQ(V.size(), 1U);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/vector_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- vector_test.cc ------------------------------------------*- C++ -*-===//
+//===-- vector_test.cpp -----------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/wrappers_c_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc (removed)
@@ -1,225 +0,0 @@
-//===-- wrappers_c_test.cc --------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "platform.h"
-
-#include "gtest/gtest.h"
-
-#include <limits.h>
-#include <malloc.h>
-#include <unistd.h>
-
-// Note that every C allocation function in the test binary will be fulfilled
-// by Scudo (this includes the gtest APIs, etc.), which is a test by itself.
-// But this might also lead to unexpected side-effects, since the allocation and
-// deallocation operations in the TEST functions will coexist with others (see
-// the EXPECT_DEATH comment below).
-
-// We have to use a small quarantine to make sure that our double-free tests
-// trigger. Otherwise EXPECT_DEATH ends up reallocating the chunk that was just
-// freed (this depends on the size obviously) and the following free succeeds.
-extern "C" __attribute__((visibility("default"))) const char *
-__scudo_default_options() {
- return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
- "quarantine_max_chunk_size=512";
-}
-
-static const size_t Size = 100U;
-
-TEST(ScudoWrappersCTest, Malloc) {
- void *P = malloc(Size);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size, malloc_usable_size(P));
- EXPECT_EQ(reinterpret_cast<uintptr_t>(P) % FIRST_32_SECOND_64(8U, 16U), 0U);
- EXPECT_DEATH(
- free(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(P) | 1U)), "");
- free(P);
- EXPECT_DEATH(free(P), "");
-
- P = malloc(0U);
- EXPECT_NE(P, nullptr);
- free(P);
-
- errno = 0;
- EXPECT_EQ(malloc(SIZE_MAX), nullptr);
- EXPECT_EQ(errno, ENOMEM);
-}
-
-TEST(ScudoWrappersCTest, Calloc) {
- void *P = calloc(1U, Size);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size, malloc_usable_size(P));
- for (size_t I = 0; I < Size; I++)
- EXPECT_EQ((reinterpret_cast<uint8_t *>(P))[I], 0U);
- free(P);
-
- P = calloc(1U, 0U);
- EXPECT_NE(P, nullptr);
- free(P);
- P = calloc(0U, 1U);
- EXPECT_NE(P, nullptr);
- free(P);
-
- errno = 0;
- EXPECT_EQ(calloc(SIZE_MAX, 1U), nullptr);
- EXPECT_EQ(errno, ENOMEM);
- errno = 0;
- EXPECT_EQ(calloc(static_cast<size_t>(LONG_MAX) + 1U, 2U), nullptr);
- if (SCUDO_ANDROID)
- EXPECT_EQ(errno, ENOMEM);
- errno = 0;
- EXPECT_EQ(calloc(SIZE_MAX, SIZE_MAX), nullptr);
- EXPECT_EQ(errno, ENOMEM);
-}
-
-TEST(ScudoWrappersCTest, Memalign) {
- void *P;
- for (size_t I = FIRST_32_SECOND_64(2U, 3U); I <= 18U; I++) {
- const size_t Alignment = 1U << I;
-
- P = memalign(Alignment, Size);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size, malloc_usable_size(P));
- EXPECT_EQ(reinterpret_cast<uintptr_t>(P) % Alignment, 0U);
- free(P);
-
- P = nullptr;
- EXPECT_EQ(posix_memalign(&P, Alignment, Size), 0);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size, malloc_usable_size(P));
- EXPECT_EQ(reinterpret_cast<uintptr_t>(P) % Alignment, 0U);
- free(P);
- }
-
- EXPECT_EQ(memalign(4096U, SIZE_MAX), nullptr);
- EXPECT_EQ(posix_memalign(&P, 15U, Size), EINVAL);
- EXPECT_EQ(posix_memalign(&P, 4096U, SIZE_MAX), ENOMEM);
-
- // Android's memalign accepts non power-of-2 alignments, and 0.
- if (SCUDO_ANDROID) {
- for (size_t Alignment = 0U; Alignment <= 128U; Alignment++) {
- P = memalign(Alignment, 1024U);
- EXPECT_NE(P, nullptr);
- free(P);
- }
- }
-}
-
-TEST(ScudoWrappersCTest, AlignedAlloc) {
- const size_t Alignment = 4096U;
- void *P = aligned_alloc(Alignment, Alignment * 4U);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Alignment * 4U, malloc_usable_size(P));
- EXPECT_EQ(reinterpret_cast<uintptr_t>(P) % Alignment, 0U);
- free(P);
-
- errno = 0;
- P = aligned_alloc(Alignment, Size);
- EXPECT_EQ(P, nullptr);
- EXPECT_EQ(errno, EINVAL);
-}
-
-TEST(ScudoWrappersCTest, Realloc) {
- // realloc(nullptr, N) is malloc(N)
- void *P = realloc(nullptr, 0U);
- EXPECT_NE(P, nullptr);
- free(P);
-
- P = malloc(Size);
- EXPECT_NE(P, nullptr);
- // realloc(P, 0U) is free(P) and returns nullptr
- EXPECT_EQ(realloc(P, 0U), nullptr);
-
- P = malloc(Size);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size, malloc_usable_size(P));
- memset(P, 0x42, Size);
-
- P = realloc(P, Size * 2U);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size * 2U, malloc_usable_size(P));
- for (size_t I = 0; I < Size; I++)
- EXPECT_EQ(0x42, (reinterpret_cast<uint8_t *>(P))[I]);
-
- P = realloc(P, Size / 2U);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size / 2U, malloc_usable_size(P));
- for (size_t I = 0; I < Size / 2U; I++)
- EXPECT_EQ(0x42, (reinterpret_cast<uint8_t *>(P))[I]);
- free(P);
-
- EXPECT_DEATH(P = realloc(P, Size), "");
-
- errno = 0;
- EXPECT_EQ(realloc(nullptr, SIZE_MAX), nullptr);
- EXPECT_EQ(errno, ENOMEM);
- P = malloc(Size);
- EXPECT_NE(P, nullptr);
- errno = 0;
- EXPECT_EQ(realloc(P, SIZE_MAX), nullptr);
- EXPECT_EQ(errno, ENOMEM);
- free(P);
-
- // Android allows realloc of memalign pointers.
- if (SCUDO_ANDROID) {
- const size_t Alignment = 1024U;
- P = memalign(Alignment, Size);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size, malloc_usable_size(P));
- EXPECT_EQ(reinterpret_cast<uintptr_t>(P) % Alignment, 0U);
- memset(P, 0x42, Size);
-
- P = realloc(P, Size * 2U);
- EXPECT_NE(P, nullptr);
- EXPECT_LE(Size * 2U, malloc_usable_size(P));
- for (size_t I = 0; I < Size; I++)
- EXPECT_EQ(0x42, (reinterpret_cast<uint8_t *>(P))[I]);
- free(P);
- }
-}
-
-#ifndef M_DECAY_TIME
-#define M_DECAY_TIME -100
-#endif
-
-#ifndef M_PURGE
-#define M_PURGE -101
-#endif
-
-TEST(ScudoWrappersCTest, Mallopt) {
- errno = 0;
- EXPECT_EQ(mallopt(-1000, 1), 0);
- // mallopt doesn't set errno.
- EXPECT_EQ(errno, 0);
-
- EXPECT_EQ(mallopt(M_PURGE, 0), 1);
-
- EXPECT_EQ(mallopt(M_DECAY_TIME, 1), 1);
- EXPECT_EQ(mallopt(M_DECAY_TIME, 0), 1);
- EXPECT_EQ(mallopt(M_DECAY_TIME, 1), 1);
- EXPECT_EQ(mallopt(M_DECAY_TIME, 0), 1);
-}
-
-TEST(ScudoWrappersCTest, OtherAlloc) {
- const size_t PageSize = sysconf(_SC_PAGESIZE);
-
- void *P = pvalloc(Size);
- EXPECT_NE(P, nullptr);
- EXPECT_EQ(reinterpret_cast<uintptr_t>(P) & (PageSize - 1), 0U);
- EXPECT_LE(PageSize, malloc_usable_size(P));
- free(P);
-
- EXPECT_EQ(pvalloc(SIZE_MAX), nullptr);
-
- P = pvalloc(Size);
- EXPECT_NE(P, nullptr);
- EXPECT_EQ(reinterpret_cast<uintptr_t>(P) & (PageSize - 1), 0U);
- free(P);
-
- EXPECT_EQ(valloc(SIZE_MAX), nullptr);
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_c_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- wrappers_c_test.cc --------------------------------------*- C++ -*-===//
+//===-- wrappers_c_test.cpp -------------------------------------*- C++ -*-===//
//
// 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/scudo/standalone/tests/wrappers_cpp_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc?rev=367568&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc (removed)
@@ -1,120 +0,0 @@
-//===-- wrappers_cpp_test.cc ------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-
-#include <condition_variable>
-#include <mutex>
-#include <thread>
-
-void operator delete(void *, size_t) noexcept;
-void operator delete[](void *, size_t) noexcept;
-
-// Note that every Cxx allocation function in the test binary will be fulfilled
-// by Scudo. See the comment in the C counterpart of this file.
-
-extern "C" __attribute__((visibility("default"))) const char *
-__scudo_default_options() {
- return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
- "quarantine_max_chunk_size=512:dealloc_type_mismatch=true";
-}
-
-template <typename T> static void testCxxNew() {
- T *P = new T;
- EXPECT_NE(P, nullptr);
- memset(P, 0x42, sizeof(T));
- EXPECT_DEATH(delete[] P, "");
- delete P;
- EXPECT_DEATH(delete P, "");
-
- P = new T;
- EXPECT_NE(P, nullptr);
- memset(P, 0x42, sizeof(T));
- operator delete(P, sizeof(T));
-
- P = new (std::nothrow) T;
- EXPECT_NE(P, nullptr);
- memset(P, 0x42, sizeof(T));
- delete P;
-
- const size_t N = 16U;
- T *A = new T[N];
- EXPECT_NE(A, nullptr);
- memset(A, 0x42, sizeof(T) * N);
- EXPECT_DEATH(delete A, "");
- delete[] A;
- EXPECT_DEATH(delete[] A, "");
-
- A = new T[N];
- EXPECT_NE(A, nullptr);
- memset(A, 0x42, sizeof(T) * N);
- operator delete[](A, sizeof(T) * N);
-
- A = new (std::nothrow) T[N];
- EXPECT_NE(A, nullptr);
- memset(A, 0x42, sizeof(T) * N);
- delete[] A;
-}
-
-class Pixel {
-public:
- enum class Color { Red, Green, Blue };
- int X = 0;
- int Y = 0;
- Color C = Color::Red;
-};
-
-TEST(ScudoWrappersCppTest, New) {
- testCxxNew<bool>();
- testCxxNew<uint8_t>();
- testCxxNew<uint16_t>();
- testCxxNew<uint32_t>();
- testCxxNew<uint64_t>();
- testCxxNew<float>();
- testCxxNew<double>();
- testCxxNew<long double>();
- testCxxNew<Pixel>();
-}
-
-static std::mutex Mutex;
-static std::condition_variable Cv;
-static bool Ready = false;
-
-static void stressNew() {
- std::vector<uintptr_t *> V;
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- while (!Ready)
- Cv.wait(Lock);
- }
- for (size_t I = 0; I < 256U; I++) {
- const size_t N = std::rand() % 128U;
- uintptr_t *P = new uintptr_t[N];
- if (P) {
- memset(P, 0x42, sizeof(uintptr_t) * N);
- V.push_back(P);
- }
- }
- while (!V.empty()) {
- delete[] V.back();
- V.pop_back();
- }
-}
-
-TEST(ScudoWrappersCppTest, ThreadedNew) {
- std::thread Threads[32];
- for (size_t I = 0U; I < sizeof(Threads) / sizeof(Threads[0]); I++)
- Threads[I] = std::thread(stressNew);
- {
- std::unique_lock<std::mutex> Lock(Mutex);
- Ready = true;
- Cv.notify_all();
- }
- for (auto &T : Threads)
- T.join();
-}
Copied: compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cpp (from r367568, compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cpp?p2=compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cpp&p1=compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc&r1=367568&r2=367569&rev=367569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cc (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/wrappers_cpp_test.cpp Thu Aug 1 07:38:49 2019
@@ -1,4 +1,4 @@
-//===-- wrappers_cpp_test.cc ------------------------------------*- C++ -*-===//
+//===-- wrappers_cpp_test.cpp -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
More information about the llvm-commits
mailing list