Skip to content

Commit

Permalink
unit-tests: switch to xmalloc, FREE_SAFE
Browse files Browse the repository at this point in the history
  • Loading branch information
agardijan committed Sep 6, 2022
1 parent 5ca6c64 commit a03bc13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tests/interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(INTERFACES_UTEST_NAME "interfaces_utest")
set(UTILS_MEMORY_LIBRARY_NAME "utils_memory")

add_executable(
${INTERFACES_UTEST_NAME}
Expand All @@ -9,12 +10,18 @@ target_include_directories(
${INTERFACES_UTEST_NAME}
PUBLIC ${CMAKE_SOURCE_DIR}/src/interfaces/src
)
add_library(
${UTILS_MEMORY_LIBRARY_NAME}
STATIC
${CMAKE_SOURCE_DIR}/src/utils/memory.c
)
target_link_libraries(
${INTERFACES_UTEST_NAME}

${CMOCKA_LIBRARIES}
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${UTILS_MEMORY_LIBRARY_NAME}
)
add_test(
NAME ${INTERFACES_UTEST_NAME}
Expand Down
7 changes: 5 additions & 2 deletions tests/interfaces/interfaces_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <errno.h>
#include <unistd.h>

/* xmalloc, FREE_SAFE */
#include "utils/memory.h"

/* load api */
#include "plugin/api/interfaces/load.h"

Expand All @@ -29,7 +32,7 @@ int main(void)

static int setup(void **state)
{
interfaces_ctx_t *ctx = malloc(sizeof(interfaces_ctx_t));
interfaces_ctx_t *ctx = xmalloc(sizeof(interfaces_ctx_t));
if (!ctx) {
return -1;
}
Expand All @@ -43,7 +46,7 @@ static int setup(void **state)
static int teardown(void **state)
{
if (*state) {
free(*state);
FREE_SAFE(*state);
}

return 0;
Expand Down

0 comments on commit a03bc13

Please sign in to comment.