Beispiel #1
0
def test_examples_protocol_https_mbedtls(env, extra_data):  # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
    """
    steps: |
      1. join AP
      2. connect to www.howsmyssl.com:443
      3. send http request
    """
    app_name = 'https_mbedtls'
    dut1 = env.get_dut(app_name, 'examples/protocols/https_mbedtls', dut_class=ttfw_idf.ESP32DUT)
    # check and log bin size
    binary_file = os.path.join(dut1.app.binary_path, 'https_mbedtls.bin')
    bin_size = os.path.getsize(binary_file)
    ttfw_idf.log_performance('https_mbedtls_bin_size', '{}KB'.format(bin_size // 1024))
    # start test
    dut1.start_app()
    dut1.expect('Connected.', timeout=30)
    Utility.console_log('TCP connection established with the server\n performing SSL/TLS handshake')
    dut1.expect('Performing the SSL/TLS handshake...')
    dut1.expect('Certificate verified.')
    Utility.console_log('SSL/TLS handshake successful')
    dut1.expect('Writing HTTP request...')
    dut1.expect('Reading HTTP response...')
    dut1.expect(re.compile(r'Completed (\d) requests'))

    # Read free heap size
    res = dut1.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE)
    if not res:
        raise ValueError('Maximum heap size info not found')
    ttfw_idf.print_heap_size(app_name, dut1.app.config_name, dut1.TARGET, res[0])
Beispiel #2
0
def test_examples_gpio(env, extra_data):
    app_name = 'gpio'
    dut = env.get_dut(app_name, 'examples/peripherals/gpio/generic_gpio')
    dut.start_app()
    res = dut.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE)
    if not res:
        raise ValueError('Maximum heap size info not found')
    ttfw_idf.print_heap_size(app_name, dut.app.config_name, dut.TARGET, res[0])
Beispiel #3
0
def test_examples_hello_world(env, extra_data):
    app_name = 'hello_world'
    dut = env.get_dut(app_name, 'examples/get-started/hello_world')
    dut.start_app()
    res = dut.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE)
    if not res:
        raise ValueError('Maximum heap size info not found')
    ttfw_idf.print_heap_size(app_name, dut.app.config_name, dut.TARGET, res[0])
Beispiel #4
0
def test_examples_protocol_https_request_dynamic_buffers(env, extra_data):
    # Check for connection using crt bundle with mbedtls dynamic resource enabled
    dut1 = env.get_dut('https_request_ssldyn',
                       'examples/protocols/https_request',
                       dut_class=ttfw_idf.ESP32DUT,
                       app_config_name='ssldyn')
    # check and log bin size
    Utility.console_log('[app_config_name] - {}'.format(dut1.app.config_name))
    binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
    bin_size = os.path.getsize(binary_file)
    ttfw_idf.log_performance('https_request_bin_size',
                             '{}KB'.format(bin_size // 1024))
    # start test
    dut1.start_app()

    dut1.expect('Loaded app from partition at offset', timeout=30)
    try:
        ip_address = dut1.expect(re.compile(r' (sta|eth) ip: ([^,]+),'),
                                 timeout=60)
        print('Connected to AP with IP: {}'.format(ip_address))
    except DUT.ExpectTimeout:
        raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')

    # only check if one connection is established
    Utility.console_log(
        "Testing for \"https_request using crt bundle\" with mbedtls dynamic resource enabled"
    )
    try:
        dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
        dut1.expect_all('Connection established...',
                        'Reading HTTP response...', 'HTTP/1.1 200 OK',
                        re.compile('connection closed'))
    except Exception:
        Utility.console_log(
            "Failed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled"
        )
        raise
    Utility.console_log(
        "Passed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled"
    )

    # Read free heap size
    res = dut1.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE, timeout=20)
    if not res:
        raise ValueError('Maximum heap size info not found')
    ttfw_idf.print_heap_size('https_request', dut1.app.config_name,
                             dut1.TARGET, res[0])

    env.close_dut('https_request_ssldyn')
Beispiel #5
0
def test_examples_protocol_https_request(env, extra_data):
    """
    steps: |
      1. join AP
      2. establish TLS connection to www.howsmyssl.com:443 with multiple
         certificate verification options
      3. send http request
    """
    dut1 = env.get_dut('https_request',
                       'examples/protocols/https_request',
                       dut_class=ttfw_idf.ESP32DUT)
    # check and log bin size
    Utility.console_log('[app_config_name] - {}'.format(dut1.app.config_name))
    binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
    bin_size = os.path.getsize(binary_file)
    ttfw_idf.log_performance('https_request_bin_size',
                             '{}KB'.format(bin_size // 1024))
    # start tes
    Utility.console_log('Starting https_request simple test app')
    dut1.start_app()

    dut1.expect('Loaded app from partition at offset', timeout=30)
    try:
        ip_address = dut1.expect(re.compile(r' (sta|eth) ip: ([^,]+),'),
                                 timeout=60)
        print('Connected to AP with IP: {}'.format(ip_address))
    except DUT.ExpectTimeout:
        raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')

    # Check for connection using crt bundle
    Utility.console_log("Testing for \"https_request using crt bundle\"")
    try:
        dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
        dut1.expect_all('Certificate validated', 'Connection established...',
                        'Reading HTTP response...', 'HTTP/1.1 200 OK',
                        re.compile('connection closed'))
    except Exception:
        Utility.console_log(
            "Failed the test for \"https_request using crt bundle\"")
        raise
    Utility.console_log(
        "Passed the test for \"https_request using crt bundle\"")

    # Read free heap size
    res = dut1.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE, timeout=20)
    if not res:
        raise ValueError('Maximum heap size info not found')
    ttfw_idf.print_heap_size('https_request', dut1.app.config_name,
                             dut1.TARGET, res[0])

    # Check for connection using cacert_buf
    Utility.console_log("Testing for \"https_request using cacert_buf\"")
    try:
        dut1.expect(re.compile('https_request using cacert_buf'), timeout=20)
        dut1.expect_all('Connection established...',
                        'Reading HTTP response...', 'HTTP/1.1 200 OK',
                        re.compile('connection closed'))
    except Exception:
        Utility.console_log(
            "Passed the test for \"https_request using cacert_buf\"")
        raise
    Utility.console_log(
        "Passed the test for \"https_request using cacert_buf\"")

    # Check for connection using global ca_store
    Utility.console_log("Testing for \"https_request using global ca_store\"")
    try:
        dut1.expect(re.compile('https_request using global ca_store'),
                    timeout=20)
        dut1.expect_all('Connection established...',
                        'Reading HTTP response...', 'HTTP/1.1 200 OK',
                        re.compile('connection closed'))
    except Exception:
        Utility.console_log(
            "Failed the test for \"https_request using global ca_store\"")
        raise
    Utility.console_log(
        "Passed the test for \"https_request using global ca_store\"")
    env.close_dut('https_request')