Skip to content

Commit

Permalink
validation: init: test new odp_log_get_fn() function
Browse files Browse the repository at this point in the history
Test that the new odp_log_get_fn() API function returns the currently
set log function.

Signed-off-by: Jere Leppänen <[email protected]>
  • Loading branch information
JereLeppanen committed Sep 25, 2024
1 parent 0960b5b commit ec45da6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/validation/api/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TESTS = \
init/init_abort.sh \
init/init_log.sh \
init/init_log_thread.sh \
init/init_log_get_fn.sh \
init/init_num_thr.sh \
init/init_feature_enabled.sh \
init/init_feature_disabled.sh \
Expand Down
3 changes: 2 additions & 1 deletion test/validation/api/init/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ EXTRA_DIST = \
init_feature_disabled.sh \
init_log_thread.sh \
init_test_param_init.sh \
init_test_term_abnormal.sh
init_test_term_abnormal.sh \
init_log_get_fn.sh

dist_check_SCRIPTS = $(EXTRA_DIST)

Expand Down
3 changes: 3 additions & 0 deletions test/validation/api/init/init_log_get_fn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
TEST_DIR="${TEST_DIR:-$(dirname $0)/..}/init"
$TEST_DIR/init_main$EXEEXT 9
37 changes: 36 additions & 1 deletion test/validation/api/init/init_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,40 @@ static void init_test_log_thread(void)
CU_ASSERT(ret == 0);
}

static void init_test_log_get_fn(void)
{
int ret;
odp_instance_t instance;
odp_init_t param;

odp_init_param_init(&param);

ret = odp_init_global(&instance, &param, NULL);
CU_ASSERT_FATAL(ret == 0);

ret = odp_init_local(instance, ODP_THREAD_WORKER);
CU_ASSERT_FATAL(ret == 0);

/* Default log function is not NULL. */
odp_log_func_t log_fn_def = odp_log_get_fn();

CU_ASSERT(log_fn_def != NULL);

/* Set log function and check that it was set. */
odp_log_thread_fn_set(my_log_thread_func);
CU_ASSERT(odp_log_get_fn() == my_log_thread_func);

/* Set to NULL and check that the default function is returned. */
odp_log_thread_fn_set(NULL);
CU_ASSERT(odp_log_get_fn() == log_fn_def);

ret = odp_term_local();
CU_ASSERT_FATAL(ret == 0);

ret = odp_term_global(instance);
CU_ASSERT(ret == 0);
}

static void init_test_num_thr(void)
{
int ret;
Expand Down Expand Up @@ -270,7 +304,8 @@ odp_testinfo_t testinfo[] = {
ODP_TEST_INFO(init_test_feature_disabled),
ODP_TEST_INFO(init_test_log_thread),
ODP_TEST_INFO(init_test_param_init),
ODP_TEST_INFO(init_test_term_abnormal)
ODP_TEST_INFO(init_test_term_abnormal),
ODP_TEST_INFO(init_test_log_get_fn),
};

odp_testinfo_t init_suite[] = {
Expand Down

0 comments on commit ec45da6

Please sign in to comment.