From 4f516124cb3bd9b779f181f358f255b2d436cd28 Mon Sep 17 00:00:00 2001 From: adi-65-ray Date: Sat, 20 Sep 2025 18:39:30 -0700 Subject: [PATCH 01/10] Timestamped logging macro --- logging/api/logging_macros.h | 17 ++++++++++++++++- test/general/logging_test.c | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/general/logging_test.c diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index 2a8a04c1b..b8b1619da 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -12,10 +12,11 @@ #define LOGGING_MACROS_H #include "logging.h" #include +#include "tag.h" /** Default log level. */ #ifndef LOG_LEVEL -#define LOG_LEVEL LOG_LEVEL_INFO +#define LOG_LEVEL LOG_LEVEL_DEBUG #endif // To prevent warnings "conditional expression is constant", we define static booleans @@ -76,6 +77,20 @@ static const bool _lf_log_level_is_debug = LOG_LEVEL >= LOG_LEVEL_DEBUG; } \ } while (0) +/** + * @brief A macro used to print timestamped(physical time) debug information. + * @ingroup API + * + * @note This macro is functionally same as @ref LF_PRINT_DEBUG but with added timestamp for physical time. + * This is to check physical time of debug logs. It uses @ref lf_time_physical to get the physical time. + */ +#define LF_TIMESTAMP_PRINT_DEBUG(format, ...) \ + do { \ + if (_lf_log_level_is_debug) { \ + lf_print_debug("[%ld] " format, lf_time_physical_elapsed(), ##__VA_ARGS__); \ + } \ + } while (0) + #if defined(NDEBUG) #define LF_ASSERT(condition, format, ...) (void)(condition) #define LF_ASSERTN(condition, format, ...) (void)(condition) diff --git a/test/general/logging_test.c b/test/general/logging_test.c new file mode 100644 index 000000000..54ba2934b --- /dev/null +++ b/test/general/logging_test.c @@ -0,0 +1,20 @@ +#include "logging_macros.h" +#include + +#define TOTAL_LOOP_CASES 10 + +/** +* @brief test for testing LF_TIMESTAMP_PRINT_DEBUG macro +* must be in LOG_LEVEL LOG_LEVEL_DEBUG +*/ +int main() +{ + LF_PRINT_DEBUG("Start time: %ld", lf_time_start()); + for(int i; i Date: Fri, 26 Sep 2025 00:20:17 -0700 Subject: [PATCH 02/10] Added unit test --- logging/api/logging_macros.h | 19 ++------- test/general/logging_test.c | 75 +++++++++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index b8b1619da..1c5357fb3 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -13,10 +13,11 @@ #include "logging.h" #include #include "tag.h" +#include "low_level_platform.h" /** Default log level. */ #ifndef LOG_LEVEL -#define LOG_LEVEL LOG_LEVEL_DEBUG +#define LOG_LEVEL LOG_LEVEL_INFO #endif // To prevent warnings "conditional expression is constant", we define static booleans @@ -73,21 +74,7 @@ static const bool _lf_log_level_is_debug = LOG_LEVEL >= LOG_LEVEL_DEBUG; #define LF_PRINT_DEBUG(format, ...) \ do { \ if (_lf_log_level_is_debug) { \ - lf_print_debug(format, ##__VA_ARGS__); \ - } \ - } while (0) - -/** - * @brief A macro used to print timestamped(physical time) debug information. - * @ingroup API - * - * @note This macro is functionally same as @ref LF_PRINT_DEBUG but with added timestamp for physical time. - * This is to check physical time of debug logs. It uses @ref lf_time_physical to get the physical time. - */ -#define LF_TIMESTAMP_PRINT_DEBUG(format, ...) \ - do { \ - if (_lf_log_level_is_debug) { \ - lf_print_debug("[%ld] " format, lf_time_physical_elapsed(), ##__VA_ARGS__); \ + lf_print_debug("["PRINTF_TIME"]"format,lf_time_physical_elapsed(), ##__VA_ARGS__); \ } \ } while (0) diff --git a/test/general/logging_test.c b/test/general/logging_test.c index 54ba2934b..631bfd026 100644 --- a/test/general/logging_test.c +++ b/test/general/logging_test.c @@ -1,20 +1,75 @@ #include "logging_macros.h" +#include +#include +#include +#include #include +#include -#define TOTAL_LOOP_CASES 10 - +#define TIMEED_DEBUG_CHAR_LEN 30 +#define SOME_EXTRA_SPACE 10 /** -* @brief test for testing LF_TIMESTAMP_PRINT_DEBUG macro +* @brief unit for LF_PRINT_DEBUG macro * must be in LOG_LEVEL LOG_LEVEL_DEBUG */ -int main() -{ - LF_PRINT_DEBUG("Start time: %ld", lf_time_start()); - for(int i; i tmp + fflush(stdout); + int fd = fileno(tmp); + if (fd == -1 || dup2(fd, STDOUT_FILENO) == -1) { + perror("redirect stdout"); + exit(1); + } + + // Call code under test + LF_PRINT_DEBUG("%s",expected); + + fflush(stdout); // flush so data goes into tmp + rewind(tmp); // reset read position + + // Read back + buffer = (char*) malloc(buffer_size); + size_t n = fread(buffer, 1, buffer_size -1, tmp); + buffer[n] = '\0'; + + // Regex to check format: DEBUG: [number]expected\n + snprintf(pattern, sizeof(pattern), + "^DEBUG: \\[-?[0-9]+\\]%s\\n?$", expected); + + if (regcomp(&re, pattern, REG_EXTENDED | REG_NEWLINE) != 0) { + perror("regcomp"); + exit(1); } + + result = regexec(&re, buffer, 0, NULL, 0); + regfree(&re); + + assert(result == 0); // match succeeded + fclose(tmp); // deletes the file + free(buffer); +} + +int main() +{ + char* str_test = "Hello World"; + test_logging_macro(str_test, strlen(str_test)); return 0; } + + From 7aa0ff7adf686e5de4b8b2f9a3a6cda014ccbca0 Mon Sep 17 00:00:00 2001 From: adi-65-ray Date: Tue, 14 Oct 2025 12:39:01 -0700 Subject: [PATCH 03/10] unit test for logging clang-format fix --- test/general/logging_test.c | 102 +++++++++++++++++------------------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/test/general/logging_test.c b/test/general/logging_test.c index 631bfd026..c5b1b421f 100644 --- a/test/general/logging_test.c +++ b/test/general/logging_test.c @@ -6,70 +6,66 @@ #include #include -#define TIMEED_DEBUG_CHAR_LEN 30 -#define SOME_EXTRA_SPACE 10 +#define TIMEED_DEBUG_CHAR_LEN 30 +#define SOME_EXTRA_SPACE 10 /** -* @brief unit for LF_PRINT_DEBUG macro -* must be in LOG_LEVEL LOG_LEVEL_DEBUG -*/ -void test_logging_macro(const char *expected, int st_len) { + * @brief unit for LF_PRINT_DEBUG macro + * must be in LOG_LEVEL LOG_LEVEL_DEBUG + */ +void test_logging_macro(const char* expected, int st_len) { - FILE *tmp = tmpfile(); // auto-deletes when closed - char* buffer; - char pattern[256]; - regex_t re; - int result; + FILE* tmp = tmpfile(); // auto-deletes when closed + char* buffer; + char pattern[256]; + regex_t re; + int result; - // strlen("DEBUG: ") + null character + new line character + some extra space - int buffer_size = st_len + TIMEED_DEBUG_CHAR_LEN + SOME_EXTRA_SPACE; + // strlen("DEBUG: ") + null character + new line character + some extra space + int buffer_size = st_len + TIMEED_DEBUG_CHAR_LEN + SOME_EXTRA_SPACE; - if (!tmp) { - perror("tmpfile"); - exit(1); - } + if (!tmp) { + perror("tmpfile"); + exit(1); + } - // Redirect stdout -> tmp - fflush(stdout); - int fd = fileno(tmp); - if (fd == -1 || dup2(fd, STDOUT_FILENO) == -1) { - perror("redirect stdout"); - exit(1); - } + // Redirect stdout -> tmp + fflush(stdout); + int fd = fileno(tmp); + if (fd == -1 || dup2(fd, STDOUT_FILENO) == -1) { + perror("redirect stdout"); + exit(1); + } - // Call code under test - LF_PRINT_DEBUG("%s",expected); + // Call code under test + LF_PRINT_DEBUG("%s", expected); - fflush(stdout); // flush so data goes into tmp - rewind(tmp); // reset read position + fflush(stdout); // flush so data goes into tmp + rewind(tmp); // reset read position - // Read back - buffer = (char*) malloc(buffer_size); - size_t n = fread(buffer, 1, buffer_size -1, tmp); - buffer[n] = '\0'; - - // Regex to check format: DEBUG: [number]expected\n - snprintf(pattern, sizeof(pattern), - "^DEBUG: \\[-?[0-9]+\\]%s\\n?$", expected); + // Read back + buffer = (char*)malloc(buffer_size); + size_t n = fread(buffer, 1, buffer_size - 1, tmp); + buffer[n] = '\0'; - if (regcomp(&re, pattern, REG_EXTENDED | REG_NEWLINE) != 0) { - perror("regcomp"); - exit(1); - } + // Regex to check format: DEBUG: [number]expected\n + snprintf(pattern, sizeof(pattern), "^DEBUG: \\[-?[0-9]+\\]%s\\n?$", expected); - result = regexec(&re, buffer, 0, NULL, 0); - regfree(&re); + if (regcomp(&re, pattern, REG_EXTENDED | REG_NEWLINE) != 0) { + perror("regcomp"); + exit(1); + } - assert(result == 0); // match succeeded - - fclose(tmp); // deletes the file - free(buffer); -} + result = regexec(&re, buffer, 0, NULL, 0); + regfree(&re); -int main() -{ - char* str_test = "Hello World"; - test_logging_macro(str_test, strlen(str_test)); - return 0; -} + assert(result == 0); // match succeeded + fclose(tmp); // deletes the file + free(buffer); +} +int main() { + char* str_test = "Hello World"; + test_logging_macro(str_test, strlen(str_test)); + return 0; +} From 995e05e3999fb40d1dc856e34df61f667c6e3fa5 Mon Sep 17 00:00:00 2001 From: adi-65-ray Date: Tue, 14 Oct 2025 12:44:27 -0700 Subject: [PATCH 04/10] logging_macros format fix --- logging/api/logging_macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index 1c5357fb3..ac408f0bd 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -74,7 +74,7 @@ static const bool _lf_log_level_is_debug = LOG_LEVEL >= LOG_LEVEL_DEBUG; #define LF_PRINT_DEBUG(format, ...) \ do { \ if (_lf_log_level_is_debug) { \ - lf_print_debug("["PRINTF_TIME"]"format,lf_time_physical_elapsed(), ##__VA_ARGS__); \ + lf_print_debug("[" PRINTF_TIME "]" format, lf_time_physical_elapsed(), ##__VA_ARGS__); \ } \ } while (0) From 9564112a89eba0d90a5e4de1952c3788127d49d5 Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Tue, 21 Oct 2025 11:57:16 -0700 Subject: [PATCH 05/10] Update test/general/logging_test.c --- test/general/logging_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/general/logging_test.c b/test/general/logging_test.c index c5b1b421f..123802e90 100644 --- a/test/general/logging_test.c +++ b/test/general/logging_test.c @@ -20,7 +20,7 @@ void test_logging_macro(const char* expected, int st_len) { regex_t re; int result; - // strlen("DEBUG: ") + null character + new line character + some extra space + // Computing the buffer size based on strlen("DEBUG: ") + \0 + \n + extra space int buffer_size = st_len + TIMEED_DEBUG_CHAR_LEN + SOME_EXTRA_SPACE; if (!tmp) { From eb05623d6bfdb277793764a8f14a996519b2f373 Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Wed, 22 Oct 2025 09:14:44 -0700 Subject: [PATCH 06/10] Remove inclusion of tag.h --- logging/api/logging_macros.h | 1 - 1 file changed, 1 deletion(-) diff --git a/logging/api/logging_macros.h b/logging/api/logging_macros.h index ac408f0bd..3a8441160 100644 --- a/logging/api/logging_macros.h +++ b/logging/api/logging_macros.h @@ -12,7 +12,6 @@ #define LOGGING_MACROS_H #include "logging.h" #include -#include "tag.h" #include "low_level_platform.h" /** Default log level. */ From 578111d16af9c935fb19e99ac41ad3085e249ef6 Mon Sep 17 00:00:00 2001 From: adi-65-ray Date: Wed, 22 Oct 2025 11:53:51 -0700 Subject: [PATCH 07/10] Enable LOG_LEVEL_DEBUG for log UT --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e7baab409..b0f86c3b1 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ clean: .PHONY: unit-tests unit-tests: clean # In case NUMBER_OF_WORKERS has been set, unset it. - cmake -B build -UNUMBER_OF_WORKERS + cmake -B build -UNUMBER_OF_WORKERS -DLOG_LEVEL=4 cmake --build build cd build && make test From 948a758a5cf7893e172b9f8b0d642759b4637764 Mon Sep 17 00:00:00 2001 From: adi-65-ray Date: Tue, 28 Oct 2025 22:35:06 -0700 Subject: [PATCH 08/10] CI fix --- .github/workflows/ci.yml | 4 ++-- core/federated/RTI/CMakeLists.txt | 24 ++++++++++++------------ test/general/logging_test.c | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae670e1fa..32abf4e24 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,12 +21,12 @@ jobs: unit-tests-single: uses: ./.github/workflows/unit-tests.yml with: - cmake-args: '-UNUMBER_OF_WORKERS -DLF_SINGLE_THREADED=1' + cmake-args: '-UNUMBER_OF_WORKERS -DLF_SINGLE_THREADED=1 -DLOG_LEVEL=4' unit-tests-multi: uses: ./.github/workflows/unit-tests.yml with: - cmake-args: '-DNUMBER_OF_WORKERS=4 -ULF_SINGLE_THREADED' + cmake-args: '-DNUMBER_OF_WORKERS=4 -ULF_SINGLE_THREADED -DLOG_LEVEL=4' build-rti: uses: ./.github/workflows/build-rti.yml diff --git a/core/federated/RTI/CMakeLists.txt b/core/federated/RTI/CMakeLists.txt index 56217d06a..4540c49b8 100644 --- a/core/federated/RTI/CMakeLists.txt +++ b/core/federated/RTI/CMakeLists.txt @@ -44,6 +44,18 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG) ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG) target_compile_definitions(${RTI_LIB} PUBLIC LOG_LEVEL=${LOG_LEVEL}) +include(${LF_ROOT}/low_level_platform/impl/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-impl) + +include(${LF_ROOT}/low_level_platform/api/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-api) + +include(${LF_ROOT}/platform/api/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::platform-api) + +include(${LF_ROOT}/platform/impl/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::platform-impl) + include(${LF_ROOT}/version/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::version-api) @@ -53,24 +65,12 @@ target_link_libraries(${RTI_LIB} PUBLIC lf::logging-api) include(${LF_ROOT}/tag/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::tag-api) -include(${LF_ROOT}/platform/api/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::platform-api) - -include(${LF_ROOT}/platform/impl/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::platform-impl) - include(${LF_ROOT}/trace/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-api) include(${LF_ROOT}/trace/impl/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-impl) -include(${LF_ROOT}/low_level_platform/impl/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-impl) - -include(${LF_ROOT}/low_level_platform/api/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-api) - # Set the STANDALONE_RTI flag to include the rti_remote and rti_common. target_compile_definitions(${RTI_LIB} PUBLIC STANDALONE_RTI=1) diff --git a/test/general/logging_test.c b/test/general/logging_test.c index 123802e90..a20f7d5e3 100644 --- a/test/general/logging_test.c +++ b/test/general/logging_test.c @@ -10,7 +10,7 @@ #define SOME_EXTRA_SPACE 10 /** * @brief unit for LF_PRINT_DEBUG macro - * must be in LOG_LEVEL LOG_LEVEL_DEBUG + * LOG_LEVEL must be in LOG_LEVEL_DEBUG */ void test_logging_macro(const char* expected, int st_len) { From dba50620de7b7294a9e7cd441abfec402b96c257 Mon Sep 17 00:00:00 2001 From: adi-65-ray Date: Wed, 29 Oct 2025 01:26:44 -0700 Subject: [PATCH 09/10] trace low-level-platform dependency --- trace/impl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/trace/impl/CMakeLists.txt b/trace/impl/CMakeLists.txt index f4a6b8b55..2da8e5bfa 100644 --- a/trace/impl/CMakeLists.txt +++ b/trace/impl/CMakeLists.txt @@ -5,6 +5,7 @@ add_library(lf-trace-impl STATIC) add_library(lf::trace-impl ALIAS lf-trace-impl) target_link_libraries(lf-trace-impl PRIVATE lf::trace-api) target_link_libraries(lf-trace-impl PRIVATE lf::platform-api) +target_link_libraries(lf-trace-impl PRIVATE lf::low-level-platform-api) target_link_libraries(lf-trace-impl PRIVATE lf::logging-api) target_link_libraries(lf-trace-impl PRIVATE lf::version-api) lf_enable_compiler_warnings(lf-trace-impl) From 9ca2499a71d855fb4d2b8be552969ae5f6ceea6e Mon Sep 17 00:00:00 2001 From: Hokeun Kim Date: Thu, 30 Oct 2025 12:06:02 -0700 Subject: [PATCH 10/10] Revert unnecessary change to CMakeLists --- core/federated/RTI/CMakeLists.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/federated/RTI/CMakeLists.txt b/core/federated/RTI/CMakeLists.txt index 4540c49b8..56217d06a 100644 --- a/core/federated/RTI/CMakeLists.txt +++ b/core/federated/RTI/CMakeLists.txt @@ -44,18 +44,6 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG) ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG) target_compile_definitions(${RTI_LIB} PUBLIC LOG_LEVEL=${LOG_LEVEL}) -include(${LF_ROOT}/low_level_platform/impl/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-impl) - -include(${LF_ROOT}/low_level_platform/api/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-api) - -include(${LF_ROOT}/platform/api/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::platform-api) - -include(${LF_ROOT}/platform/impl/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::platform-impl) - include(${LF_ROOT}/version/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::version-api) @@ -65,12 +53,24 @@ target_link_libraries(${RTI_LIB} PUBLIC lf::logging-api) include(${LF_ROOT}/tag/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::tag-api) +include(${LF_ROOT}/platform/api/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::platform-api) + +include(${LF_ROOT}/platform/impl/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::platform-impl) + include(${LF_ROOT}/trace/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-api) include(${LF_ROOT}/trace/impl/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-impl) +include(${LF_ROOT}/low_level_platform/impl/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-impl) + +include(${LF_ROOT}/low_level_platform/api/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::low-level-platform-api) + # Set the STANDALONE_RTI flag to include the rti_remote and rti_common. target_compile_definitions(${RTI_LIB} PUBLIC STANDALONE_RTI=1)