def test_examples_protocol_simple_ota_example_with_verify_app_signature_on_update_no_secure_boot_ecdsa(env, extra_data): """ steps: | 1. join AP 2. Fetch OTA image over HTTPS 3. Reboot with the new OTA image """ dut1 = env.get_dut('simple_ota_example', 'examples/system/ota/simple_ota_example', dut_class=ttfw_idf.ESP32DUT, app_config_name='on_update_no_sb_ecdsa') # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'simple_ota.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('simple_ota_bin_size', '{}KB'.format(bin_size // 1024)) # start test host_ip = get_my_ip() thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, 8000)) thread1.daemon = True thread1.start() dut1.start_app() dut1.expect('Loaded app from partition at offset 0x20000', timeout=30) try: ip_address = dut1.expect(re.compile(r' eth ip: ([^,]+),'), timeout=30) print('Connected to AP with IP: {}'.format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect('Starting OTA example', timeout=30) print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin')) dut1.write('https://' + host_ip + ':8000/simple_ota.bin') dut1.expect('Writing to partition subtype 16 at offset 0x120000', timeout=20) dut1.expect('Verifying image signature...', timeout=60) dut1.expect('Loaded app from partition at offset 0x120000', timeout=20) dut1.expect('Starting OTA example', timeout=30)
def test_examples_protocol_simple_ota_example(env, extra_data): """ steps: | 1. join AP 2. Fetch OTA image over HTTPS 3. Reboot with the new OTA image """ dut1 = env.get_dut('simple_ota_example', 'examples/system/ota/simple_ota_example', dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'simple_ota.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('simple_ota_bin_size', '{}KB'.format(bin_size // 1024)) sha256_bootloader, sha256_app = calc_all_sha256(dut1) # start test host_ip = get_my_ip() thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, 8000)) thread1.daemon = True thread1.start() dut1.start_app() dut1.expect('Loaded app from partition at offset 0x10000', timeout=30) check_sha256(sha256_bootloader, dut1.expect(re.compile(r'SHA-256 for bootloader:\s+([a-f0-9]+)'))[0]) check_sha256(sha256_app, dut1.expect(re.compile(r'SHA-256 for current firmware:\s+([a-f0-9]+)'))[0]) try: ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30) print('Connected to AP with IP: {}'.format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect('Starting OTA example', timeout=30) print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin')) dut1.write('https://' + host_ip + ':8000/simple_ota.bin') dut1.expect('Loaded app from partition at offset 0x110000', timeout=60) dut1.expect('Starting OTA example', timeout=30)
def test_examples_protocol_simple_ota_example_with_flash_encryption_wifi(env, extra_data): """ steps: | 1. join AP 2. Fetch OTA image over HTTPS 3. Reboot with the new OTA image """ dut1 = env.get_dut('simple_ota_example', 'examples/system/ota/simple_ota_example', app_config_name='flash_enc_wifi') # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'simple_ota.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('simple_ota_bin_size', '{}KB'.format(bin_size // 1024)) # erase flash on the device print('Erasing the flash in order to have an empty NVS key partiton') dut1.erase_flash() # start test host_ip = get_my_ip() thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, 8000)) thread1.daemon = True thread1.start() dut1.start_app() dut1.expect('Loaded app from partition at offset 0x20000', timeout=30) dut1.expect('Flash encryption mode is DEVELOPMENT (not secure)', timeout=10) try: ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30) print('Connected to AP with IP: {}'.format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect('Starting OTA example', timeout=30) print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin')) dut1.write('https://' + host_ip + ':8000/simple_ota.bin') dut1.expect('Loaded app from partition at offset 0x120000', timeout=60) dut1.expect('Flash encryption mode is DEVELOPMENT (not secure)', timeout=10) dut1.expect('Starting OTA example', timeout=30)
def test_examples_protocol_asio_chat_server(env, extra_data): """ steps: | 1. join AP 2. Start server 3. Test connects to server and sends a test message 4. Test evaluates received test message from server """ test_msg = b' 4ABC\n' dut1 = env.get_dut('chat_server', 'examples/protocols/asio/chat_server', dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'asio_chat_server.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('asio_chat_server_bin_size', '{}KB'.format(bin_size // 1024)) # 1. start test dut1.start_app() # 2. get the server IP address data = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30) # 3. create tcp client and connect to server cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) cli.settimeout(30) cli.connect((data[0], 2222)) cli.send(test_msg) data = cli.recv(1024) # 4. check the message received back from the server if (data == test_msg): print('PASS: Received correct message {}'.format(data)) pass else: print('Failure!') raise ValueError('Wrong data received from asi tcp server: {} (expoected:{})'.format(data, test_msg))
def test_examples_protocol_http_request(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument """ steps: | 1. join AP 2. connect to example.com 3. check conneciton success """ dut1 = env.get_dut('http_request', 'examples/protocols/http_request', dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'http-request.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('http_request_bin_size', '{}KB'.format(bin_size // 1024)) # start test dut1.start_app() dut1.expect(re.compile(r'DNS lookup succeeded.'), timeout=30) # check if connected or not dut1.expect(' ... connected', timeout=60) dut1.expect(' ... socket send success') dut1.expect(' ... set socket receiving timeout success') # check server response dut1.expect(re.compile(r'HTTP/1.0 200 OK')) # read from the socket completed dut1.expect('... done reading from socket. Last read return=0 errno=128') dut1.expect(re.compile(r'(\d)...'))
def test_examples_protocol_websocket(env, extra_data): """ steps: | 1. join AP 2. connect to ws://echo.websocket.org 3. send and receive data """ dut1 = env.get_dut("websocket", "examples/protocols/websocket", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "websocket-example.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("websocket_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("websocket_bin_size", bin_size // 1024) # start test dut1.start_app() dut1.expect("Waiting for wifi ...") dut1.expect("Connection established...", timeout=30) dut1.expect("WEBSOCKET_EVENT_CONNECTED") for i in range(0, 10): dut1.expect(re.compile(r"Sending hello (\d)")) dut1.expect(re.compile(r"Received=hello (\d)")) dut1.expect("Websocket Stopped")
def test_examples_efuse_with_virt_flash_enc_aes_256(env, _): # type: (ttfw_idf.TinyFW.Env, None) -> None # Only ESP32-S2 has support AES-256 FLASH_ENCRYPTION key dut = env.get_dut('efuse', 'examples/system/efuse', app_config_name='virt_flash_enc_aes_256') # check and log bin size binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('{}_bootloader_{}_bin_size'.format(dut.app.target, dut.app.config_name), '{}KB'.format(bin_size // 1024)) print(' - Erase flash') dut.erase_flash() print(' - Start app (flash partition_table and app)') dut.start_app_no_enc() dut.expect('Loading virtual efuse blocks from real efuses') dut.expect('Checking flash encryption...') dut.expect('Generating new flash encryption key...') dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2') dut.expect('Writing EFUSE_BLK_KEY1 with purpose 3') dut.expect('Not disabling UART bootloader encryption') dut.expect('Disable UART bootloader cache...') dut.expect('Disable JTAG...') dut.expect('bootloader encrypted successfully') dut.expect('partition table encrypted and loaded successfully') dut.expect('Flash encryption completed', timeout=90) dut.expect('Resetting with flash encryption enabled...') dut.expect('Loading virtual efuse blocks from flash') dut.expect('Checking flash encryption...') dut.expect('flash encryption is enabled (1 plaintext flashes left)') dut.expect('Flash encryption mode is DEVELOPMENT (not secure)') dut.expect('Start eFuse example') dut.expect('example: Done')
def test_examples_protocol_socket_udpclient(env, extra_data): """ steps: 1. join AP 2. have the board connect to the server 3. send and receive data """ dut1 = env.get_dut('udp_client', 'examples/protocols/sockets/udp_client', dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'udp_client.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('udp_client_bin_size', '{}KB'.format(bin_size // 1024)) # start test dut1.start_app() ipv4 = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)[0] ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form) ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0] print('Connected with IPv4={} and IPv6={}'.format(ipv4, ipv6)) # test IPv4 with UdpServer(PORT, socket.AF_INET): server_ip = get_my_ip(netifaces.AF_INET) print('Connect udp client to server IP={}'.format(server_ip)) dut1.write(server_ip) dut1.expect(re.compile(r'OK: Message from ESP32')) # test IPv6 with UdpServer(PORT, socket.AF_INET6): server_ip = get_my_ip(netifaces.AF_INET6) print('Connect udp client to server IP={}'.format(server_ip)) dut1.write(server_ip) dut1.expect(re.compile(r'OK: Message from ESP32'))
def test_app_esp_openssl(env, extra_data): dut1 = env.get_dut("openssl_connect_test", "tools/test_apps/protocols/openssl", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "openssl_connect_test.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("openssl_connect_test_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("openssl_connect_test_bin_size_vin_size", bin_size // 1024, dut1.TARGET) dut1.start_app() esp_ip = dut1.expect( re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30) print("Got IP={}".format(esp_ip[0])) ip = get_my_ip() server_port = 2222 def start_case(case, desc, negotiated_protocol, result): with TlsServer(server_port, negotiated_protocol=negotiated_protocol): print("Starting {}: {}".format(case, desc)) dut1.write("conn {} {} {}".format(ip, server_port, case)) dut1.expect(re.compile(result), timeout=10) return case
def test_examples_protocol_native_ota_example_truncated_header( env, extra_data): """ Working of OTA if headers of binary file are truncated is vaildated in this test case. Application should return with error message in this case. steps: | 1. join AP 2. Generate binary file with truncated headers 3. Fetch OTA image over HTTPS 4. Check working of code if headers are not sent completely """ dut1 = env.get_dut('native_ota_example', 'examples/system/ota/native_ota_example', dut_class=ttfw_idf.ESP32DUT) server_port = 8002 # Original binary file generated after compilation bin_name = 'native_ota.bin' # Truncated binary file to be generated from original binary file truncated_bin_name = 'truncated_header.bin' # Size of truncated file to be grnerated. This value should be less than 288 bytes (Image header size) truncated_bin_size = 180 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) f = open(binary_file, 'rb+') fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), 'wb+') fo.write(f.read(truncated_bin_size)) fo.close() f.close() binary_file = os.path.join(dut1.app.binary_path, truncated_bin_name) bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('native_ota_bin_size', '{}KB'.format(bin_size // 1024)) # start test host_ip = get_my_ip() if (get_server_status(host_ip, server_port) is False): thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port)) thread1.daemon = True thread1.start() 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') thread1.terminate() dut1.expect('Starting OTA example', timeout=30) print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name)) dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name) dut1.expect('native_ota_example: received package is not fit len', timeout=20) os.remove(binary_file) thread1.terminate()
def test_examples_protocol_advanced_https_ota_example_redirect_url( env, extra_data): """ This is a positive test case, which starts a server and a redirection server. Redirection server redirects http_request to different port Number of iterations can be specified in variable iterations. steps: | 1. join AP 2. Fetch OTA image over HTTPS 3. Reboot with the new OTA image """ dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT) server_port = 8001 # Port to which the request should be redirecetd redirection_server_port = 8081 # File to be downloaded. This file is generated after compilation bin_name = 'advanced_https_ota.bin' # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024)) # start test host_ip = get_my_ip() if (get_server_status(host_ip, server_port) is False): thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port)) thread1.daemon = True thread1.start() thread2 = multiprocessing.Process(target=start_redirect_server, args=(dut1.app.binary_path, host_ip, redirection_server_port, server_port)) thread2.daemon = True thread2.start() 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=30) print('Connected to AP with IP: {}'.format(ip_address)) except DUT.ExpectTimeout: thread1.terminate() thread2.terminate() raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect('Starting Advanced OTA example', timeout=30) print('writing to device: {}'.format('https://' + host_ip + ':' + str(redirection_server_port) + '/' + bin_name)) dut1.write('https://' + host_ip + ':' + str(redirection_server_port) + '/' + bin_name) dut1.expect('Loaded app from partition at offset', timeout=60) dut1.expect('Starting Advanced OTA example', timeout=30) dut1.reset() thread1.terminate() thread2.terminate()
def test_examples_protocol_simple_ota_example(env, extra_data): """ steps: | 1. join AP 2. Fetch OTA image over HTTPS 3. Reboot with the new OTA image """ dut1 = env.get_dut("simple_ota_example", "examples/system/ota/simple_ota_example") # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "simple_ota.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("simple_ota_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("simple_ota_bin_size", bin_size // 1024) # start test host_ip = get_my_ip() thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, 8000)) thread1.daemon = True thread1.start() dut1.start_app() dut1.expect("Loaded app from partition at offset 0x10000", timeout=30) try: ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30) print("Connected to AP with IP: {}".format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') thread1.close() dut1.expect("Starting OTA example", timeout=30) print("writing to device: {}".format("https://" + host_ip + ":8000/simple_ota.bin")) dut1.write("https://" + host_ip + ":8000/simple_ota.bin") dut1.expect("Loaded app from partition at offset 0x110000", timeout=60) dut1.expect("Starting OTA example", timeout=30)
def test_examples_protocol_native_ota_example_chunked(env, extra_data): """ This is a positive test case, which downloads complete binary file multiple number of times. Number of iterations can be specified in variable iterations. steps: | 1. join AP 2. Fetch OTA image over HTTPS 3. Reboot with the new OTA image """ dut1 = env.get_dut("native_ota_example", "examples/system/ota/native_ota_example", dut_class=ttfw_idf.ESP32DUT) # File to be downloaded. This file is generated after compilation bin_name = "native_ota.bin" # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024)) # start test host_ip = get_my_ip() chunked_server = start_chunked_server(dut1.app.binary_path, 8070) dut1.start_app() dut1.expect("Loaded app from partition at offset", timeout=30) try: ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30) print("Connected to AP with IP: {}".format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect("Starting OTA example", timeout=30) print("writing to device: {}".format("https://" + host_ip + ":8070/" + bin_name)) dut1.write("https://" + host_ip + ":8070/" + bin_name) dut1.expect("Loaded app from partition at offset", timeout=60) dut1.expect("Starting OTA example", timeout=30) chunked_server.kill() os.remove(os.path.join(dut1.app.binary_path, "server_cert.pem")) os.remove(os.path.join(dut1.app.binary_path, "server_key.pem"))
def test_examples_protocol_mqtt_wss(env, extra_data): broker_url = "" broker_port = 0 """ steps: | 1. join AP and connects to wss broker 2. Test connects a client to the same broker 3. Test evaluates it received correct qos0 message 4. Test ESP32 client received correct qos0 message """ dut1 = env.get_dut("mqtt_websocket_secure", "examples/protocols/mqtt/wss", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "mqtt_websocket_secure.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("mqtt_websocket_secure_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("mqtt_websocket_secure_size", bin_size // 1024, dut1.TARGET) # Look for host:port in sdkconfig try: value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()["CONFIG_BROKER_URI"]) broker_url = value.group(1) broker_port = int(value.group(2)) except Exception: print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig') raise client = None # 1. Test connects to a broker try: client = mqtt.Client(transport="websockets") client.on_connect = on_connect client.on_message = on_message client.tls_set(None, None, None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None) print("Connecting...") client.connect(broker_url, broker_port, 60) except Exception: print("ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:".format(broker_url, sys.exc_info()[0])) raise # Starting a py-client in a separate thread thread1 = Thread(target=mqtt_client_task, args=(client,)) thread1.start() try: print("Connecting py-client to broker {}:{}...".format(broker_url, broker_port)) if not event_client_connected.wait(timeout=30): raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_url)) dut1.start_app() try: ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30) print("Connected to AP with IP: {}".format(ip_address)) except DUT.ExpectTimeout: print('ENV_TEST_FAILURE: Cannot connect to AP') raise print("Checking py-client received msg published from esp...") if not event_client_received_correct.wait(timeout=30): raise ValueError('Wrong data received, msg log: {}'.format(message_log)) print("Checking esp-client received msg published from py-client...") dut1.expect(re.compile(r"DATA=data_to_esp32"), timeout=30) finally: event_stop_client.set() thread1.join()
def test_example_protocol_openssl_server(env, extra_data): """ steps: 1. join AP 2. connect to uri "xxxx.xxxx.xxxx.xxxx:port" 3. send data """ dut1 = env.get_dut('openssl_server', 'examples/protocols/openssl_server', dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'openssl_server.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('openssl_server_bin_size', '{}KB'.format(bin_size // 1024)) # start test dut1.start_app() ip = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)[0] port = dut1.expect(re.compile(r' SSL server socket listen on ([0-9]+)'), timeout=30)[0] # create socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10) addr = (ip, int(port)) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) # wrap socket wrappedSocket = ssl.wrap_socket(sock, ca_certs=_path('server_certs/ca.crt'), cert_reqs=ssl.CERT_REQUIRED) # connect and send data wrappedSocket.connect(addr) wrappedSocket.send('Some Data'.encode()) # close socket connection wrappedSocket.close()
def test_examples_protocol_socket(env, extra_data): """ steps: 1. join AP 2. have the board connect to the server 3. send and receive data """ dut1 = env.get_dut("tcp_client", "examples/protocols/sockets/tcp_client", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "tcp_client.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("tcp_client_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("tcp_client_bin_size", bin_size // 1024, dut1.TARGET) # start test dut1.start_app() data = dut1.expect( re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30) print("Connected with IPv4: {}".format(data[0])) # test IPv4 with TcpServer(PORT, socket.AF_INET): dut1.write(get_my_ip(netifaces.AF_INET)) dut1.expect(re.compile(r"OK: Message from ESP32")) # test IPv6 with TcpServer(PORT, socket.AF_INET6): dut1.write(get_my_ip(netifaces.AF_INET6)) dut1.expect(re.compile(r"OK: Message from ESP32"))
def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_data): """ Working of OTA when anti_rollback is enabled and security version of new image is less than current one. Application should return with error message in this case. steps: | 1. join AP 2. Generate binary file with lower security version 3. Fetch OTA image over HTTPS 4. Check working of anti_rollback feature """ dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT, app_config_name='anti_rollback') server_port = 8001 # Original binary file generated after compilation bin_name = 'advanced_https_ota.bin' # Modified firmware image to lower security version in its header. This is to enable negative test case anti_rollback_bin_name = 'advanced_https_ota_lower_sec_version.bin' # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) file_size = os.path.getsize(binary_file) f = open(binary_file, 'rb+') fo = open(os.path.join(dut1.app.binary_path, anti_rollback_bin_name), 'wb+') fo.write(f.read(file_size)) # Change security_version to 0 for negative test case fo.seek(36) fo.write(b'\x00') fo.close() f.close() binary_file = os.path.join(dut1.app.binary_path, anti_rollback_bin_name) bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024)) # start test host_ip = get_my_ip() if (get_server_status(host_ip, server_port) is False): thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port)) thread1.daemon = True thread1.start() dut1.start_app() # Positive Case dut1.expect('Loaded app from partition at offset', timeout=30) try: ip_address = dut1.expect(re.compile(r' eth ip: ([^,]+),'), timeout=30) print('Connected to AP with IP: {}'.format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect('Starting Advanced OTA example', timeout=30) # Use originally generated image with secure_version=1 print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)) dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name) dut1.expect('Loaded app from partition at offset', timeout=60) dut1.expect(re.compile(r' eth ip: ([^,]+),'), timeout=30) dut1.expect('App is valid, rollback cancelled successfully', 30) # Negative Case dut1.expect('Starting Advanced OTA example', timeout=30) # Use modified image with secure_version=0 print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + anti_rollback_bin_name)) dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + anti_rollback_bin_name) dut1.expect('New firmware security version is less than eFuse programmed, 0 < 1', timeout=30) os.remove(anti_rollback_bin_name)
def test_examples_protocol_socket(env, extra_data): MESSAGE = "Data to ESP" """ steps: 1. join AP 2. have the board connect to the server 3. send and receive data """ dut1 = env.get_dut("udp_server", "examples/protocols/sockets/udp_server", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "udp_server.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("udp_server_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("udp_server_bin_size", bin_size // 1024, dut1.TARGET) # start test dut1.start_app() ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0] ipv6 = dut1.expect(re.compile(r" IPv6 address: ([0-9A-Fa-f\:]+)"), timeout=30)[0] print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6)) # test IPv4 received = udp_client(ipv4, MESSAGE) if not received == MESSAGE: raise dut1.expect(MESSAGE) # test IPv6 received = udp_client("{}%{}".format(ipv6, INTERFACE), MESSAGE) if not received == MESSAGE: raise dut1.expect(MESSAGE)
def test_examples_protocol_http2_request(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument """ steps: | 1. join AP 2. connect to http2.golang.org 3. send http2 request 4. send http2 put response """ dut1 = env.get_dut('http2_request', 'examples/protocols/http2_request', dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, 'http2-request.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('http2_request_bin_size', '{}KB'.format(bin_size // 1024)) # start the test # check if test server is avilable test_server_available = is_test_server_available() # Skip the test if the server test server (http2.golang.org) is not available at the moment. if test_server_available: dut1.start_app() # check for connection dut1.expect('Connection done', timeout=30) # check for echo response dut1.expect('[echo-response] HELLO WORLD', timeout=30) dut1.expect('[echo-response] Frame fully received') dut1.expect('[echo-response] Stream Closed') # check for get response dut1.expect('[get-response] Frame fully received') else: Utility.console_log( 'test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.' .format(TEST_SERVER))
def test_examples_protocol_socket_tcpserver(env, extra_data): MESSAGE = "Data to ESP" """ steps: 1. join AP 2. have the board connect to the server 3. send and receive data """ dut1 = env.get_dut("tcp_client", "examples/protocols/sockets/tcp_server", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "tcp_server.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("tcp_server_bin_size", "{}KB".format(bin_size // 1024)) # start test dut1.start_app() ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0] ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form) ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0] print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6)) # test IPv4 received = tcp_client(ipv4, MESSAGE) if not received == MESSAGE: raise dut1.expect(MESSAGE) # test IPv6 received = tcp_client("{}%{}".format(ipv6, INTERFACE), MESSAGE) if not received == MESSAGE: raise dut1.expect(MESSAGE)
def test_examples_protocol_https_x509_bundle(env, extra_data): """ steps: | 1. join AP 2. connect to multiple URLs 3. send http request """ dut1 = env.get_dut("https_x509_bundle", "examples/protocols/https_x509_bundle") # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "https_x509_bundle.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("https_x509_bundle_bin_size", "{}KB".format(bin_size // 1024)) # start test dut1.start_app() num_URLS = dut1.expect(re.compile(r"Connecting to (\d+) URLs"), timeout=30) dut1.expect(re.compile(r"Connection established to ([\s\S]*)"), timeout=30) dut1.expect("Completed {} connections".format(num_URLS[0]), timeout=60) # test mbedtls dynamic resource dut1 = env.get_dut("https_x509_bundle", "examples/protocols/https_x509_bundle", app_config_name='ssldyn') # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "https_x509_bundle.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("https_x509_bundle_bin_size", "{}KB".format(bin_size // 1024)) # start test dut1.start_app() num_URLS = dut1.expect(re.compile(r"Connecting to (\d+) URLs"), timeout=30) dut1.expect(re.compile(r"Connection established to ([\s\S]*)"), timeout=30) dut1.expect("Completed {} connections".format(num_URLS[0]), timeout=60)
def test_examples_protocol_asio_tcp_server(env, extra_data): """ steps: | 1. join AP 2. Start server 3. Test connects to server and sends a test message 4. Test evaluates received test message from server 5. Test evaluates received test message on server stdout """ test_msg = b"echo message from client to server" dut1 = env.get_dut("tcp_echo_server", "examples/protocols/asio/tcp_echo_server", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "asio_tcp_echo_server.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("asio_tcp_echo_server_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("asio_tcp_echo_server_size", bin_size // 1024) # 1. start test dut1.start_app() # 2. get the server IP address data = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30) # 3. create tcp client and connect to server cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) cli.settimeout(30) cli.connect((data[0], 2222)) cli.send(test_msg) data = cli.recv(1024) # 4. check the message received back from the server if (data == test_msg): print("PASS: Received correct message") pass else: print("Failure!") raise ValueError('Wrong data received from asi tcp server: {} (expected:{})'.format(data, test_msg)) # 5. check the client message appears also on server terminal dut1.expect(test_msg.decode())
def test_examples_protocol_esp_http_client(env, extra_data): """ steps: | 1. join AP 2. Send HTTP request to httpbin.org """ dut1 = env.get_dut("esp_http_client", "examples/protocols/esp_http_client", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "esp-http-client-example.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("esp_http_client_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("esp_http_client_bin_size", bin_size // 1024) # start test dut1.start_app() dut1.expect("Connected to AP, begin http example", timeout=30) dut1.expect(re.compile(r"HTTP GET Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP POST Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP PUT Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP PATCH Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP DELETE Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP HEAD Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP Basic Auth Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP Basic Auth redirect Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP Digest Auth Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP Relative path redirect Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP Absolute path redirect Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"HTTP redirect to HTTPS Status = 200, content_length = (\d)"), timeout=10) dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = (-?\d)")) # content-len for chunked encoding is typically -1, could be a positive length in some cases dut1.expect(re.compile(r"HTTP Stream reader Status = 200, content_length = (\d)")) dut1.expect(re.compile(r"Last esp error code: 0x8001")) dut1.expect("Finish http example")
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])
def test_examples_protocol_advanced_https_ota_example_random(env, extra_data): """ Working of OTA if random data is added in binary file are validated in this test case. Magic byte verification should fail in this case. steps: | 1. join AP 2. Generate random binary image 3. Fetch OTA image over HTTPS 4. Check working of code for random binary file """ dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT) server_port = 8001 # Random binary file to be generated random_bin_name = 'random.bin' # Size of random binary file. 32000 is choosen, to reduce the time required to run the test-case random_bin_size = 32000 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, random_bin_name) fo = open(binary_file, 'wb+') # First byte of binary file is always set to zero. If first byte is generated randomly, # in some cases it may generate 0xE9 which will result in failure of testcase. fo.write(struct.pack('B', 0)) for i in range(random_bin_size - 1): fo.write(struct.pack('B', random.randrange(0, 255, 1))) fo.close() bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024)) # start test host_ip = get_my_ip() if (get_server_status(host_ip, server_port) is False): thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port)) thread1.daemon = True thread1.start() 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=30) print('Connected to AP with IP: {}'.format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') thread1.terminate() dut1.expect('Starting Advanced OTA example', timeout=30) print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name)) dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name) dut1.expect( re.compile(r'esp_https_ota: Mismatch chip id, expected 0, found \d'), timeout=10) os.remove(binary_file) thread1.terminate()
def test_examples_protocol_advanced_https_ota_example_truncated_header( env, extra_data): """ Working of OTA if headers of binary file are truncated is vaildated in this test case. Application should return with error message in this case. steps: | 1. join AP 2. Generate binary file with truncated headers 3. Fetch OTA image over HTTPS 4. Check working of code if headers are not sent completely """ dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT) server_port = 8001 # Original binary file generated after compilation bin_name = "advanced_https_ota.bin" # Truncated binary file to be generated from original binary file truncated_bin_name = "truncated_header.bin" # Size of truncated file to be grnerated. This value should be less than 288 bytes (Image header size) truncated_bin_size = 180 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) f = open(binary_file, "rb+") fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+") fo.write(f.read(truncated_bin_size)) fo.close() f.close() binary_file = os.path.join(dut1.app.binary_path, truncated_bin_name) bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("advanced_https_ota_bin_size", bin_size // 1024, dut1.TARGET) # start test host_ip = get_my_ip() if (get_server_status(host_ip, server_port) is False): thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port)) thread1.daemon = True thread1.start() dut1.start_app() dut1.expect("Loaded app from partition at offset", timeout=30) try: ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30) print("Connected to AP with IP: {}".format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect("Starting Advanced OTA example", timeout=30) print("writing to device: {}".format("https://" + host_ip + ":" + str(server_port) + "/" + truncated_bin_name)) dut1.write("https://" + host_ip + ":" + str(server_port) + "/" + truncated_bin_name) dut1.expect( "advanced_https_ota_example: esp_https_ota_read_img_desc failed", timeout=30) os.remove(binary_file)
def test_examples_protocol_socket_udpserver(env, extra_data): MESSAGE = "Data to ESP" MAX_RETRIES = 3 """ steps: 1. join AP 2. have the board connect to the server 3. send and receive data """ dut1 = env.get_dut("udp_server", "examples/protocols/sockets/udp_server", dut_class=ttfw_idf.ESP32DUT) # check and log bin size binary_file = os.path.join(dut1.app.binary_path, "udp_server.bin") bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("udp_server_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("udp_server_bin_size", bin_size // 1024, dut1.TARGET) # start test dut1.start_app() ipv4 = dut1.expect( re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0] ipv6_r = r':'.join( (r'[0-9a-fA-F]{4}', ) * 8 ) # expect all 8 octets from IPv6 (assumes it's printed in the long form) ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0] print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6)) dut1.expect(re.compile(r'Waiting for data'), timeout=10) # test IPv4 for _ in range(MAX_RETRIES): print('Testing UDP on IPv4...') received = udp_client(ipv4, MESSAGE) if received == MESSAGE: print('OK') break else: raise ValueError( 'IPv4: Did not receive UDP message after {} retries'.format( MAX_RETRIES)) dut1.expect(MESSAGE) # test IPv6 for _ in range(MAX_RETRIES): print('Testing UDP on IPv6...') received = udp_client('{}%{}'.format(ipv6, INTERFACE), MESSAGE) if received == MESSAGE: print('OK') break else: raise ValueError( 'IPv6: Did not receive UDP message after {} retries'.format( MAX_RETRIES)) dut1.expect(MESSAGE)
def test_examples_efuse_with_virt_sb_v1_and_fe(env, _): # type: (ttfw_idf.TinyFW.Env, None) -> None dut = env.get_dut('efuse', 'examples/system/efuse', app_config_name='virt_sb_v1_and_fe') # check and log bin size binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('{}_bootloader_{}_bin_size'.format(dut.app.target, dut.app.config_name), '{}KB'.format(bin_size // 1024)) print(' - Erase flash') dut.erase_flash() print(' - Flash bootloader') dut.bootloader_flash() print(' - Start app (flash partition_table and app)') dut.start_app_no_enc() dut.expect('Loading virtual efuse blocks from real efuses') dut.expect('Verifying image signature...') dut.expect('secure_boot_v1: Generating new secure boot key...') dut.expect('secure_boot_v1: Generating secure boot digest...') dut.expect('secure_boot_v1: Digest generation complete') dut.expect('Checking flash encryption...') dut.expect('flash_encrypt: Generating new flash encryption key...') dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2') dut.expect('flash_encrypt: Setting CRYPT_CONFIG efuse to 0xF') dut.expect('flash_encrypt: Not disabling UART bootloader encryption') dut.expect('flash_encrypt: Disable UART bootloader decryption...') dut.expect('flash_encrypt: Disable UART bootloader MMU cache...') dut.expect('flash_encrypt: Disable JTAG...') dut.expect('flash_encrypt: Disable ROM BASIC interpreter fallback...') dut.expect('flash_encrypt: bootloader encrypted successfully') dut.expect('flash_encrypt: partition table encrypted and loaded successfully') dut.expect('Verifying image signature...') dut.expect('flash_encrypt: Flash encryption completed', timeout=90) dut.expect('Checking secure boot...') dut.expect('secure_boot_v1: blowing secure boot efuse...') dut.expect('Read & write protecting new key...') dut.expect('Disable JTAG...') dut.expect('Disable ROM BASIC interpreter fallback...') dut.expect('secure_boot_v1: secure boot is now enabled for bootloader image') dut.expect('Resetting with flash encryption enabled...') dut.expect('Verifying image signature...') dut.expect('secure_boot_v1: bootloader secure boot is already enabled. No need to generate digest. continuing..') dut.expect('Checking flash encryption...') dut.expect('flash_encrypt: flash encryption is enabled (3 plaintext flashes left)') dut.expect('Checking secure boot...') dut.expect('secure_boot_v1: bootloader secure boot is already enabled, continuing..') dut.expect('cpu_start: Pro cpu up') dut.expect('Loading virtual efuse blocks from flash') dut.expect('flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)') dut.expect('Start eFuse example') dut.expect('example: Done')
def test_examples_efuse_with_virt_secure_boot_v2(env, _): # type: (ttfw_idf.TinyFW.Env, None) -> None # only for ESP32 ECO3 dut = env.get_dut('efuse', 'examples/system/efuse', app_config_name='virt_secure_boot_v2') # check and log bin size binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin') bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance('{}_bootloader_{}_bin_size'.format(dut.app.target, dut.app.config_name), '{}KB'.format(bin_size // 1024)) print(' - Erase flash') dut.erase_flash() print(' - Flash bootloader') dut.bootloader_flash() print(' - Start app (flash partition_table and app)') dut.start_app() dut.expect('Loading virtual efuse blocks from real efuses') dut.expect('Verifying image signature...') dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set') dut.expect('secure_boot_v2: Verifying with RSA-PSS...') dut.expect('secure_boot_v2: Signature verified successfully!') dut.expect('secure_boot_v2: enabling secure boot v2...') dut.expect('Verifying image signature...') dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set') dut.expect('secure_boot_v2: Verifying with RSA-PSS...') dut.expect('secure_boot_v2: Signature verified successfully!') dut.expect('secure_boot_v2: Secure boot digests absent, generating..') dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures') dut.expect('secure_boot_v2: 1 signature block(s) found appended to the bootloader') dut.expect('Writing EFUSE_BLK_KEY1 with purpose 3') dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures') dut.expect('secure_boot_v2: 1 signature block(s) found appended to the app') dut.expect('secure_boot_v2: Application key(0) matches with bootloader key(0)') dut.expect('secure_boot_v2: blowing secure boot efuse...') dut.expect('Disable JTAG...') dut.expect('Disable ROM BASIC interpreter fallback...') dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED') dut.expect('Prevent read disabling of additional efuses...') dut.expect('secure_boot_v2: Secure boot permanently enabled') dut.expect('cpu_start: Pro cpu up') dut.expect('Loading virtual efuse blocks from flash') dut.expect('Start eFuse example') dut.expect('example: Done') dut.reset() dut.expect('Loading virtual efuse blocks from flash') dut.expect('Verifying image signature...') dut.expect('secure_boot_v2: Verifying with RSA-PSS...') dut.expect('secure_boot_v2: Signature verified successfully!') dut.expect('secure_boot_v2: enabling secure boot v2...') dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..') dut.expect('Start eFuse example') dut.expect('example: Done')
def test_examples_protocol_native_ota_example_truncated_bin(env, extra_data): """ Working of OTA if binary file is truncated is validated in this test case. Application should return with error message in this case. steps: | 1. join AP 2. Generate truncated binary file 3. Fetch OTA image over HTTPS 4. Check working of code if bin is truncated """ dut1 = env.get_dut("native_ota_example", "examples/system/ota/native_ota_example", dut_class=ttfw_idf.ESP32DUT) server_port = 8002 # Original binary file generated after compilation bin_name = "native_ota.bin" # Truncated binary file to be generated from original binary file truncated_bin_name = "truncated.bin" # Size of truncated file to be grnerated. This value can range from 288 bytes (Image header size) to size of original binary file # truncated_bin_size is set to 64000 to reduce consumed by the test case truncated_bin_size = 64000 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) f = open(binary_file, "r+") fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "w+") fo.write(f.read(truncated_bin_size)) fo.close() f.close() binary_file = os.path.join(dut1.app.binary_path, truncated_bin_name) bin_size = os.path.getsize(binary_file) ttfw_idf.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024)) ttfw_idf.check_performance("native_ota_bin_size", bin_size // 1024) # start test host_ip = get_my_ip() if (get_server_status(host_ip, server_port) is False): thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port)) thread1.daemon = True thread1.start() dut1.start_app() dut1.expect("Loaded app from partition at offset", timeout=30) try: ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=60) print("Connected to AP with IP: {}".format(ip_address)) except DUT.ExpectTimeout: raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') dut1.expect("Starting OTA example", timeout=30) print("writing to device: {}".format("https://" + host_ip + ":" + str(server_port) + "/" + truncated_bin_name)) dut1.write("https://" + host_ip + ":" + str(server_port) + "/" + truncated_bin_name) dut1.expect( "native_ota_example: Image validation failed, image is corrupted", timeout=20) os.remove(binary_file)