Commit 511a163f authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

fix MemoryTest for 32-bit platforms

Summary: This diff makes folly/test/memoryTest pass on 32-bit platforms.

Reviewed By: shixiao

Differential Revision: D8559725

fbshipit-source-id: 472c184a655c1330f71f9f594f8804bec23e4c60
parent 8080bbbd
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <folly/Memory.h> #include <folly/Memory.h>
#include <algorithm>
#include <limits>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
...@@ -28,6 +30,10 @@ ...@@ -28,6 +30,10 @@
using namespace folly; using namespace folly;
static constexpr std::size_t kTooBig = std::max(
std::size_t{std::numeric_limits<uint32_t>::max()},
std::size_t{1} << (8 * sizeof(std::size_t) - 14));
TEST(aligned_malloc, examples) { TEST(aligned_malloc, examples) {
auto trial = [](size_t align) { auto trial = [](size_t align) {
auto const ptr = aligned_malloc(1, align); auto const ptr = aligned_malloc(1, align);
...@@ -86,7 +92,7 @@ TEST(SysAllocator, bad_alloc) { ...@@ -86,7 +92,7 @@ TEST(SysAllocator, bad_alloc) {
Alloc const alloc; Alloc const alloc;
std::vector<float, Alloc> nums(alloc); std::vector<float, Alloc> nums(alloc);
if (!kIsSanitize) { if (!kIsSanitize) {
EXPECT_THROW(nums.reserve(1ull << 50), std::bad_alloc); EXPECT_THROW(nums.reserve(kTooBig), std::bad_alloc);
} }
} }
...@@ -120,7 +126,7 @@ TEST(AlignedSysAllocator, bad_alloc_fixed) { ...@@ -120,7 +126,7 @@ TEST(AlignedSysAllocator, bad_alloc_fixed) {
Alloc const alloc; Alloc const alloc;
std::vector<float, Alloc> nums(alloc); std::vector<float, Alloc> nums(alloc);
if (!kIsSanitize) { if (!kIsSanitize) {
EXPECT_THROW(nums.reserve(1ull << 50), std::bad_alloc); EXPECT_THROW(nums.reserve(kTooBig), std::bad_alloc);
} }
} }
...@@ -156,7 +162,7 @@ TEST(AlignedSysAllocator, bad_alloc_default) { ...@@ -156,7 +162,7 @@ TEST(AlignedSysAllocator, bad_alloc_default) {
Alloc const alloc(1024); Alloc const alloc(1024);
std::vector<float, Alloc> nums(alloc); std::vector<float, Alloc> nums(alloc);
if (!kIsSanitize) { if (!kIsSanitize) {
EXPECT_THROW(nums.reserve(1ull << 50), std::bad_alloc); EXPECT_THROW(nums.reserve(kTooBig), std::bad_alloc);
} }
} }
......
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