Added tests for switch statement and the z80 loop induction problem
[fw/sdcc] / support / regression / Makefile
1 # Test suite Makefile
2 # Part of SDCC - http://sdcc.sourceforge.net/
3 # Michael Hope <michaelh@juju.net.nz> 2001
4 #
5 # This Makefile builds and runs the test suites under tests/ for each
6 # one of the supported ports located under ports/.  The test suite
7 # results are summarised and individual test failures are logged.  The
8 # expected result is a single line per port summarising the number of
9 # failures, test points, and test cases.  The philosophy is that
10 # checked in code should always pass the suite with no failures, as
11 # then if there are failures then it is in the current developers code.
12 #
13 # Only the required suites are run.  Changing sdcc causes all to be
14 # re-run.  Changing one suite causes just that to be run.  Changing
15 # one of the library files should cause all to re-run
16
17 # Dependancies:
18 #   * The sdcc-extra package, available from CVS.
19 #       o cvs -d cvs.sdcc.sourceforge.net:/cvsroot/sdcc co sdcc-extra
20 #       o Provides the emulators
21 #   * The gbdk-lib package from gbdk.
22 #       o cvs -d cvs.gbdk.sourceforge.net:/cvsroot/gbdk co gbdk-lib
23 #       o Provildes mul, div, and include files for the z80 tests.
24 #   * python 1.5 or above
25 #
26 # The paths below assume that sdcc, sdcc-extra, and gbdk-lib all reside in
27 # the same directory.
28
29 # Old notes:
30 # Starting at the bottom
31 # Set of source test suites
32 # Each source suite is processesd producing multiple device specific test suites.
33 # Each device specific test suite is compiled.
34 # Each device specific test suite is run, and the output recorded.
35 # The output from each device specific test suite derrived from a source
36 # test suite are collated.
37
38 # Uncomment this to show only errors and the summary.
39 # Comment this out for debugging.
40 #.SILENT:
41
42 # All original tests live in TESTS_DIR and below
43 TESTS_DIR = tests
44 TESTS_NAME = $(TESTS_DIR)
45 # All suite results go in RESULTS_DIR
46 RESULTS_DIR = results
47 # All data relating to supported ports live in their own directory
48 # under PORTS_DIR.
49 PORTS_DIR = ports
50
51 # Itermediate data directories
52 # Directory that generated cases and the related object code go.
53 CASES_DIR = gen
54
55 # Script that takes a source test suite and generates the iterations
56 GENERATE_CASES = generate-cases.py
57
58 # Magically generate the list of configured ports to test.
59 # Each directory under ports/ is used as a port name.  Each port is tested.
60 # The port name must be the same as the one used in the SDCC '-mxxx' argument.
61 # Each port must have a spec.mk which describes how to build the object
62 # files and how to run the emulator.
63 ALL_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*)))
64
65 all: test-ports
66
67 # Test all of the ports
68 test-ports:
69         for i in $(ALL_PORTS); do $(MAKE) inter-port-clean test-port PORT=$$i; done
70
71 # Helper rule for testing the z80 port only
72 test-z80:
73         $(MAKE) inter-port-clean test-port PORT=z80
74
75 # Helper rule for testing the mcs51 small model port only
76 test-mcs51:
77         $(MAKE) inter-port-clean test-port PORT=mcs51
78
79 # Helper rule for testing the host cc only
80 test-host:
81         $(MAKE) inter-port-clean clean test-port PORT=host
82
83 test-host2:
84         $(MAKE) test-port PORT=host
85
86 # Begin per-port rules
87 # List of all of the known source test suites.
88 ALL_TESTS = $(shell find $(TESTS_DIR) -name "*.c")
89
90 # Intermediate directory
91 PORT_CASES_DIR = $(CASES_DIR)/$(PORT)
92 PORT_RESULTS_DIR = $(RESULTS_DIR)/$(PORT)
93 # Each test generates a result log file
94 PORT_RESULTS = $(ALL_TESTS:$(TESTS_DIR)/%.c=$(PORT_RESULTS_DIR)/%.out)
95
96 SDCC_DIR = ../..
97 SDCC_EXTRA_DIR = ../../../sdcc-extra
98
99 # Defaults.  Override in spec.mk if required.
100 # Path to SDCC
101 SDCC = $(SDCC_DIR)/bin/sdcc
102 # Base flags.
103 SDCCFLAGS = -m$(PORT)
104 # Extension of object intermediate files
105 OBJEXT = .o
106 # Extension of files that can be run in the emulator
107 EXEEXT = .bin
108 # Currently unused.  Extension to append to intermediate directories.
109 DIREXT = 
110
111 # Only include if we're in a per-port call.
112 ifdef PORT
113 include $(PORTS_DIR)/$(PORT)/spec.mk
114 endif
115
116 SDCCFLAGS += -Ifwk/include -Itests
117
118 # List of intermediate files to keep.  Pretty much keep everything as
119 # disk space is free.
120 .PRECIOUS: $(PORT_CASES_DIR)/% %$(OBJEXT) %$(EXEEXT)
121
122 # Rule to generate the iterations of a test suite off the soure suite.
123 $(PORT_CASES_DIR)/%/iterations.stamp: $(TESTS_DIR)/%.c $(GENERATE_CASES)
124         echo Processing $<
125         rm -rf $(CASES_DIR)/$(TESTS_NAME)
126         mkdir -p $(CASES_DIR)/$(TESTS_NAME)
127         mkdir -p `dirname $@`
128         python $(GENERATE_CASES) $< > /dev/null
129         cp $(CASES_DIR)/$(TESTS_NAME)/*.c `dirname $@`
130         touch $@
131
132 # Rule linking the combined results log to all of the files in the
133 # iteration directory.
134 $(PORT_RESULTS_DIR)/%.out: $(PORT_CASES_DIR)/%/iterations.stamp
135         $(MAKE) iterations PORT=$(PORT) CASES=`dirname $<`
136
137 # Rule to summaries the results for one port after all of the tests
138 # have been run.
139 port-results: port-dirs $(PORT_RESULTS)
140         echo Summary for \'$(PORT)\': `cat $(PORT_RESULTS) | python collate-results.py`
141
142 port-dirs:
143         mkdir -p $(PORT_CASES_DIR) $(PORT_RESULTS_DIR)
144
145 test-port: port-results
146
147 # Begin rules that process each iteration generated from the source
148 # test
149
150 # List of all of the generated iteration source files.
151 SUB_CASES = $(sort $(wildcard $(CASES)/*.c))
152 # List of all the sub result logs generated from the iterations.
153 SUB_RESULTS = $(SUB_CASES:%.c=%.out)
154 # Overall target.  Concatenation of all of the sub results.
155 RESULTS = $(CASES:$(CASES_DIR)/%$(DIREXT)=$(RESULTS_DIR)/%.out)
156
157 iterations: $(RESULTS)
158
159 # Rule to generate the overall target from the sub results.
160 $(RESULTS): $(SUB_RESULTS)
161         cat $(SUB_RESULTS) > $@
162
163 # The remainder of the rules are in $PORT/spec.mak.  The port needs to
164 # be able to turn an iterated test suite into a sub result, normally
165 # by:
166 #    1. Compile the required library files
167 #    2. Compile this test suite.
168 #    3. Link 1, 2, and any required stdlib into an executable.
169 #    4. Run the executable inside an emulator, and capture the text
170 #    output into %.out.
171 #
172 # The emulator must exit when main() returns.
173
174 # BeginGeneric rules
175
176 clean:
177         rm -rf $(CASES_DIR) $(RESULTS_DIR) *.pyc
178
179 inter-port-clean:
180         rm -f  fwk/lib/*.o