Skip to content

Commit 8a04879

Browse files
radhikajradhikaj
authored andcommitted
Added libc-test
Signed-off-by: radhikaj <radhikajmicrosoft.com>
1 parent 5e287a5 commit 8a04879

File tree

937 files changed

+113384
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

937 files changed

+113384
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.err
2+
*.o
3+
*.so
4+
*.a
5+
*.exe
6+
config.mak
7+
REPORT
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Rich Felker
2+
Szabolcs Nagy
3+
Kirill Ternovsky
4+
John Spencer
5+
Jens Gustedt
6+
Alexander Monakov
7+
Julien Ramseier
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
libc-test is licensed under the following standard MIT license:
2+
3+
Copyright © 2005-2013 libc-test AUTHORS
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
Portions of this software is derived from software authored by
26+
third parties:
27+
28+
math tests use numbers under BSD and GPL licenses see src/math/ucb/*
29+
and src/math/crlibm/* for details
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
B:=src
2+
SRCS:=$(sort $(wildcard src/*/*.c))
3+
OBJS:=$(SRCS:src/%.c=$(B)/%.o)
4+
LOBJS:=$(SRCS:src/%.c=$(B)/%.lo)
5+
DIRS:=$(patsubst src/%/,%,$(sort $(dir $(SRCS))))
6+
BDIRS:=$(DIRS:%=$(B)/%)
7+
NAMES:=$(SRCS:src/%.c=%)
8+
CFLAGS:=-I$(B)/common -Isrc/common
9+
LDLIBS:=$(B)/common/libtest.a
10+
AR = $(CROSS_COMPILE)ar
11+
RANLIB = $(CROSS_COMPILE)ranlib
12+
RUN_TEST = $(RUN_WRAP) $(B)/common/runtest.exe -w '$(RUN_WRAP)'
13+
14+
all:
15+
%.mk:
16+
# turn off evil implicit rules
17+
.SUFFIXES:
18+
%: %.o
19+
%: %.c
20+
%: %.cc
21+
%: %.C
22+
%: %.cpp
23+
%: %.p
24+
%: %.f
25+
%: %.F
26+
%: %.r
27+
%: %.s
28+
%: %.S
29+
%: %.mod
30+
%: %.sh
31+
%: %,v
32+
%: RCS/%,v
33+
%: RCS/%
34+
%: s.%
35+
%: SCCS/s.%
36+
37+
config.mak:
38+
cp config.mak.def $@
39+
-include config.mak
40+
41+
define default_template
42+
$(1).BINS_TEMPL:=bin.exe bin-static.exe
43+
$(1).NAMES:=$$(filter $(1)/%,$$(NAMES))
44+
$(1).OBJS:=$$($(1).NAMES:%=$(B)/%.o)
45+
endef
46+
$(foreach d,$(DIRS),$(eval $(call default_template,$(d))))
47+
common.BINS_TEMPL:=
48+
api.BINS_TEMPL:=
49+
math.BINS_TEMPL:=bin.exe
50+
51+
define template
52+
D:=$$(patsubst %/,%,$$(dir $(1)))
53+
N:=$(1)
54+
$(1).BINS := $$($$(D).BINS_TEMPL:bin%=$(B)/$(1)%)
55+
-include src/$(1).mk
56+
#$$(warning D $$(D) N $$(N) B $$($(1).BINS))
57+
$(B)/$(1).exe $(B)/$(1)-static.exe: $$($(1).OBJS)
58+
$(B)/$(1).so: $$($(1).LOBJS)
59+
# make sure dynamic and static binaries are not run parallel (matters for some tests eg ipc)
60+
$(B)/$(1)-static.err: $(B)/$(1).err
61+
endef
62+
$(foreach n,$(NAMES),$(eval $(call template,$(n))))
63+
64+
BINS:=$(foreach n,$(NAMES),$($(n).BINS)) $(B)/api/main.exe
65+
LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) $(B)/common/runtest.exe
66+
ERRS:=$(BINS:%.exe=%.err)
67+
68+
debug:
69+
@echo NAMES $(NAMES)
70+
@echo BINS $(BINS)
71+
@echo LIBS $(LIBS)
72+
@echo ERRS $(ERRS)
73+
@echo DIRS $(DIRS)
74+
75+
define target_template
76+
$(1).ERRS:=$$(filter $(B)/$(1)/%,$$(ERRS))
77+
$(B)/$(1)/all: $(B)/$(1)/REPORT
78+
$(B)/$(1)/run: $(B)/$(1)/cleanerr $(B)/$(1)/REPORT
79+
$(B)/$(1)/cleanerr:
80+
rm -f $$(filter-out $(B)/$(1)/%-static.err,$$($(1).ERRS))
81+
$(B)/$(1)/clean:
82+
rm -f $$(filter $(B)/$(1)/%,$$(OBJS) $$(LOBJS) $$(BINS) $$(LIBS)) $(B)/$(1)/*.err
83+
$(B)/$(1)/REPORT: $$($(1).ERRS)
84+
cat $(B)/$(1)/*.err >$$@
85+
run: $(B)/$(1)/run
86+
$(B)/REPORT: $(B)/$(1)/REPORT
87+
.PHONY: $(B)/$(1)/all $(B)/$(1)/clean
88+
endef
89+
$(foreach d,$(DIRS),$(eval $(call target_template,$(d))))
90+
91+
$(B)/common/libtest.a: $(common.OBJS)
92+
rm -f $@
93+
$(AR) rc $@ $^
94+
$(RANLIB) $@
95+
96+
$(B)/common/all: $(B)/common/runtest.exe
97+
98+
$(ERRS): $(B)/common/runtest.exe | $(BDIRS)
99+
$(BINS) $(LIBS): $(B)/common/libtest.a
100+
$(OBJS): src/common/test.h | $(BDIRS)
101+
$(BDIRS):
102+
mkdir -p $@
103+
104+
$(B)/common/options.h: src/common/options.h.in
105+
$(CC) -E - <$< | awk ' \
106+
/optiongroups_unistd_end/ {s=1; next} \
107+
!s || !NF || /^#/ {next} \
108+
!a {a=$$1; if(NF==1)next} \
109+
{print "#define "a" "$$NF; a=""}' >[email protected]
110+
mv $@.tmp $@
111+
112+
$(B)/common/mtest.o: src/common/mtest.h
113+
$(math.OBJS): src/common/mtest.h
114+
115+
$(B)/api/main.exe: $(api.OBJS)
116+
api/main.OBJS:=$(api.OBJS)
117+
$(api.OBJS):$(B)/common/options.h
118+
$(api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
119+
120+
all run: $(B)/REPORT
121+
grep FAIL $< || echo PASS
122+
clean:
123+
rm -f $(OBJS) $(BINS) $(LIBS) $(B)/common/libtest.a $(B)/common/runtest.exe $(B)/common/options.h $(B)/*/*.err
124+
cleanall: clean
125+
rm -f $(B)/REPORT $(B)/*/REPORT
126+
$(B)/REPORT:
127+
cat $^ >$@
128+
129+
$(B)/%.o:: src/%.c
130+
$(CC) $(CFLAGS) $($*.CFLAGS) -c -o $@ $< 2>$@.err || echo BUILDERROR $@; cat $@.err
131+
$(B)/%.s:: src/%.c
132+
$(CC) $(CFLAGS) $($*.CFLAGS) -S -o $@ $< || echo BUILDERROR $@; cat $@.err
133+
$(B)/%.lo:: src/%.c
134+
$(CC) $(CFLAGS) $($*.CFLAGS) -fPIC -DSHARED -c -o $@ $< 2>$@.err || echo BUILDERROR $@; cat $@.err
135+
$(B)/%.so: $(B)/%.lo
136+
$(CC) -shared $(LDFLAGS) $($*.so.LDFLAGS) -o $@ $(sort $< $($*.so.LOBJS)) $(LDLIBS) $($*.so.LDLIBS) 2>$@.err || echo BUILDERROR $@; cat $@.err
137+
$(B)/%-static.exe: $(B)/%.o
138+
$(CC) -static $(LDFLAGS) $($*-static.LDFLAGS) -o $@ $(sort $< $($*-static.OBJS)) $(LDLIBS) $($*-static.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err
139+
$(B)/%.exe: $(B)/%.o
140+
$(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $(sort $< $($*.OBJS)) $(LDLIBS) $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err
141+
142+
%.o.err: %.o
143+
touch $@
144+
%.lo.err: %.lo
145+
touch $@
146+
%.so.err: %.so
147+
touch $@
148+
%.ld.err: %.exe
149+
touch $@
150+
%.err: %.exe
151+
$(RUN_TEST) $< >$@ || true
152+
153+
.PHONY: all run clean cleanall
154+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
libc-test is developed as part of the musl project
2+
http://www.musl-libc.org/
3+
4+
configuring:
5+
cp config.mak.def config.mak
6+
edit config.mak
7+
build and run tests:
8+
make
9+
clean up:
10+
make clean
11+
12+
make builds all test binaries and runs them to create
13+
a REPORT file that contains all build and runtime errors
14+
(this means that make does not stop at build failures)
15+
16+
contributing tests:
17+
18+
design goals:
19+
20+
- tests should be easy to run and build even a single test in isolation
21+
(so test should be self contained if possible)
22+
- failure of one test should not interfere with others
23+
(build failure, crash or unexpected results are all failures)
24+
- test output should point to the cause of the failure
25+
- test results should be robust
26+
- the test system should have minimal dependency
27+
(libc, posix sh, gnu make)
28+
- the test system should run on all archs and libcs
29+
- tests should leave the system in a clean state
30+
31+
conventions:
32+
33+
each test is in a separate file at a path like src/directory/file.c with
34+
its own main
35+
36+
the test should return 0 on success and non-0 on failure, on failure it
37+
should print error messages to standard out if possible, on success no
38+
message should be printed
39+
40+
to help with the above test protocol use t_error function for printing
41+
errors and return t_status from main, see src/common/test.h
42+
(t_error allows standard printf formatting, outputs at most 512bytes
43+
in a single write call to fd 1, so there is no buffering, long outputs
44+
are truncated, it sets the global t_status to 1)
45+
46+
it is common to do many similar checks in a test, in such cases macros
47+
may be used to simplify the code like
48+
#define T1(a,b) (check(a,b) || (t_error("check(%s,%s) failed\n", a, b),0))
49+
#define T2(f,w) (result=(f), result==(w) || (t_error("%s failed: got %s, want %s\n", #f, result, w),0))
50+
51+
binaries should be possible to run from arbitrary directory.
52+
the build system runs the tests using the src/common/runtest tool which
53+
kills the test process after a timeout and reports the exit status
54+
in case of failure
55+
56+
directories:
57+
58+
src/api: interface tests, build time include header tests
59+
src/common: common utilities compiled into libtest.a
60+
src/functional: functional tests aiming for large coverage of libc
61+
src/math: tests for each math function with input-output test vectors
62+
src/regression: regression tests aiming for testing particular bugs
63+
64+
initial set of functional tests are derived from the libc-testsuit of
65+
Rich Felker, regression tests should contain reference of the bug
66+
(musl commit hash, glibc bug tracker url, etc)
67+
68+
build system:
69+
70+
the main non-file make targets are all, run, clean and cleanall.
71+
(cleanall removes the reports unlike clean, run reruns the dynamically
72+
linked executables)
73+
74+
make variable can be overridden from config.mak or the make command line,
75+
the variable B sets the build directory which is src by default
76+
77+
for each directory under src there are targets like $(B)/directory/all,
78+
$(B)/directory/run and $(B)/directory/clean to make only the contents
79+
of that directory, each directory has its own Makefile set up so it
80+
invokes the top level make with B=src src/directory/foo for the foo
81+
target, so it is possible to work only under a specific test directory
82+
83+
the build and runtime errors of each target are accumulated into a
84+
target.err file and in the end they are concatenated into a REPORT
85+
86+
each .c file in src/functional and src/regression are built into a
87+
dynamic linked and a static linked executable test binary by default,
88+
this behaviour can be changed by a similarly named .mk file changing
89+
make variables and specifying additional rules:
90+
91+
$(B)/$(N) is the name of the binary target (the file name without the .c)
92+
$(B)/$(N)-static is the name of the static binary target
93+
$(B)/$(D) is the build directory
94+
$(N).CFLAGS are added to the CFLAGS at compilation
95+
$(N).LDFLAGS are added to the LDFLAGS at linking
96+
$(N).LDLIBS are added to the LDLIBS at linking
97+
$(N).BINS are the targets (if empty no binaries are built)
98+
$(N).LIBS are the non-executable targets (shared objects may use it)
99+
100+
if a binary is linked together from several .o files then they
101+
have to be specified as prerequisits for the binary targets and
102+
added to the $(N).LDLIBS as well
103+
104+
if a binary depends on a file at runtime (eg. a .so opened by dlopen)
105+
then the $(N).err target should depend on that file
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CFLAGS += -pipe -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wno-unused-function -Wno-missing-braces -Wno-unused -Wno-overflow
2+
CFLAGS += -Wno-unknown-pragmas -fno-builtin -frounding-math
3+
CFLAGS += -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith
4+
CFLAGS += -g
5+
LDFLAGS += -g
6+
LDLIBS += -lpthread -lm -lrt
7+
8+
# glibc specific settings
9+
CFLAGS += -D_FILE_OFFSET_BITS=64
10+
LDLIBS += -lcrypt -ldl -lresolv -lutil -lpthread
11+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all:
2+
%: FORCE
3+
$(MAKE) -C ../.. B=src src/api/$@
4+
.SUFFIXES:
5+
FORCE: ;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <aio.h>
2+
#define T(t) (t*)0;
3+
#define F(t,n) {t *y = &x.n;}
4+
#define C(n) switch(n){case n:;}
5+
static void f()
6+
{
7+
T(off_t)
8+
T(pthread_attr_t)
9+
T(size_t)
10+
T(ssize_t)
11+
T(struct timespec)
12+
13+
{
14+
struct aiocb x;
15+
F(int, aio_fildes)
16+
F(off_t, aio_offset)
17+
F(volatile void *, aio_buf)
18+
F(size_t, aio_nbytes)
19+
F(int, aio_reqprio)
20+
F(struct sigevent, aio_sigevent)
21+
F(int, aio_lio_opcode)
22+
}
23+
24+
C(AIO_ALLDONE)
25+
C(AIO_CANCELED)
26+
C(AIO_NOTCANCELED)
27+
C(LIO_NOP)
28+
C(LIO_NOWAIT)
29+
C(LIO_READ)
30+
C(LIO_WAIT)
31+
C(LIO_WRITE)
32+
33+
{int(*p)(int,struct aiocb*) = aio_cancel;}
34+
{int(*p)(const struct aiocb*) = aio_error;}
35+
{int(*p)(int,struct aiocb*) = aio_fsync;}
36+
{int(*p)(struct aiocb*) = aio_read;}
37+
{ssize_t(*p)(struct aiocb*) = aio_return;}
38+
{int(*p)(const struct aiocb*const[],int,const struct timespec*) = aio_suspend;}
39+
{int(*p)(struct aiocb*) = aio_write;}
40+
{int(*p)(int,struct aiocb*restrict const[restrict],int,struct sigevent*restrict) = lio_listio;}
41+
}

0 commit comments

Comments
 (0)