AddingTestCases.txt 4.9 KB

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