1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
5 \pdfoptionpdfminorversion=3
7 pdftitle={Proposed Test Suite Design},
8 pdfauthor={Michael Hope},
9 pdfkeywords={c case compiler framework GPL regression SDCC suite test},
11 linkcolor=blue] {hyperref}
17 \paperfontsize default
24 \use_numerical_citations 0
25 \paperorientation portrait
28 \paragraph_separation indent
30 \quotes_language english
34 \paperpagestyle default
38 Proposed Test Suite Design
51 Michael Hope (michaelh @ juju.net.nz)
54 This article describes the goals, requirements, and suggested specification
55 for a test suite for the output of the Small Device C Compiler (sdcc).
56 Also included is a short list of existing works.
63 The main goals of a test suite for sdcc are
66 To allow developers to run regression tests to check that core changes do
67 not break any of the many ports.
75 To allow developers to verify individual ports.
79 To allow developers to test port changes.
83 This design only covers the generated code.
84 It does not cover a test/unit test framework for the sdcc application itself,
88 One side effect of (1) is that it requires that the individual ports pass
91 See the section on Exceptions below.
100 The suite is intended to cover language features only.
101 Hardware specific libraries are explicitly not covered.
107 The ports often generate different code for handling different types (Byte,
108 Word, DWord, and the signed forms).
109 Meta information could be used to permute the different test cases across
116 The different ports are all at different levels of development.
117 Test cases must be able to be disabled on a per port basis.
118 Permutations also must be able to be disabled on a port level for unsupported
120 Disabling, as opposed to enabling, on a per port basis seems more maintainable.
126 The tests must be able to run unaided.
127 The test suite must run on all platforms that sdcc runs on.
128 A good minimum may be a subset of Unix command set and common tools, provided
129 by default on a Unix host and provided through cygwin on a Windows host.
132 The tests suits should be able to be sub-divided, so that the failing or
133 interesting tests may be run separately.
139 The test code within the test cases should not generate artifacts.
140 An artifact occurs when the test code itself interferes with the test and
141 generates an erroneous result.
147 sdcc is a cross compiling compiler.
148 As such, an emulator is needed for each port to run the tests.
157 DejaGnu is a toolkit written in Expect designed to test an interactive program.
158 It provides a way of specifying an interface to the program, and given
159 that interface a way of stimulating the program and interpreting the results.
160 It was originally written by Cygnus Solutions for running against development
162 I believe the gcc test suite is written against DejaGnu, perhaps partly
163 to test the Cygnus ports of gcc on target systems.
169 I don't know much about the gcc test suite.
170 It was recently removed from the gcc distribution due to issues with copyright
172 The code I saw from older distributions seemed more concerned with esoteric
173 features of the language.
179 The xUnit family, in particular JUnit, is a library of in test assertions,
180 test wrappers, and test suite wrappers designed mainly for unit testing.
184 CoreLinux++ Assertion framework
187 While not a test suite system, the assertion framework is an interesting
188 model for the types of assertions that could be used.
189 They include pre-condition, post-condition, invariants, conditional assertions,
190 unconditional assertions, and methods for checking conditions.
196 This specification borrows from the JUnit style of unit testing and the
197 CoreLinux++ style of assertions.
198 The emphasis is on maintainability and ease of writing the test cases.
204 PENDING: Align these terms with the rest of the world.
211 is a statement of how things should be.
212 PENDING: Better description, an example.
220 is the smallest unit of a test suite, and consists of a single assertion
221 that passes if the test passes.
229 is a set of test points that test a certain feature.
237 is a set of test cases that test a certain set of features.
244 Test cases shall be contained in their own C file, along with the meta data
246 Test cases shall be contained within functions whose names start with 'test'
247 and which are descriptive of the test case.
248 Any function that starts with 'test' will be automatically run in the test
252 To make the automatic code generation easier, the C code shall have this
256 Test functions shall start with 'test' to allow automatic detection.
260 Test functions shall follow the K&R intention style for ease of detection.
262 the function name shall start in the left column on a new line below the
263 return specification.
270 All assertions shall log the line number, function name, and test case file
272 Most assertions can have a more descriptive message attached to them.
273 Assertions will be implemented through macros to get at the line information.
274 This may cause trouble with artifacts.
277 The following definitions use C++ style default arguments where optional
278 messages may be inserted.
279 All assertions use double opening and closing brackets in the macros to
280 allow them to be compiled out without any side effects.
281 While this is not required for a test suite, they are there in case any
282 of this code is incorporated into the main product.
285 Borrowing from JUnit, the assertions shall include
289 \begin_inset Quotes eld
293 \begin_inset Quotes erd
297 Used when execution should not get here.
301 ASSERT((Boolean cond, String msg =
302 \begin_inset Quotes eld
306 \begin_inset Quotes erd
310 Fails if cond is false.
311 Parent to REQUIRE and ENSURE.
315 JUnit also includes may sub-cases of ASSERT, such as assertNotNull, assertEquals
319 CoreLinux++ includes the extra assertions
322 REQUIRE((Boolean cond, String msg =
323 \begin_inset Quotes eld
327 \begin_inset Quotes erd
331 Checks preconditions.
335 ENSURE((Boolean cond, String msg =
336 \begin_inset Quotes eld
340 \begin_inset Quotes erd
344 Checks post conditions.
348 CHECK((Boolean cond, String msg =
349 \begin_inset Quotes eld
353 \begin_inset Quotes erd
357 Used to call a function and to check that the return value is as expected.
359 CHECK((fread(in, buf, 10) != -1)).
360 Very similar to ASSERT, but the function still gets called in a release
366 Used to check conditions within part of the code.
367 For example, can be used to check that a list is still sorted inside each
368 loop of a sort routine.
372 All of FAIL, ASSERT, REQUIRE, ENSURE, and CHECK shall be available.
378 PENDING: It's not really meta data.
381 Meta data includes permutation information, exception information, and permutati
385 Meta data shall be global to the file.
386 Meta data names consist of the lower case alphanumerics.
387 Test case specific meta data (fields) shall be stored in a comment block
388 at the start of the file.
389 This is only due to style.
392 A field definition shall consist of
402 A comma separated list of values.
406 The values shall be stripped of leading and trailing white space.
409 Permutation exceptions are by port only.
410 Exceptions to a field are specified by a modified field definition.
411 An exception definition consists of
418 An opening square bracket.
422 A comma separated list of ports the exception applies for.
426 A closing square bracket.
434 The values to use for this field for these ports.
438 An instance of the test case shall be generated for each permutation of
439 the test case specific meta data fields.
442 The runtime meta fields are
445 port - The port this test is running on.
449 testcase - The name of this test case.
453 function - The name of the current function.
457 Most of the runtime fields are not very usable.
458 They are there for completeness.
461 Meta fields may be accessed inside the test case by enclosing them in curly
463 The curly brackets will be interpreted anywhere inside the test case, including
464 inside quoted strings.
465 Field names that are not recognised will be passed through including the
467 Note that it is therefore impossible to use some strings within the test
471 Test case function names should include the permuted fields in the name
472 to reduce name collisions.
478 I don't know how to do pre-formatted text in LaTeX.
482 The following code generates a simple increment test for all combinations
483 of the storage classes and all combinations of the data sizes.
484 This is a bad example as the optimiser will often remove most of this code.
491 /** Test for increment.
496 type: char, int, long
500 Z80 port does not fully support longs (4 byte)
509 \begin_inset Quotes eld
513 \begin_inset Quotes erd
516 , register, static */
522 testInc{class}{types}(void)
528 {class} {type} i = 0;