ref: 5eb2945975eab587998f04bf277ec09fcfcec0e1
parent: 67b4a92153e09d3e2ad6a4cd26e64e7878054785
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Sep 5 17:42:28 EDT 2018
[tests/libc] Add 0009-stdarg and 0010-stddef 0009-stdarg is known to fail but th eexact reason is not known yet.
--- a/rootdir/include/scc/limits.h
+++ b/rootdir/include/scc/limits.h
@@ -3,6 +3,6 @@
#include <arch/limits.h>
-#define MB_LEN_MAX 1
+#define MB_LEN_MAX 4
#endif
--- a/tests/libc/execute/0006-limits.c
+++ b/tests/libc/execute/0006-limits.c
@@ -76,6 +76,9 @@
LLONG_MAX < LONG_MAX || LLONG_MIN > LONG_MIN ||
ULLONG_MAX < ULONG_MAX)
puts("wrong long long definition");
+
+ if (MB_LEN_MAX < sizeof(char))
+ puts("wrong value for MB_LEN_MAX");
}
--- /dev/null
+++ b/tests/libc/execute/0009-stdarg.c
@@ -1,0 +1,79 @@
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+output:
+test 1
+test 2
+end:
+*/
+
+void
+test(char *s, char *fmt, ...)
+{
+ va_list va;
+ int cnt = 1;
+ long long *p;
+
+ puts(s);
+
+ va_start(va, fmt);
+ while (*fmt) {
+ printf("fmt = '%c'\n", *fmt);
+ switch (*fmt++) {
+ case 'c':
+ assert(va_arg(va, int) == cnt++);
+ break;
+ case 's':
+ assert(va_arg(va, int) == cnt++);
+ break;
+ case 'i':
+ assert(va_arg(va, int) == cnt++);
+ break;
+ case 'l':
+ assert(va_arg(va, long) == cnt++);
+ break;
+ case 'q':
+ assert(va_arg(va, long long) == cnt++);
+ break;
+ case 'p':
+ p = va_arg(va, void *);
+ assert(*p == cnt++);
+ break;
+ case 'f':
+ assert(va_arg(va, double) == cnt++);
+ break;
+ default:
+ abort();
+ }
+ }
+ va_end(va);
+}
+
+int
+main()
+{
+ char c;
+ short s;
+ int i;
+ long l;
+ long long ll;
+ float f;
+
+ c = 1;
+ i = 2;
+ l = 3;
+ ll = 4;
+ test("test 1", "cilp", c, i, l, (void *) &ll);
+
+
+ c = 1;
+ s = 2;
+ ll = 3;
+ f = 4.0;
+ test("test 2", "csqf", c, s, ll, f);
+
+ return 0;
+}
--- /dev/null
+++ b/tests/libc/execute/0010-stddef.c
@@ -1,0 +1,43 @@
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+
+/*
+output:
+NULL = 0
+end:
+*/
+
+typedef struct test Test;
+
+struct test {
+ int a, b, c;
+ char d;
+} test = {
+ .a = 1,
+ .b = 2,
+ .c = 3,
+ .d = 4,
+};
+
+int
+main()
+{
+ wchar_t wc = L'c';
+ char *q, *p = (char *) &test;
+
+ printf("NULL = %p\n", NULL);
+
+ p += offsetof(Test, d);
+
+ assert(sizeof(size_t) == sizeof(ptrdiff_t));
+ assert(wc == L'c');
+ assert(*p == 4);
+ assert(offsetof(Test, d) > offsetof(Test, a));
+ assert(offsetof(Test, d) > offsetof(Test, b));
+ assert(offsetof(Test, d) > offsetof(Test, c));
+ assert(sizeof(sizeof(int)) == sizeof(size_t));
+ assert(sizeof(p - q) == sizeof(ptrdiff_t));
+
+ return 0;
+}
--- a/tests/libc/execute/libc-tests.lst
+++ b/tests/libc/execute/libc-tests.lst
@@ -6,3 +6,5 @@
0006-limits
0007-signal
0008-longjmp
+0009-stdarg [TODO]
+0010-stddef