| 1 |
/*------------------------------------------------------------------ |
| 2 |
* test_memmove32_s |
| 3 |
* |
| 4 |
* |
| 5 |
*= |
| 6 |
*------------------------------------------------------------------ |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "test_private.h" |
| 10 |
#include "safe_mem_lib.h" |
| 11 |
|
| 12 |
#define LEN ( 1024 ) |
| 13 |
|
| 14 |
int test_memmove32_s() |
| 15 |
{ |
| 16 |
errno_t rc; |
| 17 |
uint32_t i; |
| 18 |
uint32_t len; |
| 19 |
|
| 20 |
uint32_t mem1[LEN]; |
| 21 |
uint32_t mem2[LEN]; |
| 22 |
|
| 23 |
/*--------------------------------------------------*/ |
| 24 |
|
| 25 |
rc = memmove32_s(NULL, LEN, mem2, LEN); |
| 26 |
if (rc != ESNULLP) { |
| 27 |
debug_printf("%s %u Error rc=%u \n", |
| 28 |
__FUNCTION__, __LINE__, rc); |
| 29 |
} |
| 30 |
|
| 31 |
/*--------------------------------------------------*/ |
| 32 |
|
| 33 |
rc = memmove32_s(mem1, 0, mem2, LEN); |
| 34 |
if (rc != ESZEROL) { |
| 35 |
debug_printf("%s %u Error rc=%u \n", |
| 36 |
__FUNCTION__, __LINE__, rc); |
| 37 |
} |
| 38 |
|
| 39 |
/*--------------------------------------------------*/ |
| 40 |
|
| 41 |
rc = memmove32_s(mem1, RSIZE_MAX_MEM16+1, mem2, LEN); |
| 42 |
if (rc != ESLEMAX) { |
| 43 |
debug_printf("%s %u Error rc=%u \n", |
| 44 |
__FUNCTION__, __LINE__, rc); |
| 45 |
} |
| 46 |
|
| 47 |
/*--------------------------------------------------*/ |
| 48 |
|
| 49 |
rc = memmove32_s(mem1, LEN, NULL, LEN); |
| 50 |
if (rc != ESNULLP) { |
| 51 |
debug_printf("%s %u Error rc=%u \n", |
| 52 |
__FUNCTION__, __LINE__, rc); |
| 53 |
} |
| 54 |
|
| 55 |
/*--------------------------------------------------*/ |
| 56 |
|
| 57 |
rc = memmove32_s(mem1, 10, mem2, 0); |
| 58 |
if (rc != ESZEROL) { |
| 59 |
debug_printf("%s %u Error rc=%u \n", |
| 60 |
__FUNCTION__, __LINE__, rc); |
| 61 |
} |
| 62 |
|
| 63 |
/*--------------------------------------------------*/ |
| 64 |
|
| 65 |
rc = memmove32_s(mem1, LEN, mem2, RSIZE_MAX_MEM16+1); |
| 66 |
if (rc != ESLEMAX) { |
| 67 |
debug_printf("%s %u Error rc=%u \n", |
| 68 |
__FUNCTION__, __LINE__, rc); |
| 69 |
} |
| 70 |
|
| 71 |
/*--------------------------------------------------*/ |
| 72 |
|
| 73 |
for (i=0; i<LEN; i++) { mem1[i] = 33; } |
| 74 |
for (i=0; i<LEN; i++) { mem2[i] = 44; } |
| 75 |
|
| 76 |
/* a valid move */ |
| 77 |
len = LEN; |
| 78 |
rc = memmove32_s(mem1, len, mem2, len); |
| 79 |
if (rc != EOK) { |
| 80 |
debug_printf("%s %u Error rc=%u \n", |
| 81 |
__FUNCTION__, __LINE__, rc); |
| 82 |
} |
| 83 |
|
| 84 |
for (i=0; i<len; i++) { |
| 85 |
if (mem1[i] != mem2[i]) { |
| 86 |
printf("%d m1=%d m2=%d \n", |
| 87 |
i, mem1[i], mem2[i]); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/*--------------------------------------------------*/ |
| 92 |
|
| 93 |
/*--------------------------------------------------*/ |
| 94 |
|
| 95 |
for (i=0; i<LEN; i++) { mem1[i] = 33; } |
| 96 |
for (i=0; i<LEN; i++) { mem2[i] = 44; } |
| 97 |
|
| 98 |
/* length error */ |
| 99 |
len = LEN/2; |
| 100 |
rc = memmove32_s(mem1, len, mem2, LEN); |
| 101 |
if (rc != ESLEMAX) { |
| 102 |
debug_printf("%s %u Error rc=%u \n", |
| 103 |
__FUNCTION__, __LINE__, rc); |
| 104 |
} |
| 105 |
|
| 106 |
/* verify mem1 was zeroed */ |
| 107 |
for (i=0; i<len; i++) { |
| 108 |
if (mem1[i] != 0) { |
| 109 |
printf("%d - %d m1=%d \n", |
| 110 |
__LINE__, i, mem1[i]); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/*--------------------------------------------------*/ |
| 115 |
|
| 116 |
for (i=0; i<LEN; i++) { mem1[i] = 33; } |
| 117 |
for (i=0; i<LEN; i++) { mem2[i] = 44; } |
| 118 |
|
| 119 |
/* invalid length - zero dest */ |
| 120 |
len = LEN; |
| 121 |
rc = memmove32_s(mem1, len, mem2, 0); |
| 122 |
if (rc != ESZEROL) { |
| 123 |
debug_printf("%s %u Error rc=%u \n", |
| 124 |
__FUNCTION__, __LINE__, rc); |
| 125 |
} |
| 126 |
|
| 127 |
/* verify mem1 was zeroed */ |
| 128 |
for (i=0; i<len; i++) { |
| 129 |
if (mem1[i] != 0) { |
| 130 |
printf("%d - %d m1=%d \n", |
| 131 |
__LINE__, i, mem1[i]); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
/*--------------------------------------------------*/ |
| 136 |
|
| 137 |
/*--------------------------------------------------*/ |
| 138 |
|
| 139 |
for (i=0; i<LEN; i++) { mem1[i] = 33; } |
| 140 |
for (i=0; i<LEN; i++) { mem2[i] = 44; } |
| 141 |
|
| 142 |
/* invalid length - zero dest */ |
| 143 |
len = LEN; |
| 144 |
rc = memmove32_s(mem1, len, mem2, RSIZE_MAX_MEM+1); |
| 145 |
if (rc != ESLEMAX) { |
| 146 |
debug_printf("%s %u Error rc=%u \n", |
| 147 |
__FUNCTION__, __LINE__, rc); |
| 148 |
} |
| 149 |
|
| 150 |
/* verify mem1 was zeroed */ |
| 151 |
for (i=0; i<len; i++) { |
| 152 |
if (mem1[i] != 0) { |
| 153 |
printf("%d - %d m1=%d \n", |
| 154 |
__LINE__, i, mem1[i]); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
/*--------------------------------------------------*/ |
| 159 |
|
| 160 |
for (i=0; i<LEN; i++) { mem1[i] = 33; } |
| 161 |
for (i=0; i<LEN; i++) { mem2[i] = 44; } |
| 162 |
|
| 163 |
/* same ptr - no move */ |
| 164 |
rc = memmove32_s(mem1, LEN, mem1, LEN); |
| 165 |
if (rc != EOK) { |
| 166 |
debug_printf("%s %u Error rc=%u \n", |
| 167 |
__FUNCTION__, __LINE__, rc); |
| 168 |
} |
| 169 |
|
| 170 |
/*--------------------------------------------------*/ |
| 171 |
|
| 172 |
for (i=0; i<LEN; i++) { mem1[i] = 25; } |
| 173 |
for (i=10; i<LEN-10; i++) { mem1[i] = 35; } |
| 174 |
|
| 175 |
/* overlap move */ |
| 176 |
len = 20; |
| 177 |
rc = memmove32_s(&mem1[0], len, &mem1[10], len); |
| 178 |
if (rc != EOK) { |
| 179 |
debug_printf("%s %u Error rc=%u \n", |
| 180 |
__FUNCTION__, __LINE__, rc); |
| 181 |
} |
| 182 |
|
| 183 |
for (i=0; i<len; i++) { |
| 184 |
if (mem1[i] != 35) { |
| 185 |
printf("%d - %d m1=%d \n", |
| 186 |
__LINE__, i, mem1[i]); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
/*--------------------------------------------------*/ |
| 191 |
|
| 192 |
for (i=0; i<LEN; i++) { mem1[i] = 25; } |
| 193 |
for (i=10; i<LEN-10; i++) { mem1[i] = 35; } |
| 194 |
|
| 195 |
/* overlap move */ |
| 196 |
len = 20; |
| 197 |
rc = memmove32_s(&mem1[10], len, &mem1[0], len); |
| 198 |
if (rc != EOK) { |
| 199 |
debug_printf("%s %u Error rc=%u \n", |
| 200 |
__FUNCTION__, __LINE__, rc); |
| 201 |
} |
| 202 |
|
| 203 |
for (i=0; i<10; i++) { |
| 204 |
if (mem1[i] != 25) { |
| 205 |
printf("%d - %d m1=%d \n", |
| 206 |
__LINE__, i, mem1[i]); |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
/*--------------------------------------------------*/ |
| 211 |
/*--------------------------------------------------*/ |
| 212 |
|
| 213 |
return (0); |
| 214 |
} |