Commit c76d6b8c authored by Xiao Shi's avatar Xiao Shi Committed by Facebook Github Bot

disable on android, fix getAllocatedMemorySize test to account for...

disable on android, fix getAllocatedMemorySize test to account for implementation-defined bucket_count for default containers

Summary:
This serves as a mitigation until we look further into the android crashes we
discovered in android instrumentation tests.

The bucket_count of the default constructed `unordered_map` is
implementation-defined. This diff takes that into account in the
`getAllocatedMemorySize` test.

`unordered_map|set` impl in Android NDK does not match the assumptions made in
`visitAllocationClasses`. Temporarily disable the tests with that method.

Reviewed By: mzlee

Differential Revision: D9578626

fbshipit-source-id: 355940b026f00f783bf65c2f1e10725d5aa920d3
parent 2d7605b0
......@@ -61,6 +61,8 @@ class F14BasicSet : public std::unordered_set<K, H, E, A> {
this->size() * sizeof(StdNodeReplica<K, typename Super::value_type, H>);
}
// TODO(T33376370): this implementation is incorrect for android. Fix it or
// disable it.
template <typename V>
void visitAllocationClasses(V&& visitor) const {
auto bc = this->bucket_count();
......
......@@ -24,7 +24,10 @@
// dependent targets don't consistently build with NEON, due to C++ templates
// and ODR, the NEON version may be linked in where a non-NEON version is
// expected.
#if !FOLLY_MOBILE && ((FOLLY_SSE >= 2) || (FOLLY_NEON && FOLLY_AARCH64))
//
// TODO: enable for android (T33376370)
#if ((FOLLY_SSE >= 2) || (FOLLY_NEON && FOLLY_AARCH64)) && \
(!FOLLY_MOBILE || defined(__APPLE__))
#define FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE 1
#else
#define FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE 0
......
......@@ -60,28 +60,33 @@ void runAllocatedMemorySizeTest() {
using A = SwapTrackingAlloc<std::pair<const K, V>>;
resetTracking();
TMap<K, V, DefaultHasher<K>, DefaultKeyEqual<K>, A> m;
EXPECT_EQ(testAllocatedMemorySize, m.getAllocatedMemorySize());
for (size_t i = 0; i < 1000; ++i) {
m.insert(std::make_pair(folly::to<K>(i), V{}));
m.erase(folly::to<K>(i / 10 + 2));
{
TMap<K, V, DefaultHasher<K>, DefaultKeyEqual<K>, A> m;
EXPECT_EQ(testAllocatedMemorySize, m.getAllocatedMemorySize());
std::size_t size = 0;
std::size_t count = 0;
m.visitAllocationClasses([&](std::size_t, std::size_t) mutable {});
m.visitAllocationClasses([&](std::size_t bytes, std::size_t n) {
size += bytes * n;
count += n;
});
EXPECT_EQ(testAllocatedMemorySize, size);
EXPECT_EQ(testAllocatedBlockCount, count);
}
auto emptyMapAllocatedMemorySize = testAllocatedMemorySize;
auto emptyMapAllocatedBlockCount = testAllocatedBlockCount;
for (size_t i = 0; i < 1000; ++i) {
m.insert(std::make_pair(folly::to<K>(i), V{}));
m.erase(folly::to<K>(i / 10 + 2));
EXPECT_EQ(testAllocatedMemorySize, m.getAllocatedMemorySize());
std::size_t size = 0;
std::size_t count = 0;
m.visitAllocationClasses([&](std::size_t, std::size_t) mutable {});
m.visitAllocationClasses([&](std::size_t bytes, std::size_t n) {
size += bytes * n;
count += n;
});
EXPECT_EQ(testAllocatedMemorySize, size);
EXPECT_EQ(testAllocatedBlockCount, count);
}
m = decltype(m){};
m = decltype(m){};
EXPECT_EQ(testAllocatedMemorySize, emptyMapAllocatedMemorySize);
EXPECT_EQ(testAllocatedBlockCount, emptyMapAllocatedBlockCount);
}
EXPECT_EQ(testAllocatedMemorySize, 0);
EXPECT_EQ(testAllocatedBlockCount, 0);
m.visitAllocationClasses([](std::size_t, std::size_t n) { EXPECT_EQ(n, 0); });
}
template <typename K, typename V>
......
......@@ -56,28 +56,37 @@ void runAllocatedMemorySizeTest() {
using A = SwapTrackingAlloc<K>;
resetTracking();
TSet<K, DefaultHasher<K>, DefaultKeyEqual<K>, A> m;
EXPECT_EQ(testAllocatedMemorySize, m.getAllocatedMemorySize());
for (size_t i = 0; i < 1000; ++i) {
m.insert(folly::to<K>(i));
m.erase(folly::to<K>(i / 10 + 2));
{
TSet<K, DefaultHasher<K>, DefaultKeyEqual<K>, A> m;
EXPECT_EQ(testAllocatedMemorySize, m.getAllocatedMemorySize());
std::size_t size = 0;
std::size_t count = 0;
m.visitAllocationClasses([&](std::size_t, std::size_t) mutable {});
m.visitAllocationClasses([&](std::size_t bytes, std::size_t n) {
size += bytes * n;
count += n;
});
EXPECT_EQ(testAllocatedMemorySize, size);
EXPECT_EQ(testAllocatedBlockCount, count);
}
auto emptySetAllocatedMemorySize = testAllocatedMemorySize;
auto emptySetAllocatedBlockCount = testAllocatedBlockCount;
// TODO(T33426422): check unordered_set impl in Android NDK for allocation
// behaviors
#if (!FOLLY_MOBILE || defined(__APPLE__))
for (size_t i = 0; i < 1000; ++i) {
m.insert(folly::to<K>(i));
m.erase(folly::to<K>(i / 10 + 2));
EXPECT_EQ(testAllocatedMemorySize, m.getAllocatedMemorySize());
std::size_t size = 0;
std::size_t count = 0;
m.visitAllocationClasses([&](std::size_t, std::size_t) mutable {});
m.visitAllocationClasses([&](std::size_t bytes, std::size_t n) {
size += bytes * n;
count += n;
});
EXPECT_EQ(testAllocatedMemorySize, size);
EXPECT_EQ(testAllocatedBlockCount, count);
}
#endif
m = decltype(m){};
m = decltype(m){};
EXPECT_EQ(testAllocatedMemorySize, emptySetAllocatedMemorySize);
EXPECT_EQ(testAllocatedBlockCount, emptySetAllocatedBlockCount);
}
EXPECT_EQ(testAllocatedMemorySize, 0);
EXPECT_EQ(testAllocatedBlockCount, 0);
m.visitAllocationClasses([](std::size_t, std::size_t n) { EXPECT_EQ(n, 0); });
}
template <typename K>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment