/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <folly/detail/CacheLocality.h>
-#include <sched.h>
+#include <folly/portability/GTest.h>
+
#include <memory>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <glog/logging.h>
-#include <gtest/gtest.h>
using namespace folly::detail;
template <typename dummy> \
struct tag {}; \
} \
- DECLARE_ACCESS_SPREADER_TYPE(tag) \
namespace folly { \
namespace detail { \
template <> \
}
}
}
+
+TEST(CoreAllocator, Basic) {
+ CoreAllocator<32> alloc;
+ auto a = alloc.get(0);
+ auto res = a->allocate(8);
+ memset(res, 0, 8);
+ a->deallocate(res);
+ res = a->allocate(8);
+ EXPECT_TRUE((intptr_t)res % 8 == 0); // check alignment
+ memset(res, 0, 8);
+ a->deallocate(res);
+ res = a->allocate(12);
+ EXPECT_TRUE((intptr_t)res % 16 == 0); // check alignment
+ memset(res, 0, 12);
+ a->deallocate(res);
+ res = a->allocate(257);
+ memset(res, 0, 257);
+ a->deallocate(res);
+
+ std::vector<void*> mems;
+ for (int i = 0; i < 10000; i++) {
+ mems.push_back(a->allocate(1));
+ }
+ for (auto& mem : mems) {
+ a->deallocate(mem);
+ }
+ mems.clear();
+}
+
#endif