strtoul test fix, infrastructure changes
authornsz <nsz@port70.net>
Thu, 22 Sep 2011 23:31:28 +0000 (01:31 +0200)
committernsz <nsz@port70.net>
Thu, 22 Sep 2011 23:31:28 +0000 (01:31 +0200)
Makefile
Makefile.inc
src/stdio/bench.c
src/stdio/fscanf.c
src/stdlib/strtol.c
src/stdlib/wcstol.c

index 856eb33..f69d6aa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-ROOTDIR=.
+TROOT=.
 include Makefile.inc
 
 
 include Makefile.inc
 
 
index ae2fa3f..22f0282 100644 (file)
@@ -2,11 +2,11 @@
 # when included in src/*/Makefile then it builds a binary locally
 # when included in ./Makefile then all tests are linked into one binary
 
 # when included in src/*/Makefile then it builds a binary locally
 # when included in ./Makefile then all tests are linked into one binary
 
-ROOTDIR ?= ../..
-ifeq ($(ROOTDIR), .)
-SRCS = $(sort $(wildcard src/*/*.c))
+TROOT ?= ../..
+ifeq ($(TROOT), .)
+SRCS ?= $(sort $(wildcard src/*/*.c))
 else
 else
-SRCS = $(sort $(wildcard *.c))
+SRCS ?= $(sort $(wildcard *.c))
 endif
 OBJS = $(SRCS:.c=.o)
 
 endif
 OBJS = $(SRCS:.c=.o)
 
@@ -20,9 +20,9 @@ RANLIB=ranlib
 
 CFLAGS += -g -D_POSIX_C_SOURCE=200809L -std=c99 -pipe -Wall
 LDFLAGS += -g -lpthread -lrt -lm
 
 CFLAGS += -g -D_POSIX_C_SOURCE=200809L -std=c99 -pipe -Wall
 LDFLAGS += -g -lpthread -lrt -lm
-INC += -I$(ROOTDIR)/common
+INC += -I$(TROOT)/common
 
 
--include $(ROOTDIR)/Makefile.conf
+-include $(TROOT)/Makefile.conf
 
 ifeq ($(usemusl), yes)
 CC=gcc
 
 ifeq ($(usemusl), yes)
 CC=gcc
