diff --git a/.gitignore b/.gitignore index d29456e74..e38da6603 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ cmake-build-* #logfies and capio files *.log files_location*.txt -capio_logs +calf_logs # Other debug diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a930e879..6d4212ac5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,18 @@ FetchContent_Declare( GIT_TAG v1.4.0 ) +FetchContent_Declare( + calf + GIT_REPOSITORY https://github.com/High-Performance-IO/calf.git + GIT_TAG main +) + +set(CALF_LOG ${CAPIO_LOG} CACHE BOOL "" FORCE) +set(CALF_BUILD_STL ON CACHE BOOL "" FORCE) +set(CALF_BUILD_SYSCALL ON CACHE BOOL "" FORCE) + +FetchContent_MakeAvailable(calf) + ##################################### # Targets ##################################### diff --git a/README.md b/README.md index d73031df9..552ebf9f2 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ CAPIO depends on the following software that needs to be manually installed: The following dependencies are automatically fetched during cmake configuration phase, and compiled when required. - [CAPIO-CL](https://github.com/High-Performance-IO/CAPIO-CL) To handle the CAPIO-CL configuration and enforce streaming directives +- [CALF](https://github.com/High-Performance-IO/CALF) To manage logging and CLI printing - [alpha-unito/syscall_intercept](https://github.com/alpha-unito/syscall_intercept) to intercept syscalls (forked from ```pmem/syscall_interept```) - [Taywee/args](https://github.com/Taywee/args) to parse server command line inputs diff --git a/capio/common/constants.hpp b/capio/common/constants.hpp index 3a230f4bc..3c456717e 100644 --- a/capio/common/constants.hpp +++ b/capio/common/constants.hpp @@ -28,13 +28,8 @@ constexpr int CAPIO_CACHE_LINE_SIZE_DEFAULT = 256 * 1024; constexpr size_t CAPIO_SERVER_REQUEST_MAX_SIZE = sizeof(char) * (PATH_MAX + 81920); constexpr size_t CAPIO_REQ_MAX_SIZE = 256 * sizeof(char); -constexpr char LOG_CAPIO_START_REQUEST[] = "\n+++++++++++ SYSCALL %s (%d) +++++++++++"; -constexpr char LOG_CAPIO_END_REQUEST[] = "----------- END SYSCALL ----------\n"; -constexpr char CAPIO_SERVER_LOG_START_REQUEST_MSG[] = "+++++++++++++++++REQUEST+++++++++++++++++"; -constexpr char CAPIO_SERVER_LOG_END_REQUEST_MSG[] = "~~~~~~~~~~~~~~~END REQUEST~~~~~~~~~~~~~~~"; -constexpr int CAPIO_LOG_MAX_MSG_LEN = 2048; -constexpr int CAPIO_SEM_RETRIES = 100; -constexpr int THEORETICAL_SIZE_DIRENT64 = sizeof(ino64_t) + sizeof(off64_t) + +constexpr int CAPIO_SEM_RETRIES = 100; +constexpr int THEORETICAL_SIZE_DIRENT64 = sizeof(ino64_t) + sizeof(off64_t) + sizeof(unsigned short) + sizeof(unsigned char) + sizeof(char) * NAME_MAX; @@ -44,10 +39,6 @@ constexpr int CAPIO_POSIX_SYSCALL_REQUEST_SKIP = -2; constexpr int CAPIO_POSIX_SYSCALL_SKIP = 1; constexpr int CAPIO_POSIX_SYSCALL_SUCCESS = 0; -// CAPIO logger - common -constexpr char CAPIO_LOG_PRE_MSG[] = "at[%.15llu][%.40s]: "; -constexpr char CAPIO_DEFAULT_LOG_FOLDER[] = "capio_logs\0"; - // CAPIO common - shared memory constant names constexpr char SHM_FIRST_ELEM[] = "_first_elem_"; constexpr char SHM_LAST_ELEM[] = "_last_elem_"; @@ -66,15 +57,8 @@ constexpr char CAPIO_SHM_OPEN_ERROR[] = "Unable to open shared memory segment. Could it be that another instance of capio server is " "running with the same WORKFLOW_NAME?"; -// CAPIO logger - POSIX -constexpr char CAPIO_LOG_POSIX_DEFAULT_LOG_FILE_PREFIX[] = "posix_thread_\0"; -constexpr char CAPIO_LOG_POSIX_SYSCALL_START[] = "\n+++++++++ SYSCALL %s (%d) +++++++++"; -constexpr char CAPIO_LOG_POSIX_SYSCALL_END[] = "~~~~~~~~~ END SYSCALL ~~~~~~~~~\n"; - -// CAPIO logger - server -constexpr char CAPIO_SERVER_DEFAULT_LOG_FILE_PREFIX[] = "server_thread_\0"; // Note: Ensure CAPIO_VERSION is defined as a string literal, e.g., #define CAPIO_VERSION "1.0.0" -constexpr char CAPIO_LOG_SERVER_BANNER[14][80] = { +constexpr char CAPIO_LOG_SERVER_BANNER[14][80] = { "", "\033[1;34m /$$$$$$ /$$$$$$ /$$$$$$$ \033[0;96m /$$$$$$ /$$$$$$ ", "\033[1;34m /$$__ $$ /$$__ $$| $$__ $$ \033[0;96m|_ $$_/ /$$__ $$", @@ -91,27 +75,24 @@ constexpr char CAPIO_LOG_SERVER_BANNER[14][80] = { "", }; -constexpr char CAPIO_LOG_SERVER_CLI_LOGGING_NOT_AVAILABLE[] = - "CAPIO_LOG set but log support was not compiled into CAPIO!"; -constexpr char CAPIO_LOG_SERVER_REQUEST_START[] = "\n+++++++++++ REQUEST +++++++++++"; -constexpr char CAPIO_LOG_SERVER_REQUEST_END[] = "~~~~~~~~~ END REQUEST ~~~~~~~~~\n"; - // Server - Warning banners -constexpr char CAPIO_LOG_SERVER_CLI_LOGGING_ENABLED_WARNING[5][80] = { +constexpr char CAPIO_LOG_SERVER_CLI_LOGGING_ENABLED_WARNING[6][80] = { "\033[1;33m|==================================================================|\033[0m", "\033[1;33m| you are running a build of CAPIO with logging enabled. |\033[0m", "\033[1;33m| this will have impact on performance. you should recompile CAPIO |\033[0m", "\033[1;33m| with -DCAPIO_LOG=FALSE |\033[0m", - "\033[1;33m|==================================================================|\033[0m"}; + "\033[1;33m|==================================================================|\033[0m", + ""}; -constexpr char CAPIO_LOG_SERVER_CLI_CONT_ON_ERR_WARNING[7][80] = { +constexpr char CAPIO_LOG_SERVER_CLI_CONT_ON_ERR_WARNING[8][80] = { "\033[1;31m|==================================================================|\033[0m", "\033[1;31m| you are running CAPIO with --continue-on-error |\033[0m", "\033[1;31m| This is extremely dangerous as CAPIO server will continue |\033[0m", "\033[1;31m| its execution even if it should terminate. |\033[0m", "\033[1;31m| |\033[0m", "\033[1;31m| USE IT AT YOUR OWN RISK |\033[0m", - "\033[1;31m|==================================================================|\033[0m"}; + "\033[1;31m|==================================================================|\033[0m", + ""}; // CAPIO server argument parser constexpr char CAPIO_SERVER_ARG_PARSER_PRE[] = @@ -146,11 +127,4 @@ constexpr char CAPIO_SERVER_ARG_PARSER_CONFIG_BACKEND_HELP[] = "Backend used in CAPIO. The value [backend] can be one of the following implemented backends: " "\n\t> mpi \n\t> mpisync \n\t> none (default)"; -// Cli pre messages -constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_RESET[] = "\033[0m"; -constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_STATUS[] = "\033[1;34m"; -constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_INFO[] = "\033[1;32m"; -constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_WARNING[] = "\033[1;33m"; -constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_ERROR[] = "\033[1;31m"; - #endif // CAPIO_COMMON_CONSTANTS_HPP diff --git a/capio/common/env.hpp b/capio/common/env.hpp index cbfdc05aa..e344cbe61 100644 --- a/capio/common/env.hpp +++ b/capio/common/env.hpp @@ -6,11 +6,18 @@ #include #include #include - #include +#include "common/constants.hpp" #include "common/syscall.hpp" -#include "logger.hpp" + +#include + +#ifdef __CAPIO_POSIX +#include "calf/SyscallLogger.h" +#else +#include "calf/StlLogger.h" +#endif // TODO: remove forward declaration of function by splitting into header and impl. capio/common inline bool is_forbidden_path(const std::string_view &path); @@ -26,19 +33,19 @@ inline const std::filesystem::path &get_capio_dir() { if (val == nullptr) { - std::cout << "\n" - << CAPIO_LOG_SERVER_CLI_LEVEL_ERROR << "Fatal: CAPIO_DIR not provided!" - << std::endl; +#ifndef __CAPIO_POSIX + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "CAPIO_DIR not provided"); +#endif ERR_EXIT("Fatal: CAPIO_DIR not provided!"); } else { const char *realpath_res = capio_realpath(val, buf.get()); if (realpath_res == nullptr) { - std::cout << "\n" - << CAPIO_LOG_SERVER_CLI_LEVEL_ERROR - << "Fatal: CAPIO_DIR set, but folder does not exists on filesystem!" - << std::endl; +#ifndef __CAPIO_POSIX + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, + "Fatal: CAPIO_DIR set, but folder does not exists on filesystem!"); +#endif ERR_EXIT("error CAPIO_DIR: directory %s does not " "exist. [buf=%s]", val, buf.get()); @@ -91,24 +98,6 @@ inline long get_cache_line_size() { return data_bufs_count; } -inline int get_capio_log_level() { - static int level = -2; - if (level == -2) { - char *log_level = std::getenv("CAPIO_LOG_LEVEL"); - if (log_level == nullptr) { - level = 0; - } else { - auto [ptr, ec] = std::from_chars(log_level, log_level + strlen(log_level), level); - if (ec != std::errc()) { - std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << "invalid CAPIO_LOG_LEVEL value" - << std::endl; - level = 0; - } - } - } - return level; -} - inline std::string get_capio_workflow_name() { static std::string name; if (name.empty()) { diff --git a/capio/common/filesystem.hpp b/capio/common/filesystem.hpp index 8098bafe0..b9a8c5bdc 100644 --- a/capio/common/filesystem.hpp +++ b/capio/common/filesystem.hpp @@ -10,7 +10,12 @@ #include -#include "common/logger.hpp" +#ifdef __CAPIO_POSIX +#include "calf/SyscallLogger.h" +#else +#include "calf/StlLogger.h" +#endif + #include "common/syscall.hpp" #include "env.hpp" diff --git a/capio/common/logger.hpp b/capio/common/logger.hpp deleted file mode 100644 index e507e5959..000000000 --- a/capio/common/logger.hpp +++ /dev/null @@ -1,404 +0,0 @@ -#ifndef CAPIO_COMMON_LOGGER_HPP -#define CAPIO_COMMON_LOGGER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "constants.hpp" -#include "syscall.hpp" - -template std::string demangled_name(const T &obj) { - int status; - const char *mangled = typeid(obj).name(); - std::unique_ptr demangled( - abi::__cxa_demangle(mangled, nullptr, nullptr, &status), std::free); - return status == 0 ? demangled.get() : mangled; -} - -inline bool continue_on_error = false; // if set to true, CAPIO does not terminate on ERR_EXIT - -inline void raise_termination(const bool raise_exception, const std::string &message) { - if (raise_exception) { - throw std::runtime_error(message); - } - capio_syscall(SYS_write, stderr, message.c_str(), message.size()); - exit(EXIT_FAILURE); -} - -#if defined(CAPIO_LOG) && defined(__CAPIO_POSIX) -#include "syscallnames.h" -#endif - -#ifndef __CAPIO_POSIX -#include -// FIXME: Remove the inline specifier by splitting into header and source code -inline thread_local std::ofstream logfile; // if building for server, self contained logfile -inline std::string log_master_dir_name = CAPIO_DEFAULT_LOG_FOLDER; -inline std::string logfile_prefix = CAPIO_SERVER_DEFAULT_LOG_FILE_PREFIX; -#else -inline thread_local bool logfileOpen = false; -inline thread_local int logfileFD = -1; -inline thread_local char logfile_path[PATH_MAX]{'\0'}; -#endif - -// FIXME: Remove the inline specifier by splitting into header and source code -inline thread_local int current_log_level = 0; - -// this variable tells the logger that syscall logging -// has started, and we are not in setup phase -// FIXME: Remove the inline specifier by splitting into header and source code -inline thread_local bool logging_syscall = false; - -#ifndef CAPIO_MAX_LOG_LEVEL // capio max log level. defaults to -1, where everything is logged -#define CAPIO_MAX_LOG_LEVEL -1 -#endif -// FIXME: Remove the inline specifier by splitting into header and source code -inline int CAPIO_LOG_LEVEL = CAPIO_MAX_LOG_LEVEL; - -#ifndef __CAPIO_POSIX -inline auto open_server_logfile() { - auto hostname = new char[HOST_NAME_MAX]; - gethostname(hostname, HOST_NAME_MAX); - - if (log_master_dir_name.empty()) { - log_master_dir_name = CAPIO_DEFAULT_LOG_FOLDER; - } - - const std::filesystem::path output_folder = - std::string{log_master_dir_name + "/server/" + hostname}; - - std::filesystem::create_directories(output_folder); - - const std::filesystem::path logfile_name = output_folder.string() + "/" + logfile_prefix + - std::to_string(capio_syscall(SYS_gettid)) + ".log"; - - logfile.open(logfile_name, std::ofstream::out); - delete[] hostname; - - return logfile_name; -} -#else - -inline auto get_hostname() { - static char *hostname_prefix = nullptr; - if (hostname_prefix == nullptr) { - hostname_prefix = new char[HOST_NAME_MAX]; - gethostname(hostname_prefix, HOST_NAME_MAX); - } - return hostname_prefix; -} - -inline auto get_log_dir() { - static char *posix_log_master_dir_name = nullptr; - if (posix_log_master_dir_name == nullptr) { - posix_log_master_dir_name = std::getenv("CAPIO_LOG_DIR"); - if (posix_log_master_dir_name == nullptr) { - posix_log_master_dir_name = new char[strlen(CAPIO_DEFAULT_LOG_FOLDER)]; - strcpy(posix_log_master_dir_name, CAPIO_DEFAULT_LOG_FOLDER); - } - } - return posix_log_master_dir_name; -} - -inline auto get_log_prefix() { - static char *posix_logfile_prefix = nullptr; - if (posix_logfile_prefix == nullptr) { - posix_logfile_prefix = std::getenv("CAPIO_LOG_PREFIX"); - if (posix_logfile_prefix == nullptr) { - posix_logfile_prefix = new char[strlen(CAPIO_LOG_POSIX_DEFAULT_LOG_FILE_PREFIX)]; - strcpy(posix_logfile_prefix, CAPIO_LOG_POSIX_DEFAULT_LOG_FILE_PREFIX); - } - } - return posix_logfile_prefix; -} - -inline auto get_posix_log_dir() { - static char *posix_log_dir_path = nullptr; - if (posix_log_dir_path == nullptr) { - // allocate space for a path in the following structure (including 10 digits for thread id - // max - // log_master_dir_name/posix/hostname/logfile_prefix_.log - auto len = strlen(get_log_dir()) + 7; - posix_log_dir_path = new char[len]{0}; - sprintf(posix_log_dir_path, "%s/posix", get_log_dir()); - } - return posix_log_dir_path; -} - -inline auto get_host_log_dir() { - static char *host_log_dir_path = nullptr; - if (host_log_dir_path == nullptr) { - // allocate space for a path in the following structure (including 10 digits for thread id - // max - // log_master_dir_name/posix/hostname/logfile_prefix_.log - auto len = strlen(get_posix_log_dir()) + HOST_NAME_MAX; - host_log_dir_path = new char[len]{0}; - sprintf(host_log_dir_path, "%s/%s", get_posix_log_dir(), get_hostname()); - } - return host_log_dir_path; -} - -inline void setup_posix_log_filename() { - if (logfile_path[0] == '\0') { - sprintf(logfile_path, "%s/%s%ld.log", get_host_log_dir(), get_log_prefix(), - capio_syscall(SYS_gettid)); - } -} -#endif - -inline long long current_time_in_millis() { - timespec ts{}; - static long long start_time = -1; - if (start_time == -1) { - capio_syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); - start_time = static_cast(ts.tv_sec) * 1000 + (ts.tv_nsec) / 1000000; - } - capio_syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); - const auto time_now = static_cast(ts.tv_sec) * 1000 + (ts.tv_nsec) / 1000000; - return time_now - start_time; -} - -inline void log_write_to(char *buffer, size_t bufflen) { -#ifdef __CAPIO_POSIX - if (current_log_level < CAPIO_MAX_LOG_LEVEL || CAPIO_MAX_LOG_LEVEL < 0) { - capio_syscall(SYS_write, logfileFD, buffer, bufflen); - capio_syscall(SYS_write, logfileFD, "\n", 1); - } -#else - if (current_log_level < CAPIO_LOG_LEVEL || CAPIO_LOG_LEVEL < 0) { - logfile << buffer << std::endl; - logfile.flush(); - } - -#endif -} - -/** - * @brief Class used to suspend the logging capabilities of CAPIO, by setting the logging_syscall - * flag to false at instantiation, and restarting the logging at destruction - * - */ -class SyscallLoggingSuspender { - public: - SyscallLoggingSuspender() { logging_syscall = false; } - ~SyscallLoggingSuspender() { logging_syscall = true; } -}; - -/** - * @brief Class that provides logging capabilities to CAPIO. - * When compiled with the CAPIO intercepting library, it uses - * direct POSIX system calls. Otherwise, it relies on the STL. - * - */ -class Logger { - private: - char invoker[256]{0}; - char file[256]{0}; - char format[CAPIO_LOG_MAX_MSG_LEN]{0}; - - public: - inline Logger(const char invoker[], const char file[], int line, long int tid, - const char *message, ...) { -#ifndef __CAPIO_POSIX - if (!logfile.is_open()) { - // NOTE: should never get to this point as capio_server opens up the log file while - // parsing command line arguments. This is only for failsafe purpose - open_server_logfile(); - } -#else - if (!logfileOpen) { - setup_posix_log_filename(); - current_log_level = - 0; // reset log level after clone, avoiding propagation to child threads - - capio_syscall(SYS_mkdirat, AT_FDCWD, get_log_dir(), 0755); - capio_syscall(SYS_mkdirat, AT_FDCWD, get_posix_log_dir(), 0755); - capio_syscall(SYS_mkdirat, AT_FDCWD, get_host_log_dir(), 0755); - - logfileFD = capio_syscall(SYS_openat, AT_FDCWD, logfile_path, - O_CREAT | O_WRONLY | O_TRUNC, 0644); - - if (logfileFD == -1) { - capio_syscall(SYS_write, fileno(stdout), - "Err fopen file: ", strlen("Err fopen file: ")); - capio_syscall(SYS_write, fileno(stdout), logfile_path, strlen(logfile_path)); - capio_syscall(SYS_write, fileno(stdout), " ", 1); - capio_syscall(SYS_write, fileno(stdout), strerror(errno), strlen(strerror(errno))); - capio_syscall(SYS_write, fileno(stdout), "\n", 1); - exit(EXIT_FAILURE); - } - logfileOpen = true; - } -#endif - strncpy(this->invoker, invoker, sizeof(this->invoker)); - strncpy(this->file, file, sizeof(this->file)); - - va_list argp, argpc; - - sprintf(format, CAPIO_LOG_PRE_MSG, current_time_in_millis(), this->invoker); - const size_t pre_msg_len = strlen(format); - - strcpy(format + pre_msg_len, message); - - va_start(argp, message); - va_copy(argpc, argp); - -#if defined(CAPIO_LOG) && defined(__CAPIO_POSIX) - if (current_log_level == 0 && logging_syscall) { - int syscallNumber; - if (strcmp(invoker, "hook_clone_child") == 0) { - // Explicitly propagate SYS_clone to child thread after clone - // to avoid spurious unknown syscall logs - syscallNumber = SYS_clone; - } else { - syscallNumber = va_arg(argp, int); - } - - auto buf1 = reinterpret_cast(capio_syscall( - SYS_mmap, nullptr, 50, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); - sprintf(buf1, CAPIO_LOG_POSIX_SYSCALL_START, sys_num_to_string(syscallNumber).c_str(), - syscallNumber); - log_write_to(buf1, strlen(buf1)); - capio_syscall(SYS_munmap, buf1, 50); - } -#endif - - int size = vsnprintf(nullptr, 0U, format, argp); - auto buf = reinterpret_cast(capio_syscall(SYS_mmap, nullptr, size + 1, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); - vsnprintf(buf, size + 1, format, argpc); - log_write_to(buf, strlen(buf)); - - va_end(argp); - va_end(argpc); - capio_syscall(SYS_munmap, buf, size); - current_log_level++; - } - - Logger(const Logger &) = delete; - Logger &operator=(const Logger &) = delete; - - inline ~Logger() { - current_log_level--; - sprintf(format, CAPIO_LOG_PRE_MSG, current_time_in_millis(), this->invoker); - size_t pre_msg_len = strlen(format); - strcpy(format + pre_msg_len, "returned"); - - log_write_to(format, strlen(format)); -#ifdef __CAPIO_POSIX - if (current_log_level == 0 && logging_syscall) { - log_write_to(const_cast(CAPIO_LOG_POSIX_SYSCALL_END), - strlen(CAPIO_LOG_POSIX_SYSCALL_END)); - } -#endif - } - - inline void log(const char *message, ...) { - va_list argp, argpc; - - sprintf(format, CAPIO_LOG_PRE_MSG, current_time_in_millis(), this->invoker); - const size_t pre_msg_len = strlen(format); - - strcpy(format + pre_msg_len, message); - -#ifndef __CAPIO_POSIX - // if the log message to serve a new request or concludes, add new spaces - if (strcmp(invoker, "capio_server") == 0 && - (strcmp(CAPIO_LOG_SERVER_REQUEST_START, message) == 0 || - strcmp(CAPIO_LOG_SERVER_REQUEST_END, message) == 0)) { - logfile << message << std::endl; - return; - } -#endif - - va_start(argp, message); - va_copy(argpc, argp); - const int size = vsnprintf(nullptr, 0U, format, argp); - const auto buf = reinterpret_cast( - capio_syscall(SYS_mmap, nullptr, size + 1, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); - vsnprintf(buf, size + 1, format, argpc); - log_write_to(buf, strlen(buf)); - - va_end(argp); - va_end(argpc); - capio_syscall(SYS_munmap, buf, size); - } -}; - -#ifdef CAPIO_LOG - -#define ERR_EXIT_EXCEPT_CHOICE(raise_exception, message, ...) \ - log.log(message, ##__VA_ARGS__); \ - if (!continue_on_error) { \ - if (!continue_on_error) { \ - char err_msg[CAPIO_LOG_MAX_MSG_LEN]; \ - snprintf(err_msg, CAPIO_LOG_MAX_MSG_LEN, message, ##__VA_ARGS__); \ - raise_termination(raise_exception, err_msg); \ - } \ - } -#define ERR_EXIT(message, ...) ERR_EXIT_EXCEPT_CHOICE(true, message, ##__VA_ARGS__) - -#define LOG(message, ...) log.log(message, ##__VA_ARGS__) -#define START_LOG(tid, message, ...) \ - Logger log(__func__, __FILE__, __LINE__, tid, message, ##__VA_ARGS__) -#define START_SYSCALL_LOGGING() logging_syscall = true -#define SUSPEND_SYSCALL_LOGGING() SyscallLoggingSuspender sls{}; - -/** - * This macro is used to inject code into debug mode. It needs a self calling lambda function, - * that is a lambda in the following form: - * - * [](){}() - * - * For example, a debug code to print a value might be injected in this way: - * - * int value = 10; - * DBG(tid, [](int i){printf("%d", i);}(value) ); - * - * This is useful to print or run debug actions with variables defined outside - * of the scope of the given lambda function Be careful that the code defined inside the DBG - * macro is not compiled when building in Release. - * - * Be even MORE CAREFUL to not use any STL code inside the DBG lambda function as it could be - * captured by syscall_intercept (ie do not use std::cout unless you are 100% sure of what you are - * doing) - */ -#define DBG(tid, lambda) \ - { \ - START_LOG(tid, "[ DBG ]~~~~~~~~~~~~ START ~~~~~~~~~~~~~~[ DBG ]"); \ - lambda; \ - LOG("[ DBG ]~~~~~~~~~~~~ END ~~~~~~~~~~~~~~[ DBG ]"); \ - } - -#else - -#define ERR_EXIT_EXCEPT_CHOICE(raise_exception, message, ...) \ - if (!continue_on_error) { \ - char err_msg[CAPIO_LOG_MAX_MSG_LEN]; \ - snprintf(err_msg, sizeof(err_msg), message, ##__VA_ARGS__); \ - raise_termination(raise_exception, err_msg); \ - } -#define ERR_EXIT(message, ...) ERR_EXIT_EXCEPT_CHOICE(true, message, ##__VA_ARGS__) -#define LOG(message, ...) -#define START_LOG(tid, message, ...) -#define START_SYSCALL_LOGGING() -#define SUSPEND_SYSCALL_LOGGING() -#define SEM_CREATE_CHECK(sem, source) \ - if (sem == SEM_FAILED) { \ - __SHM_CHECK_CLI_MSG; \ - } -#define DBG(tid, lambda) - -#endif - -#endif // CAPIO_COMMON_LOGGER_HPP \ No newline at end of file diff --git a/capio/common/queue.hpp b/capio/common/queue.hpp index bd519d464..ef824f7e8 100644 --- a/capio/common/queue.hpp +++ b/capio/common/queue.hpp @@ -7,7 +7,11 @@ #include #include "common/env.hpp" -#include "common/logger.hpp" +#ifdef __CAPIO_POSIX +#include "calf/SyscallLogger.h" +#else +#include "calf/StlLogger.h" +#endif #include "common/semaphore.hpp" #include "common/shm.hpp" #include "filesystem.hpp" diff --git a/capio/common/semaphore.hpp b/capio/common/semaphore.hpp index 73c899e05..b061ca20a 100644 --- a/capio/common/semaphore.hpp +++ b/capio/common/semaphore.hpp @@ -5,7 +5,11 @@ #include -#include "common/logger.hpp" +#ifdef __CAPIO_POSIX +#include "calf/SyscallLogger.h" +#else +#include "calf/StlLogger.h" +#endif class NoLock { public: diff --git a/capio/common/shm.hpp b/capio/common/shm.hpp index c425e080b..060e5cdb0 100644 --- a/capio/common/shm.hpp +++ b/capio/common/shm.hpp @@ -9,7 +9,11 @@ #include #include -#include "common/logger.hpp" +#ifdef __CAPIO_POSIX +#include "calf/SyscallLogger.h" +#else +#include "calf/StlLogger.h" +#endif #ifdef __CAPIO_POSIX @@ -25,19 +29,18 @@ #else -#include "utils/server_println.hpp" +#include "calf/StdOutLogger.h" #define SHM_DESTROY_CHECK(source_name) \ if (shm_unlink(source_name) == -1) { \ - std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << "Unable to destroy shared mem: '" \ - << source_name << "' (" << strerror(errno) << ")" << std::endl; \ + std::cout << CALF_CLI_LEVEL_WARNING << "Unable to destroy shared mem: '" << source_name \ + << "' (" << strerror(errno) << ")" << std::endl; \ }; #define SHM_CREATE_CHECK(condition, source) \ if (condition) { \ LOG("error while creating %s", source); \ - std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_ERROR << "Unable to create shm: " << source \ - << std::endl; \ + std::cout << CALF_CLI_LEVEL_ERROR << "Unable to create shm: " << source << std::endl; \ ERR_EXIT("Unable to open shm: %s", source); \ }; @@ -59,23 +62,21 @@ class CapioShmCanary { #ifndef __CAPIO_POSIX const auto message = new char[strlen(CAPIO_SHM_CANARY_ERROR)]; sprintf(message, CAPIO_SHM_CANARY_ERROR, _canary_name.data()); - server_println(message, capio_workflow_name, CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, - "CapioShmCanary"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "%s", message); delete[] message; #endif ERR_EXIT("ERR: shm canary flag already exists"); } #ifndef __CAPIO_POSIX - server_println("Created Capio SHM canary: " + _canary_name, capio_workflow_name, - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, "CapioShmCanary"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "Created Capio SHM canary: %s", + _canary_name.c_str()); #endif }; ~CapioShmCanary() { START_LOG(capio_syscall(SYS_gettid), "call()"); #ifndef __CAPIO_POSIX - server_println("Removing shared memory canary flag", get_capio_workflow_name(), - CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, "CapioShmCanary"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Removing shared memory canary flag"); #endif close(_shm_id); SHM_DESTROY_CHECK(_canary_name.c_str()); diff --git a/capio/posix/CMakeLists.txt b/capio/posix/CMakeLists.txt index 7345ca559..a2665b88f 100644 --- a/capio/posix/CMakeLists.txt +++ b/capio/posix/CMakeLists.txt @@ -81,7 +81,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES # Link libraries ##################################### target_link_directories(${TARGET_NAME} PRIVATE ${SYSCALL_INTERCEPT_LIB_FOLDER}) -target_link_libraries(${TARGET_NAME} PRIVATE rt syscall_intercept) +target_link_libraries(${TARGET_NAME} PRIVATE rt syscall_intercept calf::syscall) ##################################### # Install rules diff --git a/capio/posix/handlers/exit_group.hpp b/capio/posix/handlers/exit_group.hpp index 6c4acb454..498622dc0 100644 --- a/capio/posix/handlers/exit_group.hpp +++ b/capio/posix/handlers/exit_group.hpp @@ -3,8 +3,6 @@ #if defined(SYS_exit) || defined(SYS_exit_group) -#include "common/logger.hpp" - #include "utils/requests.hpp" /* diff --git a/capio/posix/libcapio_posix.cpp b/capio/posix/libcapio_posix.cpp index 3aedd1a46..91039a589 100644 --- a/capio/posix/libcapio_posix.cpp +++ b/capio/posix/libcapio_posix.cpp @@ -15,6 +15,18 @@ #include "handlers.hpp" +#ifdef CAPIO_LOG +#include "syscallnames.h" +#endif + +template std::string demangled_name(const T &obj) { + int status; + const char *mangled = typeid(obj).name(); + std::unique_ptr demangled( + abi::__cxa_demangle(mangled, nullptr, nullptr, &status), std::free); + return status == 0 ? demangled.get() : mangled; +} + /** * Handler for syscall not handled and interrupt syscall_intercept */ @@ -347,11 +359,8 @@ static int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, return 1; } -#ifdef CAPIO_LOG - CAPIO_LOG_LEVEL = get_capio_log_level(); -#endif - - START_LOG(syscall_no_intercept(SYS_gettid), "call(syscall_number=%ld)", syscall_number); + START_LOG(syscall_no_intercept(SYS_gettid), "call(syscall_number=%ld, syscall_name=%s)", + syscall_number, sys_num_to_string(syscall_number).c_str()); // If the syscall_number is higher than the maximum // syscall captured by CAPIO, simply return @@ -394,6 +403,8 @@ static int hook(long syscall_number, long arg0, long arg1, long arg2, long arg3, } static __attribute__((constructor)) void init() { + SET_CALF_COMPONENT_NAME("posix"); + SET_CALF_SYSCALL_HANDLER(syscall_no_intercept); const long tid = syscall_no_intercept(SYS_gettid); @@ -408,5 +419,6 @@ static __attribute__((constructor)) void init() { intercept_hook_point_clone_child = hook_clone_child; intercept_hook_point_clone_parent = hook_clone_parent; intercept_hook_point = hook; - START_SYSCALL_LOGGING(); -} + + ENABLE_LOGGER(); +} \ No newline at end of file diff --git a/capio/posix/utils/cache.hpp b/capio/posix/utils/cache.hpp index 597d644a5..7a4f4d0f8 100644 --- a/capio/posix/utils/cache.hpp +++ b/capio/posix/utils/cache.hpp @@ -185,4 +185,4 @@ class WriteCache { inline thread_local WriteCache *write_cache; inline thread_local ReadCache *read_cache; -#endif // CAPIO_SERVER_UTILS_CACHE +#endif // CAPIO_SERVER_UTILS_CACHE \ No newline at end of file diff --git a/capio/posix/utils/clone.hpp b/capio/posix/utils/clone.hpp index 54cd24b72..eb1c5e3bb 100644 --- a/capio/posix/utils/clone.hpp +++ b/capio/posix/utils/clone.hpp @@ -1,6 +1,7 @@ #ifndef CAPIO_POSIX_UTILS_CLONE_HPP #define CAPIO_POSIX_UTILS_CLONE_HPP +#include "calf/SyscallLogger.h" #include "common/syscall.hpp" #include "data.hpp" #include "requests.hpp" diff --git a/capio/posix/utils/common.hpp b/capio/posix/utils/common.hpp index 9727b334f..af05e5d55 100644 --- a/capio/posix/utils/common.hpp +++ b/capio/posix/utils/common.hpp @@ -1,7 +1,8 @@ -#include - #ifndef CAPIO_FUNCTIONS_H #define CAPIO_FUNCTIONS_H +#include + +#include "calf/SyscallLogger.h" int posix_return_value(long res, long *result) { START_LOG(capio_syscall(SYS_gettid), "cal(res=%ld)", res); diff --git a/capio/posix/utils/env.hpp b/capio/posix/utils/env.hpp index c43f56fcb..0893ef500 100644 --- a/capio/posix/utils/env.hpp +++ b/capio/posix/utils/env.hpp @@ -2,9 +2,6 @@ #define CAPIO_POSIX_UTILS_ENV_HPP #include -#include - -#include "common/logger.hpp" inline const char *get_capio_app_name() { static char *capio_app_name = std::getenv("CAPIO_APP_NAME"); diff --git a/capio/posix/utils/filesystem.hpp b/capio/posix/utils/filesystem.hpp index 6ba6921e8..2ac11871c 100644 --- a/capio/posix/utils/filesystem.hpp +++ b/capio/posix/utils/filesystem.hpp @@ -10,9 +10,9 @@ #include +#include "calf/SyscallLogger.h" #include "common/env.hpp" #include "common/filesystem.hpp" -#include "common/logger.hpp" #include "common/syscall.hpp" #include "types.hpp" diff --git a/capio/posix/utils/requests.hpp b/capio/posix/utils/requests.hpp index 4867e6117..46ba9e73f 100644 --- a/capio/posix/utils/requests.hpp +++ b/capio/posix/utils/requests.hpp @@ -3,6 +3,7 @@ #include "common/requests.hpp" +#include "calf/SyscallLogger.h" #include "env.hpp" #include "filesystem.hpp" #include "types.hpp" diff --git a/capio/posix/utils/snapshot.hpp b/capio/posix/utils/snapshot.hpp index 55a85553b..59b0f805f 100644 --- a/capio/posix/utils/snapshot.hpp +++ b/capio/posix/utils/snapshot.hpp @@ -5,8 +5,7 @@ #include #include -#include "common/logger.hpp" - +#include "calf/SyscallLogger.h" #include "types.hpp" inline int *get_fd_snapshot(long tid) { diff --git a/capio/server/CMakeLists.txt b/capio/server/CMakeLists.txt index 701789550..2e7d39433 100644 --- a/capio/server/CMakeLists.txt +++ b/capio/server/CMakeLists.txt @@ -54,7 +54,7 @@ ENDIF (MPI_LINK_FLAGS) ##################################### # Link libraries ##################################### -target_link_libraries(${TARGET_NAME} PRIVATE ${MPI_LIBRARIES} pthread rt stdc++fs libcapio_cl args) +target_link_libraries(${TARGET_NAME} PRIVATE ${MPI_LIBRARIES} pthread rt stdc++fs libcapio_cl args calf::stl) ##################################### # Install rules diff --git a/capio/server/capio_server.cpp b/capio/server/capio_server.cpp index 403ec8f49..b29c81326 100644 --- a/capio/server/capio_server.cpp +++ b/capio/server/capio_server.cpp @@ -17,6 +17,8 @@ #include #include +#include "calf/StlLogger.h" + #include "capiocl.hpp" #include "capiocl/engine.h" #include "capiocl/parser.h" @@ -24,7 +26,6 @@ #include "client-manager/client_manager.hpp" #include "common/env.hpp" -#include "common/logger.hpp" #include "common/requests.hpp" #include "common/semaphore.hpp" #include "remote/backend.hpp" @@ -44,6 +45,8 @@ Backend *backend; #include "remote/listener.hpp" +#include "calf/StdOutLogger.h" + /** * The capio_cl_engine is declared here to ensure that other components of the CAPIO server * can only access it through a const reference. This prevents any modifications to the engine @@ -87,8 +90,6 @@ static constexpr std::array build_request_handle static const std::array request_handlers = build_request_handlers_table(); - START_LOG(gettid(), "call()"); - setup_signal_handlers(); backend->handshake_servers(); @@ -98,26 +99,25 @@ static constexpr std::array build_request_handle auto str = std::unique_ptr(new char[CAPIO_REQ_MAX_SIZE]); while (true) { - LOG(CAPIO_LOG_SERVER_REQUEST_START); + START_LOG(gettid(), "call()"); int code = client_manager->readNextRequest(str.get()); if (code < 0 || code > CAPIO_NR_REQUESTS) { - server_println("Received invalid code: " + std::to_string(code), - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, - __func__); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "Received invalid code: %d", code); ERR_EXIT("Error: received invalid request code"); } request_handlers[code](str.get()); - LOG(CAPIO_LOG_SERVER_REQUEST_END); } } int main(int argc, char **argv) { + SET_CALF_COMPONENT_NAME("server"); + UPDATE_CALF_CLI_CONFIG("SERVER", ""); Semaphore internal_server_sem(0); for (const auto line : CAPIO_LOG_SERVER_BANNER) { - server_println(line, "", "", ""); + CALF_PRINT("%s", line); } const auto configuration = parseCLI(argc, argv); @@ -134,6 +134,8 @@ int main(int argc, char **argv) { capio_cl_engine->setWorkflowName(get_capio_workflow_name()); } + UPDATE_CALF_CLI_CONFIG("SERVER", capio_cl_engine->getWorkflowName()); + if (configuration.store_all_in_memory) { capio_cl_engine->setAllStoreInMemory(); } @@ -154,8 +156,7 @@ int main(int argc, char **argv) { LOG("capio_server thread started"); std::thread remote_listener_thread(capio_remote_listener, std::ref(internal_server_sem)); LOG("capio_remote_listener thread started."); - server_println("Server instance successfully started!", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, "main"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "Server instance successfully started!"); server_thread.join(); remote_listener_thread.join(); diff --git a/capio/server/include/client-manager/client_manager.hpp b/capio/server/include/client-manager/client_manager.hpp index 3c91eb705..245d4dcb7 100644 --- a/capio/server/include/client-manager/client_manager.hpp +++ b/capio/server/include/client-manager/client_manager.hpp @@ -5,6 +5,8 @@ #include #include +#include "calf/StlLogger.h" + #include "common/queue.hpp" /** * @brief Class to handle libcapio_posix clients applications diff --git a/capio/server/include/remote/backend.hpp b/capio/server/include/remote/backend.hpp index f1c827821..02622f0b5 100644 --- a/capio/server/include/remote/backend.hpp +++ b/capio/server/include/remote/backend.hpp @@ -2,8 +2,7 @@ #define CAPIO_SERVER_REMOTE_BACKEND_HPP #include #include - -#include "common/logger.hpp" +#include class RemoteRequest { char *_buf_recv; diff --git a/capio/server/include/remote/handlers/read.hpp b/capio/server/include/remote/handlers/read.hpp index d4a4f6cd2..b6ca85c0c 100644 --- a/capio/server/include/remote/handlers/read.hpp +++ b/capio/server/include/remote/handlers/read.hpp @@ -1,6 +1,7 @@ #ifndef CAPIO_SERVER_REMOTE_HANDLERS_READ_HPP #define CAPIO_SERVER_REMOTE_HANDLERS_READ_HPP +#include "calf/StlLogger.h" #include "remote/backend.hpp" #include "remote/requests.hpp" #include "storage/manager.hpp" diff --git a/capio/server/include/remote/handlers/stat.hpp b/capio/server/include/remote/handlers/stat.hpp index 80cd4cc47..cade1ca87 100644 --- a/capio/server/include/remote/handlers/stat.hpp +++ b/capio/server/include/remote/handlers/stat.hpp @@ -1,6 +1,7 @@ #ifndef CAPIO_SERVER_REMOTE_HANDLERS_STAT_HPP #define CAPIO_SERVER_REMOTE_HANDLERS_STAT_HPP +#include "calf/StlLogger.h" #include "client-manager/client_manager.hpp" #include "remote/backend.hpp" #include "remote/requests.hpp" diff --git a/capio/server/include/remote/listener.hpp b/capio/server/include/remote/listener.hpp index 747c20efc..f8a5af525 100644 --- a/capio/server/include/remote/listener.hpp +++ b/capio/server/include/remote/listener.hpp @@ -1,7 +1,8 @@ #ifndef CAPIO_SERVER_REMOTE_LISTENER_HPP #define CAPIO_SERVER_REMOTE_LISTENER_HPP -#include "common/logger.hpp" +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "remote/backend.hpp" #include "remote/backend/include.hpp" @@ -27,34 +28,29 @@ inline Backend *select_backend(const std::string &backend_name, int argc, char * if (backend_name.empty() || backend_name == "none") { LOG("backend selected: none"); - server_println( - "Starting CAPIO with default backend (none) as no preferred backend was chosen", - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_INFO, - "select_backend"); + CALF_PRINT_COLOR( + CALF_CLI_LEVEL_INFO, + "Starting CAPIO with default backend (none) as no preferred backend was chosen"); return new NoneBackend(argc, argv); } if (backend_name == "mpi") { LOG("backend selected: mpi"); - server_println("Starting CAPIO with MPI backend", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "select_backend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Starting CAPIO with MPI backend"); return new MPIBackend(argc, argv); } if (backend_name == "mpisync") { LOG("backend selected: mpisync"); - server_println("Starting CAPIO with MPI (SYNC) backend", - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_INFO, - "select_backend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Starting CAPIO with MPI (SYNC) backend"); return new MPISYNCBackend(argc, argv); } LOG("Backend %s does not exist in CAPIO. Reverting back to the default backend (none)", backend_name.c_str()); - server_println("Backend " + backend_name + - " does not exist. Reverting to the default backend (none)", - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, - "select_backend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, + "Backend %s does not exist. Reverting to the default backend (none)", + backend_name.c_str()); return new NoneBackend(argc, argv); } @@ -65,10 +61,10 @@ inline void capio_remote_listener(Semaphore &internal_server_sem) { internal_server_sem.lock(); if (typeid(*backend) == typeid(NoneBackend)) { - server_println( - "backend is of type NoneBackend. Stopping capio_remote_listener() execution.", - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_INFO, - "capio_remote_listener"); + + CALF_PRINT_COLOR( + CALF_CLI_LEVEL_INFO, + "backend is of type NoneBackend. Stopping capio_remote_listener() execution."); return; } diff --git a/capio/server/include/storage/capio_file.hpp b/capio/server/include/storage/capio_file.hpp index aca4ff842..4c9339601 100644 --- a/capio/server/include/storage/capio_file.hpp +++ b/capio/server/include/storage/capio_file.hpp @@ -10,6 +10,8 @@ #include #include +#include "calf/StlLogger.h" + #include "common/queue.hpp" /** diff --git a/capio/server/include/utils/common.hpp b/capio/server/include/utils/common.hpp index a0f90cdbb..906f6f06e 100644 --- a/capio/server/include/utils/common.hpp +++ b/capio/server/include/utils/common.hpp @@ -5,6 +5,7 @@ #include #include +#include "calf/StlLogger.h" #include "capiocl_adapter.hpp" #include "client-manager/client_manager.hpp" #include "common/dirent.hpp" diff --git a/capio/server/include/utils/env.hpp b/capio/server/include/utils/env.hpp index ca41cb36d..18b9588d0 100644 --- a/capio/server/include/utils/env.hpp +++ b/capio/server/include/utils/env.hpp @@ -3,6 +3,7 @@ #include +#include "calf/StlLogger.h" #include "common/constants.hpp" off64_t get_file_initial_size() { diff --git a/capio/server/include/utils/location.hpp b/capio/server/include/utils/location.hpp index 3a14af685..f830dea05 100644 --- a/capio/server/include/utils/location.hpp +++ b/capio/server/include/utils/location.hpp @@ -1,11 +1,11 @@ #ifndef CAPIO_SERVER_UTILS_LOCATIONS_HPP #define CAPIO_SERVER_UTILS_LOCATIONS_HPP - -#include "remote/backend.hpp" - #include #include +#include "remote/backend.hpp" + +#include "calf/StlLogger.h" #include "utils/types.hpp" extern Backend *backend; diff --git a/capio/server/include/utils/server_println.hpp b/capio/server/include/utils/server_println.hpp deleted file mode 100644 index bf378ede1..000000000 --- a/capio/server/include/utils/server_println.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef CAPIO_PRINT_TEXT_HPP -#define CAPIO_PRINT_TEXT_HPP -#include -#include -#include - -#include "common/constants.hpp" - -inline void server_println(const std::string_view message_line, - const std::string_view workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME, - const std::string_view message_color = CAPIO_LOG_SERVER_CLI_LEVEL_RESET, - const std::string_view component_name = "CAPIO") { - - static char node_name[HOST_NAME_MAX]; - // static init once the nodename - [[maybe_unused]] static bool host_init = []() { - if (gethostname(node_name, HOST_NAME_MAX) != 0) { - snprintf(node_name, HOST_NAME_MAX, "unknown"); - } - return true; - }(); - - if (message_color.empty()) { - std::cout << message_line << std::endl; - return; - } - - // Get current time - const auto in_time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - - std::cout << message_color << "[CAPIO-SERVER > " << workflow_name << "]" - << CAPIO_LOG_SERVER_CLI_LEVEL_RESET << " [" - << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %H:%M:%S") << "] " - << " " << node_name << "@" << std::left << std::setw(20) - << component_name.substr(0, 20) << " | " << message_line << std::endl - << std::flush; -} -#endif // CAPIO_PRINT_TEXT_HPP diff --git a/capio/server/include/utils/signals.hpp b/capio/server/include/utils/signals.hpp index 94660c0a1..dae3612b1 100644 --- a/capio/server/include/utils/signals.hpp +++ b/capio/server/include/utils/signals.hpp @@ -3,8 +3,10 @@ #include +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" + #include "remote/backend.hpp" -#include "server_println.hpp" #ifdef CAPIO_COVERAGE extern "C" void __gcov_dump(void); @@ -13,22 +15,17 @@ extern "C" void __gcov_dump(void); void sig_term_handler(int signum, siginfo_t *info, void *ptr) { START_LOG(gettid(), "call(signal=[%d] (%s) from process with pid=%ld)", signum, strsignal(signum), info != nullptr ? info->si_pid : -1); - - server_println("shutting down server", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, __func__); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "shutting down server"); if (signum == SIGSEGV) { - server_println("Segfault detected!", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, __func__); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "Segfault detected!"); } // free all the memory used delete client_manager; delete storage_manager; - - server_println("data_buffers cleanup completed", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, __func__); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "data_buffers cleanup completed"); #ifdef CAPIO_COVERAGE __gcov_dump(); @@ -37,8 +34,8 @@ void sig_term_handler(int signum, siginfo_t *info, void *ptr) { delete backend; delete shm_canary; - server_println("shutdown completed", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, __func__); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "shutdown completed"); + exit(EXIT_SUCCESS); } @@ -59,8 +56,8 @@ void setup_signal_handlers() { if (res == -1) { ERR_EXIT("sigaction for SIGTERM"); } - server_println("Installed signal handlers", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, __func__); + + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "Installed signal handlers"); } #endif // CAPIO_SERVER_HANDLERS_SIGNALS_HPP diff --git a/capio/server/src/backend.cpp b/capio/server/src/backend.cpp index 269893eae..bfa79ceda 100644 --- a/capio/server/src/backend.cpp +++ b/capio/server/src/backend.cpp @@ -1,7 +1,8 @@ #include "remote/backend.hpp" +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "utils/common.hpp" -#include "utils/server_println.hpp" #include @@ -12,11 +13,8 @@ Backend::Backend(const unsigned int node_name_max_length) gethostname(node_name.data(), node_name_max_length); node_name.resize(strlen(node_name.data())); - server_println("Node name: " + node_name, CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "Backend"); - server_println("Node count: " + std::to_string(n_servers), - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_INFO, - "Backend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Node name: %s", node_name.c_str()); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Node count: %d", n_servers); } [[nodiscard]] const std::string &Backend::get_node_name() const { diff --git a/capio/server/src/capio_file.cpp b/capio/server/src/capio_file.cpp index 0aa478863..80b9500ed 100644 --- a/capio/server/src/capio_file.cpp +++ b/capio/server/src/capio_file.cpp @@ -1,9 +1,10 @@ #include "server/include/storage/capio_file.hpp" -#include "common/logger.hpp" +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" + #include "remote/backend.hpp" #include "server/include/utils/common.hpp" -#include "server/include/utils/server_println.hpp" #include "utils/shared_mutex.hpp" extern Backend *backend; @@ -34,9 +35,8 @@ CapioFile::~CapioFile() { delete[] _buf; } else { if (munmap(_buf, _buf_size) == -1) { - server_println("WARN: unable to unmap CapioFile: " + std::string(strerror(errno)), - CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, "CapioFile"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "WARN: unable to unmap CapioFile: %s", + strerror(errno)); } } } else { diff --git a/capio/server/src/cli_parser.cpp b/capio/server/src/cli_parser.cpp index a4f55cfa8..4ba8c357a 100644 --- a/capio/server/src/cli_parser.cpp +++ b/capio/server/src/cli_parser.cpp @@ -1,15 +1,15 @@ #include "utils/cli_parser.hpp" +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" + #include "common/constants.hpp" -#include "common/logger.hpp" #include "utils/common.hpp" -#include "utils/server_println.hpp" #include CapioParsedConfig parseCLI(int argc, char **argv) { CapioParsedConfig capio_config; - Logger *log; args::ArgumentParser parser(CAPIO_SERVER_ARG_PARSER_PRE, CAPIO_SERVER_ARG_PARSER_EPILOGUE); parser.LongSeparator(" "); @@ -18,10 +18,6 @@ CapioParsedConfig parseCLI(int argc, char **argv) { args::Group arguments(parser, "Arguments"); args::HelpFlag help(arguments, "help", "Display this help menu", {'h', "help"}); - args::ValueFlag logfile_src(arguments, "filename", - CAPIO_SERVER_ARG_PARSER_LOGILE_OPT_HELP, {'l', "log"}); - args::ValueFlag logfile_folder( - arguments, "filename", CAPIO_SERVER_ARG_PARSER_LOGILE_DIR_OPT_HELP, {'d', "log-dir"}); args::ValueFlag resolve_prefix(arguments, "resolve-prefix", CAPIO_SERVER_ARG_PARSER_RESOLVE_PREFIX_OPT_HELP, {'r', "resolve-prefix"}); @@ -58,45 +54,24 @@ CapioParsedConfig parseCLI(int argc, char **argv) { #ifdef CAPIO_LOG continue_on_error = true; for (const auto line : CAPIO_LOG_SERVER_CLI_CONT_ON_ERR_WARNING) { - server_println(line, get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, - __func__); + CALF_PRINT("%s", line); } #else - server_println("--continue-on-error flag given, but logger is not compiled into CAPIO. " - "Flag is ignored.", - get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, "parseCLI"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, + "--continue-on-error flag given, but logger is not compiled into " + "CAPIO. Flag is ignored."); #endif } - if (logfile_folder) { #ifdef CAPIO_LOG - log_master_dir_name = args::get(logfile_folder); -#else - server_println("Capio logfile folder, but logging capabilities not compiled into capio!", - get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, "parseCLI"); -#endif + for (const auto line : CAPIO_LOG_SERVER_CLI_LOGGING_ENABLED_WARNING) { + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "%s", line); } - if (logfile_src) { -#ifdef CAPIO_LOG - // log file was given - std::string token = args::get(logfile_src); - if (token.find(".log") != std::string::npos) { - token.erase(token.length() - 4); // delete .log if for some reason - // is given as parameter - } - logfile_prefix = token; -#else - server_println("Capio logfile provided, but logging capabilities not compiled into capio!", - get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, "parseCLI"); -#endif - } -#ifdef CAPIO_LOG - auto logname = open_server_logfile(); - log = new Logger(__func__, __FILE__, __LINE__, gettid(), "Created new log file"); - server_println("started logging to logfile " + logname.string(), get_capio_workflow_name(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "parseCLI"); + auto log = new Logger(__func__, __FILE__, __LINE__, gettid(), "Created new log file"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "started logging to logfile %s", + log->getLogFileName().c_str()); #endif if (mem_only_flag) { @@ -108,8 +83,8 @@ CapioParsedConfig parseCLI(int argc, char **argv) { capio_config.capio_cl_config_path = args::get(config); if (std::string token = args::get(config); token == "dynamic") { - server_println("Starting CAPIO-CL engine with dynamic configuration", - get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_INFO, __func__); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, + "Starting CAPIO-CL engine with dynamic configuration"); capio_config.capio_cl_dynamic_config = true; } else { @@ -121,43 +96,21 @@ CapioParsedConfig parseCLI(int argc, char **argv) { } } else if (noConfigFile) { - - server_println("skipping config file parsing.", get_capio_workflow_name(), - CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, __func__); - server_println("Obtained from environment variable current workflow name: " + - get_capio_workflow_name(), - get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, __func__); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "skipping config file parsing."); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, + "Obtained from environment variable current workflow name: %s", + get_capio_workflow_name().c_str()); } else { - server_println( - "Error: no config file provided. To skip config file use --no-config option!", - get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, __func__); + CALF_PRINT_COLOR( + CALF_CLI_LEVEL_ERROR, + "Error: no config file provided. To skip config file use --no-config option!"); #ifdef CAPIO_LOG log->log("no config file provided, and --no-config not provided"); #endif exit(EXIT_FAILURE); } - server_println("CAPIO_DIR=" + get_capio_dir().string(), get_capio_workflow_name(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, __func__); - -#ifdef CAPIO_LOG - CAPIO_LOG_LEVEL = get_capio_log_level(); - server_println("LOG_LEVEL set to: " + std::to_string(CAPIO_LOG_LEVEL), - get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_INFO, __func__); - for (const auto &msg : CAPIO_LOG_SERVER_CLI_LOGGING_ENABLED_WARNING) { - server_println(msg, get_capio_workflow_name(), CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, - __func__); - } - - log->log("LOG_LEVEL set to: %d", CAPIO_LOG_LEVEL); - delete log; -#else - if (std::getenv("CAPIO_LOG_LEVEL") != nullptr) { - server_println(CAPIO_LOG_SERVER_CLI_LOGGING_NOT_AVAILABLE, get_capio_workflow_name(), - CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, __func__); - } -#endif - + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "CAPIO_DIR=%s", get_capio_dir().c_str()); // Backend selection phase if (backend_flag) { capio_config.backend_name = args::get(backend_flag); diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index f8000c9a7..34b30001f 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -1,13 +1,13 @@ #include -#include "utils/capiocl_adapter.hpp" - #include "client-manager/client_manager.hpp" + +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "common/constants.hpp" #include "common/queue.hpp" #include "utils/capiocl_adapter.hpp" #include "utils/common.hpp" -#include "utils/server_println.hpp" ClientManager::ClientDataBuffers::ClientDataBuffers(const std::string &clientToServerName, const std::string &serverToClientName, @@ -18,14 +18,10 @@ ClientManager::ClientDataBuffers::ClientDataBuffers(const std::string &clientToS ClientManager::ClientManager() : requests{SHM_COMM_CHAN_NAME, CAPIO_REQ_BUFF_CNT, CAPIO_REQ_MAX_SIZE, CapioCLEngine::get().getWorkflowName()} { - server_println("initialization completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, "ClientManager"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "initialization completed."); } -ClientManager::~ClientManager() { - server_println("teardown completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, "ClientManager"); -} +ClientManager::~ClientManager() { CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "teardown completed."); } void ClientManager::registerClient(pid_t tid, const std::string &app_name, const bool wait) { START_LOG(gettid(), "call(tid=%ld, app_name=%s)", tid, app_name.c_str()); @@ -40,10 +36,9 @@ void ClientManager::registerClient(pid_t tid, const std::string &app_name, const responses.try_emplace(tid, SHM_COMM_CHAN_NAME_RESP + std::to_string(tid), CAPIO_REQ_BUFF_CNT, sizeof(off_t), CapioCLEngine::get().getWorkflowName()); - DBG(tid, [](const int tid_app, const std::string &app_name) { - server_println("Registered PID " + std::to_string(tid_app) + " with app name " + app_name, - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_INFO, - "ClientManager"); + DBG(tid, [](const int tid_app, const std::string &app_name_) { + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "Registered PID %d with app name %s", tid_app, + app_name_.c_str()); }(tid, app_name)); if (wait) { @@ -83,10 +78,9 @@ void ClientManager::removeClient(const pid_t tid) { if (const auto response_buffer = responses.find(tid); response_buffer != responses.end()) { responses.erase(response_buffer); } - DBG(tid, [](const int tid_app, const std::string &app_name) { - server_println("Removed PID " + std::to_string(tid_app) + " with app name " + app_name, - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_WARNING, - "ClientManager"); + DBG(tid, [&](const int tid_app, const std::string &app_name) { + CALF_PRINT_COLOR(CALF_CLI_LEVEL_WARNING, "Removed PID %d with app name %s", tid_app, + app_name.c_str()); }(tid, app_name)); } @@ -189,12 +183,10 @@ int ClientManager::readNextRequest(char *str) { if (ec == std::errc()) { strcpy(str, ptr + 1); } else { - server_println("Received invalid request: " + std::string(str), - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, - __func__); - server_println("Code " + std::to_string(code) + " is not mapped to a valid request handler", - CapioCLEngine::get().getWorkflowName(), CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, - __func__); + + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "Received invalid request: %s", str); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_ERROR, "Code: %d is not mapped to a valid request handler", + code); return -1; } diff --git a/capio/server/src/mpi_backend.cpp b/capio/server/src/mpi_backend.cpp index ead84a42c..b77b004cb 100644 --- a/capio/server/src/mpi_backend.cpp +++ b/capio/server/src/mpi_backend.cpp @@ -1,6 +1,10 @@ #include "remote/backend/mpi.hpp" + +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" + +#include "common/constants.hpp" #include "utils/capiocl_adapter.hpp" -#include "utils/server_println.hpp" MPIBackend::MPIBackend(int argc, char **argv) : Backend(MPI_MAX_PROCESSOR_NAME) { int node_name_len, provided; @@ -22,15 +26,13 @@ MPIBackend::MPIBackend(int argc, char **argv) : Backend(MPI_MAX_PROCESSOR_NAME) nodes.emplace(node_name); rank_to_hostname[rank] = node_name; hostname_to_rank[node_name] = rank; - server_println("initialization completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, "MPIBackend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "initialization completed."); } MPIBackend::~MPIBackend() { START_LOG(gettid(), "Call()"); MPI_Finalize(); - server_println("teardown completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "MPIBackend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "teardown completed."); } const std::set MPIBackend::get_nodes() { return nodes; } @@ -123,15 +125,13 @@ void MPIBackend::recv_file(char *shm, const std::string &source, long int bytes_ MPISYNCBackend::MPISYNCBackend(int argc, char *argv[]) : MPIBackend(argc, argv) { START_LOG(gettid(), "call()"); LOG("Wrapped MPI backend with MPISYC backend"); - server_println("initialization completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, "MPISYNCBackend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "initialization completed."); } MPISYNCBackend::~MPISYNCBackend() { START_LOG(gettid(), "Call()"); MPI_Finalize(); - server_println("teardown completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "MPISYNCBackend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "teardown completed."); } RemoteRequest MPISYNCBackend::read_next_request() { diff --git a/capio/server/src/none_backend.cpp b/capio/server/src/none_backend.cpp index e0e8e3208..121710602 100644 --- a/capio/server/src/none_backend.cpp +++ b/capio/server/src/none_backend.cpp @@ -1,13 +1,14 @@ #include #include "remote/backend/none.hpp" + +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" #include "utils/capiocl_adapter.hpp" -#include "utils/server_println.hpp" NoneBackend::NoneBackend(int argc, char **argv) : Backend(HOST_NAME_MAX) { START_LOG(gettid(), "call()"); - server_println("initialization completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, "NoneBackend"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "initialization completed."); } RemoteRequest NoneBackend::read_next_request() { diff --git a/capio/server/src/remote_request.cpp b/capio/server/src/remote_request.cpp index a15bab108..101da514a 100644 --- a/capio/server/src/remote_request.cpp +++ b/capio/server/src/remote_request.cpp @@ -1,5 +1,8 @@ +#include "common/constants.hpp" #include "remote/backend.hpp" +#include "calf/StlLogger.h" + RemoteRequest::RemoteRequest(char *buf_recv, const std::string &source) : _source(source) { START_LOG(gettid(), "call(buf_recv=%s, source=%s)", buf_recv, source.c_str()); int code; diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index 4b866bd27..c2fe73bf6 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -3,11 +3,14 @@ #include #include +#include "storage/manager.hpp" + +#include "calf/StdOutLogger.h" +#include "calf/StlLogger.h" + #include "common/dirent.hpp" #include "common/filesystem.hpp" -#include "common/logger.hpp" #include "storage/capio_file.hpp" -#include "storage/manager.hpp" #include "utils/capiocl_adapter.hpp" #include "utils/common.hpp" #include "utils/location.hpp" @@ -67,8 +70,7 @@ void StorageManager::addDirectoryEntry(const pid_t tid, const std::filesystem::p } } StorageManager::StorageManager() { - server_println("initialization completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_STATUS, "StorageManager"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_STATUS, "initialization completed."); } StorageManager::~StorageManager() { @@ -83,8 +85,7 @@ StorageManager::~StorageManager() { _removeFromTid(tid, fd); } } - server_println("teardown completed.", CapioCLEngine::get().getWorkflowName(), - CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "StorageManager"); + CALF_PRINT_COLOR(CALF_CLI_LEVEL_INFO, "teardown completed."); } std::optional> diff --git a/capio/tests/unit/posix/CMakeLists.txt b/capio/tests/unit/posix/CMakeLists.txt index 092bd62c9..96125bda9 100644 --- a/capio/tests/unit/posix/CMakeLists.txt +++ b/capio/tests/unit/posix/CMakeLists.txt @@ -46,7 +46,7 @@ target_include_directories(${TARGET_NAME} PRIVATE # Link libraries ##################################### target_link_directories(${TARGET_NAME} PRIVATE ${SYSCALL_INTERCEPT_LIB_FOLDER}) -target_link_libraries(${TARGET_NAME} PRIVATE rt syscall_intercept GTest::gtest_main) +target_link_libraries(${TARGET_NAME} PRIVATE rt syscall_intercept GTest::gtest_main calf::syscall) ##################################### # Configure tests diff --git a/capio/tests/unit/posix/src/realpath.cpp b/capio/tests/unit/posix/src/realpath.cpp index cfa38e8ae..02600a906 100644 --- a/capio/tests/unit/posix/src/realpath.cpp +++ b/capio/tests/unit/posix/src/realpath.cpp @@ -4,6 +4,8 @@ #include +#include "calf/SyscallLogger.h" + #include "utils/filesystem.hpp" class RealpathPosixTest : public testing::Test { diff --git a/capio/tests/unit/server/CMakeLists.txt b/capio/tests/unit/server/CMakeLists.txt index ca41e31bc..487e2d887 100644 --- a/capio/tests/unit/server/CMakeLists.txt +++ b/capio/tests/unit/server/CMakeLists.txt @@ -37,7 +37,7 @@ target_include_directories(${TARGET_NAME} PRIVATE ##################################### # Link libraries ##################################### -target_link_libraries(${TARGET_NAME} PRIVATE GTest::gtest_main rt libcapio_cl MPI::MPI_CXX args) +target_link_libraries(${TARGET_NAME} PRIVATE GTest::gtest_main rt libcapio_cl MPI::MPI_CXX args calf::stl) ##################################### # Configure tests diff --git a/capio/tests/unit/server/src/capio_file.cpp b/capio/tests/unit/server/src/capio_file.cpp index db7ead849..3dfc8cb77 100644 --- a/capio/tests/unit/server/src/capio_file.cpp +++ b/capio/tests/unit/server/src/capio_file.cpp @@ -323,34 +323,7 @@ TEST(ServerTest, TestFileSetCommitToFalse) { EXPECT_FALSE(file.isCommitted()); } -class MockBackend : public Backend { - public: - MockBackend() : Backend(HOST_NAME_MAX) {} - - void recv_file(char *shm, const std::string &source, const long int bytes_expected) override { - for (long int i = 0; i < bytes_expected; ++i) { - shm[i] = 33 + (i % 93); - } - } - - const std::set get_nodes() override { return {node_name}; } - void handshake_servers() override {} - RemoteRequest read_next_request() override { return {nullptr, ""}; } - void send_file(char *shm, long int nbytes, const std::string &target) override {} - void send_request(const char *message, int message_len, const std::string &target) override {} -}; - -class MockBackendTestFixture : public ::testing::Test { - protected: - void SetUp() override { - backend = new MockBackend(); - open_files_location(); - } - - void TearDown() override { delete backend; } -}; - -TEST_F(MockBackendTestFixture, TestReadFromNodeMockBackend) { +TEST(ServerTest, TestReadFromNodeMockBackend) { CapioFile file1; file1.createBuffer("testDir", true); @@ -377,7 +350,7 @@ TEST(ServerTest, TestGetSectorEnd) { EXPECT_EQ(file.getSectorEnd(12000), -1); } -TEST_F(MockBackendTestFixture, TestSimulateDirectoryStreaming) { +TEST(ServerTest, TestSimulateDirectoryStreaming) { constexpr int NUM_FILES_EXPECTED = 10; diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index 28cb277e4..b57f22e41 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -14,6 +14,23 @@ Backend *backend = nullptr; const capiocl::engine::Engine &CapioCLEngine::get() { return *capio_cl_engine; } +class MockBackend : public Backend { + public: + MockBackend() : Backend(HOST_NAME_MAX) {} + + void recv_file(char *shm, const std::string &source, const long int bytes_expected) override { + for (long int i = 0; i < bytes_expected; ++i) { + shm[i] = 33 + (i % 93); + } + } + + const std::set get_nodes() override { return {node_name}; } + void handshake_servers() override {} + RemoteRequest read_next_request() override { return {nullptr, ""}; } + void send_file(char *shm, long int nbytes, const std::string &target) override {} + void send_request(const char *message, int message_len, const std::string &target) override {} +}; + class ServerUnitTestEnvironment : public testing::Environment { public: explicit ServerUnitTestEnvironment() = default; @@ -22,12 +39,15 @@ class ServerUnitTestEnvironment : public testing::Environment { capio_cl_engine = new capiocl::engine::Engine(false); client_manager = new ClientManager(); storage_manager = new StorageManager(); + backend = new MockBackend(); + open_files_location(); } void TearDown() override { delete storage_manager; delete client_manager; delete capio_cl_engine; + delete backend; } }; diff --git a/capio/tests/unit/syscall/CMakeLists.txt b/capio/tests/unit/syscall/CMakeLists.txt index abfbff475..87a24c003 100644 --- a/capio/tests/unit/syscall/CMakeLists.txt +++ b/capio/tests/unit/syscall/CMakeLists.txt @@ -14,7 +14,7 @@ add_executable(${TARGET_NAME} ${TARGET_SOURCES}) ##################################### # Link libraries ##################################### -target_link_libraries(${TARGET_NAME} PRIVATE GTest::gtest) +target_link_libraries(${TARGET_NAME} PRIVATE GTest::gtest calf::syscall) ##################################### # Configure tests