예제 #1
0
def test_examples_provisioning_softap(env, extra_data):
    # Acquire DUT
    dut1 = env.get_dut("softap_prov",
                       "examples/provisioning/legacy/softap_prov",
                       dut_class=ttfw_idf.ESP32DUT)

    # Get binary file
    binary_file = os.path.join(dut1.app.binary_path, "softap_prov.bin")
    bin_size = os.path.getsize(binary_file)
    ttfw_idf.log_performance("softap_prov_bin_size",
                             "{}KB".format(bin_size // 1024))
    ttfw_idf.check_performance("softap_prov_bin_size", bin_size // 1024,
                               dut1.TARGET)

    # Upload binary and start testing
    dut1.start_app()

    # Parse IP address of STA
    dut1.expect("Starting WiFi SoftAP provisioning", timeout=60)
    [ssid, password] = dut1.expect(re.compile(
        r"SoftAP Provisioning started with SSID '(\S+)', Password '(\S+)'"),
                                   timeout=30)

    iface = wifi_tools.get_wiface_name()
    if iface is None:
        raise RuntimeError("Failed to get Wi-Fi interface on host")
    print("Interface name  : " + iface)
    print("SoftAP SSID     : " + ssid)
    print("SoftAP Password : "******"Connecting to DUT SoftAP...")
        ip = ctrl.connect(ssid, password)
        got_ip = dut1.expect(re.compile(
            r"DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)"),
                             timeout=60)[0]
        if ip != got_ip:
            raise RuntimeError("SoftAP connected to another host! " + ip +
                               "!=" + got_ip)
        print("Connected to DUT SoftAP")

        print("Starting Provisioning")
        verbose = False
        protover = "V0.1"
        secver = 1
        pop = "abcd1234"
        provmode = "softap"
        ap_ssid = "myssid"
        ap_password = "******"
        softap_endpoint = ip.split('.')[0] + "." + ip.split(
            '.')[1] + "." + ip.split('.')[2] + ".1:80"

        print("Getting security")
        security = esp_prov.get_security(secver, pop, verbose)
        if security is None:
            raise RuntimeError("Failed to get security")

        print("Getting transport")
        transport = esp_prov.get_transport(provmode, softap_endpoint)
        if transport is None:
            raise RuntimeError("Failed to get transport")

        print("Verifying protocol version")
        if not esp_prov.version_match(transport, protover):
            raise RuntimeError("Mismatch in protocol version")

        print("Starting Session")
        if not esp_prov.establish_session(transport, security):
            raise RuntimeError("Failed to start session")

        print("Sending Wifi credential to DUT")
        if not esp_prov.send_wifi_config(transport, security, ap_ssid,
                                         ap_password):
            raise RuntimeError("Failed to send Wi-Fi config")

        print("Applying config")
        if not esp_prov.apply_wifi_config(transport, security):
            raise RuntimeError("Failed to send apply config")

        if not esp_prov.wait_wifi_connected(transport, security):
            raise RuntimeError("Provisioning failed")
    finally:
        ctrl.reset()
예제 #2
0
def test_examples_provisioning_softap(env, extra_data):
    # Acquire DUT
    dut1 = env.get_dut('softap_prov',
                       'examples/provisioning/legacy/softap_prov',
                       dut_class=ttfw_idf.ESP32DUT)

    # Get binary file
    binary_file = os.path.join(dut1.app.binary_path, 'softap_prov.bin')
    bin_size = os.path.getsize(binary_file)
    ttfw_idf.log_performance('softap_prov_bin_size',
                             '{}KB'.format(bin_size // 1024))

    # Upload binary and start testing
    dut1.start_app()

    # Parse IP address of STA
    dut1.expect('Starting WiFi SoftAP provisioning', timeout=60)
    [ssid, password] = dut1.expect(re.compile(
        r"SoftAP Provisioning started with SSID '(\S+)', Password '(\S+)'"),
                                   timeout=30)

    iface = wifi_tools.get_wiface_name()
    if iface is None:
        raise RuntimeError('Failed to get Wi-Fi interface on host')
    print('Interface name  : ' + iface)
    print('SoftAP SSID     : ' + ssid)
    print('SoftAP Password : '******'Connecting to DUT SoftAP...')
        ip = ctrl.connect(ssid, password)
        got_ip = dut1.expect(re.compile(
            r'DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)'),
                             timeout=60)[0]
        if ip != got_ip:
            raise RuntimeError('SoftAP connected to another host! ' + ip +
                               '!=' + got_ip)
        print('Connected to DUT SoftAP')

        print('Starting Provisioning')
        verbose = False
        protover = 'V0.1'
        secver = 1
        pop = 'abcd1234'
        provmode = 'softap'
        ap_ssid = 'myssid'
        ap_password = '******'
        softap_endpoint = ip.split('.')[0] + '.' + ip.split(
            '.')[1] + '.' + ip.split('.')[2] + '.1:80'

        print('Getting security')
        security = esp_prov.get_security(secver, pop, verbose)
        if security is None:
            raise RuntimeError('Failed to get security')

        print('Getting transport')
        transport = esp_prov.get_transport(provmode, softap_endpoint)
        if transport is None:
            raise RuntimeError('Failed to get transport')

        print('Verifying protocol version')
        if not esp_prov.version_match(transport, protover):
            raise RuntimeError('Mismatch in protocol version')

        print('Starting Session')
        if not esp_prov.establish_session(transport, security):
            raise RuntimeError('Failed to start session')

        print('Sending Wifi credential to DUT')
        if not esp_prov.send_wifi_config(transport, security, ap_ssid,
                                         ap_password):
            raise RuntimeError('Failed to send Wi-Fi config')

        print('Applying config')
        if not esp_prov.apply_wifi_config(transport, security):
            raise RuntimeError('Failed to send apply config')

        if not esp_prov.wait_wifi_connected(transport, security):
            raise RuntimeError('Provisioning failed')
    finally:
        ctrl.reset()
예제 #3
0
def test_example_captive_portal(env, extra_data):  # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
    # Acquire DUT
    dut1 = env.get_dut('captive_portal',
                       'examples/protocols/http_server/captive_portal',
                       dut_class=ttfw_idf.ESP32DUT)

    # Get binary file
    binary_file = os.path.join(dut1.app.binary_path, 'captive_portal.bin')
    bin_size = os.path.getsize(binary_file)
    ttfw_idf.log_performance('captive_portal_bin_size',
                             '{}KB'.format(bin_size // 1024))

    # Upload binary and start testing
    dut1.start_app()

    # Parse IP address of STA
    Utility.console_log('Waiting to connect with softAP')
    ap_ip = dut1.expect(
        re.compile(r'Set up softAP with IP: (\d+.\d+.\d+.\d+)'), timeout=60)[0]

    [ssid, password] = dut1.expect(re.compile(
        r"wifi_init_softap finished. SSID:'(\S+)' password:'******'"),
                                   timeout=30)
    port = dut1.expect(
        re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"),
        timeout=30)[0]

    iface = wifi_tools.get_wiface_name()
    if iface is None:
        raise RuntimeError('Failed to get Wi-Fi interface on host')
    print('Interface name  : ' + iface)
    print('SoftAP SSID     : ' + ssid)
    print('SoftAP Password : '******'Connecting to DUT SoftAP...')
        try:
            ip = ctrl.connect(ssid, password)
        except RuntimeError as err:
            Utility.console_log('error: {}'.format(err))
        try:
            got_ip = dut1.expect(re.compile(
                r'DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)'
            ),
                                 timeout=60)
            Utility.console_log('got_ip: {}'.format(got_ip))
            got_ip = got_ip[0]
            if ip != got_ip:
                raise RuntimeError(
                    'SoftAP connected to another host! {} != {}'.format(
                        ip, got_ip))
        except tiny_test_fw.DUT.ExpectTimeout:
            # print what is happening on DUT side
            Utility.console_log('in exception tiny_test_fw.DUT.ExpectTimeout')
            Utility.console_log(dut1.read())
            raise
        print('Connected to DUT SoftAP')

        host_name = 'www.google.com'
        host = socket.gethostbyname(host_name)
        print('hostname: {} resolved to: {}'.format(host_name, host))
        if host != ap_ip:
            raise RuntimeError(
                "DNS server failed to redirect question to the softAP's IP")

        uri = test_redirect(ap_ip, port)
        test_captive_page(ap_ip, port, uri)
    finally:
        ctrl.reset()
예제 #4
0
def test_example_captive_portal(dut: Dut) -> None:

    # Get binary file
    binary_file = os.path.join(dut.app.binary_path, 'captive_portal.bin')
    bin_size = os.path.getsize(binary_file)
    logging.info('captive_portal_bin_size : {}KB'.format(bin_size // 1024))

    # Parse IP address of STA
    logging.info('Waiting to connect with softAP')
    ap_ip = dut.expect(r'Set up softAP with IP: (\d+.\d+.\d+.\d+)',
                       timeout=60)[1]

    wifi_info = dut.expect(
        r"wifi_init_softap finished. SSID:'(\S+)' password:'******'",
        timeout=30)
    ssid = wifi_info[1].decode()
    password = wifi_info[2].decode()
    port = dut.expect(r"(?:[\s\S]*)Starting server on port: '(\d+)'",
                      timeout=30)[1]

    iface = wifi_tools.get_wiface_name()
    if iface is None:
        raise RuntimeError('Failed to get Wi-Fi interface on host')
    print('Interface name  : ' + iface)
    print('SoftAP SSID     : ' + ssid)
    print('SoftAP Password : '******'Connecting to DUT SoftAP...')
        try:
            ip = ctrl.connect(ssid, password)
        except RuntimeError as err:
            logging.info('error: {}'.format(err))
        try:
            got_ip = dut.expect(
                r'DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)',
                timeout=60)[1].decode()
            logging.info('got_ip: {}'.format(got_ip))
            if ip != got_ip:
                raise RuntimeError(
                    'SoftAP connected to another host! {} != {}'.format(
                        ip, got_ip))
        except pexpect.exceptions.TIMEOUT:
            # print what is happening on DUT side
            logging.info('in exception tiny_test_fw.DUT.ExpectTimeout')
            logging.info(dut.read())
            raise
        print('Connected to DUT SoftAP')

        host_name = 'www.google.com'
        host = socket.gethostbyname(host_name)
        print('hostname: {} resolved to: {}'.format(host_name, host))
        if host != ap_ip:
            raise RuntimeError(
                "DNS server failed to redirect question to the softAP's IP")

        uri = test_redirect(ap_ip, port)
        test_captive_page(ap_ip, port, uri)
    finally:
        ctrl.reset()
예제 #5
0
def test_examples_provisioning_softap(env, extra_data):
    # Acquire DUT
    dut1 = env.get_dut("softap_prov", "examples/provisioning/softap_prov")

    # Get binary file
    binary_file = os.path.join(dut1.app.binary_path, "softap_prov.bin")
    bin_size = os.path.getsize(binary_file)
    IDF.log_performance("softap_prov_bin_size", "{}KB".format(bin_size // 1024))
    IDF.check_performance("softap_prov_bin_size", bin_size // 1024)

    # Upload binary and start testing
    dut1.start_app()

    # Parse IP address of STA
    dut1.expect("Starting WiFi SoftAP provisioning", timeout=60)
    dut1.expect("SoftAP started", timeout=30)
    [ssid, password] = dut1.expect(re.compile(r"SoftAP Provisioning started with SSID '(\S+)', Password '(\S+)'"), timeout=30)

    iface = wifi_tools.get_wiface_name()
    if iface is None:
        raise RuntimeError("Failed to get Wi-Fi interface on host")
    print("Interface name  : " + iface)
    print("SoftAP SSID     : " + ssid)
    print("SoftAP Password : "******"Connecting to DUT SoftAP...")
    ip = ctrl.connect(ssid, password)
    got_ip = dut1.expect(re.compile(r"softAP assign IP to station,IP is: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
    if ip != got_ip:
        raise RuntimeError("SoftAP connected to another host! " + ip + "!=" + got_ip)
    print("Connected to DUT SoftAP")

    print("Starting Provisioning")
    verbose = False
    protover = "V0.1"
    secver = 1
    pop = "abcd1234"
    provmode = "softap"
    ap_ssid = "myssid"
    ap_password = "******"
    softap_endpoint = ip.split('.')[0] + "." + ip.split('.')[1] + "." + ip.split('.')[2] + ".1:80"

    print("Getting security")
    security = esp_prov.get_security(secver, pop, verbose)
    if security is None:
        raise RuntimeError("Failed to get security")

    print("Getting transport")
    transport = esp_prov.get_transport(provmode, softap_endpoint, None)
    if transport is None:
        raise RuntimeError("Failed to get transport")

    print("Verifying protocol version")
    if not esp_prov.version_match(transport, protover):
        raise RuntimeError("Mismatch in protocol version")

    print("Starting Session")
    if not esp_prov.establish_session(transport, security):
        raise RuntimeError("Failed to start session")

    print("Sending Wifi credential to DUT")
    if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password):
        raise RuntimeError("Failed to send Wi-Fi config")

    print("Applying config")
    if not esp_prov.apply_wifi_config(transport, security):
        raise RuntimeError("Failed to send apply config")

    success = False
    while True:
        time.sleep(5)
        print("Wi-Fi connection state")
        ret = esp_prov.get_wifi_config(transport, security)
        if (ret == 1):
            continue
        elif (ret == 0):
            print("Provisioning was successful")
            success = True
        break

    if not success:
        raise RuntimeError("Provisioning failed")