1*4882a593Smuzhiyuntdc - Adding test cases for tdc 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunAuthor: Lucas Bates - lucasb@mojatatu.com 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunADDING TEST CASES 6*4882a593Smuzhiyun----------------- 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunUser-defined tests should be added by defining a separate JSON file. This 9*4882a593Smuzhiyunwill help prevent conflicts when updating the repository. Refer to 10*4882a593Smuzhiyuntemplate.json for the required JSON format for test cases. 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunInclude the 'id' field, but do not assign a value. Running tdc with the -i 13*4882a593Smuzhiyunoption will generate a unique ID for that test case. 14*4882a593Smuzhiyun 15*4882a593Smuzhiyuntdc will recursively search the 'tc-tests' subdirectory (or the 16*4882a593Smuzhiyundirectories named with the -D option) for .json files. Any test case 17*4882a593Smuzhiyunfiles you create in these directories will automatically be included. 18*4882a593SmuzhiyunIf you wish to store your custom test cases elsewhere, be sure to run 19*4882a593Smuzhiyuntdc with the -f argument and the path to your file, or the -D argument 20*4882a593Smuzhiyunand the path to your directory(ies). 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunBe aware of required escape characters in the JSON data - particularly 23*4882a593Smuzhiyunwhen defining the match pattern. Refer to the supplied json test files 24*4882a593Smuzhiyunfor examples when in doubt. The match pattern is written in json, and 25*4882a593Smuzhiyunwill be used by python. So the match pattern will be a python regular 26*4882a593Smuzhiyunexpression, but should be written using json syntax. 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun 29*4882a593SmuzhiyunTEST CASE STRUCTURE 30*4882a593Smuzhiyun------------------- 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunEach test case has required data: 33*4882a593Smuzhiyun 34*4882a593Smuzhiyunid: A unique alphanumeric value to identify a particular test case 35*4882a593Smuzhiyunname: Descriptive name that explains the command under test 36*4882a593Smuzhiyunskip: A completely optional key, if the corresponding value is "yes" 37*4882a593Smuzhiyun then tdc will not execute the test case in question. However, 38*4882a593Smuzhiyun this test case will still appear in the results output but 39*4882a593Smuzhiyun marked as skipped. This key can be placed anywhere inside the 40*4882a593Smuzhiyun test case at the top level. 41*4882a593Smuzhiyuncategory: A list of single-word descriptions covering what the command 42*4882a593Smuzhiyun under test is testing. Example: filter, actions, u32, gact, etc. 43*4882a593Smuzhiyunsetup: The list of commands required to ensure the command under test 44*4882a593Smuzhiyun succeeds. For example: if testing a filter, the command to create 45*4882a593Smuzhiyun the qdisc would appear here. 46*4882a593Smuzhiyun This list can be empty. 47*4882a593Smuzhiyun Each command can be a string to be executed, or a list consisting 48*4882a593Smuzhiyun of a string which is a command to be executed, followed by 1 or 49*4882a593Smuzhiyun more acceptable exit codes for this command. 50*4882a593Smuzhiyun If only a string is given for the command, then an exit code of 0 51*4882a593Smuzhiyun will be expected. 52*4882a593SmuzhiyuncmdUnderTest: The tc command being tested itself. 53*4882a593SmuzhiyunexpExitCode: The code returned by the command under test upon its termination. 54*4882a593Smuzhiyun tdc will compare this value against the actual returned value. 55*4882a593SmuzhiyunverifyCmd: The tc command to be run to verify successful execution. 56*4882a593Smuzhiyun For example: if the command under test creates a gact action, 57*4882a593Smuzhiyun verifyCmd should be "$TC actions show action gact" 58*4882a593SmuzhiyunmatchPattern: A regular expression to be applied against the output of the 59*4882a593Smuzhiyun verifyCmd to prove the command under test succeeded. This pattern 60*4882a593Smuzhiyun should be as specific as possible so that a false positive is not 61*4882a593Smuzhiyun matched. 62*4882a593SmuzhiyunmatchCount: How many times the regex in matchPattern should match. A value 63*4882a593Smuzhiyun of 0 is acceptable. 64*4882a593Smuzhiyunteardown: The list of commands to clean up after the test is completed. 65*4882a593Smuzhiyun The environment should be returned to the same state as when 66*4882a593Smuzhiyun this test was started: qdiscs deleted, actions flushed, etc. 67*4882a593Smuzhiyun This list can be empty. 68*4882a593Smuzhiyun Each command can be a string to be executed, or a list consisting 69*4882a593Smuzhiyun of a string which is a command to be executed, followed by 1 or 70*4882a593Smuzhiyun more acceptable exit codes for this command. 71*4882a593Smuzhiyun If only a string is given for the command, then an exit code of 0 72*4882a593Smuzhiyun will be expected. 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunSETUP/TEARDOWN ERRORS 76*4882a593Smuzhiyun--------------------- 77*4882a593Smuzhiyun 78*4882a593SmuzhiyunIf an error is detected during the setup/teardown process, execution of the 79*4882a593Smuzhiyuntests will immediately stop with an error message and the namespace in which 80*4882a593Smuzhiyunthe tests are run will be destroyed. This is to prevent inaccurate results 81*4882a593Smuzhiyunin the test cases. tdc will output a series of TAP results for the skipped 82*4882a593Smuzhiyuntests. 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunRepeated failures of the setup/teardown may indicate a problem with the test 85*4882a593Smuzhiyuncase, or possibly even a bug in one of the commands that are not being tested. 86*4882a593Smuzhiyun 87*4882a593SmuzhiyunIt's possible to include acceptable exit codes with the setup/teardown command 88*4882a593Smuzhiyunso that it doesn't halt the script for an error that doesn't matter. Turn the 89*4882a593Smuzhiyunindividual command into a list, with the command being first, followed by all 90*4882a593Smuzhiyunacceptable exit codes for the command. 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunExample: 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunA pair of setup commands. The first can have exit code 0, 1 or 255, the 95*4882a593Smuzhiyunsecond must have exit code 0. 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun "setup": [ 98*4882a593Smuzhiyun [ 99*4882a593Smuzhiyun "$TC actions flush action gact", 100*4882a593Smuzhiyun 0, 101*4882a593Smuzhiyun 1, 102*4882a593Smuzhiyun 255 103*4882a593Smuzhiyun ], 104*4882a593Smuzhiyun "$TC actions add action reclassify index 65536" 105*4882a593Smuzhiyun ], 106