Skip to content

Commit 8ddd804

Browse files
authored
[scudo] Use anonymous namespace for test helper code (#157207)
Tests can be at top-level or inside an anonymous namespace, doesn't matter. But putting their helper code inside anonymous namespaces both makes the code compatible with compiling using -Wmissing-declarations and might let the compiler optimize the test good a bit better.
1 parent bdf645b commit 8ddd804

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "tests/scudo_unit_test.h"
10-
119
#include "quarantine.h"
1210

1311
#include <pthread.h>
1412
#include <stdlib.h>
1513

16-
static void *FakePtr = reinterpret_cast<void *>(0xFA83FA83);
17-
static const scudo::uptr BlockSize = 8UL;
18-
static const scudo::uptr LargeBlockSize = 16384UL;
14+
#include "tests/scudo_unit_test.h"
15+
16+
namespace {
17+
18+
void *FakePtr = reinterpret_cast<void *>(0xFA83FA83);
19+
const scudo::uptr BlockSize = 8UL;
20+
const scudo::uptr LargeBlockSize = 16384UL;
1921

2022
struct QuarantineCallback {
2123
void recycle(void *P) { EXPECT_EQ(P, FakePtr); }
@@ -26,9 +28,9 @@ struct QuarantineCallback {
2628
typedef scudo::GlobalQuarantine<QuarantineCallback, void> QuarantineT;
2729
typedef typename QuarantineT::CacheT CacheT;
2830

29-
static QuarantineCallback Cb;
31+
QuarantineCallback Cb;
3032

31-
static void deallocateCache(CacheT *Cache) {
33+
void deallocateCache(CacheT *Cache) {
3234
while (scudo::QuarantineBatch *Batch = Cache->dequeueBatch())
3335
Cb.deallocate(Batch);
3436
}
@@ -187,8 +189,8 @@ TEST(ScudoQuarantineTest, QuarantineCacheMergeBatchesALotOfBatches) {
187189
deallocateCache(&ToDeallocate);
188190
}
189191

190-
static const scudo::uptr MaxQuarantineSize = 1024UL << 10; // 1MB
191-
static const scudo::uptr MaxCacheSize = 256UL << 10; // 256KB
192+
const scudo::uptr MaxQuarantineSize = 1024UL << 10; // 1MB
193+
const scudo::uptr MaxCacheSize = 256UL << 10; // 256KB
192194

193195
TEST(ScudoQuarantineTest, GlobalQuarantine) {
194196
QuarantineT Quarantine;
@@ -253,3 +255,5 @@ TEST(ScudoQuarantineTest, ThreadedGlobalQuarantine) {
253255
for (scudo::uptr I = 0; I < NumberOfThreads; I++)
254256
Quarantine.drainAndRecycle(&T[I].Cache, Cb);
255257
}
258+
259+
} // namespace

0 commit comments

Comments
 (0)