Reshaped doc's
[fw/sdcc] / doc / test_suite_spec.lyx
1 #LyX 1.1 created this file. For more info see http://www.lyx.org/
2 \lyxformat 218
3 \textclass article
4 \begin_preamble
5 \usepackage{url}
6 \end_preamble
7 \language english
8 \inputencoding auto
9 \fontscheme times
10 \graphics default
11 \paperfontsize default
12 \spacing single 
13 \papersize Default
14 \paperpackage a4
15 \use_geometry 0
16 \use_amsmath 0
17 \paperorientation portrait
18 \secnumdepth 3
19 \tocdepth 3
20 \paragraph_separation indent
21 \defskip medskip
22 \quotes_language english
23 \quotes_times 2
24 \papercolumns 1
25 \papersides 1
26 \paperpagestyle default
27
28 \layout Title
29
30 Proposed Test Suite Design
31 \layout Author
32
33 Michael Hope (michaelh@juju.net.nz)
34 \layout Date
35
36
37 \latex latex 
38
39 \backslash 
40 today{}
41 \layout Abstract
42
43 This article describes the goals, requirements, and suggested specification
44  for a test suite for the output of the Small Device C Compiler (sdcc).
45  Also included is a short list of existing works.
46  
47 \layout Section
48
49 Goals
50 \layout Standard
51
52 The main goals of a test suite for sdcc are 
53 \layout Enumerate
54
55 To allow developers to run regression tests to check that core changes do
56  not break any of the many ports.
57  
58 \layout Enumerate
59
60 To verify the core.
61  
62 \layout Enumerate
63
64 To allow developers to verify individual ports.
65  
66 \layout Enumerate
67
68 To allow developers to test port changes.
69  
70 \layout Standard
71
72 This design only covers the generated code.
73  It does not cover a test/unit test framework for the sdcc application itself,
74  which may be useful.
75 \layout Standard
76
77 One side effect of (1) is that it requires that the individual ports pass
78  the tests originally.
79  This may be too hard.
80  See the section on Exceptions below.
81 \layout Section
82
83 Requirements
84 \layout Subsection
85
86 Coverage
87 \layout Standard
88
89 The suite is intended to cover language features only.
90  Hardware specific libraries are explicitly not covered.
91 \layout Subsection
92
93 Permutations
94 \layout Standard
95
96 The ports often generate different code for handling different types (Byte,
97  Word, DWord, and the signed forms).
98  Meta information could be used to permute the different test cases across
99  the different types.
100 \layout Subsection
101
102 Exceptions
103 \layout Standard
104
105 The different ports are all at different levels of development.
106  Test cases must be able to be disabled on a per port basis.
107  Permutations also must be able to be disabled on a port level for unsupported
108  cases.
109  Disabling, as opposed to enabling, on a per port basis seems more maintainable.
110 \layout Subsection
111
112 Running
113 \layout Standard
114
115 The tests must be able to run unaided.
116  The test suite must run on all platforms that sdcc runs on.
117  A good minimum may be a subset of Unix command set and common tools, provided
118  by default on a Unix host and provided through cygwin on a Windows host.
119 \layout Standard
120
121 The tests suits should be able to be sub-divided, so that the failing or
122  interesting tests may be run separately.
123 \layout Subsection
124
125 Artifcats
126 \layout Standard
127
128 The test code within the test cases should not generate artifacts.
129  An artifact occurs when the test code itself interferes with the test and
130  generates an erroneous result.
131 \layout Subsection
132
133 Emulators
134 \layout Standard
135
136 sdcc is a cross compiling compiler.
137  As such, an emulator is needed for each port to run the tests.
138 \layout Section
139
140 Existing works
141 \layout Subsection
142
143 DejaGnu
144 \layout Standard
145
146 DejaGnu is a toolkit written in Expect designed to test an interactive program.
147  It provides a way of specifying an interface to the program, and given
148  that interface a way of stimulating the program and interpreting the results.
149  It was originally written by Cygnus Solutions for running against development
150  boards.
151  I believe the gcc test suite is written against DejaGnu, perhaps partly
152  to test the Cygnus ports of gcc on target systems.
153 \layout Subsection
154
155 gcc test suite
156 \layout Standard
157
158 I don't know much about the gcc test suite.
159  It was recently removed from the gcc distribution due to issues with copyright
160  ownership.
161  The code I saw from older distributions seemed more concerned with esoteric
162  features of the language.
163 \layout Subsection
164
165 xUnit
166 \layout Standard
167
168 The xUnit family, in particular JUnit, is a library of in test assertions,
169  test wrappers, and test suite wrappers designed mainly for unit testing.
170  PENDING: More.
171 \layout Subsection
172
173 CoreLinux++ Assertion framework
174 \layout Standard
175
176 While not a test suite system, the assertion framework is an interesting
177  model for the types of assertions that could be used.
178  They include pre-condition, post-condition, invariants, conditional assertions,
179  unconditional assertions, and methods for checking conditions.
180 \layout Section
181
182 Specification
183 \layout Standard
184
185 This specification borrows from the JUnit style of unit testing and the
186  CoreLinux++ style of assertions.
187  The emphasis is on maintainability and ease of writing the test cases.
188 \layout Subsection
189
190 Terms
191 \layout Standard
192
193 PENDING: Align these terms with the rest of the world.
194 \layout Itemize
195
196 An 
197 \emph on 
198 assertion
199 \emph default 
200  is a statement of how things should be.
201  PENDING: Better description, an example.
202  
203 \layout Itemize
204
205
206 \emph on 
207 test point
208 \emph default 
209  is the smallest unit of a test suite, and consists of a single assertion
210  that passes if the test passes.
211  
212 \layout Itemize
213
214
215 \emph on 
216 test case
217 \emph default 
218  is a set of test points that test a certain feature.
219  
220 \layout Itemize
221
222
223 \emph on 
224 test suite
225 \emph default 
226  is a set of test cases that test a certain set of features.
227  
228 \layout Subsection
229
230 Test cases
231 \layout Standard
232
233 Test cases shall be contained in their own C file, along with the meta data
234  on the test.
235  Test cases shall be contained within functions whose names start with 'test'
236  and which are descriptive of the test case.
237  Any function that starts with 'test' will be automatically run in the test
238  suite.
239 \layout Standard
240
241 To make the automatic code generation easier, the C code shall have this
242  format 
243 \layout Itemize
244
245 Test functions shall start with 'test' to allow automatic detection.
246  
247 \layout Itemize
248
249 Test functions shall follow the K&R intention style for ease of detection.
250  i.e.
251  the function name shall start in the left column on a new line below the
252  return specification.
253  
254 \layout Subsection
255
256 Assertions
257 \layout Standard
258
259 All assertions shall log the line number, function name, and test case file
260  when they fail.
261  Most assertions can have a more descriptive message attached to them.
262  Assertions will be implemented through macros to get at the line information.
263  This may cause trouble with artifacts.
264 \layout Standard
265
266 The following definitions use C++ style default arguments where optional
267  messages may be inserted.
268  All assertions use double opening and closing brackets in the macros to
269  allow them to be compiled out without any side effects.
270  While this is not required for a test suite, they are there in case any
271  of this code is incorporated into the main product.
272 \layout Standard
273
274 Borrowing from JUnit, the assertions shall include 
275 \layout Itemize
276
277 FAIL((String msg = 
278 \begin_inset Quotes eld
279 \end_inset 
280
281 Failed
282 \begin_inset Quotes erd
283 \end_inset 
284
285 )).
286  Used when execution should not get here.
287  
288 \layout Itemize
289
290 ASSERT((Boolean cond, String msg = 
291 \begin_inset Quotes eld
292 \end_inset 
293
294 Assertion failed
295 \begin_inset Quotes erd
296 \end_inset 
297
298 ).
299  Fails if cond is false.
300  Parent to REQUIRE and ENSURE.
301  
302 \layout Standard
303
304 JUnit also includes may sub-cases of ASSERT, such as assertNotNull, assertEquals
305 , and assertSame.
306 \layout Standard
307
308 CoreLinux++ includes the extra assertions 
309 \layout Itemize
310
311 REQUIRE((Boolean cond, String msg = 
312 \begin_inset Quotes eld
313 \end_inset 
314
315 Precondition failed
316 \begin_inset Quotes erd
317 \end_inset 
318
319 ).
320  Checks preconditions.
321  
322 \layout Itemize
323
324 ENSURE((Boolean cond, String msg = 
325 \begin_inset Quotes eld
326 \end_inset 
327
328 Postcondition failed
329 \begin_inset Quotes erd
330 \end_inset 
331
332 ).
333  Checks post conditions.
334  
335 \layout Itemize
336
337 CHECK((Boolean cond, String msg = 
338 \begin_inset Quotes eld
339 \end_inset 
340
341 Check failed
342 \begin_inset Quotes erd
343 \end_inset 
344
345 )).
346  Used to call a function and to check that the return value is as expected.
347  i.e.
348  CHECK((fread(in, buf, 10) != -1)).
349  Very similar to ASSERT, but the function still gets called in a release
350  build.
351  
352 \layout Itemize
353
354 FORALL and EXISTS.
355  Used to check conditions within part of the code.
356  For example, can be used to check that a list is still sorted inside each
357  loop of a sort routine.
358  
359 \layout Standard
360
361 All of FAIL, ASSERT, REQUIRE, ENSURE, and CHECK shall be available.
362 \layout Subsection
363
364 Meta data
365 \layout Standard
366
367 PENDING: It's not really meta data.
368 \layout Standard
369
370 Meta data includes permutation information, exception information, and permutati
371 on exceptions.
372 \layout Standard
373
374 Meta data shall be global to the file.
375  Meta data names consist of the lower case alphanumerics.
376  Test case specific meta data (fields) shall be stored in a comment block
377  at the start of the file.
378  This is only due to style.
379 \layout Standard
380
381 A field definition shall consist of 
382 \layout Itemize
383
384 The field name 
385 \layout Itemize
386
387 A colon.
388  
389 \layout Itemize
390
391 A comma separated list of values.
392  
393 \layout Standard
394
395 The values shall be stripped of leading and trailing white space.
396 \layout Standard
397
398 Permutation exceptions are by port only.
399  Exceptions to a field are specified by a modified field definition.
400  An exception definition consists of
401 \layout Itemize
402
403 The field name.
404  
405 \layout Itemize
406
407 An opening square bracket.
408  
409 \layout Itemize
410
411 A comma separated list of ports the exception applies for.
412  
413 \layout Itemize
414
415 A closing square bracket.
416  
417 \layout Itemize
418
419 A colon.
420  
421 \layout Itemize
422
423 The values to use for this field for these ports.
424  
425 \layout Standard
426
427 An instance of the test case shall be generated for each permutation of
428  the test case specific meta data fields.
429 \layout Standard
430
431 The runtime meta fields are 
432 \layout Itemize
433
434 port - The port this test is running on.
435  
436 \layout Itemize
437
438 testcase - The name of this test case.
439  
440 \layout Itemize
441
442 function - The name of the current function.
443  
444 \layout Standard
445
446 Most of the runtime fields are not very usable.
447  They are there for completeness.
448 \layout Standard
449
450 Meta fields may be accessed inside the test case by enclosing them in curly
451  brackets.
452  The curly brackets will be interpreted anywhere inside the test case, including
453  inside quoted strings.
454  Field names that are not recognised will be passed through including the
455  brackets.
456  Note that it is therefore impossible to use some strings within the test
457  case.
458 \layout Standard
459
460 Test case function names should include the permuted fields in the name
461  to reduce name collisions.
462 \layout Subsection
463
464 An example
465 \layout Standard
466
467 I don't know how to do pre-formatted text in LaTeX.
468  Sigh.
469 \layout Standard
470
471 The following code generates a simple increment test for all combinations
472  of the storage classes and all combinations of the data sizes.
473  This is a bad example as the optimiser will often remove most of this code.
474 \layout Standard
475
476
477 \family typewriter 
478 /** Test for increment.
479  
480 \layout Standard
481
482
483 \family typewriter 
484 type: char, int, long
485 \layout Standard
486
487
488 \family typewriter 
489 Z80 port does not fully support longs (4 byte)
490 \layout Standard
491
492
493 \family typewriter 
494 type[z80]: char, int
495 \layout Standard
496
497
498 \family typewriter 
499 class: 
500 \begin_inset Quotes eld
501 \end_inset 
502
503
504 \begin_inset Quotes erd
505 \end_inset 
506
507 , register, static */
508 \layout Standard
509
510
511 \family typewriter 
512 static void
513 \layout Standard
514
515
516 \family typewriter 
517 testInc{class}{types}(void)
518 \layout Standard
519
520
521 \family typewriter 
522 {
523 \layout Standard
524
525
526 \family typewriter 
527 {class} {type} i = 0; 
528 \layout Standard
529
530
531 \family typewriter 
532 i = i + 1;
533 \layout Standard
534
535
536 \family typewriter 
537 ASSERT((i == 1));
538 \layout Standard
539
540
541 \family typewriter 
542 }
543 \the_end