http_server_advanced_test.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. import imp
  17. import re
  18. import os
  19. import sys
  20. import string
  21. import random
  22. import socket
  23. # This environment variable is expected on the host machine
  24. test_fw_path = os.getenv("TEST_FW_PATH")
  25. if test_fw_path and test_fw_path not in sys.path:
  26. sys.path.insert(0, test_fw_path)
  27. # When running on local machine execute the following before running this script
  28. # > export TEST_FW_PATH='~/esp/esp-idf/tools/tiny-test-fw'
  29. # > make print_flash_cmd | tail -n 1 > build/download.config
  30. # > make app bootloader
  31. import TinyFW
  32. import IDF
  33. # Import client module
  34. expath = os.path.dirname(os.path.realpath(__file__))
  35. client = imp.load_source("client", expath + "/scripts/test.py")
  36. @IDF.idf_example_test(env_tag="Example_WIFI", ignore=True)
  37. def test_examples_protocol_http_server_advanced(env, extra_data):
  38. # Acquire DUT
  39. dut1 = env.get_dut("http_server", "examples/protocols/http_server/advanced_tests")
  40. # Get binary file
  41. binary_file = os.path.join(dut1.app.binary_path, "tests.bin")
  42. bin_size = os.path.getsize(binary_file)
  43. IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size//1024))
  44. IDF.check_performance("http_server_bin_size", bin_size//1024)
  45. # Upload binary and start testing
  46. dut1.start_app()
  47. # Parse IP address of STA
  48. got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)Got IP: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
  49. print "Leak Tests..."
  50. # Expected Leak test Logs
  51. dut1.expect("Leak Test Started...");
  52. dut1.expect("Leak Test Passed");
  53. got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Started HTTP server on port: (\d+)"))[0]
  54. result = dut1.expect(re.compile(r"(?:[\s\S]*)Max URI handlers: (\d+)(?:[\s\S]*)Max Open Sessions: (\d+)(?:[\s\S]*)Max Header Length: (\d+)(?:[\s\S]*)Max URI Length: (\d+)(?:[\s\S]*)Max Stack Size: (\d+)"))
  55. max_uri_handlers = int(result[0])
  56. max_sessions = int(result[1])
  57. max_hdr_len = int(result[2])
  58. max_uri_len = int(result[3])
  59. max_stack_size = int(result[4])
  60. print "Got IP : " + got_ip
  61. print "Got Port : " + got_port
  62. print "Handler Tests..."
  63. # Expected Handler Test Logs
  64. dut1.expect("Test: Register Max URI handlers")
  65. dut1.expect("Success")
  66. dut1.expect("Test: Register Max URI + 1 handlers")
  67. dut1.expect("no slots left for registering handler")
  68. dut1.expect("Success")
  69. dut1.expect("Test: Unregister 0th handler")
  70. dut1.expect("Success")
  71. dut1.expect("Test: Again unregister 0th handler not registered")
  72. dut1.expect("handler 0 with method 1 not found")
  73. dut1.expect("Success")
  74. dut1.expect("Test: Register back 0th handler")
  75. dut1.expect("Success")
  76. dut1.expect("Test: Register 0th handler again after registering")
  77. dut1.expect("handler 0 with method 1 already registered")
  78. dut1.expect("Success")
  79. dut1.expect("Test: Register 1 more handler")
  80. dut1.expect("no slots left for registering handler")
  81. dut1.expect("Success")
  82. dut1.expect("Test: Unregister all handlers")
  83. dut1.expect("Success")
  84. dut1.expect("Registering basic handlers")
  85. dut1.expect("Success")
  86. # Run test script
  87. # If failed raise appropriate exception
  88. print "Basic HTTP Client Tests..."
  89. if not client.get_hello(got_ip, got_port):
  90. raise RuntimeError
  91. inital_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: (\d+)"))[0])
  92. if inital_stack < 0.1*max_stack_size:
  93. print "More than 90% of stack being used on server start"
  94. raise RuntimeError
  95. if not client.post_hello(got_ip, got_port):
  96. raise RuntimeError
  97. if not client.put_hello(got_ip, got_port):
  98. raise RuntimeError
  99. if not client.post_echo(got_ip, got_port):
  100. raise RuntimeError
  101. if not client.get_echo(got_ip, got_port):
  102. raise RuntimeError
  103. if not client.put_echo(got_ip, got_port):
  104. raise RuntimeError
  105. if not client.get_hello_type(got_ip, got_port):
  106. raise RuntimeError
  107. if not client.get_hello_status(got_ip, got_port):
  108. raise RuntimeError
  109. if not client.get_false_uri(got_ip, got_port):
  110. raise RuntimeError
  111. print "Error code tests..."
  112. if not client.code_500_server_error_test(got_ip, got_port):
  113. raise RuntimeError
  114. if not client.code_501_method_not_impl(got_ip, got_port):
  115. raise RuntimeError
  116. if not client.code_505_version_not_supported(got_ip, got_port):
  117. raise RuntimeError
  118. if not client.code_400_bad_request(got_ip, got_port):
  119. raise RuntimeError
  120. if not client.code_404_not_found(got_ip, got_port):
  121. raise RuntimeError
  122. if not client.code_405_method_not_allowed(got_ip, got_port):
  123. raise RuntimeError
  124. if not client.code_408_req_timeout(got_ip, got_port):
  125. raise RuntimeError
  126. if not client.code_414_uri_too_long(got_ip, got_port, max_uri_len):
  127. raise RuntimeError
  128. if not client.code_431_hdr_too_long(got_ip, got_port, max_hdr_len):
  129. raise RuntimeError
  130. if not client.test_upgrade_not_supported(got_ip, got_port):
  131. raise RuntimeError
  132. print "Sessions and Context Tests..."
  133. if not client.parallel_sessions_adder(got_ip, got_port, max_sessions):
  134. raise RuntimeError
  135. if not client.leftover_data_test(got_ip, got_port):
  136. raise RuntimeError
  137. if not client.async_response_test(got_ip, got_port):
  138. raise RuntimeError
  139. if not client.spillover_session(got_ip, got_port, max_sessions):
  140. raise RuntimeError
  141. if not client.recv_timeout_test(got_ip, got_port):
  142. raise RuntimeError
  143. # May timeout in case requests are sent slower than responses are read.
  144. # Instead use httperf stress test
  145. #if not client.pipeline_test(got_ip, got_port, max_sessions):
  146. # raise RuntimeError
  147. test_size = 50*1024 # 50KB
  148. if not client.packet_size_limit_test(got_ip, got_port, test_size):
  149. raise RuntimeError
  150. if not client.get_hello(got_ip, got_port):
  151. raise RuntimeError
  152. final_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: (\d+)"))[0])
  153. if final_stack < 0.05*max_stack_size:
  154. print "More than 95% of stack got used during tests"
  155. raise RuntimeError
  156. if __name__ == '__main__':
  157. test_examples_protocol_http_server_advanced()