3 We use [Travis CI](https://travis-ci.org/) service to execute NASM tests,
4 which basically prepares the environment and runs our `nasm-t.py` script.
6 The script scans a testing directory for `*.json` test descriptor files
7 and runs test by descriptor content.
11 `nasm-t.py` script is a simple test engine written by Python3 language
12 which allows either execute a single test or run them all in a sequence.
14 A typical test case processed by the following steps:
16 - a test descriptor get parsed to figure out which arguments
17 are to be provided into the NASM command line;
18 - invoke the NASM with arguments;
19 - compare generated files with precompiled templates.
21 `nasm-t.py` supports the following commands:
23 - `list`: to list all test cases
24 - `run`: to run test cases
25 - `update`: to update precompiled templates
27 Use `nasm-t.py -h` command to get the detailed description of every option.
29 ### Test unit structure
30 Each test consists at least of three files:
32 - a test descriptor in with `*.json` extension;
33 - a source file to compile;
34 - a target file to compare result with, it is assumed to have
35 the same name as output generated during the pass file but with `*.t`
36 extension; thus if a test generates `*.bin` file the appropriate target
37 should have `*.bin.t` name.
41 To run all currently available tests simply type the following
44 python3 travis/nasm-t.py run
47 By default the `nasm-t.py` scans `test` subdirectory for `*.json` files and
48 consider each as a test descriptor. Then every test is executed sequentially.
49 If the descriptor can not be parsed it silently ignored.
51 To run a particular test provide the test name, for example
54 python3 travis/nasm-t.py list
56 ./travis/test/utf Test __utf__ helpers
57 ./travis/test/utf Test errors in __utf__ helpers
59 python3 travis/nasm-t.py run -t ./travis/test/utf
62 Test name duplicates in the listing above means that the descriptor
63 carries several tests with same name but different options.
67 A descriptor file should provide enough information how to run the NASM
68 itself and which output files or streams to compare with predefined ones.
69 We use *JSON* format with the following fields:
71 - `description`: a short description of a test which is shown to
72 a user when tests are being listed;
73 - `id`: descriptor internal name to use with `ref` field;
74 - `ref`: a reference to `id` from where settings should be
75 copied, it is convenient when say only `option` is different
76 while the rest of the fields are the same;
77 - `format`: NASM output format to use (`bin`,`elf` and etc);
78 - `source`: is a source file name to compile, this file must
79 be shipped together with descriptor file itself;
80 - `option`: an additional option passed to the command line;
81 - `update`: a trigger to skip updating targets when running
83 - `target`: an array of targets which the test engine should
84 check once compilation finished:
85 - `stderr`: a file containing *stderr* stream output to check;
86 - `stdout`: a file containing *stdout* stream output to check;
87 - `output`: a file containing compiled result to check, in other
88 words it is a name passed as `-o` option to the compiler;
89 - `error`: an error handler, can be either *over* to ignore any
90 error happened, or *expected* to make sure the test is failing.
93 A simple test where no additional options are used, simply compile
94 `absolute.asm` file with `bin` format for output, then compare
95 produced `absolute.bin` file with precompiled `absolute.bin.t`.
99 "description": "Check absolute addressing",
101 "source": "absolute.asm",
103 { "output": "absolute.bin" }
108 Note the `output` target is named as *absolute.bin* where *absolute.bin.t*
109 should be already precompiled (we will talk about it in `update` action)
112 A slightly complex example: compile one source file with different optimization
113 options and all results must be the same. To not write three descriptors
114 we assign `id` to the first one and use `ref` term to copy settings.
115 Also, it is expected that `stderr` stream will not be empty but carry some
121 "description": "Check 64-bit addressing (-Ox)",
124 "source": "addr64x.asm",
127 { "output": "addr64x.bin" },
128 { "stderr": "addr64x.stderr" }
132 "description": "Check 64-bit addressing (-O1)",
138 "description": "Check 64-bit addressing (-O0)",
148 If during development some of the targets are expected to change
149 the tests will start to fail so the should be updated. Thus new
150 precompiled results will be treated as templates to compare with.
152 To update all tests in one pass run
155 python3 travis/nasm-t.py update
157 === Updating ./travis/test/xcrypt ===
158 Processing ./travis/test/xcrypt
159 Executing ./nasm -f bin -o ./travis/test/xcrypt.bin ./travis/test/xcrypt.asm
160 Moving ./travis/test/xcrypt.bin to ./travis/test/xcrypt.bin.t
161 === Test ./travis/test/xcrypt UPDATED ===
165 and commit the results. To update a particular test provide its name