18c2ecf20Sopenharmony_citdc - Adding test cases for tdc
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciAuthor: Lucas Bates - lucasb@mojatatu.com
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciADDING TEST CASES
68c2ecf20Sopenharmony_ci-----------------
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciUser-defined tests should be added by defining a separate JSON file.  This
98c2ecf20Sopenharmony_ciwill help prevent conflicts when updating the repository. Refer to
108c2ecf20Sopenharmony_citemplate.json for the required JSON format for test cases.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciInclude the 'id' field, but do not assign a value. Running tdc with the -i
138c2ecf20Sopenharmony_cioption will generate a unique ID for that test case.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_citdc will recursively search the 'tc-tests' subdirectory (or the
168c2ecf20Sopenharmony_cidirectories named with the -D option) for .json files.  Any test case
178c2ecf20Sopenharmony_cifiles you create in these directories will automatically be included.
188c2ecf20Sopenharmony_ciIf you wish to store your custom test cases elsewhere, be sure to run
198c2ecf20Sopenharmony_citdc with the -f argument and the path to your file, or the -D argument
208c2ecf20Sopenharmony_ciand the path to your directory(ies).
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciBe aware of required escape characters in the JSON data - particularly
238c2ecf20Sopenharmony_ciwhen defining the match pattern. Refer to the supplied json test files
248c2ecf20Sopenharmony_cifor examples when in doubt.  The match pattern is written in json, and
258c2ecf20Sopenharmony_ciwill be used by python.  So the match pattern will be a python regular
268c2ecf20Sopenharmony_ciexpression, but should be written using json syntax.
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciTEST CASE STRUCTURE
308c2ecf20Sopenharmony_ci-------------------
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciEach test case has required data:
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciid:           A unique alphanumeric value to identify a particular test case
358c2ecf20Sopenharmony_ciname:         Descriptive name that explains the command under test
368c2ecf20Sopenharmony_ciskip:         A completely optional key, if the corresponding value is "yes"
378c2ecf20Sopenharmony_ci              then tdc will not execute the test case in question. However,
388c2ecf20Sopenharmony_ci              this test case will still appear in the results output but
398c2ecf20Sopenharmony_ci              marked as skipped. This key can be placed anywhere inside the
408c2ecf20Sopenharmony_ci              test case at the top level.
418c2ecf20Sopenharmony_cicategory:     A list of single-word descriptions covering what the command
428c2ecf20Sopenharmony_ci              under test is testing. Example: filter, actions, u32, gact, etc.
438c2ecf20Sopenharmony_cisetup:        The list of commands required to ensure the command under test
448c2ecf20Sopenharmony_ci              succeeds. For example: if testing a filter, the command to create
458c2ecf20Sopenharmony_ci              the qdisc would appear here.
468c2ecf20Sopenharmony_ci	      This list can be empty.
478c2ecf20Sopenharmony_ci	      Each command can be a string to be executed, or a list consisting
488c2ecf20Sopenharmony_ci	      of a string which is a command to be executed, followed by 1 or
498c2ecf20Sopenharmony_ci	      more acceptable exit codes for this command.
508c2ecf20Sopenharmony_ci	      If only a string is given for the command, then an exit code of 0
518c2ecf20Sopenharmony_ci	      will be expected.
528c2ecf20Sopenharmony_cicmdUnderTest: The tc command being tested itself.
538c2ecf20Sopenharmony_ciexpExitCode:  The code returned by the command under test upon its termination.
548c2ecf20Sopenharmony_ci              tdc will compare this value against the actual returned value.
558c2ecf20Sopenharmony_civerifyCmd:    The tc command to be run to verify successful execution.
568c2ecf20Sopenharmony_ci              For example: if the command under test creates a gact action,
578c2ecf20Sopenharmony_ci              verifyCmd should be "$TC actions show action gact"
588c2ecf20Sopenharmony_cimatchPattern: A regular expression to be applied against the output of the
598c2ecf20Sopenharmony_ci              verifyCmd to prove the command under test succeeded. This pattern
608c2ecf20Sopenharmony_ci              should be as specific as possible so that a false positive is not
618c2ecf20Sopenharmony_ci              matched.
628c2ecf20Sopenharmony_cimatchCount:   How many times the regex in matchPattern should match. A value
638c2ecf20Sopenharmony_ci              of 0 is acceptable.
648c2ecf20Sopenharmony_citeardown:     The list of commands to clean up after the test is completed.
658c2ecf20Sopenharmony_ci              The environment should be returned to the same state as when
668c2ecf20Sopenharmony_ci              this test was started: qdiscs deleted, actions flushed, etc.
678c2ecf20Sopenharmony_ci	      This list can be empty.
688c2ecf20Sopenharmony_ci	      Each command can be a string to be executed, or a list consisting
698c2ecf20Sopenharmony_ci	      of a string which is a command to be executed, followed by 1 or
708c2ecf20Sopenharmony_ci	      more acceptable exit codes for this command.
718c2ecf20Sopenharmony_ci	      If only a string is given for the command, then an exit code of 0
728c2ecf20Sopenharmony_ci	      will be expected.
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciSETUP/TEARDOWN ERRORS
768c2ecf20Sopenharmony_ci---------------------
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciIf an error is detected during the setup/teardown process, execution of the
798c2ecf20Sopenharmony_citests will immediately stop with an error message and the namespace in which
808c2ecf20Sopenharmony_cithe tests are run will be destroyed. This is to prevent inaccurate results
818c2ecf20Sopenharmony_ciin the test cases.  tdc will output a series of TAP results for the skipped
828c2ecf20Sopenharmony_citests.
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciRepeated failures of the setup/teardown may indicate a problem with the test
858c2ecf20Sopenharmony_cicase, or possibly even a bug in one of the commands that are not being tested.
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciIt's possible to include acceptable exit codes with the setup/teardown command
888c2ecf20Sopenharmony_ciso that it doesn't halt the script for an error that doesn't matter. Turn the
898c2ecf20Sopenharmony_ciindividual command into a list, with the command being first, followed by all
908c2ecf20Sopenharmony_ciacceptable exit codes for the command.
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ciExample:
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciA pair of setup commands.  The first can have exit code 0, 1 or 255, the
958c2ecf20Sopenharmony_cisecond must have exit code 0.
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci        "setup": [
988c2ecf20Sopenharmony_ci            [
998c2ecf20Sopenharmony_ci                "$TC actions flush action gact",
1008c2ecf20Sopenharmony_ci                0,
1018c2ecf20Sopenharmony_ci                1,
1028c2ecf20Sopenharmony_ci                255
1038c2ecf20Sopenharmony_ci            ],
1048c2ecf20Sopenharmony_ci            "$TC actions add action reclassify index 65536"
1058c2ecf20Sopenharmony_ci        ],
106