Skip to content

Commit

Permalink
hil: ota: add test for observation after restart
Browse files Browse the repository at this point in the history
Test that the firmware update observation is reestablished after a client
restart.

Signed-off-by: Mike Szczys <[email protected]>
  • Loading branch information
szczys committed May 29, 2024
1 parent 91525a7 commit be677d4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
28 changes: 28 additions & 0 deletions tests/hil/tests/ota/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ 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 golioth_sys_sem_t restart_in_progress_sem;

#define GOLIOTH_OTA_REASON_CNT 10
#define GOLIOTH_OTA_STATE_CNT 4
Expand All @@ -24,6 +26,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 +171,21 @@ static void test_block_ops(void)
}
}

static void test_restart(void)
{

if (golioth_sys_sem_take(restart_in_progress_sem, 0)) {
golioth_client_stop(client);
golioth_sys_msleep(3000);
GLTH_LOGI(TAG, "Restarting Client");
golioth_client_start(client);
}
else {
GLTH_LOGI(TAG, "Restart successful");
golioth_sys_sem_give(restart_in_progress_sem);
}
}

static void on_manifest(struct golioth_client *client,
const struct golioth_response *response,
const char *path,
Expand Down Expand Up @@ -225,6 +243,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 +265,8 @@ 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);
restart_in_progress_sem = golioth_sys_sem_create(1, 1);

golioth_debug_set_cloud_log_enabled(false);

Expand All @@ -263,6 +287,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=30)
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

0 comments on commit be677d4

Please sign in to comment.