1#!/usr/bin/env python
2#
3# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
4# SPDX-License-Identifier: Apache-2.0
5
6import os
7import re
8
9import tiny_test_fw
10import ttfw_idf
11from tiny_test_fw import Utility
12
13
14@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
15def test_examples_protocol_https_mbedtls(env, extra_data):  # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
16    """
17    steps: |
18      1. join AP
19      2. connect to www.howsmyssl.com:443
20      3. send http request
21    """
22    app_name = 'https_mbedtls'
23    dut1 = env.get_dut(app_name, 'examples/protocols/https_mbedtls', dut_class=ttfw_idf.ESP32DUT)
24    # check and log bin size
25    binary_file = os.path.join(dut1.app.binary_path, 'https_mbedtls.bin')
26    bin_size = os.path.getsize(binary_file)
27    ttfw_idf.log_performance('https_mbedtls_bin_size', '{}KB'.format(bin_size // 1024))
28    # start test
29    dut1.start_app()
30    dut1.expect('Connected.', timeout=30)
31    Utility.console_log('TCP connection established with the server\n performing SSL/TLS handshake')
32    dut1.expect('Performing the SSL/TLS handshake...')
33    dut1.expect('Certificate verified.')
34    Utility.console_log('SSL/TLS handshake successful')
35    dut1.expect('Writing HTTP request...')
36    dut1.expect('Reading HTTP response...')
37    dut1.expect(re.compile(r'Completed (\d) requests'))
38
39    # Read free heap size
40    res = dut1.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE)
41    if not res:
42        raise ValueError('Maximum heap size info not found')
43    ttfw_idf.print_heap_size(app_name, dut1.app.config_name, dut1.TARGET, res[0])
44
45
46if __name__ == '__main__':
47    test_examples_protocol_https_mbedtls()  # pylint: disable=no-value-for-parameter
48