1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
5 \pdfoptionpdfminorversion=3
12 \paperfontsize default
19 \use_numerical_citations 0
20 \paperorientation portrait
23 \paragraph_separation indent
25 \quotes_language english
29 \paperpagestyle default
33 Proposed Test Suite Design
36 Michael Hope (michaelh@juju.net.nz)
52 This article describes the goals, requirements, and suggested specification
53 for a test suite for the output of the Small Device C Compiler (sdcc).
54 Also included is a short list of existing works.
61 The main goals of a test suite for sdcc are
64 To allow developers to run regression tests to check that core changes do
65 not break any of the many ports.
73 To allow developers to verify individual ports.
77 To allow developers to test port changes.
81 This design only covers the generated code.
82 It does not cover a test/unit test framework for the sdcc application itself,
86 One side effect of (1) is that it requires that the individual ports pass
89 See the section on Exceptions below.
98 The suite is intended to cover language features only.
99 Hardware specific libraries are explicitly not covered.
105 The ports often generate different code for handling different types (Byte,
106 Word, DWord, and the signed forms).
107 Meta information could be used to permute the different test cases across
114 The different ports are all at different levels of development.
115 Test cases must be able to be disabled on a per port basis.
116 Permutations also must be able to be disabled on a port level for unsupported
118 Disabling, as opposed to enabling, on a per port basis seems more maintainable.
124 The tests must be able to run unaided.
125 The test suite must run on all platforms that sdcc runs on.
126 A good minimum may be a subset of Unix command set and common tools, provided
127 by default on a Unix host and provided through cygwin on a Windows host.
130 The tests suits should be able to be sub-divided, so that the failing or
131 interesting tests may be run separately.
137 The test code within the test cases should not generate artifacts.
138 An artifact occurs when the test code itself interferes with the test and
139 generates an erroneous result.
145 sdcc is a cross compiling compiler.
146 As such, an emulator is needed for each port to run the tests.
155 DejaGnu is a toolkit written in Expect designed to test an interactive program.
156 It provides a way of specifying an interface to the program, and given
157 that interface a way of stimulating the program and interpreting the results.
158 It was originally written by Cygnus Solutions for running against development
160 I believe the gcc test suite is written against DejaGnu, perhaps partly
161 to test the Cygnus ports of gcc on target systems.
167 I don't know much about the gcc test suite.
168 It was recently removed from the gcc distribution due to issues with copyright
170 The code I saw from older distributions seemed more concerned with esoteric
171 features of the language.
177 The xUnit family, in particular JUnit, is a library of in test assertions,
178 test wrappers, and test suite wrappers designed mainly for unit testing.
182 CoreLinux++ Assertion framework
185 While not a test suite system, the assertion framework is an interesting
186 model for the types of assertions that could be used.
187 They include pre-condition, post-condition, invariants, conditional assertions,
188 unconditional assertions, and methods for checking conditions.
194 This specification borrows from the JUnit style of unit testing and the
195 CoreLinux++ style of assertions.
196 The emphasis is on maintainability and ease of writing the test cases.
202 PENDING: Align these terms with the rest of the world.
209 is a statement of how things should be.
210 PENDING: Better description, an example.
218 is the smallest unit of a test suite, and consists of a single assertion
219 that passes if the test passes.
227 is a set of test points that test a certain feature.
235 is a set of test cases that test a certain set of features.
242 Test cases shall be contained in their own C file, along with the meta data
244 Test cases shall be contained within functions whose names start with 'test'
245 and which are descriptive of the test case.
246 Any function that starts with 'test' will be automatically run in the test
250 To make the automatic code generation easier, the C code shall have this
254 Test functions shall start with 'test' to allow automatic detection.
258 Test functions shall follow the K&R intention style for ease of detection.
260 the function name shall start in the left column on a new line below the
261 return specification.
268 All assertions shall log the line number, function name, and test case file
270 Most assertions can have a more descriptive message attached to them.
271 Assertions will be implemented through macros to get at the line information.
272 This may cause trouble with artifacts.
275 The following definitions use C++ style default arguments where optional
276 messages may be inserted.
277 All assertions use double opening and closing brackets in the macros to
278 allow them to be compiled out without any side effects.
279 While this is not required for a test suite, they are there in case any
280 of this code is incorporated into the main product.
283 Borrowing from JUnit, the assertions shall include
287 \begin_inset Quotes eld
291 \begin_inset Quotes erd
295 Used when execution should not get here.
299 ASSERT((Boolean cond, String msg =
300 \begin_inset Quotes eld
304 \begin_inset Quotes erd
308 Fails if cond is false.
309 Parent to REQUIRE and ENSURE.
313 JUnit also includes may sub-cases of ASSERT, such as assertNotNull, assertEquals
317 CoreLinux++ includes the extra assertions
320 REQUIRE((Boolean cond, String msg =
321 \begin_inset Quotes eld
325 \begin_inset Quotes erd
329 Checks preconditions.
333 ENSURE((Boolean cond, String msg =
334 \begin_inset Quotes eld
338 \begin_inset Quotes erd
342 Checks post conditions.
346 CHECK((Boolean cond, String msg =
347 \begin_inset Quotes eld
351 \begin_inset Quotes erd
355 Used to call a function and to check that the return value is as expected.
357 CHECK((fread(in, buf, 10) != -1)).
358 Very similar to ASSERT, but the function still gets called in a release
364 Used to check conditions within part of the code.
365 For example, can be used to check that a list is still sorted inside each
366 loop of a sort routine.
370 All of FAIL, ASSERT, REQUIRE, ENSURE, and CHECK shall be available.
376 PENDING: It's not really meta data.
379 Meta data includes permutation information, exception information, and permutati
383 Meta data shall be global to the file.
384 Meta data names consist of the lower case alphanumerics.
385 Test case specific meta data (fields) shall be stored in a comment block
386 at the start of the file.
387 This is only due to style.
390 A field definition shall consist of
400 A comma separated list of values.
404 The values shall be stripped of leading and trailing white space.
407 Permutation exceptions are by port only.
408 Exceptions to a field are specified by a modified field definition.
409 An exception definition consists of
416 An opening square bracket.
420 A comma separated list of ports the exception applies for.
424 A closing square bracket.
432 The values to use for this field for these ports.
436 An instance of the test case shall be generated for each permutation of
437 the test case specific meta data fields.
440 The runtime meta fields are
443 port - The port this test is running on.
447 testcase - The name of this test case.
451 function - The name of the current function.
455 Most of the runtime fields are not very usable.
456 They are there for completeness.
459 Meta fields may be accessed inside the test case by enclosing them in curly
461 The curly brackets will be interpreted anywhere inside the test case, including
462 inside quoted strings.
463 Field names that are not recognised will be passed through including the
465 Note that it is therefore impossible to use some strings within the test
469 Test case function names should include the permuted fields in the name
470 to reduce name collisions.
476 I don't know how to do pre-formatted text in LaTeX.
480 The following code generates a simple increment test for all combinations
481 of the storage classes and all combinations of the data sizes.
482 This is a bad example as the optimiser will often remove most of this code.
487 /** Test for increment.
493 type: char, int, long
498 Z80 port does not fully support longs (4 byte)
509 \begin_inset Quotes eld
513 \begin_inset Quotes erd
516 , register, static */
526 testInc{class}{types}(void)
536 {class} {type} i = 0;