http_server_advanced_test.py 6.8 KB

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