[PATCH 3/3] Tests: Add test for finalization garbage collector

1 view
Skip to first unread message

Andreas J. Reichel

unread,
Mar 12, 2018, 1:14:17 PM3/12/18
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

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 <andreas.r...@siemens.com>
---
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

Reply all
Reply to author
Forward
0 new messages