AddingTestCases.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. category: A list of single-word descriptions covering what the command
  27. under test is testing. Example: filter, actions, u32, gact, etc.
  28. setup: The list of commands required to ensure the command under test
  29. succeeds. For example: if testing a filter, the command to create
  30. the qdisc would appear here.
  31. This list can be empty.
  32. Each command can be a string to be executed, or a list consisting
  33. of a string which is a command to be executed, followed by 1 or
  34. more acceptable exit codes for this command.
  35. If only a string is given for the command, then an exit code of 0
  36. will be expected.
  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. This list can be empty.
  53. Each command can be a string to be executed, or a list consisting
  54. of a string which is a command to be executed, followed by 1 or
  55. more acceptable exit codes for this command.
  56. If only a string is given for the command, then an exit code of 0
  57. will be expected.
  58. SETUP/TEARDOWN ERRORS
  59. ---------------------
  60. If an error is detected during the setup/teardown process, execution of the
  61. tests will immediately stop with an error message and the namespace in which
  62. the tests are run will be destroyed. This is to prevent inaccurate results
  63. in the test cases. tdc will output a series of TAP results for the skipped
  64. tests.
  65. Repeated failures of the setup/teardown may indicate a problem with the test
  66. case, or possibly even a bug in one of the commands that are not being tested.
  67. It's possible to include acceptable exit codes with the setup/teardown command
  68. so that it doesn't halt the script for an error that doesn't matter. Turn the
  69. individual command into a list, with the command being first, followed by all
  70. acceptable exit codes for the command.
  71. Example:
  72. A pair of setup commands. The first can have exit code 0, 1 or 255, the
  73. second must have exit code 0.
  74. "setup": [
  75. [
  76. "$TC actions flush action gact",
  77. 0,
  78. 1,
  79. 255
  80. ],
  81. "$TC actions add action reclassify index 65536"
  82. ],