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

hil: ota: add test for observation after restart #506

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/hil/platform/zephyr/boards/nrf52840dk_nrf52840.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ CONFIG_WIFI_ESP_AT_MDM_RX_BUF_COUNT=40
CONFIG_NET_L2_WIFI_SHELL=y
CONFIG_GOLIOTH_SAMPLE_WIFI=y

CONFIG_NET_PKT_TX_COUNT=8
CONFIG_NET_PKT_TX_COUNT=12
31 changes: 31 additions & 0 deletions tests/hil/tests/ota/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ LOG_TAG_DEFINE(test_ota);
static golioth_sys_sem_t connected_sem;
static golioth_sys_sem_t reason_test_sem;
static golioth_sys_sem_t block_test_sem;
static golioth_sys_sem_t restart_test_sem;

static bool client_has_been_restarted = false;

#define GOLIOTH_OTA_REASON_CNT 10
#define GOLIOTH_OTA_STATE_CNT 4
Expand All @@ -24,6 +27,7 @@ static golioth_sys_sem_t block_test_sem;
#define DUMMY_VER_SAME "1.2.3"
#define DUMMY_VER_UPDATE "1.2.4"
#define DUMMY_VER_EXTRA "1.2.5"
#define DUMMY_VER_RESTART "1.2.6"

static uint8_t callback_arg = 17;
static uint8_t block_buf[GOLIOTH_OTA_BLOCKSIZE];
Expand Down Expand Up @@ -168,6 +172,24 @@ static void test_block_ops(void)
}
}

static void test_restart(void)
{

if (!client_has_been_restarted)
{
golioth_client_stop(client);
golioth_sys_msleep(3000);
GLTH_LOGI(TAG, "Restarting Client");
client_has_been_restarted = true;
golioth_client_start(client);
}
else
{
GLTH_LOGI(TAG, "Restart successful");
client_has_been_restarted = false;
}
}

static void on_manifest(struct golioth_client *client,
const struct golioth_response *response,
const char *path,
Expand Down Expand Up @@ -225,6 +247,10 @@ static void on_manifest(struct golioth_client *client,
{
golioth_sys_sem_give(reason_test_sem);
}
else if (strcmp(main->version, DUMMY_VER_RESTART) == 0)
{
golioth_sys_sem_give(restart_test_sem);
}
}
}

Expand All @@ -243,6 +269,7 @@ void hil_test_entry(const struct golioth_client_config *config)
connected_sem = golioth_sys_sem_create(1, 0);
reason_test_sem = golioth_sys_sem_create(1, 0);
block_test_sem = golioth_sys_sem_create(1, 0);
restart_test_sem = golioth_sys_sem_create(1, 0);

golioth_debug_set_cloud_log_enabled(false);

Expand All @@ -263,6 +290,10 @@ void hil_test_entry(const struct golioth_client_config *config)
{
test_block_ops();
}
if (golioth_sys_sem_take(restart_test_sem, 0))
{
test_restart();
}

golioth_sys_msleep(100);
}
Expand Down
14 changes: 13 additions & 1 deletion tests/hil/tests/ota/test_ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
DUMMY_VER_SAME = '1.2.3'
DUMMY_VER_UPDATE = '1.2.4'
DUMMY_VER_EXTRA = '1.2.5'
DUMMY_VER_RESTART = '1.2.6'
MULTI_PACKAGE = 'walrus'
MULTI_PACKAGE_VER = '0.4.2'

Expand Down Expand Up @@ -82,8 +83,10 @@ async def artifacts(project):
artifacts["test_multiple"] = a
elif a.version == MULTI_PACKAGE_VER and a.package == MULTI_PACKAGE:
artifacts["multi_artifact"] = a
elif a.version == DUMMY_VER_RESTART and a.package == UPDATE_PACKAGE:
artifacts["test_restart"] = a

assert len(artifacts) == 5
assert len(artifacts) == 6

return artifacts

Expand All @@ -95,6 +98,7 @@ async def releases(project, artifacts, tag):
releases["test_multiple"] = await project.releases.create([artifacts["test_multiple"].id, artifacts["multi_artifact"].id], [], [tag.id], False)
releases["test_blocks"] = await project.releases.create([artifacts["test_blocks"].id], [], [tag.id], False)
releases["test_reasons"] = await project.releases.create([artifacts["test_reasons"].id], [], [tag.id], False)
releases["test_restart"] = await project.releases.create([artifacts["test_restart"].id], [], [tag.id], False)
yield releases

# Clean Up
Expand Down Expand Up @@ -157,6 +161,14 @@ async def test_multiple_artifacts(artifacts, board, project, releases):

verify_component_values(board, artifacts["multi_artifact"].info)

async def test_restart(artifacts, board, project, releases):
await project.releases.rollout_set(releases["test_restart"].id, True)

assert None != board.wait_for_regex_in_line('Found main component', timeout_s=30)
assert None != board.wait_for_regex_in_line('Ending session', timeout_s=10)
assert None != board.wait_for_regex_in_line('Found main component', timeout_s=60)
assert None != board.wait_for_regex_in_line('Restart successful', timeout_s=2)

async def test_block_operations(board, project, releases):
await project.releases.rollout_set(releases["test_blocks"].id, True)
assert None != board.wait_for_regex_in_line(f"golioth_ota_size_to_nblocks: {TEST_BLOCK_CNT + 1}", timeout_s=12)
Expand Down
Loading