mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-11 15:22:13 +03:00
Device tests updates (#9246)
Stop pyexpect from closing serial port when running with WSL2 Remove makefile flags & opts making it too silent. At some point it makes a lot of useful info just disappear. There are external means of silencing make, so probably best to leave useful data always available Replace SPIFFS with LittleFS in FS test Re-use certs-from-mozilla.py in FS test Fix libc tests w/o -fno-builtin not actually testing anything, also add the flag via .globals.h in case it breaks Fix libc tests generating warnings when using invalid (but safe) size arguments
This commit is contained in:
@ -3,51 +3,130 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define memcmp memcmp_P
|
||||
#define memcpy memcpy_P
|
||||
#define memmem memmem_P
|
||||
#define memchr memchr_P
|
||||
#define strcat strcat_P
|
||||
#define strncat strncat_P
|
||||
#define strcpy strcpy_P
|
||||
#define strncpy strncpy_P
|
||||
#define strlen strlen_P
|
||||
#define strnlen strnlen_P
|
||||
#define strcmp strcmp_P
|
||||
#define strncmp strncmp_P
|
||||
#include <sys/pgmspace.h>
|
||||
|
||||
_CONST char* it = "<UNSET>"; /* Routine name for message routines. */
|
||||
/* esp8266/Arduino note
|
||||
*
|
||||
* Prevent the compiler from
|
||||
* - solving test cases below at compile time, effectively removing any checks
|
||||
* - optimizing out libc func calls, replacing them with bytewise memory access
|
||||
*
|
||||
* Plus, test framework cannot pass -fno-builtin-... per-file, only globally
|
||||
*/
|
||||
|
||||
#define xDST_SRC_N(T, NAME)\
|
||||
static T* __attribute__((used, noinline)) x ## NAME (T* dst, const T* src, size_t n)\
|
||||
{\
|
||||
return NAME (dst, src, n);\
|
||||
}
|
||||
|
||||
xDST_SRC_N (void, memcpy)
|
||||
xDST_SRC_N (void, memmove)
|
||||
xDST_SRC_N (char, strncat)
|
||||
xDST_SRC_N (char, strncpy)
|
||||
|
||||
#define xDST_SRC(T, NAME)\
|
||||
static T* __attribute__((used, noinline)) x ## NAME (T* dst, const T* src)\
|
||||
{\
|
||||
return NAME (dst, src);\
|
||||
}
|
||||
|
||||
xDST_SRC (char, strcat)
|
||||
xDST_SRC (char, strcpy)
|
||||
|
||||
#define xS1_S2_N(RET, T, NAME)\
|
||||
static RET __attribute__((used, noinline)) x ## NAME (const T *s1, const T *s2, size_t n)\
|
||||
{\
|
||||
return NAME (s1, s2, n);\
|
||||
}
|
||||
|
||||
xS1_S2_N(int, void, memcmp)
|
||||
xS1_S2_N(int, char, strncmp)
|
||||
|
||||
static int __attribute__((used, noinline)) xstrcmp (const char *s1, const char *s2)
|
||||
{
|
||||
return strcmp (s1, s2);
|
||||
}
|
||||
|
||||
static void* __attribute__((used, noinline)) xmemchr (const void* s, int c, size_t n)
|
||||
{
|
||||
return memchr (s, c, n);
|
||||
}
|
||||
|
||||
static size_t __attribute__((used, noinline)) xstrlen (const char* s)
|
||||
{
|
||||
return strlen (s);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/* TODO remove when libc supports pointers to flash */
|
||||
#undef PSTR
|
||||
#define PSTR(X) X
|
||||
|
||||
#define memcmp(s1,s2,n) xmemcmp(s1,PSTR(s2),n)
|
||||
#define memcpy(dest,src,n) xmemcpy(dest,PSTR(src),n)
|
||||
#define memmove(dest,src,n) xmemmove(dest,PSTR(src),n)
|
||||
#define memchr(s,c,n) xmemchr(PSTR(s),c,n)
|
||||
#define strcat(dst,src) xstrcat(dst,PSTR(src))
|
||||
#define strncat(dst,src,ssize) xstrncat(dst,PSTR(src),ssize)
|
||||
#define strcpy(dst,src) xstrcpy(dst,PSTR(src))
|
||||
#define strncpy(dst,src,dsize) xstrncpy(dst,PSTR(src),dsize)
|
||||
#define strlen(s) xstrlen(PSTR(s))
|
||||
#define strcmp(s1,s2) xstrcmp(s1,PSTR(s2))
|
||||
#define strncmp(s1,s2,n) xstrncmp(s1,PSTR(s2),n)
|
||||
|
||||
#else
|
||||
|
||||
/* in case wrapped calls are not required */
|
||||
|
||||
#define memcmp(s1,s2,n) memcmp_P(s1,PSTR(s2),n)
|
||||
#define memcpy(dest,src,n) memcpy_P(dest,PSTR(src),n)
|
||||
#define memmove(dest,src,n) memmove_P(dest,PSTR(src),n)
|
||||
#define memchr(s,c,n) memchr_P(PSTR(s),c,n)
|
||||
#define strcat(dst,src) strcat_P(dst,PSTR(src))
|
||||
#define strncat(dst,src,ssize) strncat_P(dst,PSTR(src),ssize)
|
||||
#define strcpy(dst,src) strcpy_P(dst,PSTR(src))
|
||||
#define strncpy(dst,src,dsize) strncpy_P(dst,PSTR(src),dsize)
|
||||
#define strlen(s) strlen_P(PSTR(s))
|
||||
#define strcmp(s1,s2) strcmp_P(s1,PSTR(s2))
|
||||
#define strncmp(s1,s2,n) strncmp_P(s1,PSTR(s2),n)
|
||||
|
||||
#endif
|
||||
|
||||
static const char Unset[] PROGMEM = "<UNSET>";
|
||||
|
||||
const char* it = Unset; /* Routine name for message routines. */
|
||||
static int errors = 0;
|
||||
|
||||
/* Complain if condition is not true. */
|
||||
#define check(thing) checkit(thing, __LINE__)
|
||||
|
||||
static void _DEFUN(checkit, (ok, l), int ok _AND int l)
|
||||
|
||||
static void checkit(int ok, int l)
|
||||
{
|
||||
// newfunc(it);
|
||||
// line(l);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
printf("string.c:%d %s\n", l, it);
|
||||
printf(PSTR("string.c:%d %s\n"), l, it);
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
|
||||
/* Complain if first two args don't strcmp as equal. */
|
||||
#define equal(a, b) funcqual(a, b, __LINE__);
|
||||
#define equal(a, b) funcqual(a, PSTR(b), __LINE__);
|
||||
|
||||
static void _DEFUN(funcqual, (a, b, l), char* a _AND char* b _AND int l)
|
||||
static void funcqual(const char *a, const char *b, int l)
|
||||
{
|
||||
// newfunc(it);
|
||||
|
||||
// line(l);
|
||||
if (a == NULL && b == NULL)
|
||||
return;
|
||||
if (strcmp(a, b))
|
||||
if (strcmp_P(a, b))
|
||||
{
|
||||
printf("string.c:%d (%s)\n", l, it);
|
||||
printf(PSTR("string.c:%d (%s)\n"), l, it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +136,7 @@ static char two[50];
|
||||
void libm_test_string()
|
||||
{
|
||||
/* Test strcmp first because we use it to test other things. */
|
||||
it = "strcmp";
|
||||
it = PSTR("strcmp");
|
||||
check(strcmp("", "") == 0); /* Trivial case. */
|
||||
check(strcmp("a", "a") == 0); /* Identity. */
|
||||
check(strcmp("abc", "abc") == 0); /* Multicharacter. */
|
||||
@ -69,7 +148,7 @@ void libm_test_string()
|
||||
check(strcmp("a\103", "a\003") > 0);
|
||||
|
||||
/* Test strcpy next because we need it to set up other tests. */
|
||||
it = "strcpy";
|
||||
it = PSTR("strcpy");
|
||||
check(strcpy(one, "abcd") == one); /* Returned value. */
|
||||
equal(one, "abcd"); /* Basic test. */
|
||||
|
||||
@ -78,7 +157,7 @@ void libm_test_string()
|
||||
equal(one + 2, "cd"); /* Wrote too much? */
|
||||
|
||||
(void)strcpy(two, "hi there");
|
||||
(void)strcpy(one, two);
|
||||
(void)xstrcpy(one, two);
|
||||
equal(one, "hi there"); /* Basic test encore. */
|
||||
equal(two, "hi there"); /* Stomped on source? */
|
||||
|
||||
@ -86,7 +165,7 @@ void libm_test_string()
|
||||
equal(one, ""); /* Boundary condition. */
|
||||
|
||||
/* strcat. */
|
||||
it = "strcat";
|
||||
it = PSTR("strcat");
|
||||
(void)strcpy(one, "ijk");
|
||||
check(strcat(one, "lmn") == one); /* Returned value. */
|
||||
equal(one, "ijklmn"); /* Basic test. */
|
||||
@ -98,7 +177,7 @@ void libm_test_string()
|
||||
|
||||
(void)strcpy(one, "gh");
|
||||
(void)strcpy(two, "ef");
|
||||
(void)strcat(one, two);
|
||||
(void)xstrcpy(one, two);
|
||||
equal(one, "ghef"); /* Basic test encore. */
|
||||
equal(two, "ef"); /* Stomped on source? */
|
||||
|
||||
@ -114,42 +193,67 @@ void libm_test_string()
|
||||
|
||||
/* strncat - first test it as strcat, with big counts,
|
||||
then test the count mechanism. */
|
||||
it = "strncat";
|
||||
it = PSTR("strncat");
|
||||
(void)strcpy(one, "ijk");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow="
|
||||
check(strncat(one, "lmn", 99) == one); /* Returned value. */
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "ijklmn"); /* Basic test. */
|
||||
|
||||
(void)strcpy(one, "x");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow="
|
||||
(void)strncat(one, "yz", 99);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "xyz"); /* Writeover. */
|
||||
equal(one + 4, "mn"); /* Wrote too much? */
|
||||
|
||||
(void)strcpy(one, "gh");
|
||||
(void)strcpy(two, "ef");
|
||||
(void)strncat(one, two, 99);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Warray-bounds="
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow="
|
||||
(void)xstrncat(one, two, 99);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "ghef"); /* Basic test encore. */
|
||||
equal(two, "ef"); /* Stomped on source? */
|
||||
|
||||
(void)strcpy(one, "");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow="
|
||||
(void)strncat(one, "", 99);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, ""); /* Boundary conditions. */
|
||||
(void)strcpy(one, "ab");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow="
|
||||
(void)strncat(one, "", 99);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "ab");
|
||||
(void)strcpy(one, "");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow="
|
||||
(void)strncat(one, "cd", 99);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "cd");
|
||||
|
||||
(void)strcpy(one, "ab");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
(void)strncat(one, "cdef", 2);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "abcd"); /* Count-limited. */
|
||||
|
||||
(void)strncat(one, "gh", 0);
|
||||
equal(one, "abcd"); /* Zero count. */
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
||||
(void)strncat(one, "gh", 2);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "abcdgh"); /* Count _AND length equal. */
|
||||
it = "strncmp";
|
||||
it = PSTR("strncmp");
|
||||
/* strncmp - first test as strcmp with big counts";*/
|
||||
check(strncmp("", "", 99) == 0); /* Trivial case. */
|
||||
check(strncmp("a", "a", 99) == 0); /* Identity. */
|
||||
@ -164,16 +268,22 @@ void libm_test_string()
|
||||
check(strncmp("abc", "def", 0) == 0); /* Zero count. */
|
||||
|
||||
/* strncpy - testing is a bit different because of odd semantics. */
|
||||
it = "strncpy";
|
||||
it = PSTR("strncpy");
|
||||
check(strncpy(one, "abc", 4) == one); /* Returned value. */
|
||||
equal(one, "abc"); /* Did the copy go right? */
|
||||
|
||||
(void)strcpy(one, "abcdefgh");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
(void)strncpy(one, "xyz", 2);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "xycdefgh"); /* Copy cut by count. */
|
||||
|
||||
(void)strcpy(one, "abcdefgh");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
(void)strncpy(one, "xyz", 3); /* Copy cut just before NUL. */
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "xyzdefgh");
|
||||
|
||||
(void)strcpy(one, "abcdefgh");
|
||||
@ -188,7 +298,10 @@ void libm_test_string()
|
||||
equal(one + 5, "fgh");
|
||||
|
||||
(void)strcpy(one, "abc");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
(void)strncpy(one, "xyz", 0); /* Zero-length copy. */
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "abc");
|
||||
|
||||
(void)strncpy(one, "", 2); /* Zero-length source. */
|
||||
@ -197,18 +310,18 @@ void libm_test_string()
|
||||
equal(one + 2, "c");
|
||||
|
||||
(void)strcpy(one, "hi there");
|
||||
(void)strncpy(two, one, 9);
|
||||
(void)xstrncpy(two, one, 9);
|
||||
equal(two, "hi there"); /* Just paranoia. */
|
||||
equal(one, "hi there"); /* Stomped on source? */
|
||||
|
||||
/* strlen. */
|
||||
it = "strlen";
|
||||
it = PSTR("strlen");
|
||||
check(strlen("") == 0); /* Empty. */
|
||||
check(strlen("a") == 1); /* Single char. */
|
||||
check(strlen("abcd") == 4); /* Multiple chars. */
|
||||
|
||||
/* strchr. */
|
||||
it = "strchr";
|
||||
it = PSTR("strchr");
|
||||
check(strchr("abcd", 'z') == NULL); /* Not found. */
|
||||
(void)strcpy(one, "abcd");
|
||||
check(strchr(one, 'c') == one + 2); /* Basic test. */
|
||||
@ -222,7 +335,7 @@ void libm_test_string()
|
||||
check(strchr(one, '\0') == one); /* NUL in empty string. */
|
||||
|
||||
/* index - just like strchr. */
|
||||
it = "index";
|
||||
it = PSTR("index");
|
||||
check(index("abcd", 'z') == NULL); /* Not found. */
|
||||
(void)strcpy(one, "abcd");
|
||||
check(index(one, 'c') == one + 2); /* Basic test. */
|
||||
@ -236,7 +349,7 @@ void libm_test_string()
|
||||
check(index(one, '\0') == one); /* NUL in empty string. */
|
||||
|
||||
/* strrchr. */
|
||||
it = "strrchr";
|
||||
it = PSTR("strrchr");
|
||||
check(strrchr("abcd", 'z') == NULL); /* Not found. */
|
||||
(void)strcpy(one, "abcd");
|
||||
check(strrchr(one, 'c') == one + 2); /* Basic test. */
|
||||
@ -250,7 +363,7 @@ void libm_test_string()
|
||||
check(strrchr(one, '\0') == one); /* NUL in empty string. */
|
||||
|
||||
/* rindex - just like strrchr. */
|
||||
it = "rindex";
|
||||
it = PSTR("rindex");
|
||||
check(rindex("abcd", 'z') == NULL); /* Not found. */
|
||||
(void)strcpy(one, "abcd");
|
||||
check(rindex(one, 'c') == one + 2); /* Basic test. */
|
||||
@ -264,7 +377,7 @@ void libm_test_string()
|
||||
check(rindex(one, '\0') == one); /* NUL in empty string. */
|
||||
|
||||
/* strpbrk - somewhat like strchr. */
|
||||
it = "strpbrk";
|
||||
it = PSTR("strpbrk");
|
||||
check(strpbrk("abcd", "z") == NULL); /* Not found. */
|
||||
(void)strcpy(one, "abcd");
|
||||
check(strpbrk(one, "c") == one + 2); /* Basic test. */
|
||||
@ -281,7 +394,7 @@ void libm_test_string()
|
||||
check(strpbrk(one, "") == NULL); /* Both strings empty. */
|
||||
|
||||
/* strstr - somewhat like strchr. */
|
||||
it = "strstr";
|
||||
it = PSTR("strstr");
|
||||
check(strstr("z", "abcd") == NULL); /* Not found. */
|
||||
check(strstr("abx", "abcd") == NULL); /* Dead end. */
|
||||
(void)strcpy(one, "abcd");
|
||||
@ -304,7 +417,7 @@ void libm_test_string()
|
||||
check(strstr(one, "bbca") == one + 1); /* With overlap. */
|
||||
|
||||
/* strspn. */
|
||||
it = "strspn";
|
||||
it = PSTR("strspn");
|
||||
check(strspn("abcba", "abc") == 5); /* Whole string. */
|
||||
check(strspn("abcba", "ab") == 2); /* Partial. */
|
||||
check(strspn("abc", "qx") == 0); /* None. */
|
||||
@ -312,7 +425,7 @@ void libm_test_string()
|
||||
check(strspn("abc", "") == 0); /* Null search list. */
|
||||
|
||||
/* strcspn. */
|
||||
it = "strcspn";
|
||||
it = PSTR("strcspn");
|
||||
check(strcspn("abcba", "qx") == 5); /* Whole string. */
|
||||
check(strcspn("abcba", "cx") == 2); /* Partial. */
|
||||
check(strcspn("abc", "abc") == 0); /* None. */
|
||||
@ -320,7 +433,7 @@ void libm_test_string()
|
||||
check(strcspn("abc", "") == 3); /* Null search list. */
|
||||
|
||||
/* strtok - the hard one. */
|
||||
it = "strtok";
|
||||
it = PSTR("strtok");
|
||||
(void)strcpy(one, "first, second, third");
|
||||
equal(strtok(one, ", "), "first"); /* Basic test. */
|
||||
equal(one, "first");
|
||||
@ -367,7 +480,7 @@ void libm_test_string()
|
||||
equal(one + 4, "c");
|
||||
|
||||
/* memcmp. */
|
||||
it = "memcmp";
|
||||
it = PSTR("memcmp");
|
||||
check(memcmp("a", "a", 1) == 0); /* Identity. */
|
||||
check(memcmp("abc", "abc", 3) == 0); /* Multicharacter. */
|
||||
check(memcmp("abcd", "abce", 4) < 0); /* Honestly unequal. */
|
||||
@ -379,25 +492,25 @@ void libm_test_string()
|
||||
/* memcmp should test strings as unsigned */
|
||||
one[0] = 0xfe;
|
||||
two[0] = 0x03;
|
||||
check(memcmp(one, two, 1) > 0);
|
||||
check(xmemcmp(one, two, 1) > 0);
|
||||
|
||||
/* memchr. */
|
||||
it = "memchr";
|
||||
it = PSTR("memchr");
|
||||
check(memchr("abcd", 'z', 4) == NULL); /* Not found. */
|
||||
(void)strcpy(one, "abcd");
|
||||
check(memchr(one, 'c', 4) == one + 2); /* Basic test. */
|
||||
check(memchr(one, 'd', 4) == one + 3); /* End of string. */
|
||||
check(memchr(one, 'a', 4) == one); /* Beginning. */
|
||||
check(memchr(one, '\0', 5) == one + 4); /* Finding NUL. */
|
||||
check(xmemchr(one, 'c', 4) == one + 2); /* Basic test. */
|
||||
check(xmemchr(one, 'd', 4) == one + 3); /* End of string. */
|
||||
check(xmemchr(one, 'a', 4) == one); /* Beginning. */
|
||||
check(xmemchr(one, '\0', 5) == one + 4); /* Finding NUL. */
|
||||
(void)strcpy(one, "ababa");
|
||||
check(memchr(one, 'b', 5) == one + 1); /* Finding first. */
|
||||
check(memchr(one, 'b', 0) == NULL); /* Zero count. */
|
||||
check(memchr(one, 'a', 1) == one); /* Singleton case. */
|
||||
check(xmemchr(one, 'b', 5) == one + 1); /* Finding first. */
|
||||
check(xmemchr(one, 'b', 0) == NULL); /* Zero count. */
|
||||
check(xmemchr(one, 'a', 1) == one); /* Singleton case. */
|
||||
(void)strcpy(one, "a\203b");
|
||||
check(memchr(one, 0203, 3) == one + 1); /* Unsignedness. */
|
||||
check(xmemchr(one, 0203, 3) == one + 1); /* Unsignedness. */
|
||||
|
||||
/* memcpy - need not work for overlap. */
|
||||
it = "memcpy";
|
||||
it = PSTR("memcpy");
|
||||
check(memcpy(one, "abc", 4) == one); /* Returned value. */
|
||||
equal(one, "abc"); /* Did the copy go right? */
|
||||
|
||||
@ -411,13 +524,13 @@ void libm_test_string()
|
||||
|
||||
(void)strcpy(one, "hi there");
|
||||
(void)strcpy(two, "foo");
|
||||
(void)memcpy(two, one, 9);
|
||||
(void)xmemcpy(two, one, 9);
|
||||
equal(two, "hi there"); /* Just paranoia. */
|
||||
equal(one, "hi there"); /* Stomped on source? */
|
||||
#if 0
|
||||
#if 1
|
||||
/* memmove - must work on overlap. */
|
||||
it = "memmove";
|
||||
check(memmove(one, "abc", 4) == one); /* Returned value. */
|
||||
it = PSTR("memmove");
|
||||
check(xmemmove(one, "abc", 4) == one); /* Returned value. */
|
||||
equal(one, "abc"); /* Did the copy go right? */
|
||||
|
||||
(void) strcpy(one, "abcdefgh");
|
||||
@ -430,20 +543,20 @@ void libm_test_string()
|
||||
|
||||
(void) strcpy(one, "hi there");
|
||||
(void) strcpy(two, "foo");
|
||||
(void) memmove(two, one, 9);
|
||||
(void) xmemmove(two, one, 9);
|
||||
equal(two, "hi there"); /* Just paranoia. */
|
||||
equal(one, "hi there"); /* Stomped on source? */
|
||||
|
||||
(void) strcpy(one, "abcdefgh");
|
||||
(void) memmove(one+1, one, 9);
|
||||
(void) xmemmove(one+1, one, 9);
|
||||
equal(one, "aabcdefgh"); /* Overlap, right-to-left. */
|
||||
|
||||
(void) strcpy(one, "abcdefgh");
|
||||
(void) memmove(one+1, one+2, 7);
|
||||
(void) xmemmove(one+1, one+2, 7);
|
||||
equal(one, "acdefgh"); /* Overlap, left-to-right. */
|
||||
|
||||
(void) strcpy(one, "abcdefgh");
|
||||
(void) memmove(one, one, 9);
|
||||
(void) xmemmove(one, one, 9);
|
||||
equal(one, "abcdefgh"); /* 100% overlap. */
|
||||
#endif
|
||||
#if 0
|
||||
@ -451,7 +564,7 @@ void libm_test_string()
|
||||
The SVID, the only place where memccpy is mentioned, says
|
||||
overlap might fail, so we don't try it. Besides, it's hard
|
||||
to see the rationale for a non-left-to-right memccpy. */
|
||||
it = "memccpy";
|
||||
it = PSTR("memccpy");
|
||||
check(memccpy(one, "abc", 'q', 4) == NULL); /* Returned value. */
|
||||
equal(one, "abc"); /* Did the copy go right? */
|
||||
|
||||
@ -486,12 +599,15 @@ void libm_test_string()
|
||||
equal(two, "xbcdlebee");
|
||||
#endif
|
||||
/* memset. */
|
||||
it = "memset";
|
||||
it = PSTR("memset");
|
||||
(void)strcpy(one, "abcdefgh");
|
||||
check(memset(one + 1, 'x', 3) == one + 1); /* Return value. */
|
||||
equal(one, "axxxefgh"); /* Basic test. */
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmemset-transposed-args"
|
||||
(void)memset(one + 2, 'y', 0);
|
||||
#pragma GCC diagnostic pop
|
||||
equal(one, "axxxefgh"); /* Zero-length set. */
|
||||
|
||||
(void)memset(one + 5, 0, 1);
|
||||
@ -503,7 +619,7 @@ void libm_test_string()
|
||||
|
||||
/* bcopy - much like memcpy.
|
||||
Berklix manual is silent about overlap, so don't test it. */
|
||||
it = "bcopy";
|
||||
it = PSTR("bcopy");
|
||||
(void)bcopy("abc", one, 4);
|
||||
equal(one, "abc"); /* Simple copy. */
|
||||
|
||||
@ -522,7 +638,7 @@ void libm_test_string()
|
||||
equal(one, "hi there"); /* Stomped on source? */
|
||||
|
||||
/* bzero. */
|
||||
it = "bzero";
|
||||
it = PSTR("bzero");
|
||||
(void)strcpy(one, "abcdef");
|
||||
bzero(one + 2, 2);
|
||||
equal(one, "ab"); /* Basic test. */
|
||||
@ -534,7 +650,7 @@ void libm_test_string()
|
||||
equal(one, "abcdef"); /* Zero-length copy. */
|
||||
|
||||
/* bcmp - somewhat like memcmp. */
|
||||
it = "bcmp";
|
||||
it = PSTR("bcmp");
|
||||
check(bcmp("a", "a", 1) == 0); /* Identity. */
|
||||
check(bcmp("abc", "abc", 3) == 0); /* Multicharacter. */
|
||||
check(bcmp("abcd", "abce", 4) != 0); /* Honestly unequal. */
|
||||
|
Reference in New Issue
Block a user