Skip to content

Commit

Permalink
feat(tests): add tests for umlua env manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dfranusic committed Oct 6, 2023
1 parent ca9e311 commit 7d7400e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/check_umlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
*/

#include <umink_pkg_config.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
Expand All @@ -25,6 +26,7 @@
#include <unistd.h>
#include <math.h>
#include <cmocka_tests.h>
#include <umlua.h>

// fwd declarations
void umlua_shutdown();
Expand Down Expand Up @@ -127,6 +129,61 @@ umlua_test_signal(void **state)
assert_null(b);
}

// test lua env manager
static struct lua_env_mngr *tmp_lenvm;
struct lua_env_mngr *lenvm_new();
void lenvm_free(struct lua_env_mngr *m);
struct lua_env_d *lenvm_get_envd(struct lua_env_mngr *lem, const char *n);
struct lua_env_d *lenvm_new_envd(struct lua_env_mngr *lem,
struct lua_env_d *env);
bool lenvm_envd_exists(struct lua_env_mngr *lem, const char *n);
void lenvm_process_envs(struct lua_env_mngr *lem,
void (*f)(struct lua_env_d *env));
struct lua_env_d *
lenvm_del_envd(struct lua_env_mngr *lem, const char *n, bool th_safe);

static void
shutdown_envs(struct lua_env_d *env)
{
// cleanup
lenvm_del_envd(tmp_lenvm, env->name, false);
free(env->name);
free(env->path);
free(env->sgnl_perf);
free(env);
}

static void
umlua_test_lenvm(void **state)
{
// new env mngr
tmp_lenvm = lenvm_new();
assert_non_null(tmp_lenvm);

// new dummy env
struct lua_env_d *env = calloc(1, sizeof(struct lua_env_d));
env->name = strdup("test_env_id");
lenvm_new_envd(tmp_lenvm, env);

// exists
bool found = lenvm_envd_exists(tmp_lenvm, "test_env_id");
assert_int_equal(found, 1);

// get
env = lenvm_get_envd(tmp_lenvm, "test_env_id");
assert_non_null(env);
env = lenvm_get_envd(tmp_lenvm, "test_env_id_XX");
assert_null(env);

// doesn't exist
found = lenvm_envd_exists(tmp_lenvm, "test_env_id_XX");
assert_int_equal(found, 0);

// free
lenvm_process_envs(tmp_lenvm, &shutdown_envs);
lenvm_free(tmp_lenvm);
}

static void
signal_match_cb(umplg_sh_t *shd, void *args)
{
Expand Down Expand Up @@ -556,6 +613,7 @@ main(int argc, char **argv)
{
const struct CMUnitTest tests[] = { cmocka_unit_test(umlua_test_env_01),
cmocka_unit_test(umlua_test_signal),
cmocka_unit_test(umlua_test_lenvm),
cmocka_unit_test(umlua_test_user_privs),
cmocka_unit_test(umlua_test_01),
cmocka_unit_test(umlua_test_02),
Expand Down
1 change: 1 addition & 0 deletions test/check_umplg.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static int
umplg_run_dtor(void **state)
{
test_t *data = *state;
umplg_terminate_all(data->m, 0);
umplg_free_mngr(data->m);
umd_destroy(data->umd);
free(data);
Expand Down

0 comments on commit 7d7400e

Please sign in to comment.