xref: /relibc/tests/Makefile (revision 9f3aa6d4a88e5eebb7bc5ca9e3ded38b71dbd68e)
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	wctype/towlower \
119	wctype/towupper
120	# TODO: Fix these
121	# mkfifo
122	# netdb/netdb \
123
124DYNAMIC_ONLY_NAMES=\
125	dlfcn
126
127# Binaries that may generate varied output
128NAMES=\
129	$(EXPECT_NAMES) \
130	dirent/main \
131	pwd \
132	stdio/tempnam \
133	stdio/tmpnam \
134	stdlib/bsearch \
135	stdlib/mktemp \
136	stdlib/realpath \
137	sys_epoll/epoll \
138	sys_utsname/uname \
139	time/gettimeofday \
140	unistd/chdir \
141	unistd/getcwd \
142	unistd/gethostname \
143	unistd/getid \
144	unistd/getpagesize \
145	unistd/isatty \
146	unistd/link \
147	unistd/pathconf \
148	unistd/setid \
149	unistd/stat \
150	unistd/sysconf
151#	resource/getrusage
152#	time/times
153
154BINS=$(patsubst %,bins_static/%,$(NAMES))
155BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
156BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
157EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
158EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
159EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
160
161CARGO_TEST?=cargo
162TEST_RUNNER?=
163
164.PHONY: all clean run expected verify
165
166all: $(BINS)
167
168clean:
169	rm -rf bins_* gen *.out
170
171run: | $(BINS)
172	for bin in $(BINS); \
173	do \
174		echo "# $${bin} #"; \
175		"$${bin}" test args || exit $$?; \
176	done
177
178expected: | $(EXPECT_BINS)
179	rm -rf expected
180	mkdir -p expected
181	for bin in $(EXPECT_BINS); \
182	do \
183		echo "# $${bin} #"; \
184		mkdir -p expected/`dirname $${bin}`; \
185		"$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \
186	done
187
188bins_verify/relibc-tests: src/main.rs
189	$(CARGO_TEST) build --release --bin relibc-tests --out-dir bins_verify -Z unstable-options
190
191verify: bins_verify/relibc-tests | $(EXPECT_BINS)
192	$(TEST_RUNNER) $< $(EXPECT_BINS)
193
194FLAGS=\
195	-std=c11 \
196	-fno-builtin \
197	-fno-stack-protector \
198	-Wall \
199	-pedantic \
200	-g \
201	-I .
202
203STATIC_FLAGS=\
204	-static
205
206DYNAMIC_FLAGS=\
207	-Wl,--enable-new-dtags \
208	-Wl,-export-dynamic
209
210../sysroot:
211	$(MAKE) -C .. sysroot
212
213NATIVE_RELIBC?=0
214ifeq ($(NATIVE_RELIBC),0)
215FLAGS+=\
216	-nostdinc \
217	-nostdlib \
218	-isystem ../sysroot/include \
219	../sysroot/lib/crt0.o \
220	../sysroot/lib/crti.o \
221	../sysroot/lib/crtn.o
222
223SYSROOT_LIB=$(shell realpath ../sysroot/lib/)
224
225STATIC_FLAGS+=\
226	$(SYSROOT_LIB)/libc.a
227
228DYNAMIC_FLAGS+=\
229	-Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
230	-Wl,-rpath=$(SYSROOT_LIB):\$$ORIGIN \
231	-L $(SYSROOT_LIB) \
232	-lc
233
234DEPS=../sysroot
235else
236DYNAMIC_FLAGS+=\
237	-Wl,-rpath=\$$ORIGIN
238endif
239
240bins_static/%: %.c $(DEPS)
241	mkdir -p "$$(dirname "$@")"
242	$(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
243
244bins_dynamic/%.so: %.c $(DEPS)
245	mkdir -p "$$(dirname "$@")"
246	$(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS)
247
248bins_dynamic/dlfcn: dlfcn.c bins_dynamic/sharedlib.so $(DEPS)
249	mkdir -p "$$(dirname "$@")"
250	$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
251
252bins_dynamic/%: %.c $(DEPS)
253	mkdir -p "$$(dirname "$@")"
254	$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
255