Home
       tests/libc: Add va_copy test to 0009-stdarg - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 2e9e1c983fcb90689350f0d8783bae8ef4dfae31
   DIR parent 3c7a64d19b6654f885beeef04dca15952066c615
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
       Date:   Wed, 16 Oct 2024 15:26:45 +0200
       
       tests/libc: Add va_copy test to 0009-stdarg
       
       Diffstat:
         M tests/libc/execute/0009-stdarg.c    |      25 +++++++++++++++++--------
         M tests/libc/execute/libc-tests.lst   |       2 +-
       
       2 files changed, 18 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/tests/libc/execute/0009-stdarg.c b/tests/libc/execute/0009-stdarg.c
       @@ -4,25 +4,21 @@
        #include <stdlib.h>
        
        /*
       -TODO: Test va_copy, new c99 extension.
        output:
       +testing
        test 1
        test 2
       +done
        end:
        */
        
        void
       -test(char *s, char *fmt, ...)
       +vtest(char *fmt, va_list va)
        {
       -        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++);
       @@ -50,6 +46,18 @@ test(char *s, char *fmt, ...)
                                abort();
                        }
                }
       +}
       +
       +void
       +test(char *s, char *fmt, ...)
       +{
       +        va_list va, vc;
       +
       +        puts(s);
       +        va_start(va, fmt);
       +        va_copy(vc, va);
       +        vtest(fmt, vc);
       +        va_end(vc);
                va_end(va);
        }
        
       @@ -63,18 +71,19 @@ main()
                long long ll;
                float f;
        
       +        puts("testing");
                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);
       +        puts("done");
        
                return 0;
        }
   DIR diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -6,7 +6,7 @@
        0006-limits
        0007-signal
        0008-longjmp
       -0009-stdarg [TODO]
       +0009-stdarg
        0010-stddef
        0011-strcat
        0012-strchr