162306a36Sopenharmony_citdc - Adding test cases for tdc
262306a36Sopenharmony_ci
362306a36Sopenharmony_ciAuthor: Lucas Bates - lucasb@mojatatu.com
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciADDING TEST CASES
662306a36Sopenharmony_ci-----------------
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciUser-defined tests should be added by defining a separate JSON file.  This
962306a36Sopenharmony_ciwill help prevent conflicts when updating the repository. Refer to
1062306a36Sopenharmony_citemplate.json for the required JSON format for test cases.
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciInclude the 'id' field, but do not assign a value. Running tdc with the -i
1362306a36Sopenharmony_cioption will generate a unique ID for that test case.
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_citdc will recursively search the 'tc-tests' subdirectory (or the
1662306a36Sopenharmony_cidirectories named with the -D option) for .json files.  Any test case
1762306a36Sopenharmony_cifiles you create in these directories will automatically be included.
1862306a36Sopenharmony_ciIf you wish to store your custom test cases elsewhere, be sure to run
1962306a36Sopenharmony_citdc with the -f argument and the path to your file, or the -D argument
2062306a36Sopenharmony_ciand the path to your directory(ies).
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciBe aware of required escape characters in the JSON data - particularly
2362306a36Sopenharmony_ciwhen defining the match pattern. Refer to the supplied json test files
2462306a36Sopenharmony_cifor examples when in doubt.  The match pattern is written in json, and
2562306a36Sopenharmony_ciwill be used by python.  So the match pattern will be a python regular
2662306a36Sopenharmony_ciexpression, but should be written using json syntax.
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciTEST CASE STRUCTURE
3062306a36Sopenharmony_ci-------------------
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ciEach test case has required data:
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ciid:           A unique alphanumeric value to identify a particular test case
3562306a36Sopenharmony_ciname:         Descriptive name that explains the command under test
3662306a36Sopenharmony_ciskip:         A completely optional key, if the corresponding value is "yes"
3762306a36Sopenharmony_ci              then tdc will not execute the test case in question. However,
3862306a36Sopenharmony_ci              this test case will still appear in the results output but
3962306a36Sopenharmony_ci              marked as skipped. This key can be placed anywhere inside the
4062306a36Sopenharmony_ci              test case at the top level.
4162306a36Sopenharmony_cidependsOn:    Same as 'skip', but the value is executed as a command. The test
4262306a36Sopenharmony_ci              is skipped when the command returns non-zero.
4362306a36Sopenharmony_cicategory:     A list of single-word descriptions covering what the command
4462306a36Sopenharmony_ci              under test is testing. Example: filter, actions, u32, gact, etc.
4562306a36Sopenharmony_cisetup:        The list of commands required to ensure the command under test
4662306a36Sopenharmony_ci              succeeds. For example: if testing a filter, the command to create
4762306a36Sopenharmony_ci              the qdisc would appear here.
4862306a36Sopenharmony_ci	      This list can be empty.
4962306a36Sopenharmony_ci	      Each command can be a string to be executed, or a list consisting
5062306a36Sopenharmony_ci	      of a string which is a command to be executed, followed by 1 or
5162306a36Sopenharmony_ci	      more acceptable exit codes for this command.
5262306a36Sopenharmony_ci	      If only a string is given for the command, then an exit code of 0
5362306a36Sopenharmony_ci	      will be expected.
5462306a36Sopenharmony_cicmdUnderTest: The tc command being tested itself.
5562306a36Sopenharmony_ciexpExitCode:  The code returned by the command under test upon its termination.
5662306a36Sopenharmony_ci              tdc will compare this value against the actual returned value.
5762306a36Sopenharmony_civerifyCmd:    The tc command to be run to verify successful execution.
5862306a36Sopenharmony_ci              For example: if the command under test creates a gact action,
5962306a36Sopenharmony_ci              verifyCmd should be "$TC actions show action gact"
6062306a36Sopenharmony_cimatchPattern: A regular expression to be applied against the output of the
6162306a36Sopenharmony_ci              verifyCmd to prove the command under test succeeded. This pattern
6262306a36Sopenharmony_ci              should be as specific as possible so that a false positive is not
6362306a36Sopenharmony_ci              matched.
6462306a36Sopenharmony_cimatchCount:   How many times the regex in matchPattern should match. A value
6562306a36Sopenharmony_ci              of 0 is acceptable.
6662306a36Sopenharmony_citeardown:     The list of commands to clean up after the test is completed.
6762306a36Sopenharmony_ci              The environment should be returned to the same state as when
6862306a36Sopenharmony_ci              this test was started: qdiscs deleted, actions flushed, etc.
6962306a36Sopenharmony_ci	      This list can be empty.
7062306a36Sopenharmony_ci	      Each command can be a string to be executed, or a list consisting
7162306a36Sopenharmony_ci	      of a string which is a command to be executed, followed by 1 or
7262306a36Sopenharmony_ci	      more acceptable exit codes for this command.
7362306a36Sopenharmony_ci	      If only a string is given for the command, then an exit code of 0
7462306a36Sopenharmony_ci	      will be expected.
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ciSETUP/TEARDOWN ERRORS
7862306a36Sopenharmony_ci---------------------
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciIf an error is detected during the setup/teardown process, execution of the
8162306a36Sopenharmony_citests will immediately stop with an error message and the namespace in which
8262306a36Sopenharmony_cithe tests are run will be destroyed. This is to prevent inaccurate results
8362306a36Sopenharmony_ciin the test cases.  tdc will output a series of TAP results for the skipped
8462306a36Sopenharmony_citests.
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ciRepeated failures of the setup/teardown may indicate a problem with the test
8762306a36Sopenharmony_cicase, or possibly even a bug in one of the commands that are not being tested.
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciIt's possible to include acceptable exit codes with the setup/teardown command
9062306a36Sopenharmony_ciso that it doesn't halt the script for an error that doesn't matter. Turn the
9162306a36Sopenharmony_ciindividual command into a list, with the command being first, followed by all
9262306a36Sopenharmony_ciacceptable exit codes for the command.
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ciExample:
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ciA pair of setup commands.  The first can have exit code 0, 1 or 255, the
9762306a36Sopenharmony_cisecond must have exit code 0.
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci        "setup": [
10062306a36Sopenharmony_ci            [
10162306a36Sopenharmony_ci                "$TC actions flush action gact",
10262306a36Sopenharmony_ci                0,
10362306a36Sopenharmony_ci                1,
10462306a36Sopenharmony_ci                255
10562306a36Sopenharmony_ci            ],
10662306a36Sopenharmony_ci            "$TC actions add action reclassify index 65536"
10762306a36Sopenharmony_ci        ],
108