|
| 1 | +########################################################################################## |
| 2 | +# Copyright (c) 2025 Nordic Semiconductor |
| 3 | +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 4 | +########################################################################################## |
| 5 | + |
| 6 | +import os |
| 7 | +import pytest |
| 8 | +import time |
| 9 | +from utils.flash_tools import flash_device, reset_device |
| 10 | +import sys |
| 11 | +sys.path.append(os.getcwd()) |
| 12 | +from utils.logger import get_logger |
| 13 | + |
| 14 | +logger = get_logger() |
| 15 | + |
| 16 | +CLOUD_TIMEOUT = 60 * 3 |
| 17 | +DEFAULT_UPDATE_INTERVAL = 600 |
| 18 | +TEST_UPDATE_INTERVAL = 150 |
| 19 | + |
| 20 | +def test_config(dut_cloud, hex_file): |
| 21 | + ''' |
| 22 | + Test that verifies shadow changes are applied c2d and d2c. |
| 23 | + ''' |
| 24 | + flash_device(os.path.abspath(hex_file)) |
| 25 | + dut_cloud.uart.xfactoryreset() |
| 26 | + dut_cloud.uart.flush() |
| 27 | + reset_device() |
| 28 | + dut_cloud.uart.wait_for_str("Connected to Cloud", timeout=120) |
| 29 | + |
| 30 | + dut_cloud.cloud.patch_update_interval(dut_cloud.device_id, interval=TEST_UPDATE_INTERVAL) |
| 31 | + dut_cloud.uart.wait_for_str(f"main: Received new interval: {TEST_UPDATE_INTERVAL} seconds", timeout=120) |
| 32 | + |
| 33 | + # # Wait for shadow to be reported to cloud |
| 34 | + start = time.time() |
| 35 | + try: |
| 36 | + while time.time() - start < CLOUD_TIMEOUT: |
| 37 | + time.sleep(5) |
| 38 | + try: |
| 39 | + device = dut_cloud.cloud.get_device(dut_cloud.device_id) |
| 40 | + device_state = device["state"] |
| 41 | + update_interval = device_state["reported"]["config"]["update_interval"] |
| 42 | + except Exception as e: |
| 43 | + pytest.skip(f"Unable to retrieve device state from cloud, e: {e}") |
| 44 | + |
| 45 | + logger.debug(f"Device state: {device_state}") |
| 46 | + if update_interval == TEST_UPDATE_INTERVAL: |
| 47 | + break |
| 48 | + else: |
| 49 | + logger.debug("No correct interval update reported yet, retrying...") |
| 50 | + continue |
| 51 | + else: |
| 52 | + raise RuntimeError(f"No correct update interval reported back to cloud, desired {TEST_UPDATE_INTERVAL}, reported {update_interval}") |
| 53 | + finally: |
| 54 | + # Back to default interval no matter what |
| 55 | + dut_cloud.cloud.patch_update_interval(dut_cloud.device_id, interval=DEFAULT_UPDATE_INTERVAL) |
0 commit comments