From eff0880f3b026a1c2a26eb56e4eb7c844c0f9a3e Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sat, 29 Jan 2022 19:55:44 +0600 Subject: [PATCH] tests/logging: also test printing the filename information This commit demonstrates a bug introduced in [1], which can be observed when the logging is configured to print the filename *after* the logging message (LOG_FILENAME_POS_HEADER_END): logging print file 1 last ^^^^ In this mode, the code in _output_buf() overwrites the '\n' sybmol contained in the logging message itself by shifting the 'offset' backwards, and appends the nipped '\n' after the filename info. The problem is that the 'len' variable is not updated in this case, so the resulting length includes +1 character - '\0', which gets printed at the end of every logging line. Interestingly enough, this problem affects only the wqueue mode. Change-Id: I54bf5e5c036efb1908232fe3d8e8e2989715fbb3 Related: [1] I393907b3c9e0cc1145e102328adad0a83ee13a9f --- tests/logging/logging_test.c | 8 ++++++++ tests/logging/logging_test_stream.err | 2 ++ tests/logging/logging_test_wqueue.err | Bin 348 -> 488 bytes 3 files changed, 10 insertions(+) diff --git a/tests/logging/logging_test.c b/tests/logging/logging_test.c index 12a7374f0..3548b1dd6 100644 --- a/tests/logging/logging_test.c +++ b/tests/logging/logging_test.c @@ -130,5 +130,13 @@ int main(int argc, char **argv) log_set_category_filter(stderr_target, DLGLOBAL, 1, LOGL_DEBUG); DEBUGP(DLGLOBAL, "You should see this (DLGLOBAL on DEBUG)\n"); + /* Test printing of the filename */ + log_set_print_filename2(stderr_target, LOG_FILENAME_BASENAME); + + log_set_print_filename_pos(stderr_target, LOG_FILENAME_POS_HEADER_END); + DEBUGP(DLGLOBAL, "A message with source info printed first\n"); + log_set_print_filename_pos(stderr_target, LOG_FILENAME_POS_LINE_END); + DEBUGP(DLGLOBAL, "A message with source info printed last\n"); + return 0; } diff --git a/tests/logging/logging_test_stream.err b/tests/logging/logging_test_stream.err index 17b3cad06..01ab87827 100644 --- a/tests/logging/logging_test_stream.err +++ b/tests/logging/logging_test_stream.err @@ -7,3 +7,5 @@ DLGLOBAL You should see this on DLGLOBAL (c) DLGLOBAL You should see this on DLGLOBAL (d) DLGLOBAL You should see this on DLGLOBAL (e) DLGLOBAL You should see this (DLGLOBAL on DEBUG) +DLGLOBAL logging_test.c:137 A message with source info printed first +DLGLOBAL A message with source info printed last (logging_test.c:139) diff --git a/tests/logging/logging_test_wqueue.err b/tests/logging/logging_test_wqueue.err index 17b3cad06b99f802e83836f7ad89fc44e56a1ccc..3e2008ba81443693bc2d48eade291ec251acc6ce 100644 GIT binary patch delta 149 zcmcb^^n!Uq3}d~EkGqe*lcSG9PJViNW?p)HNosM4Ub2;;vAKeyLT+ktabkL^LV0FM zhC*?EX;E^jLS|lCzCuA!W?o5Zib7guQE>?u+z=vk