GNU Linux-libre 4.14.251-gnu1
[releases.git] / tools / testing / selftests / tc-testing / creating-testcases / AddingTestCases.txt
1 tdc - Adding test cases for tdc
2
3 Author: Lucas Bates - lucasb@mojatatu.com
4
5 ADDING TEST CASES
6 -----------------
7
8 User-defined tests should be added by defining a separate JSON file.  This
9 will help prevent conflicts when updating the repository. Refer to
10 template.json for the required JSON format for test cases.
11
12 Include the 'id' field, but do not assign a value. Running tdc with the -i
13 option will generate a unique ID for that test case.
14
15 tdc will recursively search the 'tc' subdirectory for .json files.  Any
16 test case files you create in these directories will automatically be included.
17 If you wish to store your custom test cases elsewhere, be sure to run tdc
18 with the -f argument and the path to your file.
19
20 Be aware of required escape characters in the JSON data - particularly when
21 defining the match pattern. Refer to the tctests.json file for examples when
22 in doubt.
23
24
25 TEST CASE STRUCTURE
26 -------------------
27
28 Each test case has required data:
29
30 id:           A unique alphanumeric value to identify a particular test case
31 name:         Descriptive name that explains the command under test
32 category:     A list of single-word descriptions covering what the command
33               under test is testing. Example: filter, actions, u32, gact, etc.
34 setup:        The list of commands required to ensure the command under test
35               succeeds. For example: if testing a filter, the command to create
36               the qdisc would appear here.
37 cmdUnderTest: The tc command being tested itself.
38 expExitCode:  The code returned by the command under test upon its termination.
39               tdc will compare this value against the actual returned value.
40 verifyCmd:    The tc command to be run to verify successful execution.
41               For example: if the command under test creates a gact action,
42               verifyCmd should be "$TC actions show action gact"
43 matchPattern: A regular expression to be applied against the output of the
44               verifyCmd to prove the command under test succeeded. This pattern
45               should be as specific as possible so that a false positive is not
46               matched.
47 matchCount:   How many times the regex in matchPattern should match. A value
48               of 0 is acceptable.
49 teardown:     The list of commands to clean up after the test is completed.
50               The environment should be returned to the same state as when
51               this test was started: qdiscs deleted, actions flushed, etc.
52
53
54 SETUP/TEARDOWN ERRORS
55 ---------------------
56
57 If an error is detected during the setup/teardown process, execution of the
58 tests will immediately stop with an error message and the namespace in which
59 the tests are run will be destroyed. This is to prevent inaccurate results
60 in the test cases.
61
62 Repeated failures of the setup/teardown may indicate a problem with the test
63 case, or possibly even a bug in one of the commands that are not being tested.
64
65 It's possible to include acceptable exit codes with the setup/teardown command
66 so that it doesn't halt the script for an error that doesn't matter. Turn the
67 individual command into a list, with the command being first, followed by all
68 acceptable exit codes for the command.
69