From 6a6b4613a17dda5e8b79cc1afbe2a499a67f6e61 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Thu, 23 May 2024 14:11:04 +0200 Subject: [PATCH] tests UPDATE possible to adjust test dirs --- tests/CMakeLists.txt | 10 +++++++++- tests/np2_test.c | 8 ++++---- tests/np2_test_config.h.in | 9 +++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ea98ad85..366ce6fe 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,6 +8,14 @@ set(CMAKE_MACOSX_RPATH TRUE) # set ROOT_DIR to realpath get_filename_component(ROOT_DIR "${CMAKE_SOURCE_DIR}" REALPATH) +# test directories that can be adjusted +if(NOT NP2_TEST_ROOT_DIR) + set(NP2_TEST_ROOT_DIR @CMAKE_CURRENT_BINARY_DIR@/repositories) +endif() +if(NOT NP2_TEST_MODULE_DIR) + set(NP2_TEST_MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/modules) +endif() + # generate config configure_file("${CMAKE_CURRENT_SOURCE_DIR}/np2_test_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/np2_test_config.h" ESCAPE_QUOTES @ONLY) @@ -103,4 +111,4 @@ set(TESTS ${TESTS} PARENT_SCOPE) set(TEST_SRC ${TEST_SRC} PARENT_SCOPE) set(TEST_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) set(TEST_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) -set(TEST_MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/modules PARENT_SCOPE) +set(TEST_MODULE_DIR ${NP2_TEST_MODULE_DIR} PARENT_SCOPE) diff --git a/tests/np2_test.c b/tests/np2_test.c index 3c5ece74..ae299438 100644 --- a/tests/np2_test.c +++ b/tests/np2_test.c @@ -81,12 +81,12 @@ np2_glob_test_setup_env(const char *test_name) char *sr_repo_path = NULL, *sr_shm_prefix = NULL; /* set sysrepo environment variables */ - sr_repo_path = malloc(strlen(NP_SR_REPOS_DIR) + 1 + strlen(test_name) + 1); + sr_repo_path = malloc(strlen(NP_TEST_DIR) + 1 + strlen(test_name) + 1); if (!sr_repo_path) { SETUP_FAIL_LOG; goto cleanup; } - sprintf(sr_repo_path, "%s/%s", NP_SR_REPOS_DIR, test_name); + sprintf(sr_repo_path, "%s/%s", NP_TEST_DIR, test_name); if (setenv("SYSREPO_REPOSITORY_PATH", sr_repo_path, 1)) { SETUP_FAIL_LOG; goto cleanup; @@ -341,7 +341,7 @@ np2_glob_test_teardown_notif(const char *test_name) struct dirent *ent; /* open notification dir */ - if (asprintf(&path, "%s/%s/data/notif", NP_SR_REPOS_DIR, test_name) == -1) { + if (asprintf(&path, "%s/%s/data/notif", NP_TEST_DIR, test_name) == -1) { return 1; } dir = opendir(path); @@ -353,7 +353,7 @@ np2_glob_test_teardown_notif(const char *test_name) /* remove all notif1 notifications */ while ((ent = readdir(dir))) { if (!strncmp(ent->d_name, "notif1.notif", 12)) { - if (asprintf(&path, "%s/%s/data/notif/%s", NP_SR_REPOS_DIR, test_name, ent->d_name) == -1) { + if (asprintf(&path, "%s/%s/data/notif/%s", NP_TEST_DIR, test_name, ent->d_name) == -1) { closedir(dir); return 1; } diff --git a/tests/np2_test_config.h.in b/tests/np2_test_config.h.in index 1f53a515..7c2df745 100644 --- a/tests/np2_test_config.h.in +++ b/tests/np2_test_config.h.in @@ -22,18 +22,15 @@ /* binary dir */ #define NP_BINARY_DIR "@PROJECT_BINARY_DIR@" -/* sysrepo test repository */ -#define NP_SR_REPOS_DIR "@CMAKE_CURRENT_BINARY_DIR@/repositories" +/* path to put test-specific directory into and to serve as test SR repository */ +#define NP_TEST_DIR "@NP2_TEST_ROOT_DIR@" /* directory with test YANG modules */ -#define NP_TEST_MODULE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/modules" +#define NP_TEST_MODULE_DIR "@NP2_TEST_MODULE_DIR@" /* sysrepo SHM prefix */ #define NP_SR_SHM_PREFIX "_tests_np_" -/* path to put test-specific directory into */ -#define NP_TEST_DIR NP_SR_REPOS_DIR - /* server PID file */ #define NP_PID_FILE "np2.pid"