test(errno): make test_strerror self-contained under -Iinclude
This commit is contained in:
+30
-6
@@ -18,22 +18,44 @@
|
|||||||
* writing it would corrupt the host (see tests/syscall_test.c). All coverage
|
* writing it would corrupt the host (see tests/syscall_test.c). All coverage
|
||||||
* here is through the errnum parameters.
|
* here is through the errnum parameters.
|
||||||
*
|
*
|
||||||
|
* All diagnostics go through raw SYS_write (no stdio): under -Iinclude the
|
||||||
|
* vlibc public headers shadow GCC's internal ones, so mixing in a host
|
||||||
|
* <stdio.h> breaks compilation (glibc's stdio.h pulls in our minimal
|
||||||
|
* <stdarg.h>, which lacks __gnuc_va_list). <string.h> below is vlibc's own
|
||||||
|
* header, which is safe.
|
||||||
|
*
|
||||||
* Not part of the library proper; compiled manually for this todo (the
|
* Not part of the library proper; compiled manually for this todo (the
|
||||||
* tests/ + make check wiring is owned by a later todo).
|
* tests/ + make check wiring is owned by a later todo).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../src/internal/syscall.h"
|
||||||
|
|
||||||
static int failures;
|
static int failures;
|
||||||
|
|
||||||
|
/* Write a NUL-terminated string to fd via the raw syscall layer. */
|
||||||
|
static void
|
||||||
|
say(int fd, const char *s)
|
||||||
|
{
|
||||||
|
long n = 0;
|
||||||
|
|
||||||
|
while (s[n] != '\0')
|
||||||
|
{
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
__syscall3(SYS_write, fd, (long)s, n);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check(int cond, const char *what)
|
check(int cond, const char *what)
|
||||||
{
|
{
|
||||||
if (!cond)
|
if (!cond)
|
||||||
{
|
{
|
||||||
printf("FAIL: %s\n", what);
|
say(2, "FAIL: ");
|
||||||
|
say(2, what);
|
||||||
|
say(2, "\n");
|
||||||
failures++;
|
failures++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,10 +72,12 @@ failure_scenario(void)
|
|||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
{
|
{
|
||||||
printf("strerror(9999)=NULL\n");
|
say(1, "strerror(9999)=NULL\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("strerror(9999)=%s\n", s);
|
say(1, "strerror(9999)=");
|
||||||
|
say(1, s);
|
||||||
|
say(1, "\n");
|
||||||
return strcmp(s, "Unknown error 9999") == 0 ? 0 : 1;
|
return strcmp(s, "Unknown error 9999") == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,11 +159,11 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (failures > 0)
|
if (failures > 0)
|
||||||
{
|
{
|
||||||
printf("FAILED\n");
|
say(2, "FAILED\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("strerror ok\n");
|
say(1, "strerror ok\n");
|
||||||
}
|
}
|
||||||
return failures == 0 ? 0 : 1;
|
return failures == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user