Skip to content

Commit

Permalink
Refactor tests to support ENV_NUM_CONFIG_PARTS == 1
Browse files Browse the repository at this point in the history
Work around the absence of a spare slot when there is only
one configuration slot

Signed-off-by: Earl Chew <[email protected]>
[Jan: rewrapped to 80 chars, reduced scope of bufferw]
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
earlchew authored and jan-kiszka committed Jul 17, 2023
1 parent 9dadbe7 commit a621bd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 19 additions & 9 deletions tools/tests/test_ebgenv_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ START_TEST(ebgenv_api_ebg_env_create_new)
{
ebgenv_t e;
int ret;
char16_t bufferw[10];
char buffer[10];
char *kernelfile = "kernel123";
char *kernelparams = "param456";
int watchdogtimeout = 44;

memset(&e, 0, sizeof(e));
memset(envdata, 0, sizeof(envdata));
Expand All @@ -110,13 +110,22 @@ START_TEST(ebgenv_api_ebg_env_create_new)
* environment is created. The new environment must overwrite the
* oldest environment and revision and ustate must be set correctly.
*/
envdata[ENV_NUM_CONFIG_PARTS-1].watchdog_timeout_sec = 44;
(void)str8to16(bufferw, kernelfile);
memcpy(envdata[ENV_NUM_CONFIG_PARTS-1].kernelfile, bufferw,
strlen(kernelfile) * 2 + 2);
(void)str8to16(bufferw, kernelparams);
memcpy(envdata[ENV_NUM_CONFIG_PARTS-1].kernelparams, bufferw,
strlen(kernelparams) * 2 + 2);
if (ENV_NUM_CONFIG_PARTS > 1) {
char16_t bufferw[10];

envdata[ENV_NUM_CONFIG_PARTS-1].watchdog_timeout_sec =
watchdogtimeout;
(void)str8to16(bufferw, kernelfile);
memcpy(envdata[ENV_NUM_CONFIG_PARTS-1].kernelfile, bufferw,
strlen(kernelfile) * 2 + 2);
(void)str8to16(bufferw, kernelparams);
memcpy(envdata[ENV_NUM_CONFIG_PARTS-1].kernelparams, bufferw,
strlen(kernelparams) * 2 + 2);
} else {
kernelfile = "";
kernelparams = "";
watchdogtimeout = 0;
}
errno = 0;

bgenv_init_fake.return_val = true;
Expand All @@ -132,7 +141,8 @@ START_TEST(ebgenv_api_ebg_env_create_new)
((BGENV *)e.bgenv)->data->revision, ENV_NUM_CONFIG_PARTS+1);

ck_assert_int_eq(((BGENV *)e.bgenv)->data->ustate, USTATE_OK);
ck_assert_int_eq(((BGENV *)e.bgenv)->data->watchdog_timeout_sec, 44);
ck_assert_int_eq(((BGENV *)e.bgenv)->data->watchdog_timeout_sec,
watchdogtimeout);
(void)str16to8(buffer, ((BGENV *)e.bgenv)->data->kernelfile);
ck_assert_int_eq(strcmp(buffer, kernelfile), 0);
(void)str16to8(buffer, ((BGENV *)e.bgenv)->data->kernelparams);
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/test_ebgenv_api_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ START_TEST(ebgenv_api_internal_bgenv_create_new)
ck_assert(handle != NULL);
ck_assert(handle->data == &envdata[max-1]);
ck_assert(envdata[max-1].revision == max+1);
ck_assert(envdata[max-1].watchdog_timeout_sec == 30);
ck_assert(envdata[max-1].watchdog_timeout_sec == (max == 1 ? 0 : 30));

free(handle);
}
Expand Down

0 comments on commit a621bd9

Please sign in to comment.