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