[PATCH] Refactor tests to support ENV_NUM_CONFIG_PARTS == 1

13 views
Skip to first unread message

Earl Chew

unread,
Jul 15, 2023, 11:44:15 AM7/15/23
to efibootg...@googlegroups.com, Earl Chew
Work around the absence of a spare slot when there is only
one configuration slot

Signed-off-by: Earl Chew <earl...@yahoo.com>
---
tools/tests/test_ebgenv_api.c | 23 +++++++++++++++--------
tools/tests/test_ebgenv_api_internal.c | 2 +-
2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/tools/tests/test_ebgenv_api.c b/tools/tests/test_ebgenv_api.c
index 8efa9d3..a248989 100644
--- a/tools/tests/test_ebgenv_api.c
+++ b/tools/tests/test_ebgenv_api.c
@@ -91,6 +91,7 @@ START_TEST(ebgenv_api_ebg_env_create_new)
char buffer[10];
char *kernelfile = "kernel123";
char *kernelparams = "param456";
+ int watchdogtimeout = 44;

memset(&e, 0, sizeof(e));
memset(envdata, 0, sizeof(envdata));
@@ -110,13 +111,19 @@ 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) {
+ 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;
@@ -132,7 +139,7 @@ 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);
diff --git a/tools/tests/test_ebgenv_api_internal.c b/tools/tests/test_ebgenv_api_internal.c
index 1ed1d99..6a3d816 100644
--- a/tools/tests/test_ebgenv_api_internal.c
+++ b/tools/tests/test_ebgenv_api_internal.c
@@ -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);
}
--
2.39.1

Jan Kiszka

unread,
Jul 17, 2023, 6:32:27 AM7/17/23
to Earl Chew, efibootg...@googlegroups.com
Thanks, applied with minor rewrappings to 80 chars.

Curious: Which corners of EBG are you testing here?

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Jan Kiszka

unread,
Jul 17, 2023, 6:53:56 AM7/17/23
to Earl Chew, efibootg...@googlegroups.com
+ scope reduction of a local var because cppcheck started to complain.
Please run full tests in the future.

Earl Chew

unread,
Jul 17, 2023, 10:11:47 AM7/17/23
to Jan Kiszka, efibootg...@googlegroups.com
Jan,

> Please run full tests in the future.


I was following guidance in
https://github.com/siemens/efibootguard/blob/master/docs/COMPILE.md#testing

Is there additional guidance you can point me at for contributions?

Earl

Earl Chew

unread,
Jul 17, 2023, 10:22:35 AM7/17/23
to Jan Kiszka, efibootg...@googlegroups.com
Jan

> Curious: Which corners of EBG are you testing here?

I'm working the configuration options --with-num-config-parts and
--with-mem-uservars to suit my use case.

I have a couple more relatively minor refactoring changes for
consideration, but I'll wait for some guidance regarding the
testing regime before proceeding.

I'm working my way up to my suggestion for decoupling from zlib:

https://groups.google.com/g/efibootguard-dev/c/PaLhKj1nFPc


Earl

Jan Kiszka

unread,
Jul 18, 2023, 1:52:22 AM7/18/23
to Earl Chew, efibootg...@googlegroups.com
On 17.07.23 16:11, 'Earl Chew' via EFI Boot Guard wrote:
> Jan,
>
>> Please run full tests in the future.
>
>
> I was following guidance in
> https://github.com/siemens/efibootguard/blob/master/docs/COMPILE.md#testing
>
> Is there additional guidance you can point me at for contributions?

Ouch, we are missing the hint to cppcheck there. It's part of the github
workflows
(https://github.com/siemens/efibootguard/blob/master/.github/workflows/main.yaml#L162).
Reply all
Reply to author
Forward
0 new messages