summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-01-14 01:07:53 +0100
committerSander Vrijders <sander@ouroboros.rocks>2026-01-19 08:14:55 +0100
commit8aa6ab4d29df80adde0d512244d43d38264bf32e (patch)
tree314b0f5aad45f740d6de34d9830853fb24a4fcf0
parent1433fa50cb4e162a0557f207a1097d165392ba8e (diff)
downloadouroboros-8aa6ab4d29df80adde0d512244d43d38264bf32e.tar.gz
ouroboros-8aa6ab4d29df80adde0d512244d43d38264bf32e.zip
build: Add option to toggle Ouroboros logging in tests
The test output is a bit polluted with logs originating fomr the logging system, e.g.: 23: test_bind_prog started. 23: ==16636== reg/name(DB): Add prog reg_test to name testname. 23: ==16636== reg(EE): Removing from names. 23: test_bind_prog succeeded. This adds a flag DISABLE_TEST_LOGGING that suppresses log_* output in tests to keep them clean: 23: test_bind_prog started. 23: test_bind_prog succeeded. The status is printed in CMake output: -- Ouroboros logging in test output disabled -- Ouroboros logging in test output enabled By default the flag is ON (clean test output). Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
-rw-r--r--cmake/tests.cmake2
-rw-r--r--cmake/utils/DisableTestLogging.cmake12
-rw-r--r--include/ouroboros/logs.h26
-rw-r--r--src/ipcpd/unicast/dir/dht.c2
-rw-r--r--src/ipcpd/unicast/dir/tests/CMakeLists.txt2
-rw-r--r--src/ipcpd/unicast/pff/tests/CMakeLists.txt1
-rw-r--r--src/ipcpd/unicast/routing/tests/CMakeLists.txt2
-rw-r--r--src/irmd/reg/tests/CMakeLists.txt2
-rw-r--r--src/lib/tests/CMakeLists.txt1
9 files changed, 42 insertions, 8 deletions
diff --git a/cmake/tests.cmake b/cmake/tests.cmake
index 01dd2ecd..4c16171c 100644
--- a/cmake/tests.cmake
+++ b/cmake/tests.cmake
@@ -1,5 +1,7 @@
include(CTest) # Sets BUILD_TESTING by default to on.
+include(utils/DisableTestLogging)
+
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
set(BUILD_TESTS ON)
else ()
diff --git a/cmake/utils/DisableTestLogging.cmake b/cmake/utils/DisableTestLogging.cmake
new file mode 100644
index 00000000..730b0bc0
--- /dev/null
+++ b/cmake/utils/DisableTestLogging.cmake
@@ -0,0 +1,12 @@
+set(DISABLE_TESTS_LOGGING TRUE CACHE BOOL "Disable Ouroboros log output in tests")
+if (DISABLE_TESTS_LOGGING)
+ message(STATUS "Ouroboros logging in test output disabled")
+else ()
+ message(STATUS "Ouroboros logging in test output enabled")
+endif ()
+
+macro(disable_test_logging_for_target target)
+ if (DISABLE_TESTS_LOGGING)
+ target_compile_definitions(${target} PRIVATE OUROBOROS_DISABLE_LOGGING)
+ endif ()
+endmacro()
diff --git a/include/ouroboros/logs.h b/include/ouroboros/logs.h
index f1c401fa..31f11836 100644
--- a/include/ouroboros/logs.h
+++ b/include/ouroboros/logs.h
@@ -81,6 +81,7 @@ void log_fini(void);
} \
} while (0)
+#ifndef OUROBOROS_DISABLE_LOGGING
#define log_err(...) \
__olog(CLR_RED, ERROR_CODE, LOG_ERR, __VA_ARGS__)
#define log_warn(...) \
@@ -95,20 +96,29 @@ void log_fini(void);
__olog_id(CLR_YELLOW, WARN_CODE, LOG_WARNING, id, fmt, ## __VA_ARGS__)
#define log_info_id(id, fmt, ...) \
__olog_id(CLR_GREEN, INFO_CODE, LOG_INFO, id, fmt, ## __VA_ARGS__)
+#else /* OUROBOROS_DISABLE_LOGGING: all logging disabled */
+#define log_err(...) do { } while (0)
+#define log_warn(...) do { } while (0)
+#define log_info(...) do { } while (0)
-#ifdef CONFIG_OUROBOROS_DEBUG
+#define log_err_id(id, fmt, ...) do { (void)(id); } while (0)
+#define log_warn_id(id, fmt, ...) do { (void)(id); } while (0)
+#define log_info_id(id, fmt, ...) do { (void)(id); } while (0)
+
+#endif /* OUROBOROS_DISABLE_LOGGING */
+
+#if defined(OUROBOROS_DISABLE_LOGGING) || !defined(CONFIG_OUROBOROS_DEBUG)
+#define log_dbg(...) do { } while (0)
+#define log_dbg_id(id, ...) do { (void)(id); } while (0)
+#define log_proto(...) do { } while (0)
+#define log_proto_id(id, ...) do { (void)(id); } while (0)
+#else
#define log_dbg(...) __olog("", DEBUG_CODE, LOG_DEBUG, __VA_ARGS__)
#define log_dbg_id(id, fmt, ...) \
__olog_id("", DEBUG_CODE, LOG_DEBUG, id, fmt, ## __VA_ARGS__)
#define log_proto(...) __olog(CLR_BLUE, PROTO_CODE, LOG_DEBUG, __VA_ARGS__)
-#define log_proto_id(id, fmt, ...) \
+#define log_proto_id(id, fmt, ...) \
__olog_id(CLR_BLUE, INFO_CODE, LOG_INFO, id, fmt, ## __VA_ARGS__)
-
-#else
-#define log_dbg(...) do { } while (0)
-#define log_dbg_id(...) do { } while (0)
-#define log_proto(...) do { } while (0)
-#define log_proto_id(...) do { } while (0)
#endif
#endif /* OUROBOROS_LIB_LOGS_H */
diff --git a/src/ipcpd/unicast/dir/dht.c b/src/ipcpd/unicast/dir/dht.c
index 6b06def9..1388c2de 100644
--- a/src/ipcpd/unicast/dir/dht.c
+++ b/src/ipcpd/unicast/dir/dht.c
@@ -2851,6 +2851,8 @@ static void do_dht_kv_store(const dht_store_msg_t * store)
uint8_t * key;
time_t exp;
+ (void) key; /* Only in logs, not used with DISABLE_TEST_LOGGING */
+
assert(store != NULL);
val.data = store->val.data;
diff --git a/src/ipcpd/unicast/dir/tests/CMakeLists.txt b/src/ipcpd/unicast/dir/tests/CMakeLists.txt
index bc0f26a4..870603dc 100644
--- a/src/ipcpd/unicast/dir/tests/CMakeLists.txt
+++ b/src/ipcpd/unicast/dir/tests/CMakeLists.txt
@@ -29,6 +29,8 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
protobuf_generate_c(DHT_PROTO_SRCS KAD_PROTO_HDRS ../dht.proto)
add_executable(${PARENT_DIR}_test ${${PARENT_DIR}_tests}
${DHT_PROTO_SRCS})
+
+disable_test_logging_for_target(${PARENT_DIR}_test)
target_link_libraries(${PARENT_DIR}_test ouroboros-common)
add_dependencies(build_tests ${PARENT_DIR}_test)
diff --git a/src/ipcpd/unicast/pff/tests/CMakeLists.txt b/src/ipcpd/unicast/pff/tests/CMakeLists.txt
index 923d1b27..358da56e 100644
--- a/src/ipcpd/unicast/pff/tests/CMakeLists.txt
+++ b/src/ipcpd/unicast/pff/tests/CMakeLists.txt
@@ -25,6 +25,7 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
)
add_executable(${PARENT_DIR}_test ${${PARENT_DIR}_tests})
+disable_test_logging_for_target(${PARENT_DIR}_test)
target_link_libraries(${PARENT_DIR}_test ouroboros-common)
add_dependencies(build_tests ${PARENT_DIR}_test)
diff --git a/src/ipcpd/unicast/routing/tests/CMakeLists.txt b/src/ipcpd/unicast/routing/tests/CMakeLists.txt
index fb9c92a6..e4168600 100644
--- a/src/ipcpd/unicast/routing/tests/CMakeLists.txt
+++ b/src/ipcpd/unicast/routing/tests/CMakeLists.txt
@@ -24,6 +24,8 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
)
add_executable(${PARENT_DIR}_test ${${PARENT_DIR}_tests})
+
+disable_test_logging_for_target(${PARENT_DIR}_test)
target_link_libraries(${PARENT_DIR}_test ouroboros-common)
add_dependencies(build_tests ${PARENT_DIR}_test)
diff --git a/src/irmd/reg/tests/CMakeLists.txt b/src/irmd/reg/tests/CMakeLists.txt
index eb7a1765..e33bd056 100644
--- a/src/irmd/reg/tests/CMakeLists.txt
+++ b/src/irmd/reg/tests/CMakeLists.txt
@@ -20,6 +20,8 @@ create_test_sourcelist(${src_folder}_tests test_suite.c
)
add_executable(${src_folder}_test ${${src_folder}_tests})
+
+disable_test_logging_for_target(${src_folder}_test)
target_link_libraries(${src_folder}_test ouroboros-common)
if (CMAKE_BUILD_TYPE MATCHES "Debug*")
diff --git a/src/lib/tests/CMakeLists.txt b/src/lib/tests/CMakeLists.txt
index 8af8e9dd..69fdf18b 100644
--- a/src/lib/tests/CMakeLists.txt
+++ b/src/lib/tests/CMakeLists.txt
@@ -19,6 +19,7 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c
add_executable(${PARENT_DIR}_test ${${PARENT_DIR}_tests})
+disable_test_logging_for_target(${PARENT_DIR}_test)
target_link_libraries(${PARENT_DIR}_test ouroboros-common)
add_dependencies(build_tests ${PARENT_DIR}_test)