Skip to content

Commit

Permalink
start test impl
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Jul 24, 2024
1 parent c310274 commit b1b88cd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
17 changes: 17 additions & 0 deletions tests/robot/libraries/serial_keywords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging
import serial
from usb_keywords import find_port_name_from_USB_ids
from robot.libraries.BuiltIn import BuiltIn


def a_serial_connection_to_the_device_is_opened():

port_name = find_port_name_from_USB_ids(0x16c0, 0x05E1)
logging.info(f"Try to open port: {port_name}")

ser = serial.Serial(port_name, 9600, timeout=1)
ser.open()

BuiltIn().set_global_variable('${SERIAL}', ser)


27 changes: 26 additions & 1 deletion tests/robot/libraries/usb_keywords.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import serial
import logging
import serial.tools.list_ports

from robot.libraries.BuiltIn import BuiltIn


###############################################################################

def I_list_all_the_USB_devices():
pass
devices_object = []
devices = serial.tools.list_ports.comports()
for device in devices:
devices_object.append({
"port_name": device.device,
"pid": device.pid,
"vid": device.vid,
"serial_number": device.serial_number
})
logging.debug("All devices: ", devices_object)
BuiltIn().set_global_variable('${ALL_DEVICES}', devices_object)

###############################################################################

def find_port_name_from_USB_ids(vid, pid):
devices = serial.tools.list_ports.comports()
for device in devices:
if device.vid == vid and device.pid == pid:
return device.device
return None

###############################################################################

10 changes: 8 additions & 2 deletions tests/robot/picoha-dio/2-robustness.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ Test Teardown Main Test Platform Cleanup
*** Test Cases ***

Test corrupted data
Given a serial connection to the device
Given A serial connection to the device is opened
When I send "100" random bytes to the device
Then the device must still be able to respond correctly
Then The device must still be able to respond correctly

*** Keywords ***

# A serial connection to the device is opened


I send "${number_of_bytes}" random bytes to the device
Log message: ${number_of_bytes}
Log need to implement



1 change: 1 addition & 0 deletions tests/robot/platform/local/platform.resource
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Variables platform_data.py

# All Library must be imported here
Library usb_keywords.py
Library serial_keywords.py

*** Keywords ***

Expand Down
3 changes: 3 additions & 0 deletions tests/robot/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pip install -r requirements.txt
pyserial==3.4

0 comments on commit b1b88cd

Please sign in to comment.