http_server_advanced_test.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from __future__ import division
  17. from __future__ import print_function
  18. from __future__ import unicode_literals
  19. import re
  20. import os
  21. import sys
  22. try:
  23. import IDF
  24. from IDF.IDFDUT import ESP32DUT
  25. except ImportError:
  26. # This environment variable is expected on the host machine
  27. test_fw_path = os.getenv("TEST_FW_PATH")
  28. if test_fw_path and test_fw_path not in sys.path:
  29. sys.path.insert(0, test_fw_path)
  30. import IDF
  31. import Utility
  32. # When running on local machine execute the following before running this script
  33. # > make app bootloader
  34. # > make print_flash_cmd | tail -n 1 > build/download.config
  35. # > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
  36. # Import client module
  37. expath = os.path.dirname(os.path.realpath(__file__))
  38. client = Utility.load_source("client", expath + "/scripts/test.py")
  39. # Due to connectivity issues (between runner host and DUT) in the runner environment,
  40. # some of the `advanced_tests` are ignored. These tests are intended for verifying
  41. # the expected limits of the http_server capabilities, and implement sending and receiving
  42. # of large HTTP packets and malformed requests, running multiple parallel sessions, etc.
  43. # It is advised that all these tests be run locally, when making changes or adding new
  44. # features to this component.
  45. @IDF.idf_example_test(env_tag="Example_WIFI")
  46. def test_examples_protocol_http_server_advanced(env, extra_data):
  47. # Acquire DUT
  48. dut1 = env.get_dut("http_server", "examples/protocols/http_server/advanced_tests", dut_class=ESP32DUT)
  49. # Get binary file
  50. binary_file = os.path.join(dut1.app.binary_path, "tests.bin")
  51. bin_size = os.path.getsize(binary_file)
  52. IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size // 1024))
  53. IDF.check_performance("http_server_bin_size", bin_size // 1024)
  54. # Upload binary and start testing
  55. Utility.console_log("Starting http_server advanced test app")
  56. dut1.start_app()
  57. # Parse IP address of STA
  58. Utility.console_log("Waiting to connect with AP")
  59. got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
  60. got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Started HTTP server on port: '(\d+)'"), timeout=15)[0]
  61. result = dut1.expect(re.compile(r"(?:[\s\S]*)Max URI handlers: '(\d+)'(?:[\s\S]*)Max Open Sessions: " # noqa: W605
  62. r"'(\d+)'(?:[\s\S]*)Max Header Length: '(\d+)'(?:[\s\S]*)Max URI Length: "
  63. r"'(\d+)'(?:[\s\S]*)Max Stack Size: '(\d+)'"), timeout=15)
  64. # max_uri_handlers = int(result[0])
  65. max_sessions = int(result[1])
  66. max_hdr_len = int(result[2])
  67. max_uri_len = int(result[3])
  68. max_stack_size = int(result[4])
  69. Utility.console_log("Got IP : " + got_ip)
  70. Utility.console_log("Got Port : " + got_port)
  71. # Run test script
  72. # If failed raise appropriate exception
  73. failed = False
  74. Utility.console_log("Sessions and Context Tests...")
  75. if not client.spillover_session(got_ip, got_port, max_sessions):
  76. Utility.console_log("Ignoring failure")
  77. if not client.parallel_sessions_adder(got_ip, got_port, max_sessions):
  78. Utility.console_log("Ignoring failure")
  79. if not client.leftover_data_test(got_ip, got_port):
  80. failed = True
  81. if not client.async_response_test(got_ip, got_port):
  82. failed = True
  83. if not client.recv_timeout_test(got_ip, got_port):
  84. failed = True
  85. if not client.arbitrary_termination_test(got_ip, got_port):
  86. failed = True
  87. # This test fails a lot! Enable when connection is stable
  88. # test_size = 50*1024 # 50KB
  89. # if not client.packet_size_limit_test(got_ip, got_port, test_size):
  90. # Utility.console_log("Ignoring failure")
  91. Utility.console_log("Getting initial stack usage...")
  92. if not client.get_hello(got_ip, got_port):
  93. failed = True
  94. inital_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
  95. if inital_stack < 0.1 * max_stack_size:
  96. Utility.console_log("More than 90% of stack being used on server start")
  97. failed = True
  98. Utility.console_log("Basic HTTP Client Tests...")
  99. if not client.get_hello(got_ip, got_port):
  100. failed = True
  101. if not client.post_hello(got_ip, got_port):
  102. failed = True
  103. if not client.put_hello(got_ip, got_port):
  104. failed = True
  105. if not client.post_echo(got_ip, got_port):
  106. failed = True
  107. if not client.get_echo(got_ip, got_port):
  108. failed = True
  109. if not client.put_echo(got_ip, got_port):
  110. failed = True
  111. if not client.get_hello_type(got_ip, got_port):
  112. failed = True
  113. if not client.get_hello_status(got_ip, got_port):
  114. failed = True
  115. if not client.get_false_uri(got_ip, got_port):
  116. failed = True
  117. if not client.get_test_headers(got_ip, got_port):
  118. failed = True
  119. Utility.console_log("Error code tests...")
  120. if not client.code_500_server_error_test(got_ip, got_port):
  121. failed = True
  122. if not client.code_501_method_not_impl(got_ip, got_port):
  123. failed = True
  124. if not client.code_505_version_not_supported(got_ip, got_port):
  125. failed = True
  126. if not client.code_400_bad_request(got_ip, got_port):
  127. failed = True
  128. if not client.code_404_not_found(got_ip, got_port):
  129. failed = True
  130. if not client.code_405_method_not_allowed(got_ip, got_port):
  131. failed = True
  132. if not client.code_408_req_timeout(got_ip, got_port):
  133. failed = True
  134. if not client.code_414_uri_too_long(got_ip, got_port, max_uri_len):
  135. Utility.console_log("Ignoring failure")
  136. if not client.code_431_hdr_too_long(got_ip, got_port, max_hdr_len):
  137. Utility.console_log("Ignoring failure")
  138. if not client.test_upgrade_not_supported(got_ip, got_port):
  139. failed = True
  140. Utility.console_log("Getting final stack usage...")
  141. if not client.get_hello(got_ip, got_port):
  142. failed = True
  143. final_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
  144. if final_stack < 0.05 * max_stack_size:
  145. Utility.console_log("More than 95% of stack got used during tests")
  146. failed = True
  147. if failed:
  148. raise RuntimeError
  149. if __name__ == '__main__':
  150. test_examples_protocol_http_server_advanced()