1 # Copyright (c) 2002, Intel Corporation. All rights reserved.
2 # Created by: inaky.perez-gonzalez REMOVE-THIS AT intel DOT com
3 # This file is licensed under the GPL license. For the full content
4 # of this license, see the COPYING file at the top level of this
7 # Kind of a little bit bastardized automakefile ... This is the
8 # temporary glue to hold it all together; once our needs change or we
9 # need something more advanced, we'll implement it.
11 # So far, I understand Make is not the best language, but I felt lazy
12 # today and wanted to use the default rules of automake [did I alredy
13 # mentioned I am bastardizing it?].
15 # Ok, I don't use Automake any more
17 # Added patch from dank REMOVE-THIS AT kegel DOT com
20 # Added tests timeout from Sebastien Decugis (http://nptl.bullopensource.org)
21 # Expiration delay is 240 seconds
23 # The following value is the shell return value of a timedout application.
24 # with the bash shell, the ret val of a killed application is 128 + signum
25 # and under Linux, SIGALRM=14, so we have (Linux+bash) 142.
26 TIMEOUT_RET = $(shell cat $(top_builddir)/t0.val)
30 LOGFILE = $(top_builddir)/logfile
32 LDFLAGS := $(shell cat LDFLAGS | grep -v \^\#)
34 RUN_TESTS := $(shell $(top_builddir)/locate-test \
35 --execs $(top_builddir)/$(POSIX_TARGET))
36 BUILD_TESTS := $(shell $(top_builddir)/locate-test \
37 --buildable $(top_builddir)/$(POSIX_TARGET))
38 FUNCTIONAL_MAKE := $(shell $(top_builddir)/locate-test --fmake)
39 FUNCTIONAL_RUN := $(shell $(top_builddir)/locate-test --frun)
40 STRESS_MAKE := $(shell $(top_builddir)/locate-test --smake)
41 STRESS_RUN := $(shell $(top_builddir)/locate-test --srun)
43 TIMEOUT = $(top_builddir)/t0 $(TIMEOUT_VAL)
46 all: build-tests run-tests
48 build-tests: $(BUILD_TESTS:.c=.test)
49 run-tests: $(RUN_TESTS:.test=.run-test)
51 functional-tests: functional-make functional-run
52 stress-tests: stress-make stress-run
55 $(MAKE) all | column -t -s:
57 CFLAGS = -g -O2 -Wall -Werror -D_POSIX_C_SOURCE=200112L
59 # add -std=c99, -std=gnu99 if compiler supports it (gcc-2.95.3 does not).
60 check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
61 CFLAGS += $(call check_gcc,-std=c99,)
62 CFLAGS += $(call check_gcc,-std=gnu99,)
66 # FIXME: exaust cmd line length
69 # Timeout helper files
70 @rm -f $(top_builddir)/t0{,.val}
71 # Built runnable tests
72 @find $(top_builddir) -iname \*.test | xargs -n 40 rm -f {}
73 @find $(top_builddir) -iname \*~ -o -iname \*.o | xargs -n 40 rm -f {}
74 @$(foreach DIR,$(FUNCTIONAL_MAKE),make -C $(DIR) clean >> /dev/null 2>&1;) >> /dev/null 2>&1
76 # Rule to run a build test
77 # If the .o doesn't export main, then we don't need to link
80 @COMPLOG=$(LOGFILE).$$$$; \
81 [ -f $< ] || exit 0; \
82 { nm -g $< | grep -q " T main"; } || \
83 { echo "$(@:.test=): link: SKIP" | tee -a $(LOGFILE) && exit 0; }; \
84 if $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) > $$COMPLOG 2>&1; \
86 echo "$(@:.test=): link: PASS" | tee -a $(LOGFILE); \
89 echo "$(@:.test=): link: FAILED. Linker output: "; \
92 echo "$(@:.test=): link: FAILED "; \
96 # Rule to run an executable test
97 # If it is only a build test, then the binary exist, so we don't need to run
99 %.run-test: %.test $(top_builddir)/t0 $(top_builddir)/t0.val
100 @COMPLOG=$(LOGFILE).$$$$; \
101 [ -f $< ] || exit 0; \
102 $(TIMEOUT) $< > $$COMPLOG 2>&1; \
104 if [ $$RESULT -eq 1 ]; \
108 if [ $$RESULT -eq 2 ]; \
112 if [ $$RESULT -eq 4 ]; \
116 if [ $$RESULT -eq 5 ]; \
120 if [ $$RESULT -eq $(TIMEOUT_RET) ]; \
124 if [ $$RESULT -gt 5 -a $$RESULT -ne $(TIMEOUT_RET) ]; \
128 if [ $$RESULT -eq 0 ]; \
130 echo "$(@:.run-test=): execution: PASS" | tee -a $(LOGFILE); \
133 echo "$(@:.run-test=): execution: $$MSG: Output: "; \
136 echo "$(@:.run-test=): execution: $$MSG "; \
140 $(top_builddir)/t0: $(top_builddir)/t0.c
141 @echo Building timeout helper files; \
144 $(top_builddir)/t0.val: $(top_builddir)/t0
145 echo `$(top_builddir)/t0 0; echo $$?` > $(top_builddir)/t0.val
147 %.run-test: %.sh $(top_builddir)/t0 $(top_builddir)/t0.val
148 @COMPLOG=$(LOGFILE).$$$$; \
150 $(TIMEOUT) $< > $$COMPLOG 2>&1; \
152 if [ $$RESULT -eq 0 ]; \
154 echo "$(@:.run-test=): execution: PASS" | tee -a $(LOGFILE);\
157 echo "$(@:.run-test=): execution: FAILED: Output: ";\
160 echo "$(@:.run-test=): execution: FAILED "; \
167 @COMPLOG=$(LOGFILE).$$$$; \
168 if $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS) > $$COMPLOG 2>&1; \
170 echo "$(@:.o=): build: PASS" | tee -a $(LOGFILE); \
173 echo "$(@:.o=): build: FAILED: Compiler output: "; \
176 echo "$(@:.o=): build: FAILED "; \
180 # Functional/Stress test build and execution
182 $(foreach DIR,$(FUNCTIONAL_MAKE),make -C $(DIR);)
184 .PHONY: $(FUNCTIONAL_RUN)
186 functional-run: $(FUNCTIONAL_RUN)
193 $(foreach DIR,$(STRESS_MAKE),make -C $(DIR);)
195 .PHONY: $(STRESS_RUN)
197 stress-run: $(STRESS_RUN)