proxygen
MemcpyTest.cpp File Reference

Go to the source code of this file.

Functions

 FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER ("nonnull-attribute")
 
void testLen (size_t len)
 
 TEST (memcpy, small)
 
 TEST (memcpy, main)
 

Function Documentation

FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER ( "nonnull-attribute"  )

Definition at line 36 of file MemcpyTest.cpp.

36  {
37  // If length is 0, we shouldn't touch any memory. So this should
38  // not crash.
39  char* srcNull = nullptr;
40  char* dstNull = nullptr;
41  memcpy(dstNull, srcNull, 0);
42 }
TEST ( memcpy  ,
small   
)

Definition at line 61 of file MemcpyTest.cpp.

References testLen().

61  {
62  for (size_t len = 1; len < 8; ++len) {
63  testLen(len);
64  }
65 }
void testLen(size_t len)
Definition: MemcpyTest.cpp:45
TEST ( memcpy  ,
main   
)

Definition at line 67 of file MemcpyTest.cpp.

References testLen().

67  {
68  for (size_t len = 8; len < 128; ++len) {
69  testLen(len);
70  }
71 
72  for (size_t len = 128; len < kSize; len += 128) {
73  testLen(len);
74  }
75 
76  for (size_t len = 128; len < kSize; len += 73) {
77  testLen(len);
78  }
79 }
void testLen(size_t len)
Definition: MemcpyTest.cpp:45
void testLen ( size_t  len)

Definition at line 45 of file MemcpyTest.cpp.

References EXPECT_EQ, i, and bm::init().

Referenced by TEST().

45  {
46  if (len > kSize) {
47  return;
48  }
49  init();
50  memcpy(dst, src, len);
51  for (size_t i = 0; i < len; ++i) {
52  EXPECT_EQ(src[i], static_cast<char>(i));
53  EXPECT_EQ(src[i], dst[i]);
54  }
55  if (len < kSize) {
56  EXPECT_EQ(src[len], static_cast<char>(len));
57  EXPECT_EQ(dst[len], static_cast<char>(255 - len));
58  }
59 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void init()