1import os 2import re 3 4import ttfw_idf 5 6 7@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1') 8def test_examples_protocol_esp_http_client(env, extra_data): 9 """ 10 steps: | 11 1. join AP 12 2. Send HTTP request to httpbin.org 13 """ 14 dut1 = env.get_dut('esp_http_client', 'examples/protocols/esp_http_client', dut_class=ttfw_idf.ESP32DUT) 15 # check and log bin size 16 binary_file = os.path.join(dut1.app.binary_path, 'esp_http_client_example.bin') 17 bin_size = os.path.getsize(binary_file) 18 ttfw_idf.log_performance('esp_http_client_bin_size', '{}KB'.format(bin_size // 1024)) 19 # start test 20 dut1.start_app() 21 dut1.expect('Connected to AP, begin http example', timeout=30) 22 dut1.expect(re.compile(r'HTTP GET Status = 200, content_length = (\d)')) 23 dut1.expect(re.compile(r'HTTP POST Status = 200, content_length = (\d)')) 24 dut1.expect(re.compile(r'HTTP PUT Status = 200, content_length = (\d)')) 25 dut1.expect(re.compile(r'HTTP PATCH Status = 200, content_length = (\d)')) 26 dut1.expect(re.compile(r'HTTP DELETE Status = 200, content_length = (\d)')) 27 dut1.expect(re.compile(r'HTTP HEAD Status = 200, content_length = (\d)')) 28 dut1.expect(re.compile(r'HTTP Basic Auth Status = 200, content_length = (\d)')) 29 dut1.expect(re.compile(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)')) 30 dut1.expect(re.compile(r'HTTP Digest Auth Status = 200, content_length = (\d)')) 31 dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)')) 32 dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)')) 33 dut1.expect(re.compile(r'HTTP chunk encoding Status = 200, content_length = (-?\d)')) 34 # content-len for chunked encoding is typically -1, could be a positive length in some cases 35 dut1.expect(re.compile(r'HTTP Stream reader Status = 200, content_length = (\d)')) 36 dut1.expect(re.compile(r'Last esp error code: 0x8001')) 37 dut1.expect(re.compile(r'HTTP Status = 206, content_length = (\d)')) 38 dut1.expect(re.compile(r'HTTP Status = 206, content_length = 10')) 39 dut1.expect(re.compile(r'HTTP Status = 206, content_length = 10')) 40 dut1.expect('Finish http example') 41 42 # test mbedtls dynamic resource 43 dut1 = env.get_dut('esp_http_client', 'examples/protocols/esp_http_client', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn') 44 # check and log bin size 45 binary_file = os.path.join(dut1.app.binary_path, 'esp_http_client_example.bin') 46 bin_size = os.path.getsize(binary_file) 47 ttfw_idf.log_performance('esp_http_client_bin_size', '{}KB'.format(bin_size // 1024)) 48 # start test 49 dut1.start_app() 50 dut1.expect('Connected to AP, begin http example', timeout=30) 51 dut1.expect(re.compile(r'HTTP GET Status = 200, content_length = (\d)')) 52 dut1.expect(re.compile(r'HTTP POST Status = 200, content_length = (\d)')) 53 dut1.expect(re.compile(r'HTTP PUT Status = 200, content_length = (\d)')) 54 dut1.expect(re.compile(r'HTTP PATCH Status = 200, content_length = (\d)')) 55 dut1.expect(re.compile(r'HTTP DELETE Status = 200, content_length = (\d)')) 56 dut1.expect(re.compile(r'HTTP HEAD Status = 200, content_length = (\d)')) 57 dut1.expect(re.compile(r'HTTP Basic Auth Status = 200, content_length = (\d)')) 58 dut1.expect(re.compile(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)')) 59 dut1.expect(re.compile(r'HTTP Digest Auth Status = 200, content_length = (\d)')) 60 dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)')) 61 dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)')) 62 dut1.expect(re.compile(r'HTTP chunk encoding Status = 200, content_length = (-?\d)')) 63 # content-len for chunked encoding is typically -1, could be a positive length in some cases 64 dut1.expect(re.compile(r'HTTP Stream reader Status = 200, content_length = (\d)')) 65 dut1.expect(re.compile(r'Last esp error code: 0x8001')) 66 dut1.expect(re.compile(r'HTTP Status = 206, content_length = (\d)')) 67 dut1.expect(re.compile(r'HTTP Status = 206, content_length = 10')) 68 dut1.expect(re.compile(r'HTTP Status = 206, content_length = 10')) 69 dut1.expect('Finish http example') 70 71 72if __name__ == '__main__': 73 test_examples_protocol_esp_http_client() 74