index.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 can be adapted to other applications by writing new bundles.
  11. Example
  12. -------
  13. Let's first check a simple example::
  14. import re
  15. import os
  16. import sys
  17. test_fw_path = os.getenv("TEST_FW_PATH")
  18. if test_fw_path:
  19. sys.path.insert(0, test_fw_path)
  20. import TinyFW
  21. from IDF import IDFApp, IDFDUT
  22. @TinyFW.test_method(app=IDFApp.Example, dut=IDFDUT.IDFDUT, env_tag="Example_WIFI",
  23. chip="ESP32", module="examples", execution_time=1)
  24. def test_examples_protocol_https_request(env, extra_data):
  25. """
  26. steps: |
  27. 1. join AP
  28. 2. connect to www.howsmyssl.com:443
  29. 3. send http request
  30. """
  31. dut1 = env.get_dut("https_request", "examples/protocols/https_request")
  32. dut1.start_app()
  33. dut1.expect("Connecting to www.howsmyssl.com:443", timeout=30)
  34. dut1.expect("Performing the SSL/TLS handshake")
  35. dut1.expect("Certificate verified.", timeout=15)
  36. dut1.expect_all(re.compile(r"Cipher suite is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256"),
  37. "Reading HTTP response",
  38. timeout=20)
  39. dut1.expect(re.compile(r"Completed (\d) requests"))
  40. if __name__ == '__main__':
  41. TinyFW.set_default_config(env_config_file="EnvConfigTemplate.yml")
  42. test_examples_protocol_https_request()
  43. SOP for adding test cases
  44. -------------------------
  45. 1. Import test framework:
  46. ^^^^^^^^^^^^^^^^^^^^^^^^^
  47. * We assume ``TEST_FW_PATH`` is pre-defined before running the tests
  48. * Then we can import python packages and files from ``TEST_FW_PATH``
  49. 2. Define test case:
  50. ^^^^^^^^^^^^^^^^^^^^
  51. 1. Define test case ``test_xxx(env, extra_data)``
  52. * env: instance of test env, see :doc:`Test Env <Env>` for details
  53. * extra_data: extra data passed from test case caller
  54. 2. Add decorator for test case
  55. * add decorator ``TinyFW.test_method`` to test method
  56. * define default case configs and filters in decorator, see :doc:`TinyFW.test_method <TinyFW>`
  57. 3. Execute test cases:
  58. ^^^^^^^^^^^^^^^^^^^^^^
  59. * define in ``main`` section and execute from this file
  60. 1. set preset configs(optional). If the config is not define in case decorator, it will use the preset configs.
  61. 2. call test case method:
  62. * if you don't pass any arguments, it will use default values
  63. * you can pass ``extra_data`` to test case by adding ``extra_data=some_data`` as kwarg of test case method.
  64. default value for extra_data is None.
  65. * you can overwrite test case config by adding them as kwarg of test case method.
  66. It will overwrite preset configs and case default configs.
  67. Examples::
  68. test_examples_protocol_https_request(extra_data=["data1", "data2"], dut=SomeOtherDUT, env_tag="OtherEnv")
  69. * or, use ``runner`` to execute. see :doc:`runner <Runner>` for details
  70. Test FW features
  71. ----------------
  72. 1. Test Environment:
  73. 1. DUT: DUT class provides methods to interact with DUT
  74. * read/write through port
  75. * expect method which supports expect one or multiple string or RegEx
  76. * tool methods provided by the tool bundle, like ``start_app``, ``reset``
  77. 2. App:
  78. * provide some specific features to the test application of DUT, for example:
  79. * SDK path
  80. * SDK tools
  81. * application information like partition table, download configs
  82. 3. Environment Configs:
  83. * support get env configs from config file or auto-detect from current PC
  84. * provide ``get_variable`` method to get variables
  85. 2. Allow to customize components (DUT, App) to support different devices
  86. 3. Integrate to CI:
  87. * provide interfaces for Gitlab-CI
  88. * provide ``search case`` and ``runner`` interfaces, able to integrate with other CI
  89. Class Diagram
  90. =============
  91. .. uml::
  92. class BaseDUT {
  93. {field} app
  94. {method} expect
  95. {method} expect_any
  96. {method} expect_all
  97. {method} read
  98. {method} write
  99. {method} start_receive
  100. {method} stop_receive
  101. {method} close
  102. }
  103. class SerialDUT {
  104. {method} _port_read
  105. {method} _port_write
  106. {method} _port_open
  107. {method} _port_close
  108. }
  109. class IDFDUT {
  110. {method} reset
  111. {method} start_app
  112. }
  113. class BaseApp {
  114. {method} get_sdk_path
  115. {method} get_log_folder
  116. }
  117. class IDFApp {
  118. {field} flash_files
  119. {field} flash_settings
  120. {field} partition_table
  121. }
  122. class Example {
  123. {method} get_binary_path
  124. }
  125. class EnvConfig {
  126. {method} get_variable
  127. }
  128. class Env {
  129. {field} config
  130. {field} allocated_duts
  131. {field} app_cls
  132. {method} get_dut
  133. {method} close_dut
  134. {method} get_variable
  135. {method} get_pc_nic_info
  136. {method} close
  137. }
  138. SerialDUT --|> BaseDUT
  139. IDFDUT --|> SerialDUT
  140. IDFApp --|> BaseApp
  141. Example --|> IDFApp
  142. Env *-- EnvConfig
  143. Env *-- BaseDUT
  144. Env o-- BaseApp
  145. BaseDUT o-- BaseApp
  146. .. toctree::
  147. :maxdepth: 2
  148. :caption: Contents:
  149. modules
  150. Dependencies
  151. ============
  152. Support for both Python2 and Python3 (tested on python 2.7.13 and 3.6.2).
  153. The following 3rd party lib is required:
  154. * pyserial
  155. * pyyaml
  156. * junit_xml
  157. * netifaces
  158. * matplotlib (if use Utility.LineChart)
  159. These libraries can be installed by running ``pip install --user -r requirements.txt`` in tiny-test-fw directory.
  160. To build document, we need to install ``Sphinx``, ``plantweb`` and ``sphinx-rtd-theme`` (you may replace this with your own theme). ``plantweb`` requires internet access during building document.
  161. Indices and tables
  162. ==================
  163. * :ref:`genindex`
  164. * :ref:`modindex`
  165. * :ref:`search`