Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: nightly: Fix and add more tests #84

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/on_target/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Run desired tests, example commands
```shell
pytest -s -v -m "not slow" tests
pytest -s -v -m "not slow" tests/test_functional/test_uart_output.py
pytest -s -v -m "not slow" tests/test_functional/test_location.py::test_wifi_location
pytest -s -v -m "not slow" tests/test_functional/test_sampling.py
pytest -s -v -m "slow" tests/test_functional/test_fota.py::test_full_mfw_fota
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,40 @@

logger = get_logger()

def test_wifi_location(t91x_board, hex_file):
'''
Test that the device can get location using Wi-Fi
'''
run_location(t91x_board, hex_file, location_method="Wi-Fi")

@pytest.mark.skip(reason="GNSS location is not supported on this device")
def test_gnss_location(t91x_board, hex_file):
'''
Test that the device can get location using GNSS
'''
run_location(t91x_board, hex_file, location_method="GNSS")

def run_location(t91x_board, hex_file, location_method):
def test_sampling(t91x_board, hex_file):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring of the test function from location-specific tests to a more general sampling test is appropriate given the changes in the location library. However, ensure that the new test adequately covers all necessary functionality previously tested.

flash_device(os.path.abspath(hex_file))
t91x_board.uart.xfactoryreset()
patterns_cloud_connection = [
"Network connectivity established",
"Connected to Cloud"
]

patterns_location = ["Wi-Fi and cellular methods combined"] if location_method == "Wi-Fi" else []
patterns_location = patterns_location + [
"location_event_handler: Got location: lat:"]
# Log patterns
pattern_location = "location_event_handler: Got location: lat:"
pattern_shadow_poll = "Requesting device shadow from the device"
pattern_environmental = "Environmental values sample request received, getting data"
pattern_fota_poll = "Checking for FOTA job..."
pattern_battery = "State of charge:"

# Combine patterns for convenience
pattern_list = [
pattern_location,
pattern_shadow_poll,
pattern_environmental,
pattern_fota_poll,
pattern_battery
]

# Cloud connection
t91x_board.uart.flush()
reset_device()
t91x_board.uart.wait_for_str(patterns_cloud_connection, timeout=120)

# Location
t91x_board.uart.wait_for_str(patterns_location, timeout=180)
# Sampling
t91x_board.uart.wait_for_str(pattern_list, timeout=60)

# Extract coordinates from UART output
values = t91x_board.uart.extract_value( \
r"location_event_handler: Got location: lat: ([\d.]+), lon: ([\d.]+), acc: ([\d.]+), method: ([\d.]+)")
assert values
lat, lon, acc, method = values
assert abs(float(lat) - 61.5) < 2 and abs(float(lon) - 10.5) < 1
method = int(method)
expected_method = 4 if location_method == "Wi-Fi" else 1
assert method == expected_method
4 changes: 2 additions & 2 deletions tests/on_target/utils/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def wait_for_str_ordered(
break
if start_t + timeout < time.time():
raise AssertionError(
f"{missing if missing else msgs} missing in UART log in the expected order. {error_msg}\nUart log:\n{self.log}"
f"{missing if missing else msgs} missing in UART log in the expected order. {error_msg}"
)
if self._evt.is_set():
raise RuntimeError(f"Uart thread stopped, log:\n{self.log}")
Expand All @@ -210,7 +210,7 @@ def wait_for_str(self, msgs: Union[str, list], error_msg: str = "", timeout: int
if missing_msgs == []:
return self.get_size()
if start_t + timeout < time.time():
raise AssertionError(f"{missing_msgs} missing in UART log. {error_msg}\nUart log:\n{self.log}")
raise AssertionError(f"{missing_msgs} missing in UART log. {error_msg}\n")
if self._evt.is_set():
raise RuntimeError(f"Uart thread stopped, log:\n{self.log}")
time.sleep(1)
Expand Down
Loading