From: Andreas Reichel <[email protected]> Register three user variables, add two of them to the registry of the garbage collector and call finalize to check if the third remains and the registered ones are deleted.
Signed-off-by: Andreas Reichel <[email protected]> --- tools/tests/test_ebgenv_api.c | 53 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/tools/tests/test_ebgenv_api.c b/tools/tests/test_ebgenv_api.c index 533b50b..d99dc91 100644 --- a/tools/tests/test_ebgenv_api.c +++ b/tools/tests/test_ebgenv_api.c @@ -615,6 +615,56 @@ START_TEST(ebgenv_api_ebg_env_close) } END_TEST +START_TEST(ebgenv_api_ebg_env_gc_register_var) +{ + ebgenv_t e; + int ret; + memset(&e, 0, sizeof(e)); + + bgenv_write_fake.return_val = true; + bgenv_close_fake.return_val = true; + + bgenv_init_fake.return_val = true; + + for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) { + envdata[i].revision = i + 1; + } + + ret = ebg_env_create_new(&e); + + /* Create three user variables VarA, VarB and VarC */ + ebg_env_set(&e, "VarA", "TestA"); + ebg_env_set(&e, "VarB", "TestB"); + ebg_env_set(&e, "VarC", "TestC"); + + /* Check if variables exist */ + int res; + res = ebg_env_get(&e, "VarA", NULL); + ck_assert_int_eq(res, strlen("TestA") + 1); + res = ebg_env_get(&e, "VarB", NULL); + ck_assert_int_eq(res, strlen("TestB") + 1); + res = ebg_env_get(&e, "VarC", NULL); + ck_assert_int_eq(res, strlen("TestC") + 1); + + /* Register variables for deletion */ + ebg_env_gc_register_var(&e, "VarA"); + ebg_env_gc_register_var(&e, "VarC"); + + ebg_env_finalize_update(&e); + + /* Check if variables are deleted */ + res = ebg_env_get(&e, "VarA", NULL); + ck_assert_int_eq(res, -EINVAL); + res = ebg_env_get(&e, "VarB", NULL); + ck_assert_int_eq(res, strlen("TestB") + 1); + res = ebg_env_get(&e, "VarC", NULL); + ck_assert_int_eq(res, -EINVAL); + + ebg_env_close(&e); + +} +END_TEST + Suite *ebg_test_suite(void) { Suite *s; @@ -632,7 +682,8 @@ Suite *ebg_test_suite(void) ebgenv_api_ebg_env_user_free, ebgenv_api_ebg_env_getglobalstate, ebgenv_api_ebg_env_setglobalstate, - ebgenv_api_ebg_env_close + ebgenv_api_ebg_env_close, + ebgenv_api_ebg_env_gc_register_var }; tc_core = tcase_create("Core"); -- 2.16.2 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/20180312171044.16058-4-andreas.reichel.ext%40siemens.com. For more options, visit https://groups.google.com/d/optout.
