Use std::this_thread::yield rather than sched_yield
[folly.git] / folly / test / MemcpyTest.cpp
index f31d54e04ec06e37702fc622d63d6540282a4203..f9f5a4336e8614cab2b0375438b69edc4c97ba3e 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/Portability.h>
 
-#include <gtest/gtest.h>
+#include <folly/portability/GTest.h>
 
 namespace {
 
-constexpr size_t SIZE = 4096 * 4;
-char src[SIZE];
-char dst[SIZE];
+constexpr size_t kSize = 4096 * 4;
+char src[kSize];
+char dst[kSize];
 
 void init() {
-  for (size_t i = 0; i < SIZE; ++i) {
+  for (size_t i = 0; i < kSize; ++i) {
     src[i] = static_cast<char>(i);
     dst[i] = static_cast<char>(255 - i);
   }
 }
 }
 
-TEST(memcpy, zero_len) UBSAN_DISABLE("nonnull-attribute") {
+TEST(memcpy, zero_len)
+    FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER("nonnull-attribute") {
   // If length is 0, we shouldn't touch any memory.  So this should
   // not crash.
   char* srcNull = nullptr;
@@ -42,7 +43,7 @@ TEST(memcpy, zero_len) UBSAN_DISABLE("nonnull-attribute") {
 
 // Test copy `len' bytes and verify that exactly `len' bytes are copied.
 void testLen(size_t len) {
-  if (len > SIZE) {
+  if (len > kSize) {
     return;
   }
   init();
@@ -51,7 +52,7 @@ void testLen(size_t len) {
     EXPECT_EQ(src[i], static_cast<char>(i));
     EXPECT_EQ(src[i], dst[i]);
   }
-  if (len < SIZE) {
+  if (len < kSize) {
     EXPECT_EQ(src[len], static_cast<char>(len));
     EXPECT_EQ(dst[len], static_cast<char>(255 - len));
   }
@@ -68,11 +69,11 @@ TEST(memcpy, main) {
     testLen(len);
   }
 
-  for (size_t len = 128; len < SIZE; len += 128) {
+  for (size_t len = 128; len < kSize; len += 128) {
     testLen(len);
   }
 
-  for (size_t len = 128; len < SIZE; len += 73) {
+  for (size_t len = 128; len < kSize; len += 73) {
     testLen(len);
   }
 }