index.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. .. TinyTestFW documentation master file, created by
  2. sphinx-quickstart on Thu Sep 21 20:19:12 2017.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. Welcome to TinyTestFW's documentation!
  6. ======================================
  7. We have a lot of test which depends on interact with DUT via communication port.
  8. Usually we send command to the port and then check response to see if the test succeed.
  9. TinyTestFW is designed for such scenarios.
  10. It supports ESP-IDF applications and is able for other applications by writing new bundles.
  11. Test FW features
  12. ----------------
  13. 1. Test Environment:
  14. 1. DUT: DUT provides methods to interact with DUT
  15. * read/write through port
  16. * expect method which supports expect one or multiple string or RegEx
  17. * tool methods provided by the tool bundle, like ``start_app``, ``reset``
  18. 2. App:
  19. * provide some specific features to the test application of DUT, for example:
  20. * SDK path
  21. * SDK tools
  22. * application information like partition table, download configs
  23. 3. Environment Configs:
  24. * support get env configs from config file or auto-detect from current PC
  25. * provide ``get_variable`` method to get variables
  26. 2. allow to customize components (DUT, App) to support different devices
  27. 3. Integrate to CI:
  28. * provide interfaces for Gitlab-CI
  29. * provide ``search case`` and ``runner`` interfaces, able to integrate with other CI
  30. Example
  31. -------
  32. Let's first check a simple simple::
  33. import re
  34. import os
  35. import sys
  36. test_fw_path = os.getenv("TEST_FW_PATH")
  37. if test_fw_path:
  38. sys.path.insert(0, test_fw_path)
  39. import TinyFW
  40. from IDF import IDFApp, IDFDUT
  41. @TinyFW.test_method(app=IDFApp.Example, dut=IDFDUT.IDFDUT, env_tag="Example_WIFI",
  42. chip="ESP32", module="examples", execution_time=1)
  43. def test_examples_protocol_https_request(env, extra_data):
  44. """
  45. steps: |
  46. 1. join AP
  47. 2. connect to www.howsmyssl.com:443
  48. 3. send http request
  49. """
  50. dut1 = env.get_dut("https_request", "examples/protocols/https_request")
  51. dut1.start_app()
  52. dut1.expect("Connecting to www.howsmyssl.com:443", timeout=30)
  53. dut1.expect("Performing the SSL/TLS handshake")
  54. dut1.expect("Certificate verified.", timeout=15)
  55. dut1.expect_all(re.compile(r"Cipher suite is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256"),
  56. "Reading HTTP response",
  57. timeout=20)
  58. dut1.expect(re.compile(r"Completed (\d) requests"))
  59. if __name__ == '__main__':
  60. TinyFW.set_default_config(config_file="EnvConfigTemplate.yml")
  61. test_examples_protocol_https_request()
  62. SOP for adding test cases
  63. -------------------------
  64. 1. import test framework:
  65. ^^^^^^^^^^^^^^^^^^^^^^^^^
  66. * we assume ``TEST_FW_PATH`` is pre-defined before running the tests
  67. * Then we can import python packages and files from ``TEST_FW_PATH``
  68. 2. define test case:
  69. ^^^^^^^^^^^^^^^^^^^^
  70. 1. define test case ``test_xxx(env, extra_data)``
  71. * env: instance of test env, see :doc:`Test Env <Env>` for details
  72. * extra_data: extra data passed from test case caller
  73. 2. add decorator for test case
  74. * add decorator ``TinyFW.test_method`` to test method
  75. * define default case configs and filters in decorator, see :doc:`TinyFW.test_method <TinyFW>`
  76. 3. execute test cases:
  77. ^^^^^^^^^^^^^^^^^^^^^^
  78. * define in ``main`` section and execute from this file
  79. 1. set preset configs(optional). If the config is not define in case decorator, it will use the preset configs.
  80. 2. call test case method:
  81. * if you don't pass any arguments, it will use default values
  82. * you can pass ``extra_data`` to test case by adding ``extra_data=some_data`` as kwarg of test case method.
  83. default value for extra_data is None.
  84. * you can overwrite test case config by adding them as kwarg of test case method.
  85. It will overwrite preset configs and case default configs.
  86. Examples::
  87. test_examples_protocol_https_request(extra_data=["data1", "data2"], dut=SomeOtherDUT, env_tag="OtherEnv")
  88. * or, use ``runner`` to execute. see :doc:`runner <Runner>` for details
  89. .. toctree::
  90. :maxdepth: 2
  91. :caption: Contents:
  92. modules
  93. Dependency
  94. ==========
  95. Support for both Python2 and Python3 (tested on python 2.7.13 and 3.6.2).
  96. The following 3rd party lib is required:
  97. * pyserial
  98. * pyyaml
  99. * xunitgen
  100. To build document, we need to install ``Sphinx`` and ``sphinx-rtd-theme`` (you may replace this with your own theme).
  101. Indices and tables
  102. ==================
  103. * :ref:`genindex`
  104. * :ref:`modindex`
  105. * :ref:`search`