Skip to content

Commit ed00588

Browse files
cferris1000aadeshps-mcw
authored andcommitted
[scudo] Only print stats when the test fails. (llvm#168000)
When running the tests on other platforms, printing the stats on all of the passing tests makes it hard to see failure output. Therefore, this change only prints the stats if the test actually fails.
1 parent 4bd6560 commit ed00588

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ void ScudoCombinedTest<Config>::BasicTest(scudo::uptr SizeLog) {
326326
}
327327
}
328328

329-
Allocator->printStats();
330-
Allocator->printFragmentationInfo();
329+
if (TEST_HAS_FAILURE) {
330+
Allocator->printStats();
331+
Allocator->printFragmentationInfo();
332+
}
331333
}
332334

333335
#define SCUDO_MAKE_BASIC_TEST(SizeLog) \

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ SCUDO_TYPED_TEST(ScudoPrimaryTest, BasicPrimary) {
230230
}
231231
SizeClassAllocator.destroy(nullptr);
232232
Allocator->releaseToOS(scudo::ReleaseToOS::Force);
233-
scudo::ScopedString Str;
234-
Allocator->getStats(&Str);
235-
Str.output();
233+
if (TEST_HAS_FAILURE) {
234+
scudo::ScopedString Str;
235+
Allocator->getStats(&Str);
236+
Str.output();
237+
}
236238
}
237239

238240
struct SmallRegionsConfig {
@@ -289,10 +291,12 @@ TEST(ScudoPrimaryTest, Primary64OOM) {
289291

290292
SizeClassAllocator.destroy(nullptr);
291293
Allocator.releaseToOS(scudo::ReleaseToOS::Force);
292-
scudo::ScopedString Str;
293-
Allocator.getStats(&Str);
294-
Str.output();
295294
EXPECT_EQ(AllocationFailed, true);
295+
if (TEST_HAS_FAILURE) {
296+
scudo::ScopedString Str;
297+
Allocator.getStats(&Str);
298+
Str.output();
299+
}
296300
Allocator.unmapTestOnly();
297301
}
298302

@@ -328,9 +332,11 @@ SCUDO_TYPED_TEST(ScudoPrimaryTest, PrimaryIterate) {
328332
}
329333
SizeClassAllocator.destroy(nullptr);
330334
Allocator->releaseToOS(scudo::ReleaseToOS::Force);
331-
scudo::ScopedString Str;
332-
Allocator->getStats(&Str);
333-
Str.output();
335+
if (TEST_HAS_FAILURE) {
336+
scudo::ScopedString Str;
337+
Allocator->getStats(&Str);
338+
Str.output();
339+
}
334340
}
335341

336342
SCUDO_TYPED_TEST(ScudoPrimaryTest, PrimaryThreaded) {
@@ -385,11 +391,13 @@ SCUDO_TYPED_TEST(ScudoPrimaryTest, PrimaryThreaded) {
385391
for (auto &T : Threads)
386392
T.join();
387393
Allocator->releaseToOS(scudo::ReleaseToOS::Force);
388-
scudo::ScopedString Str;
389-
Allocator->getStats(&Str);
390-
Allocator->getFragmentationInfo(&Str);
391-
Allocator->getMemoryGroupFragmentationInfo(&Str);
392-
Str.output();
394+
if (TEST_HAS_FAILURE) {
395+
scudo::ScopedString Str;
396+
Allocator->getStats(&Str);
397+
Allocator->getFragmentationInfo(&Str);
398+
Allocator->getMemoryGroupFragmentationInfo(&Str);
399+
Str.output();
400+
}
393401
}
394402

395403
// Through a simple allocation that spans two pages, verify that releaseToOS

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,11 @@ TEST(ScudoQuarantineTest, GlobalQuarantine) {
216216
Quarantine.drainAndRecycle(&Cache, Cb);
217217
EXPECT_EQ(Cache.getSize(), 0UL);
218218

219-
scudo::ScopedString Str;
220-
Quarantine.getStats(&Str);
221-
Str.output();
219+
if (TEST_HAS_FAILURE) {
220+
scudo::ScopedString Str;
221+
Quarantine.getStats(&Str);
222+
Str.output();
223+
}
222224
}
223225

224226
struct PopulateQuarantineThread {
@@ -248,9 +250,11 @@ TEST(ScudoQuarantineTest, ThreadedGlobalQuarantine) {
248250
for (scudo::uptr I = 0; I < NumberOfThreads; I++)
249251
pthread_join(T[I].Thread, 0);
250252

251-
scudo::ScopedString Str;
252-
Quarantine.getStats(&Str);
253-
Str.output();
253+
if (TEST_HAS_FAILURE) {
254+
scudo::ScopedString Str;
255+
Quarantine.getStats(&Str);
256+
Str.output();
257+
}
254258

255259
for (scudo::uptr I = 0; I < NumberOfThreads; I++)
256260
Quarantine.drainAndRecycle(&T[I].Cache, Cb);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
template <class SizeClassMap> void testSizeClassMap() {
1414
typedef SizeClassMap SCMap;
15-
scudo::printMap<SCMap>();
1615
scudo::validateMap<SCMap>();
16+
if (TEST_HAS_FAILURE) {
17+
scudo::printMap<SCMap>();
18+
}
1719
}
1820

1921
TEST(ScudoSizeClassMapTest, DefaultSizeClassMap) {

0 commit comments

Comments
 (0)