2 # Part of SDCC - http://sdcc.sourceforge.net/
3 # Michael Hope <michaelh@juju.net.nz> 2001
4 # refactored: Felix Salfelder 2022
6 # This Makefile builds and runs the test suites under tests/ for each
7 # one of the supported ports located under ports/. The test suite
8 # results are summarised and individual test failures are logged. The
9 # expected result is a single line per port summarising the number of
10 # failures, test points, and test cases. The philosophy is that
11 # checked in code should always pass the suite with no failures, as
12 # then if there are failures then it is in the current developers code.
14 # Only the required suites are run. Changing sdcc causes all to be
15 # re-run. Changing one suite causes just that to be run. Changing
16 # one of the library files should cause all to re-run
18 # Test individual ports using the command
20 # For port=rrz80 port=rrgbz80, tests will use rrz80 and rrgbz80 simulators
23 # pic1{4,6} uses gpsim.
24 # port=host does not simulate.
25 # The others use uCsim.
28 # * The sdcc-extra package, available from svn.
29 # o svn co https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc-extra
30 # o Provides the emulators
31 # * The gbdk-lib package from gbdk.
32 # o cvs -d cvs.gbdk.sourceforge.net:/cvsroot/gbdk co gbdk-lib
33 # o Provides mul, div, and include files for the z80 tests.
34 # * python 1.5 or above
35 # * uCsim for the mcs51 port
37 # The paths below assume that sdcc, sdcc-extra, and gbdk-lib all reside in
41 # Starting at the bottom
42 # Set of source test suites
43 # Each source suite is processed producing multiple device specific test suites.
44 # Each device specific test suite is compiled.
45 # Each device specific test suite is run, and the output recorded.
46 # The output from each device specific test suite derived from a source
47 # test suite are collated.
49 # set V=0 for normal verbosity
50 # set V=1 for more verbosity
56 # TEST_PREFIX: select tests matching a pattern
63 # TEST_SLICE. Subselect tests from list of all tests.
64 # This is Python syntax for slicing, start:stop:step
66 # All tests, 0 1 2... (default)
75 # delete failed attempts (so make will retry...)
80 CPPFLAGS
= @CPPFLAGS@
-DNO_VARARGS
85 MAKE_SUB_FLAGS
= --no-print-directory
88 top_srcdir
= @top_srcdir@
89 top_builddir
= @top_builddir@
91 DEFAULT_VERBOSITY
= silent
92 M_V_at
= $(m__v_at_
$(V
))
93 m__v_at_
= $(m__v_at_
$(DEFAULT_VERBOSITY
))
98 M_V_GEN
= $(m__v_GEN_
$(V
))
99 m__v_GEN_
= $(m__v_GEN_
$(DEFAULT_VERBOSITY
))
101 m__v_GEN_0
= @echo
" GEN " $@
;
104 M_V_EMU
= $(m__v_EMU_
$(V
))
106 m__v_EMU_
= $(m__v_EMU_
$(DEFAULT_VERBOSITY
))
107 m__v_EMU_0
= echo
" EMU " $@
;
110 M_V_echo
= $(m__v_echo_
$(V
))
111 m__v_echo_
= $(m__v_EMU_
$(DEFAULT_VERBOSITY
))
112 m__v_echo_silent
= echo
> /dev
/null
113 m__v_echo_0
= echo
> /dev
/null
116 M_V_CC
= $(m__v_CC_
$(V
))
117 m__v_CC_
= $(m__v_CC_
$(DEFAULT_VERBOSITY
))
119 m__v_CC_0
= @echo
" CC " $@
;
122 M_V_CCLD
= $(m__v_CCLD_
$(V
))
123 m__v_CCLD_
= $(m__v_CCLD_
$(DEFAULT_VERBOSITY
))
125 m__v_CCLD_0
= @echo
" CCLD " $@
;
128 # All original tests live in TESTS_DIR and below
129 TESTS_DIR
= $(srcdir)/tests
130 # All suite results go in RESULTS_DIR
131 RESULTS_DIR
= results
132 # All data relating to supported ports live in their own directory
134 PORTS_DIR
= $(srcdir)/ports
136 # Intermediate data directories
137 # Directory where test cases and the generated object code go.
141 # The directories in PORTS_DIR correspond to ports.
142 PORTS
= $(filter-out .svn
, $(notdir $(wildcard $(PORTS_DIR
)/*)))
157 # simulator may be unavailable
167 # redundant, uCSim works better.
172 # Generate the list of ports to test. Each port has a spec.mk with build and
173 # emulator flags. Some ports are tested by default, these are the tests
174 # associated to the "all" target.
175 ALL_PORTS
= $(filter-out ${EXCLUDE_PORTS}, $(PORTS
))
177 # These ports will be cleaned with 'make clean'
178 CLEAN_PORTS
= $(filter-out mcs51-common host
, $(PORTS
))
183 vpath
%.c
$(CASES_DIR
)
184 vpath
%.c.in
$(TESTS_DIR
)
188 print-summary
: test-ports
189 @cat
$(RESULTS_DIR
)/*.sum
191 .PHONY
: print-summary
193 # Test all ports that you normally would want to test,
194 # normally a subset of all ports.
196 $(MAKE
) $(MAKE_SUB_FLAGS
) test-common
197 for i in
$(ALL_PORTS
); \
198 do
$(MAKE
) $(MAKE_SUB_FLAGS
) make_library test-port PORT
=$$i; \
201 # Helper rule for testing various ports
202 ${PORTS
:%=test-
%} : test-
%: test-common
203 $(MAKE
) test-port PORT
=$*
204 cat
$(RESULTS_DIR
)/$*.sum
206 # Shorthand for testing the mcs51 port only
212 test-mcs51-small-stack-auto \
213 test-mcs51-large-stack-auto \
214 test-mcs51-xstack-auto
215 test-mcs51
: $(filter-out ${EXCLUDE_PORTS
:%=test-
%}, $(TEST_MCS51
))
217 # Shorthand for testing the z80 related ports only
218 test-z80
: test-ucz80 test-ucz80-undoc test-ucz80-resiy test-ucz180 test-ucz180-resiy test-ucz80n test-ucgbz80 test-ucr2k test-ucr2ka test-ucr3ka test-ez80-z80 test-tlcs90 test-ucr800
220 # Shorthand for testing the pdk ports only
221 test-pdk
: test-pdk14 test-pdk15 test-pdk15-stack-auto
225 $(MAKE
) $(MAKE_SUB_FLAGS
) test-common
226 $(MAKE
) $(MAKE_SUB_FLAGS
) test-port PORT
=host
228 # generate test list (and possibly expand tests)
230 $(MAKE
) -C cases MakeList
233 include cases
/MakeList
236 # Intermediate directory
237 PORT_TMP_DIR
= $(TMP_DIR
)/$(PORT
)
238 # BUG. used in spec.mk
239 PORT_CASES_DIR
= $(TMP_DIR
)/$(PORT
)
240 # PORT_CASES_DIRR = $(TMP_DIR)/$(PORT)
241 PORT_RESULTS_DIR
= $(RESULTS_DIR
)/$(PORT
)
243 ##### per-port exclude (cases, not tests) #####
244 ## BUG/Feature: after excluding tests, manually delete .sum
245 include $(srcdir)/MakeList
247 SDCC_EXTRA_DIR
= $(top_builddir
)/..
/sdcc-extra
249 # Defaults. Override in spec.mk if required.
250 # Simulation timeout in seconds.
255 SDCC
= export PATH
=$(SDCC_BIN_PATH
); sdcc
$(EXEEXT
)
257 SDCC
= $(top_builddir
)/bin
/sdcc
$(EXEEXT
)
258 INC_DIR ?
= $(top_srcdir
)/device
/include
261 SDCCFLAGS
+= --fverbose-asm
-DNO_VARARGS
262 # Extension of object intermediate files
264 # Extension of files that can be run in the emulator
266 # Currently unused. Extension to append to intermediate directories.
271 # Only include if we're in a per-port call.
274 EMU_INPUT
= < $(PORTS_DIR
)/$(PORT_BASE
)/uCsim.cmd
276 # run simulator with SIM_TIMEOUT seconds timeout
277 # include ./$(PORT)/spec.mk if exists, else include $(PORTS_DIR)/$(PORT)/spec.mk
278 ifeq ($(shell if
test -f .
/ports
/$(PORT
)/spec.mk
; then echo OK
; fi
),OK
)
279 include .
/ports
/$(PORT
)/spec.mk
281 include $(PORTS_DIR
)/$(PORT
)/spec.mk
284 $(RESULTS_DIR
)/$(PORT
)/%.out
: $(CASES_DIR
)/%.c
$(TMP_DIR
)/timeout
286 @
# BUG: need "Running" in .out, regardless of whether we run anything.
287 @echo
--- Running
: $< > $@
;
289 @
# BUG: does not respect --dry-run
290 -${M_V_at}if
$(MAKE
) $(MAKE_SUB_FLAGS
) $(TMP_DIR
)/$(PORT
)/$*$(BINEXT
) PORT
=$(PORT
); then \
291 ${M_V_echo} "$(TMP_DIR)/timeout $(SIM_TIMEOUT) $(EMU) $(EMU_PORT_FLAG) $(EMU_FLAGS) $(TMP_DIR)/$(PORT)/$*$(BINEXT) ${EMU_INPUT} > $@"; \
292 ${M_V_EMU}$(TMP_DIR
)/timeout
$(SIM_TIMEOUT
) $(EMU
) $(EMU_PORT_FLAG
) $(EMU_FLAGS
) $(TMP_DIR
)/$(PORT
)/$*$(BINEXT
) ${EMU_INPUT} > $@
; \
293 if
[ 0 -ne
$$?
]; then \
294 echo
--- FAIL
: \"timeout
, simulation killed
\" in
$< >> $@
; \
295 echo
--- Summary
: 1/1/1: timeout
>> $@
; \
298 echo
--- FAIL
: cannot compile
/link
$< >> $@
; \
299 echo
--- Summary
: 1/1/1: compile
>> $@
; \
302 @
# always count ticks?
303 @
$(PYTHON
) $(srcdir)/get_ticks.py
< $@
>> $@
304 @grep
-n FAIL
$@
/dev
/null | head
-n
20 || true
308 # For each test we produce a result log file, %.log
310 TEST_STEMS_FILTERED_
= $(filter-out ${EXCLUDE_
${PORT}}, $(TEST_STEMS
))
311 TEST_STEMS_FILTERED__
= $(filter ${TEST_PREFIX}%, $(TEST_STEMS_FILTERED_
))
312 TEST_STEMS_FILTERED
= $(shell ${PYTHON} -c
'for i in "${TEST_STEMS_FILTERED__}".split(" ")[${TEST_SLICE}]: print(i)')
313 PORT_RESULTS
= $(TEST_STEMS_FILTERED
:%=$(PORT_RESULTS_DIR
)/%.log
)
316 make_library
: $(MAKE_LIBRARY
)
318 SDCCFLAGS
+= -I
$(srcdir)/fwk
/include -I
$(srcdir)/tests
320 SDCCFLAGS
+= -I
$(INC_DIR
)
323 # List of intermediate files to keep. Pretty much keep everything as
324 # disk space is free.
325 .SECONDARY
: $(RESULTS_DIR
) $(CASES_DIR
)/% $(PORT_TMP_DIR
)/% %$(OBJEXT
) %$(EXEEXT
) %$(BINEXT
) \
326 $(CASES_DIR
)/%/stamp \
327 ${TEST_STEMS
:%=$(RESULTS_DIR
)/$(PORT
)/%.out
}
329 # $(TMP_DIR)/stamp is really a proxy for $(TMP_DIR). We shouldn't use
330 # $(TMP_DIR) as a dependency directly, because as a directory its time
331 # stamp updates every time something in the directory is updated (which
332 # can then cause spurious rebuilds of other targets that can conflict
333 # with parallel make jobs)
338 # Rule linking the combined results log to all of the files in the
339 # iteration directory.
340 $(PORT_RESULTS_DIR
)/%.out
: $(CASES_DIR
)/%/stamp
341 @
# mkdir -p $(dir $@)/$*
342 ${M_V_at}$(MAKE
) $(MAKE_SUB_FLAGS
) iterations PORT
=$(PORT
) CASES
=$*/
344 $(PORT_RESULTS_DIR
)/%.log
: $(PORT_RESULTS_DIR
)/%.out
345 @
# compact-results prints the stats. Do once per test.
346 ${M_V_GEN}$(PYTHON
) $(srcdir)/compact-results.py
$* < $< | tee
$@
348 # Rule to summarise the results for one port after all of the tests
350 $(RESULTS_DIR
)/$(PORT
).sum
: $(PORT_RESULTS
) cases
/MakeList
351 ${M_V_at}echo | cat
- $(PORT_RESULTS
:%.log
=%.out
) |
$(PYTHON
) $(srcdir)/collate-results.py
$(PORT
) > $@
353 port-fwklib
: port-dirs
$(EXTRAS
) $(FWKLIB
)
356 ${M_V_GEN}mkdir
-p
$(PORT_TMP_DIR
) $(PORT_RESULTS_DIR
)
358 # Files shared between all ports need to be built by the test-common target,
359 # which should always be built before the port specific targets.
360 test-common
: $(TMP_DIR
)/timeout
364 test-port
: test-common port-dirs
365 @
# recurse: force vpath to re-read the $(CASES_DIR)
366 ${M_V_at}$(MAKE
) $(MAKE_SUB_FLAGS
) port-fwklib PORT
=$(PORT
) V
=${V}
367 @echo Running
${PORT} regression tests
368 ${M_V_at}$(MAKE
) $(MAKE_SUB_FLAGS
) $(RESULTS_DIR
)/$(PORT
).sum PORT
=$(PORT
)
371 # Begin rules that process each iteration generated from the source
374 # List of all of the generated iteration source files.
375 SUB_CASES
= $(sort $(wildcard $(CASES_DIR
)/$(CASES
)*.c
))
376 # List of all the sub result logs generated from the iterations.
377 # these are stored in TMP_DIR...
378 SUB_RESULTS_
= $(SUB_CASES
:%.c
=%.out
)
379 SUB_RESULTS
= $(SUB_RESULTS_
:cases
%=$(RESULTS_DIR
)/$(PORT
)%)
380 SUB_RESULTS_FILES
= $(SUB_RESULTS_
:cases
/%=%)
381 SUB_RESULTS_DIR
= $(RESULTS_DIR
)/$(PORT
)
382 # Overall target. Concatenation of all of the sub results.
383 RESULTS
= $(CASES
:%/$(DIREXT
)=$(PORT_RESULTS_DIR
)/%.out
)
385 iterations
: $(RESULTS
)
387 # Rule to generate the overall target from the sub results.
388 $(RESULTS
): $(SUB_RESULTS
)
389 ${M_V_at}( cd
$(SUB_RESULTS_DIR
); echo | cat
- $(SUB_RESULTS_FILES
) ) > $@
# subresult rule
391 $(TMP_DIR
)/timeout
: $(srcdir)/fwk
/lib
/timeout.c
$(TMP_DIR
)/stamp
392 $(CC_FOR_BUILD
) $(CFLAGS
) $< -o
$@
394 # The remainder of the rules are in $PORT/spec.mk. The port needs to
395 # be able to turn an iterated test suite into a sub result, normally
397 # 1. Compile the required library files
398 # 2. Compile this test suite.
399 # 3. Link 1, 2, and any required stdlib into an executable.
400 # 4. Run the executable inside an emulator, and capture the text
403 # The emulator must exit when main() returns.
408 $(MAKE
) -C
$(CASES_DIR
) clean
411 rm -rf
$(TMP_DIR
) $(RESULTS_DIR
) *.pyc __pycache__
412 for i in
$(CLEAN_PORTS
); do \
413 $(MAKE
) $(MAKE_RECURSE_FLAGS
) -f
$(PORTS_DIR
)/$$i/spec.mk _clean PORTS_DIR
=$(PORTS_DIR
) PORT
=$$i srcdir=$(srcdir); \
417 $(MAKE
) -C
$(CASES_DIR
) distclean
418 rm -f
$(PORTS_DIR
)/host
/spec.mk
421 # Rule to link into .ihx
422 %$(BINEXT
): %$(OBJEXT
) $(EXTRAS
) $(FWKLIB
) $(PORT_CASES_DIR
)/fwk.lib
423 ${M_V_CCLD}$(SDCC
) $(SDCCFLAGS
) $(LINKFLAGS
) $(EXTRAS
) $(PORT_CASES_DIR
)/fwk.lib
$< -o
$@
425 # ignore (preprocessor) warnings
426 gen
/%/tst_p99-conformance.rel
: EXTRA_COMPILE_HACK
=2>/dev
/null
428 $(PORT_CASES_DIR
)/%$(OBJEXT
): %.c
429 @mkdir
-p
$(dir $@
) # BUG?
430 ${M_V_CC}$(SDCC
) $(SDCCFLAGS
) -c
$< -o
$@
${EXTRA_COMPILE_HACK}
432 $(PORT_CASES_DIR
)/%$(OBJEXT
): $(PORTS_DIR
)/$(PORT_BASE
)/%.c
433 ${M_V_CC}$(SDCC
) $(SDCCFLAGS
) -c
$< -o
$@
435 $(PORT_CASES_DIR
)/%$(OBJEXT
): $(srcdir)/fwk
/lib
/%.c
436 ${M_V_CC}$(SDCC
) $(SDCCFLAGS
) -c
$< -o
$@
438 $(PORT_CASES_DIR
)/fwk.lib
: $(srcdir)/fwk
/lib
/fwk.lib
${SPEC_LIB}
439 ${M_V_GEN}cat
$(srcdir)/fwk
/lib
/fwk.lib
${SPEC_LIB} > $@
441 Makefile
: $(srcdir)/Makefile.in
442 cd
$(top_builddir
); .
/config.status support
/regression
/Makefile