Skip to content

Commit

Permalink
tests UPDATE possible to adjust test dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed May 23, 2024
1 parent f2fad83 commit 6a6b461
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 9 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
8 changes: 4 additions & 4 deletions tests/np2_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
9 changes: 3 additions & 6 deletions tests/np2_test_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 6a6b461

Please sign in to comment.