Fix class member shadowing in folly::ProducerConsumerQueue
[folly.git] / folly / test / CacheLocalityTest.cpp
index 9c326fde4ba320b7f88b198ee8fc5ac8d695da8b..cb18f14c8fd50955778c347ff86c99dc48ddcf6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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;
 
@@ -413,7 +413,6 @@ TEST(AccessSpreader, Simple) {
   template <typename dummy>                            \
   struct tag {};                                       \
   }                                                    \
-  DECLARE_ACCESS_SPREADER_TYPE(tag)                    \
   namespace folly {                                    \
   namespace detail {                                   \
   template <>                                          \
@@ -445,4 +444,33 @@ TEST(AccessSpreader, Wrapping) {
     }
   }
 }
+
+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