Sign in Join
Wiki copytemporary

Testing FPC: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11Development of a compiler and a corresponding runtime library requires an extensive amount of tests to ensure that the addition of a new feature or the fixing of a bug doesn't break any existing code. In FPC this task is handled by the testsuite located in the *tests* subdirectory of the top level directory ([SVN WebView](http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/)).
22
33# Overview
44
55The testsuite consists of the makefiles and utilities that execute the tests as well as the tests themselves. For this article the makefiles and utilities will be used as is and thus they won't be looked at any further.
66
77Detailed information about the testsuite and its parameters can be found in the [ReadMe](http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/readme.txt?view=markup).
88
99## Directory Structure
1010
1111The tests themselves are separated into multiple directories:
1212
1313- *test*: systematic tests, usually developed by test driven development
1414- *tbs*: tests derived from non tracker reports or ideas while fixing something requiring successfull compilation and (optionally) run
1515- *tbf*: tests derived from non tracker reports or ideas while fixing something requiring failing compilation
1616- *webtbs*: tests derived from bug tracker bugs requiring successful compilation and (optionally) run
1717- *webtbf*: tests derived from bug tracker bugs requiring failing of compilation
1818
1919Additionally selected *tests* subdirectories of directories in *packages* are searched. These are specified in *\$fpcdir/tests/Makefile.fpc* with the variable *TESTPACKAGESDIRECTDIRS* (the directories are simply separated by spaces). You need to regenerate the Makefile using *fpcmake -Tall* if you change this.
2020
2121Not all files in these directories are eligible for the testsuite however as they need to fullfill two formal criteria:
2222
2323- correct prefix (*t* for *test*, *tb* for *tbs* and *tbf*, *tw* for *webtbs* and *webtbf*)
2424- correct file extension (only '.pp' is accepted)
2525
2626The remaining name of the test is freely chosen, however there are some general guidelines for this as well:
2727
2828- tests in *test* have some short name describing the feature the tests are testing (e.g. *rhlp* for record helper tests and *genfunc* for generic function tests)
2929- tests in *tbf* and *tbs* have a unique, four digit index
3030- tests in *webtbs* and *webtbf* have their corresponding bug ID from Mantis as name plus eventually a small letter as suffix if there are multiple tests for the same report
3131- units that are used by some test have the prefix *u*, *ub* or *uw* depending on the test directory as well as the name of the first test they are used for (e.g. if both *thlp3.pp* and *thlp7.pp* use a unit the unit is named *uhlp3.pp*)
3232
3333## Test Results
3434
3535When a test is executed its execution essentially consists of two *stages*, namely *compilation* and *run*. The *run* stage is optional (see Test Options) or not required at all (e.g. if the test should already fail the *compilation* stage).
3636
3737The *compilation* stage can have the following outcomes:
3838
3939- successful compilation
4040- compilation failed with a compiler error
4141- compilation failed with an internal error
4242- compilation failed with another exception
4343
4444If the test should succeed then the first is treated as success, the other three as failures. If a test should fail then the second outcome is treated as a success, the other three are treated as failures.
4545
4646The *run* stage can have the following outcomes:
4747
4848- successful run
4949- failed run
5050
5151The result of the run is determined with the exit code of the test's execution.
5252
5353## Test Files
5454
5555A test file is either a program, library or unit file. A library and unit test is never run, only compiled while a program is always run unless told otherwise with the *{%NORUN}* option.
5656
5757## Test Options
5858
5959Various options can be used to influence the behavior of the testsuite. This options are given at the top of the testfile using a Borland style comment that starts with a *%*. The first comment without that marker ends the option parsing (usually that's the mode switch).
6060
6161The following is a non-extensive list of options that are supported:
6262
6363- *NORUN*: don't execute the resulting test program (useful if merely the compilation should be tested)
6464- *SKIP*: don't compile the test at all
6565- *CONFIGFILE*: Specifies a config file in *\$fpcdir/tests/config* that is to be copied to test. This option can take one or two parameters: in the two parameter form the first name is the source filename and the second the destination filename, in the one parameter form source and destination filename are equal.
6666
6767For a complete overview of all possible options, see the [ReadMe](http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/readme.txt?view=markup), under the header *Test directives*.
6868
6969# Running the testsuite
7070
7171To run the test suite a complete compilation (compiler, rtl, packages) should have been done beforehand. Then after changing into the *tests* directory you execute the following command:
7272
73-`make full TEST_FPC=/path/to/ppc TEST_CPU=<cpu> TEST_OS=<os> TEST_OPT=<options> CHUNKSIZE=50 -j <count>`
73+```text
74+make full TEST_FPC=/path/to/ppc TEST_CPU=<cpu> TEST_OS=<os> TEST_OPT=<options> CHUNKSIZE=50 -j <count>
75+```
7476
7577- *TEST_FPC*: absolute path to the compiler that should be tested (mandatory)
7678- *TEST_CPU*: name of the CPU for which the tests are run (default is the given compiler's default CPU)
7779- *TEST_OS*: name of the OS for which the test should be run (default is the given compiler's default OS)
7880- *TEST_OPT*: options that should be passed to the compiler
7981- *CHUNKSIZE* and *-j \<count\>*: the testsuite can use multiple cpu cores in parallel. It does so by launching *\<count\>* instances of the *dotest* program, each of which will execute *CHUNKSIZE* tests before terminating (after which a new instance of *dotest* will be started to check *CHUNKSIZE* more tests). We split up the test collection in chunks because not all tests take the same amount of time to compile and run. To get optimal throughput (avoiding some cores sitting idle near the end of the testsuite run), choose a smaller CHUNKSIZE when your number of cores increases. The default, *CHUNKSIZE=100*, performs fairly well for up to 4 cores. Don't make *CHUNKSIZE* too small, or the overhead from starting more instances of *dotest* will erase any gains you may get.
8082
8183At the end of the testsuite run there'll be an ordered list of failed tests available in *tests/output/\<cpu\>-\<os\>/faillist* that can be compared with other runs.
8284
8385# Recommended Workflow
8486
8587Before doing any changes:
8688
8789- complete build
8890- testsuite run
8991- save *faillist* file (e.g. to *tests/output/unmodified/faillist*)
9092
9193To test your changes:
9294
9395- complete build (fix any failures that might occur here)
9496- testsuite run
9597- compare new *faillist* with stored *faillist* (due to the tests being ordered a diff or similar is sufficient)
9698- fix failures in compiler/RTL/packages
9799- rinse and repeat
98100
99101---
100102*From the Free Pascal wiki, page "Testing FPC", as it stood on 2018-06-24 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
101103Category: FPC development
102104Category: Testing

Back to history