-ROOTDIR=.
+TROOT=.
include Makefile.inc
# 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
-SRCS = $(sort $(wildcard *.c))
+SRCS ?= $(sort $(wildcard *.c))
endif
OBJS = $(SRCS:.c=.o)
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
INC += -isystem $(includedir)
endif
-all: t b
+test: t b
+ ./t
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 $@ $<
-$(OBJS): $(ROOTDIR)/common/test.h $(ROOTDIR)/Makefile.conf
+$(OBJS): $(TROOT)/common/test.h $(TROOT)/Makefile.conf
tests.h: $(OBJS)
nm -f posix $+ |awk ' \
$(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 $@ $<
-t: t.o tests.a
+t: t_.o tests.a
$(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 $@ $<
-b: b.o tests.a
+b: b_.o tests.a
$(CC) $+ $(LDFLAGS) -lrt -o $@
.PHONY: all clean
#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;
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
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];
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, 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, 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, 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 {
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, 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, 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, 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 {