5d596da459177266290ac218c150ddc74a145091
[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 nores:
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 # All suite results go in RESULTS_DIR
45 RESULTS_DIR = results
46 # All data relating to supported ports live in their own directory
47 # under PORTS_DIR.
48 PORTS_DIR = ports
49
50 # Itermediate data directories
51 # Directory that generated cases and the related object code go.
52 CASES_DIR = gen
53
54 # Script that takes a source test suite and generates the iterations
55 GENERATE_CASES = generate-cases.py
56
57 # Magically generate the list of configured ports to test.
58 # Each directory under ports/ is used as a port name.  Each port is tested.
59 # The port name must be the same as the one used in the SDCC '-mxxx' argument.
60 # Each port must have a spec.mk which describes how to build the object
61 # files and how to run the emulator.
62 ALL_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*)))
63
64 # Test all of the ports
65 test-ports:
66         for i in $(ALL_PORTS); do $(MAKE) inter-port-clean test-port PORT=$$i; done
67
68 # Begin per-port rules
69 # List of all of the known source test suites.
70 ALL_TESTS = $(shell find $(TESTS_DIR) -name "*.c")
71
72 # Intermediate directory
73 PORT_CASES_DIR = $(CASES_DIR)/$(PORT)
74 PORT_RESULTS_DIR = $(RESULTS_DIR)/$(PORT)
75 # Each test generates a result log file
76 PORT_RESULTS = $(ALL_TESTS:$(TESTS_DIR)/%.c=$(PORT_RESULTS_DIR)/%.out)
77
78 SDCC_DIR = ../..
79 SDCC_EXTRA_DIR = ../../../sdcc-extra
80
81 # Defaults.  Override in spec.mk if required.
82 # Path to SDCC
83 SDCC = $(SDCC_DIR)/bin/sdcc
84 # Base flags.
85 SDCCFLAGS = -m$(PORT)
86 # Extension of object intermediate files
87 OBJEXT = .o
88 # Extension of files that can be run in the emulator
89 EXEEXT = .bin
90 # Currently unused.  Extension to append to intermediate directories.
91 DIREXT = 
92
93 # Only include if we're in a per-port call.
94 ifdef PORT
95 include $(PORTS_DIR)/$(PORT)/spec.mk
96 endif
97
98 SDCCFLAGS += -Ifwk/include
99
100 # List of intermediate files to keep.  Pretty much keep everything as
101 # disk space is free.
102 .PRECIOUS: $(PORT_CASES_DIR)/% %$(OBJEXT) %$(EXEEXT)
103
104 # Rule to generate the iterations of a test suite off the soure suite.
105 $(PORT_CASES_DIR)/%$(DIREXT): $(TESTS_DIR)/%.c $(GENERATE_CASES)
106         rm -rf $(CASES_DIR)/tests
107         mkdir -p $(CASES_DIR)/tests
108         mkdir -p $@
109         python $(GENERATE_CASES) $< > /dev/null
110         cp $(CASES_DIR)/tests/*.c $@
111         touch $@
112
113 # Rule linking the combined results log to all of the files in the
114 # iteration directory.
115 $(PORT_RESULTS_DIR)/%.out: $(PORT_CASES_DIR)/%$(DIREXT)
116         $(MAKE) iterations PORT=$(PORT) CASES=$<
117
118 # Rule to summaries the results for one port after all of the tests
119 # have been run.
120 port-results: port-dirs $(PORT_RESULTS)
121         echo Summary for \'$(PORT)\': `cat $(PORT_RESULTS) | python collate-results.py`
122
123 port-dirs:
124         mkdir -p $(PORT_CASES_DIR) $(PORT_RESULTS_DIR)
125
126 test-port: port-results
127
128 # Begin rules that process each iteration generated from the source
129 # test
130
131 # List of all of the generated iteration source files.
132 SUB_CASES = $(wildcard $(CASES)/*.c)
133 # List of all the sub result logs generated from the iterations.
134 SUB_RESULTS = $(SUB_CASES:%.c=%.out)
135 # Overall target.  Concatenation of all of the sub results.
136 RESULTS = $(CASES:$(CASES_DIR)/%$(DIREXT)=$(RESULTS_DIR)/%.out)
137
138 iterations: $(RESULTS)
139
140 # Rule to generate the overall target from the sub results.
141 $(RESULTS): $(SUB_RESULTS)
142         cat $(SUB_RESULTS) > $@
143
144 # The remainder of the rules are in $PORT/spec.mak.  The port needs to
145 # be able to turn an iterated test suite into a sub result, normally
146 # by:
147 #    1. Compile the required library files
148 #    2. Compile this test suite.
149 #    3. Link 1, 2, and any required stdlib into an executable.
150 #    4. Run the executable inside an emulator, and capture the text
151 #    output into %.out.
152 #
153 # The emulator must exit when main() returns.
154
155 # BeginGeneric rules
156
157 clean:
158         rm -rf $(CASES_DIR) $(RESULTS_DIR)
159
160 inter-port-clean:
161         rm -f  fwk/lib/*.o