From c703a29aa3d3938ad5780aa0c2efeec7b527b392 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Mon, 20 May 2024 14:55:25 +0200 Subject: [PATCH] tests UPDATE use only absolute paths Drops the requirement for the tests to be run only from binary dir. --- tests/np_test.c | 18 +++++++----------- tests/np_test_config.h.in | 8 ++++---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tests/np_test.c b/tests/np_test.c index f7424395..80328838 100644 --- a/tests/np_test.c +++ b/tests/np_test.c @@ -138,17 +138,6 @@ np_glob_setup_np2(void **state, const char *test_name, const char **modules) char str[256], server_dir[256], extdata_path[256], sock_path[256], pidfile_path[256]; int fd, pipefd[2], buf; - if (!getcwd(str, 256)) { - SETUP_FAIL_LOG; - return 1; - } - if (strcmp(str, NP_BINARY_DIR)) { - printf("Tests must be started from the build directory \"%s\".\n", NP_BINARY_DIR); - printf("CWD = %s\n", str); - SETUP_FAIL_LOG; - return 1; - } - /* sysrepo environment variables must be set by NP_GLOB_SETUP_ENV_FUNC prior */ /* install modules */ if (setenv("NP2_MODULE_DIR", NP_ROOT_DIR "/modules", 1)) { @@ -206,6 +195,13 @@ np_glob_setup_np2(void **state, const char *test_name, const char **modules) /* fork and start the server */ if (!(pid = fork())) { + /* create test dir */ + sprintf(str, "%s/%s", NP_TEST_DIR, test_name); + if ((mkdir(str, 00700) == -1) && (errno != EEXIST)) { + SETUP_FAIL_LOG; + goto child_error; + } + /* open log file */ sprintf(str, "%s/%s/%s", NP_TEST_DIR, test_name, NP_LOG_FILE); fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 00600); diff --git a/tests/np_test_config.h.in b/tests/np_test_config.h.in index b5dc4aa7..44178103 100644 --- a/tests/np_test_config.h.in +++ b/tests/np_test_config.h.in @@ -4,8 +4,8 @@ * @brief test configuration header * * @copyright - * Copyright (c) 2019 - 2022 Deutsche Telekom AG. - * Copyright (c) 2017 - 2022 CESNET, z.s.p.o. + * Copyright (c) 2019 - 2024 Deutsche Telekom AG. + * Copyright (c) 2017 - 2024 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ /* sysrepo SHM prefix */ #define NP_SR_SHM_PREFIX "_tests_np_" -/* path to put test-specific directory into, just relative NP_SR_REPOS_DIR to NP_BINARY_DIR */ -#define NP_TEST_DIR "./tests/repositories" +/* path to put test-specific directory into */ +#define NP_TEST_DIR NP_SR_REPOS_DIR /* server PID file */ #define NP_PID_FILE "np2.pid"