Skip to content

Commit c0a3c5c

Browse files
authored
[scudo] Change tests that use setrlimit to cause mmap to fail. (llvm#87004)
It appears that qemu does not actually cause mmap to fail when calling setrlimit to limit the address space size. In the two tests that use setrlimit, detect if mmap still works and skip the tests in that case. Since all Android targets should support setrlimit, compile out the mmap check code for them.
1 parent 13b3762 commit c0a3c5c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,27 @@ TEST(ScudoStringsTest, Padding) {
129129
}
130130

131131
#if defined(__linux__)
132+
132133
#include <sys/resource.h>
133134

134135
TEST(ScudoStringsTest, CapacityIncreaseFails) {
135136
scudo::ScopedString Str;
136137

137138
rlimit Limit = {};
138139
EXPECT_EQ(0, getrlimit(RLIMIT_AS, &Limit));
140+
139141
rlimit EmptyLimit = {.rlim_cur = 0, .rlim_max = Limit.rlim_max};
140142
EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit));
141143

144+
// qemu does not honor the setrlimit, so verify before proceeding.
145+
scudo::MemMapT MemMap;
146+
if (MemMap.map(/*Addr=*/0U, scudo::getPageSizeCached(), "scudo:test",
147+
MAP_ALLOWNOMEM)) {
148+
MemMap.unmap(MemMap.getBase(), MemMap.getCapacity());
149+
setrlimit(RLIMIT_AS, &Limit);
150+
GTEST_SKIP() << "Limiting address space does not prevent mmap.";
151+
}
152+
142153
// Test requires that the default length is at least 6 characters.
143154
scudo::uptr MaxSize = Str.capacity();
144155
EXPECT_LE(6u, MaxSize);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ TEST(ScudoVectorTest, ReallocateFails) {
5858
rlimit EmptyLimit = {.rlim_cur = 0, .rlim_max = Limit.rlim_max};
5959
EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit));
6060

61+
// qemu does not honor the setrlimit, so verify before proceeding.
62+
scudo::MemMapT MemMap;
63+
if (MemMap.map(/*Addr=*/0U, scudo::getPageSizeCached(), "scudo:test",
64+
MAP_ALLOWNOMEM)) {
65+
MemMap.unmap(MemMap.getBase(), MemMap.getCapacity());
66+
setrlimit(RLIMIT_AS, &Limit);
67+
GTEST_SKIP() << "Limiting address space does not prevent mmap.";
68+
}
69+
6170
V.resize(capacity);
6271
// Set the last element so we can check it later.
6372
V.back() = '\0';

0 commit comments

Comments
 (0)