Skip to content

Commit 7b432a7

Browse files
author
noname
committedFeb 17, 2024
Add sys reset to tests
1 parent 3f6256d commit 7b432a7

6 files changed

+21
-46
lines changed
 

‎helper.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import sys
2+
import time
23
import string
34
import random
5+
import pytest
46
import serial.tools.list_ports
7+
from msg import tiny_frame
58
from msg import proto_i2c_msg as pm
9+
from msg import proto_ctrl_msg as ctrl_pm
610

711

812
def print_error(*args, **kwargs):
@@ -18,6 +22,17 @@ def get_com_port() -> str:
1822
raise Exception("No Serial Port found!")
1923

2024

25+
@pytest.fixture()
26+
def serial_port():
27+
with serial.Serial(get_com_port(), 115200, timeout=1) as ser:
28+
tiny_frame.tf_init(ser.write)
29+
ctrl_pm.CtrlInterface.send_system_reset_msg()
30+
time.sleep(2)
31+
32+
with serial.Serial(get_com_port(), 115200, timeout=1) as ser:
33+
yield ser
34+
35+
2136
def generate_ascii_data(min_size: int, max_size: int) -> bytes:
2237
size = random.randint(min_size, max_size)
2338
tx_data = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(size))

‎test_Gpio.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@
44
"""
55

66
import pytest
7-
import serial
87
from msg import tiny_frame
98
from msg import proto_gpio_msg as pm
10-
from helper import get_com_port
11-
12-
13-
@pytest.fixture()
14-
def serial_port():
15-
with serial.Serial(get_com_port(), 115200, timeout=1) as ser:
16-
yield ser
9+
from helper import serial_port
1710

1811

1912
class TestGpio:
20-
REQUEST_COUNT = 1000
13+
REQUEST_COUNT = 10000
2114

2215
def setup_class(self):
2316
self.reverse = False

‎test_I2cMaster.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@
33
""" Testing I2c master write/read
44
"""
55

6-
import pytest
7-
import serial
86
from msg import tiny_frame
97
from msg import proto_i2c_msg as pm
10-
from helper import (get_com_port, generate_master_write_read_requests,
8+
from helper import (serial_port, generate_master_write_read_requests,
119
i2c_send_master_request, verify_master_write_read_requests)
1210

1311

14-
@pytest.fixture()
15-
def serial_port():
16-
with serial.Serial(get_com_port(), 115200, timeout=1) as ser:
17-
yield ser
18-
19-
2012
class TestI2cMaster:
2113
REQUEST_COUNT = 4 * 1000
2214
DATA_SIZE_MIN = 1

‎test_I2cMasterSlave.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
"""
55

66
import pytest
7-
import serial
87
from msg import tiny_frame
98
from msg import proto_i2c_msg as pm
10-
from helper import (get_com_port, generate_master_write_read_requests,
9+
from helper import (serial_port, generate_master_write_read_requests,
1110
i2c_send_master_request, verify_master_write_read_requests)
1211

1312

14-
@pytest.fixture()
15-
def serial_port():
16-
with serial.Serial(get_com_port(), 115200, timeout=1) as ser:
17-
yield ser
18-
19-
2013
class TestI2cMasterSlave:
2114
REQUEST_COUNT = 4 * 1000
2215
DATA_SIZE_MIN = 1

‎test_I2cSlave.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
""" Testing I2c slave write and read memory updates (no physical I2c communication involved)
44
"""
55

6-
import pytest
7-
import serial
86
import random
97
from msg import tiny_frame
108
from msg import proto_i2c_msg as pm
11-
from helper import get_com_port, generate_ascii_data
12-
13-
14-
@pytest.fixture()
15-
def serial_port():
16-
with serial.Serial(get_com_port(), 115200, timeout=1) as ser:
17-
yield ser
9+
from helper import serial_port, generate_ascii_data
1810

1911

2012
class TestI2cSlave:

‎test_UsbCom.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,8 @@
33
""" Testing USB communication with tinyframe in a loop
44
"""
55

6-
import pytest
7-
import serial
8-
import time
96
from msg import tiny_frame
10-
from msg import proto_ctrl_msg as ctrl_pm
11-
from helper import get_com_port, generate_ascii_data
12-
13-
14-
@pytest.fixture()
15-
def serial_port():
16-
with serial.Serial(get_com_port(), 115200, timeout=1) as ser:
17-
yield ser
7+
from helper import serial_port, generate_ascii_data
188

199

2010
def tiny_frame_receive_cb(_, tf_msg):

0 commit comments

Comments
 (0)
Please sign in to comment.