-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial test suite covering the control transfers of the gs_usb USB device class implementation. Signed-off-by: Henrik Brix Andersen <[email protected]>
- Loading branch information
1 parent
5d4a557
commit c5f1cdf
Showing
17 changed files
with
1,297 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pyusb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-r requirements-run-test.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024 Henrik Brix Andersen <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(host) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright (c) 2024 Henrik Brix Andersen <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
menu "Test suite for gs_usb" | ||
|
||
config TEST_USB_MANUFACTURER | ||
string "USB device manufacturer string" | ||
default "CANnectivity" | ||
help | ||
USB device manufacturer string. | ||
|
||
config TEST_USB_PRODUCT | ||
string "USB device product string" | ||
default "CANnectivity gs_usb Test Suite" | ||
help | ||
USB product string. | ||
|
||
config TEST_USB_VID | ||
hex "USB device Vendor ID (VID)" | ||
default 0x1209 | ||
help | ||
USB device Vendor ID (VID). | ||
|
||
config TEST_USB_PID | ||
hex "USB device Product ID (PID)" | ||
default 0x0001 | ||
help | ||
USB device Product ID (PID). | ||
|
||
config TEST_USB_MAX_POWER | ||
int "USB device maximum power" | ||
default 125 | ||
range 0 250 | ||
help | ||
USB maximum current draw in milliampere (mA) divided by 2. | ||
A value of 125 results in a maximum current draw value of 250 mA. | ||
|
||
if USB_DEVICE_STACK | ||
|
||
configdefault USB_DEVICE_MANUFACTURER | ||
default TEST_USB_MANUFACTURER | ||
|
||
configdefault USB_DEVICE_PRODUCT | ||
default TEST_USB_PRODUCT | ||
|
||
configdefault USB_DEVICE_VID | ||
default TEST_USB_VID | ||
|
||
configdefault USB_DEVICE_PID | ||
default TEST_USB_PID | ||
|
||
configdefault USB_MAX_POWER | ||
default TEST_USB_MAX_POWER | ||
|
||
endif # USB_DEVICE_STACK | ||
|
||
endmenu | ||
|
||
source "Kconfig.zephyr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Geschwister Schneider USB/CAN Protocol Tests | ||
############################################ | ||
|
||
Overview | ||
******** | ||
|
||
This test suite uses `PyUSB`_ for testing the Geschwister Schneider USB/CAN protocol implementation. | ||
|
||
Prerequisites | ||
************* | ||
|
||
The test suite has the following prerequisites: | ||
|
||
* The PyUSB library must be installed on the host PC. | ||
* The DUT must be connected to the host PC via USB. | ||
|
||
Building and Running | ||
******************** | ||
|
||
Below is an example for running the test suite on the ``frdm_k64f`` board: | ||
|
||
.. code-block:: shell | ||
west twister -v -p frdm_k64f/mk64f12 --device-testing --device-serial /dev/ttyACM0 -X usb -T tests/subsys/usb/gs_usb/host/ | ||
.. _PyUSB: | ||
https://pyusb.github.io/pyusb/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2022-2024 Henrik Brix Andersen <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
fake_can0: fake_can0 { | ||
status = "okay"; | ||
compatible = "zephyr,fake-can"; | ||
}; | ||
|
||
fake_can1: fake_can1 { | ||
status = "okay"; | ||
compatible = "zephyr,fake-can"; | ||
}; | ||
|
||
can_loopback0: can_loopback0 { | ||
status = "okay"; | ||
compatible = "zephyr,can-loopback"; | ||
}; | ||
|
||
can_loopback1: can_loopback1 { | ||
status = "okay"; | ||
compatible = "zephyr,can-loopback"; | ||
}; | ||
}; | ||
|
||
&zephyr_udc0 { | ||
gs_usb0: gs_usb0 { | ||
compatible = "gs_usb"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CONFIG_TEST=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y | ||
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y | ||
CONFIG_USB_DEVICE_GS_USB_LOG_LEVEL_DBG=y | ||
|
||
CONFIG_SHELL=y | ||
|
||
CONFIG_USB_DEVICE_STACK=y | ||
CONFIG_USB_DEVICE_BOS=y | ||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n | ||
CONFIG_USB_COMPOSITE_DEVICE=y | ||
|
||
CONFIG_CAN=y | ||
CONFIG_CAN_FD_MODE=y | ||
|
||
CONFIG_USB_DEVICE_GS_USB_MAX_CHANNELS=4 | ||
CONFIG_USB_DEVICE_GS_USB_IDENTIFICATION=y | ||
CONFIG_USB_DEVICE_GS_USB_TIMESTAMP=y | ||
CONFIG_USB_DEVICE_GS_USB_TERMINATION=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CONFIG_TEST=y | ||
# Some usbd_next drivers suffer from calling mutexes in ISR context. Disable asserts until fixed | ||
# upstream. | ||
#CONFIG_ASSERT=n | ||
|
||
CONFIG_LOG=y | ||
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y | ||
CONFIG_USBD_LOG_LEVEL_WRN=y | ||
CONFIG_USBD_GS_USB_LOG_LEVEL_DBG=y | ||
|
||
CONFIG_SHELL=y | ||
|
||
CONFIG_USB_DEVICE_STACK_NEXT=y | ||
|
||
CONFIG_CAN=y | ||
CONFIG_CAN_FD_MODE=y | ||
|
||
CONFIG_USBD_GS_USB_MAX_CHANNELS=4 | ||
CONFIG_USBD_GS_USB_IDENTIFICATION=y | ||
CONFIG_USBD_GS_USB_TIMESTAMP=y | ||
CONFIG_USBD_GS_USB_TERMINATION=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright (c) 2024 Henrik Brix Andersen <[email protected]> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
""" | ||
Configuration of gs_usb test suite. | ||
""" | ||
|
||
import re | ||
import logging | ||
import time | ||
import pytest | ||
|
||
from twister_harness import DeviceAdapter, Shell | ||
from gs_usb import GsUSB | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def pytest_addoption(parser) -> None: | ||
"""Add local parser options to pytest.""" | ||
parser.addoption('--usb-delay', default=5, | ||
help='Delay to wait for USB enumeration after flashing (default: 5 seconds)') | ||
parser.addoption('--usb-sn', default=None, | ||
help='USB serial number of the DUT (default: None)') | ||
|
||
@pytest.fixture(name='usb_vid', scope='module') | ||
def fixture_usb_vid(shell: Shell) -> int: | ||
"""Return the USB VID used by the DUT.""" | ||
regex = re.compile(r'USB VID:\s+(\S+)') | ||
lines = shell.get_filtered_output(shell.exec_command('gs_usb vid')) | ||
|
||
for line in lines: | ||
m = regex.match(line) | ||
if m: | ||
vid = int(m.groups()[0], 16) | ||
return vid | ||
|
||
pytest.fail('USB VID not found') | ||
return 0x0000 | ||
|
||
@pytest.fixture(name='usb_pid', scope='module') | ||
def fixture_usb_pid(shell: Shell) -> int: | ||
"""Return the USB PID used by the DUT.""" | ||
regex = re.compile(r'USB PID:\s+(\S+)') | ||
lines = shell.get_filtered_output(shell.exec_command('gs_usb pid')) | ||
|
||
for line in lines: | ||
m = regex.match(line) | ||
if m: | ||
pid = int(m.groups()[0], 16) | ||
return pid | ||
|
||
pytest.fail('USB PID not found') | ||
return 0x0000 | ||
|
||
@pytest.fixture(name='usb_sn', scope='module') | ||
def fixture_usb_sn(request, dut: DeviceAdapter) -> str: | ||
"""Return the USB serial number used by the DUT.""" | ||
|
||
sn = request.config.getoption('--usb-sn') | ||
|
||
if sn is None: | ||
for fixture in dut.device_config.fixtures: | ||
if fixture.startswith('usb:'): | ||
sn = fixture.split(sep=':', maxsplit=1)[1] | ||
break | ||
|
||
if sn is not None: | ||
logger.info('using USB S/N: "%s"', sn) | ||
|
||
return sn | ||
|
||
@pytest.fixture(name='dev', scope='module') | ||
def fixture_gs_usb(request, usb_vid: int, usb_pid: int, usb_sn: str) -> GsUSB: | ||
"""Return gs_usb instance for testing""" | ||
|
||
delay = request.config.getoption('--usb-delay') | ||
logger.info('Waiting %d seconds for USB enumeration...', delay) | ||
time.sleep(delay) | ||
|
||
return GsUSB(usb_vid, usb_pid, usb_sn) |
Oops, something went wrong.