MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_single_memcpy

Function test_single_memcpy

dpdk/app/test/test_memcpy.c:46–97  ·  view source on GitHub ↗

* Create two buffers, and initialise one with random values. These are copied * to the second buffer and then compared to see if the copy was successful. * The bytes outside the copied area are also checked to make sure they were not * changed. */

Source from the content-addressed store, hash-verified

44 * changed.
45 */
46static int
47test_single_memcpy(unsigned int off_src, unsigned int off_dst, size_t size)
48{
49 unsigned int i;
50 uint8_t dest[SMALL_BUFFER_SIZE + ALIGNMENT_UNIT];
51 uint8_t src[SMALL_BUFFER_SIZE + ALIGNMENT_UNIT];
52 void * ret;
53
54 /* Setup buffers */
55 for (i = 0; i < SMALL_BUFFER_SIZE + ALIGNMENT_UNIT; i++) {
56 dest[i] = 0;
57 src[i] = (uint8_t) rte_rand();
58 }
59
60 /* Do the copy */
61 ret = rte_memcpy(dest + off_dst, src + off_src, size);
62 if (ret != (dest + off_dst)) {
63 printf("rte_memcpy() returned %p, not %p\n",
64 ret, dest + off_dst);
65 }
66
67 /* Check nothing before offset is affected */
68 for (i = 0; i < off_dst; i++) {
69 if (dest[i] != 0) {
70 printf("rte_memcpy() failed for %u bytes (offsets=%u,%u): "
71 "[modified before start of dst].\n",
72 (unsigned)size, off_src, off_dst);
73 return -1;
74 }
75 }
76
77 /* Check everything was copied */
78 for (i = 0; i < size; i++) {
79 if (dest[i + off_dst] != src[i + off_src]) {
80 printf("rte_memcpy() failed for %u bytes (offsets=%u,%u): "
81 "[didn't copy byte %u].\n",
82 (unsigned)size, off_src, off_dst, i);
83 return -1;
84 }
85 }
86
87 /* Check nothing after copy was affected */
88 for (i = size; i < SMALL_BUFFER_SIZE; i++) {
89 if (dest[i + off_dst] != 0) {
90 printf("rte_memcpy() failed for %u bytes (offsets=%u,%u): "
91 "[copied too many].\n",
92 (unsigned)size, off_src, off_dst);
93 return -1;
94 }
95 }
96 return 0;
97}
98
99/*
100 * Check functionality for various buffer sizes and data offsets/alignments.

Callers 1

func_testFunction · 0.85

Calls 3

rte_randFunction · 0.85
rte_memcpyFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected