xref: /relibc/tests/Makefile (revision 393489b38bb3255af0b3e7b61f44ad1a2a97146b)
1# Binaries that should generate the same output every time
2EXPECT_NAMES=\
3	alloca \
4	args \
5	arpainet \
6	assert \
7	constructor \
8	ctype \
9	destructor \
10	dirent/scandir \
11	errno \
12	error \
13	fcntl/create \
14	fcntl/fcntl \
15	fnmatch \
16	futimens \
17	libgen \
18	locale \
19	math \
20	netdb/getaddrinfo \
21	ptrace \
22	regex \
23	select \
24	setjmp \
25	sigaction \
26	signal \
27	stdio/all \
28	stdio/buffer \
29	stdio/fgets \
30	stdio/fputs \
31	stdio/fread \
32	stdio/freopen \
33	stdio/fseek \
34	stdio/fwrite \
35	stdio/getc_unget \
36	stdio/mutex \
37	stdio/popen \
38	stdio/printf \
39	stdio/rename \
40	stdio/scanf \
41	stdio/setvbuf \
42	stdio/sprintf \
43	stdio/printf_space_pad \
44	stdio/ungetc_ftell \
45	stdio/ungetc_multiple \
46	stdio/fscanf_offby1 \
47	stdio/fscanf \
48	stdio/printf_neg_pad \
49	stdlib/a64l \
50	stdlib/alloc \
51	stdlib/atof \
52	stdlib/atoi \
53	stdlib/div \
54	stdlib/env \
55	stdlib/mkostemps \
56	stdlib/rand \
57	stdlib/rand48 \
58	stdlib/random \
59	stdlib/strtod \
60	stdlib/strtol \
61	stdlib/strtoul \
62	stdlib/system \
63	string/mem \
64	string/strcat \
65	string/strchr \
66	string/strcpy \
67	string/strcspn \
68	string/strlen \
69	string/strncmp \
70	string/strpbrk \
71	string/strrchr \
72	string/strspn \
73	string/strstr \
74	string/strtok \
75	string/strtok_r \
76	string/strsignal \
77	strings \
78	sys_mman \
79	time/asctime \
80	time/constants \
81	time/gmtime \
82	time/localtime \
83	time/macros \
84	time/mktime \
85	time/strftime \
86	time/time \
87	tls \
88	unistd/access \
89	unistd/brk \
90	unistd/dup \
91	unistd/exec \
92	unistd/fchdir \
93	unistd/fork \
94	unistd/fsync \
95	unistd/ftruncate \
96	unistd/getopt \
97	unistd/getopt_long \
98	unistd/pipe \
99	unistd/rmdir \
100	unistd/sleep \
101	unistd/swab \
102	unistd/write \
103	waitpid \
104	wchar/fwide \
105	wchar/mbrtowc \
106	wchar/mbsrtowcs \
107	wchar/printf-on-wchars \
108	wchar/putwchar \
109	wchar/wcrtomb \
110	wchar/wcscspn \
111	wchar/wcsrchr \
112	wchar/wcsstr \
113	wchar/wcstod \
114	wchar/wcstok \
115	wchar/wcstol \
116	wchar/wcscasecmp \
117	wchar/wcsncasecmp \
118	wchar/wcswidth \
119	wctype/towlower \
120	wctype/towupper
121	# TODO: Fix these
122	# mkfifo
123	# netdb/netdb \
124
125DYNAMIC_ONLY_NAMES=\
126	dlfcn
127
128# Binaries that may generate varied output
129NAMES=\
130	$(EXPECT_NAMES) \
131	dirent/main \
132	pwd \
133	stdio/tempnam \
134	stdio/tmpnam \
135	stdlib/bsearch \
136	stdlib/mktemp \
137	stdlib/realpath \
138	sys_epoll/epoll \
139	sys_utsname/uname \
140	time/gettimeofday \
141	unistd/chdir \
142	unistd/getcwd \
143	unistd/gethostname \
144	unistd/getid \
145	unistd/getpagesize \
146	unistd/isatty \
147	unistd/link \
148	unistd/pathconf \
149	unistd/setid \
150	unistd/stat \
151	unistd/sysconf
152#	resource/getrusage
153#	time/times
154
155#TODO: dynamic tests currently broken
156BINS=$(patsubst %,bins_static/%,$(NAMES))
157#BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
158#BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
159EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
160#EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
161#EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
162
163CARGO_TEST?=cargo
164TEST_RUNNER?=
165
166.PHONY: all clean run expected verify
167
168all: $(BINS)
169
170clean:
171	rm -rf bins_* gen *.out
172
173run: | $(BINS)
174	for bin in $(BINS); \
175	do \
176		echo "# $${bin} #"; \
177		"$${bin}" test args || exit $$?; \
178	done
179
180expected: | $(EXPECT_BINS)
181	rm -rf expected
182	mkdir -p expected
183	for bin in $(EXPECT_BINS); \
184	do \
185		echo "# $${bin} #"; \
186		mkdir -p expected/`dirname $${bin}`; \
187		"$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \
188	done
189
190bins_verify/relibc-tests: src/main.rs
191	$(CARGO_TEST) build --release --bin relibc-tests --out-dir bins_verify -Z unstable-options
192
193verify: bins_verify/relibc-tests | $(EXPECT_BINS)
194	$(TEST_RUNNER) $< $(EXPECT_BINS)
195
196FLAGS=\
197	-std=c11 \
198	-fno-builtin \
199	-fno-stack-protector \
200	-Wall \
201	-pedantic \
202	-g \
203	-I .
204
205STATIC_FLAGS=\
206	-static
207
208DYNAMIC_FLAGS=\
209	-Wl,--enable-new-dtags \
210	-Wl,-export-dynamic
211
212../sysroot:
213	$(MAKE) -C .. sysroot
214
215NATIVE_RELIBC?=0
216ifeq ($(NATIVE_RELIBC),0)
217FLAGS+=\
218	-nostdinc \
219	-nostdlib \
220	-isystem ../sysroot/include \
221	../sysroot/lib/crt0.o \
222	../sysroot/lib/crti.o \
223	../sysroot/lib/crtn.o
224
225SYSROOT_LIB=$(shell realpath ../sysroot/lib/)
226
227STATIC_FLAGS+=\
228	$(SYSROOT_LIB)/libc.a
229
230DYNAMIC_FLAGS+=\
231	-Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
232	-Wl,-rpath=$(SYSROOT_LIB):\$$ORIGIN \
233	-L $(SYSROOT_LIB) \
234	-lc
235
236DEPS=../sysroot
237else
238DYNAMIC_FLAGS+=\
239	-Wl,-rpath=\$$ORIGIN
240endif
241
242bins_static/%: %.c $(DEPS)
243	mkdir -p "$$(dirname "$@")"
244	$(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
245
246bins_dynamic/%.so: %.c $(DEPS)
247	mkdir -p "$$(dirname "$@")"
248	$(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS)
249
250bins_dynamic/dlfcn: dlfcn.c bins_dynamic/sharedlib.so $(DEPS)
251	mkdir -p "$$(dirname "$@")"
252	$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
253
254bins_dynamic/%: %.c $(DEPS)
255	mkdir -p "$$(dirname "$@")"
256	$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
257