2025-03-21 09:07:53 +01:00
|
|
|
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
2023-06-28 13:45:15 +02:00
|
|
|
# SPDX-License-Identifier: CC0-1.0
|
|
|
|
import pytest
|
|
|
|
from pytest_embedded import Dut
|
|
|
|
|
|
|
|
|
2025-03-21 09:07:53 +01:00
|
|
|
CONFIGS = [
|
|
|
|
pytest.param('default', marks=[pytest.mark.esp32s2, pytest.mark.esp32s3, pytest.mark.esp32p4]),
|
|
|
|
pytest.param('esp32p4_psram', marks=[pytest.mark.esp32p4])
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2023-06-28 13:45:15 +02:00
|
|
|
@pytest.mark.usb_host_flash_disk
|
2025-03-21 09:07:53 +01:00
|
|
|
@pytest.mark.temp_skip_ci(targets=['esp32s2'], reason='lack of runners with usb_host_flash_disk tag')
|
|
|
|
@pytest.mark.parametrize('config', CONFIGS, indirect=True)
|
2023-06-28 13:45:15 +02:00
|
|
|
def test_usb_host_msc_example(dut: Dut) -> None:
|
2025-03-21 09:07:53 +01:00
|
|
|
# Check whether the USB-DWC DMA capable memory is allocated in PSRAM
|
|
|
|
usb_dwc_in_psram = bool(dut.app.sdkconfig.get('USB_HOST_DWC_DMA_CAP_MEMORY_IN_PSRAM'))
|
|
|
|
|
2024-01-30 12:13:46 +01:00
|
|
|
# Get wMaxPacketSize to get USB device speed
|
|
|
|
max_packet_size = int(dut.expect(r'wMaxPacketSize (\d{2,3})')[1].decode())
|
|
|
|
|
2023-06-28 13:45:15 +02:00
|
|
|
# Check result of file_operations()
|
|
|
|
dut.expect_exact("example: Read from file '/usb/esp/test.txt': 'Hello World!'")
|
|
|
|
|
|
|
|
# Check result of speed_test()
|
|
|
|
write_throughput = float(dut.expect(r'example: Write speed ([0-9]*[.]?[0-9]+) MiB')[1].decode())
|
|
|
|
read_throughput = float(dut.expect(r'example: Read speed ([0-9]*[.]?[0-9]+) MiB')[1].decode())
|
|
|
|
|
2024-01-30 12:13:46 +01:00
|
|
|
# Set write and read throughput limits
|
2025-03-21 09:07:53 +01:00
|
|
|
if max_packet_size == 512: # wMaxPacketSize = 512 for HS
|
|
|
|
write_throughput_limit = 3.5 if usb_dwc_in_psram else 4.9
|
|
|
|
read_throughput_limit = 9.9 if usb_dwc_in_psram else 11.5
|
|
|
|
else: # wMaxPacketSize = 64 for FS
|
2024-01-30 12:13:46 +01:00
|
|
|
write_throughput_limit = 0.9
|
|
|
|
read_throughput_limit = 1.0
|
|
|
|
|
2025-03-21 09:07:53 +01:00
|
|
|
# Evaluate the speed measurements
|
2024-01-30 12:13:46 +01:00
|
|
|
if write_throughput > write_throughput_limit:
|
2023-06-28 13:45:15 +02:00
|
|
|
print('Write throughput put OK')
|
|
|
|
else:
|
|
|
|
print('write throughput too slow!')
|
2024-01-30 12:13:46 +01:00
|
|
|
if read_throughput > read_throughput_limit:
|
2023-06-28 13:45:15 +02:00
|
|
|
print('Read throughput put OK')
|
|
|
|
else:
|
|
|
|
print('Read throughput too slow!')
|