@@ -33,15 +33,16 @@ LDFLAGS += -nostdlib -Wl,-e,_start,-Bstatic $(libdir)/crti.o $(libdir)/crt1.o $(
 INC     += -isystem $(includedir)
 endif
 
 INC     += -isystem $(includedir)
 endif
 
-all: t b
+test: t b
+       ./t
 
 clean:
 
 clean:
-       rm -f $(OBJS) t t.o b b.o tests.a tests.h
+       rm -f $(OBJS) t t_.o b b_.o tests.a tests.h
 
 .c.o:
        $(CC) $(CFLAGS) $(INC) -c -o $@ $<
 
 
 .c.o:
        $(CC) $(CFLAGS) $(INC) -c -o $@ $<
 
-$(OBJS): $(ROOTDIR)/common/test.h $(ROOTDIR)/Makefile.conf
+$(OBJS): $(TROOT)/common/test.h $(TROOT)/Makefile.conf
 
 tests.h: $(OBJS)
        nm -f posix $+ |awk ' \
 
 tests.h: $(OBJS)
        nm -f posix $+ |awk ' \
@@ -53,16 +54,17 @@ tests.a: $(OBJS)
        $(AR) rc $@ $+
        $(RANLIB) $@
 
        $(AR) rc $@ $+
        $(RANLIB) $@
 
-t.o: $(ROOTDIR)/common/t.c $(ROOTDIR)/common/test.h tests.h
+# TODO: /tmp/t.o ?
+t_.o: $(TROOT)/common/t.c $(TROOT)/common/test.h tests.h
        $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
 
        $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
 
-t: t.o tests.a
+t: t_.o tests.a
        $(CC) $+ $(LDFLAGS) -o $@
 
        $(CC) $+ $(LDFLAGS) -o $@
 
-b.o: $(ROOTDIR)/common/b.c $(ROOTDIR)/common/test.h tests.h
+b_.o: $(TROOT)/common/b.c $(TROOT)/common/test.h tests.h
        $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
 
        $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
 
-b: b.o tests.a
+b: b_.o tests.a
        $(CC) $+ $(LDFLAGS) -lrt -o $@
 
 .PHONY: all clean
        $(CC) $+ $(LDFLAGS) -lrt -o $@
 
 .PHONY: all clean
index 95f9b90..0e87845 100644 (file)
@@ -3,6 +3,22 @@
 #include <string.h>
 #include "test.h"
 
 #include <string.h>
 #include "test.h"
 
+void bench_stdio_getc_unlocked(int N) {
+       FILE *f = tmpfile();
+       size_t i;
+       size_t cs = 0;
+
+       for (i=0; i<N; i++)
+               putc('x', f);
+       fseeko(f, 0, SEEK_SET);
+       reset_timer();
+       for (i=0; i<N; i++)
+               cs += getc_unlocked(f);
+       fclose(f);
+       if (cs != (size_t)N*'x')
+               abort();
+}
+
 void bench_stdio_putcgetc(int N) {
        FILE *f = tmpfile();
        size_t i;
 void bench_stdio_putcgetc(int N) {
        FILE *f = tmpfile();
        size_t i;
index 1de09c3..d5da238 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -18,6 +19,18 @@ static void S(const char *s, const char *x, const char *m) {
                error("got [%s], expected [%s] (%s)\n", s, x, m);
 }
 
                error("got [%s], expected [%s] (%s)\n", s, x, m);
 }
 
+void test_scanf_long(void) {
+       enum {n = 1<<21};
+       char *s = malloc(n+1);
+       int i;
+       int r;
+
+       for (i = 0; i < n; i++) s[i] = '1';
+       s[n] = 0;
+       r = sscanf(s, "%d", &i);
+       free(s);
+}
+
 void test_fscanf(void) {
        int i, x, y;
        char a[100], b[100];
 void test_fscanf(void) {
        int i, x, y;
        char a[100], b[100];
index 7d9213f..0656527 100644 (file)
@@ -39,16 +39,19 @@ void test_strtol(void) {
                TEST(ul, strtoul(s="4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
                TEST2(i, c-s, 10, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
                TEST(ul, strtoul(s="4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
                TEST2(i, c-s, 10, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, strtoul(s="-1", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST(ul, strtoul(s="-1", &c, 0), (unsigned long)-1, "bad conversion result: %lu != %lu");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
-               TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, strtoul(s="-2", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, strtoul(s="-2", &c, 0), (unsigned long)-2, "bad conversion result: %lu != %lu");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
-               TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, strtoul(s="-2147483648", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, strtoul(s="-2147483648", &c, 0), (unsigned long)-2147483648, "bad conversion result: %lu != %lu");
                TEST2(i, c-s, 11, "wrong final position %d != %d");
                TEST2(i, c-s, 11, "wrong final position %d != %d");
-               TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, strtoul(s="-2147483649", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, strtoul(s="-2147483649", &c, 0), (unsigned long)-2147483649, "bad conversion result: %lu != %lu");
+               TEST2(i, c-s, 11, "wrong final position %d != %d");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, strtoul(s="-4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
                TEST2(i, c-s, 11, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
        } else {
                TEST2(i, c-s, 11, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
        } else {
index fe8d747..c0d49d4 100644 (file)
@@ -33,16 +33,19 @@ void test_wcstol(void) {
                TEST(ul, wcstoul(s=L"4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
                TEST2(i, c-s, 10, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
                TEST(ul, wcstoul(s=L"4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
                TEST2(i, c-s, 10, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, wcstoul(s=L"-1", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST(ul, wcstoul(s=L"-1", &c, 0), (unsigned long)-1, "bad conversion result: %lu != %lu");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
-               TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, wcstoul(s=L"-2", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, wcstoul(s=L"-2", &c, 0), (unsigned long)-2, "bad conversion result: %lu != %lu");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
                TEST2(i, c-s, 2, "wrong final position %d != %d");
-               TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, wcstoul(s=L"-2147483648", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, wcstoul(s=L"-2147483648", &c, 0), (unsigned long)-2147483648, "bad conversion result: %lu != %lu");
                TEST2(i, c-s, 11, "wrong final position %d != %d");
                TEST2(i, c-s, 11, "wrong final position %d != %d");
-               TEST2(i, errno, ERANGE, "missing errno %d != %d");
-               TEST(ul, wcstoul(s=L"-2147483649", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, wcstoul(s=L"-2147483649", &c, 0), (unsigned long)-2147483649, "bad conversion result: %lu != %lu");
+               TEST2(i, c-s, 11, "wrong final position %d != %d");
+               TEST2(i, errno, 0, "no overflow, but errno is %d != %d");
+               TEST(ul, wcstoul(s=L"-4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
                TEST2(i, c-s, 11, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
        } else {
                TEST2(i, c-s, 11, "wrong final position %d != %d");
                TEST2(i, errno, ERANGE, "missing errno %d != %d");
        } else {