This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new 0d2c5c8d multiprocessrollingtest in macOS: fix compilation and the
test itself (#502)
0d2c5c8d is described below
commit 0d2c5c8dbe8fe2fd3dedac82a90f371ea7de8687
Author: RK-BFX <[email protected]>
AuthorDate: Sat Jun 14 07:58:04 2025 +0300
multiprocessrollingtest in macOS: fix compilation and the test itself (#502)
Fixes apache#501:
1. Add necessary `#include`s to get the per-platform calls in
`GetExecutableFileName()` to compile.
2. Fix buffer size passed to `_NSGetExecutablePath()` in macOS.
Plus:
A. Add more diagnostics for test failures like this.
B. Add useful TODO comments.
Also fix some linter warnings:
a. 3 signed-unsigned comparison mismatches;
b. 1 possibly unused variable.
* Add the Multiprocess Rolling File Appender to GitHub CI macOS
---
.github/workflows/log4cxx-macos.yml | 11 ++++++-
src/test/cpp/rolling/multiprocessrollingtest.cpp | 38 +++++++++++++++++++-----
2 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/log4cxx-macos.yml
b/.github/workflows/log4cxx-macos.yml
index 21186763..55b56d23 100644
--- a/.github/workflows/log4cxx-macos.yml
+++ b/.github/workflows/log4cxx-macos.yml
@@ -31,16 +31,19 @@ jobs:
cxx: clang++
odbc: OFF
qt: ON
+ multiprocess: OFF
- name: osx-14
os: macos-14
cxx: clang++
odbc: ON
qt: OFF
+ multiprocess: ON
- name: osx-g++
os: macos-latest
cxx: g++-14
odbc: OFF
qt: OFF
+ multiprocess: OFF
steps:
- uses: actions/checkout@v4
@@ -59,7 +62,13 @@ jobs:
cd main
mkdir build
cd build
- cmake -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DLOG4CXX_ENABLE_ODBC=${{
matrix.odbc }} -DLOG4CXX_CFSTRING=ON -DCMAKE_BUILD_TYPE=Debug ..
+ cmake \
+ -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
+ -DLOG4CXX_ENABLE_ODBC=${{ matrix.odbc }} \
+ -DLOG4CXX_MULTIPROCESS_ROLLING_FILE_APPENDER=${{ matrix.multiprocess
}} \
+ -DLOG4CXX_CFSTRING=ON \
+ -DCMAKE_BUILD_TYPE=Debug \
+ ..
cmake --build .
- name: run unit tests
diff --git a/src/test/cpp/rolling/multiprocessrollingtest.cpp
b/src/test/cpp/rolling/multiprocessrollingtest.cpp
index cf365f3d..244b12a6 100644
--- a/src/test/cpp/rolling/multiprocessrollingtest.cpp
+++ b/src/test/cpp/rolling/multiprocessrollingtest.cpp
@@ -31,7 +31,16 @@
#include <filesystem>
#include <fstream>
#include <apr_thread_proc.h>
-#include <thread>
+
+#ifdef _WIN32
+#include <windows.h> // GetModuleFileName
+#elif __APPLE__
+#include <mach-o/dyld.h> // _NSGetExecutablePath
+#elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500) ||
(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L)
+#include <unistd.h> // getpid
+#else
+#include <cstring> // strncpy
+#endif
using namespace LOG4CXX_NS;
@@ -131,7 +140,7 @@ public:
approxBytesPerLogFile =
pPolicy->getMaxFileSize();
}
auto requiredLogEventCount = (approxBytesPerLogFile *
requiredLogFileCount + approxBytesPerLogEvent - 1) / approxBytesPerLogEvent;
- for ( int x = 0; x < requiredLogEventCount; x++ )
+ for ( size_t x = 0; x < requiredLogEventCount; x++ )
{
LOG4CXX_INFO( logger, "This is test message " << x );
}
@@ -167,7 +176,7 @@ public:
approxBytesPerLogFile =
pPolicy->getMaxFileSize();
}
auto requiredLogEventCount = (approxBytesPerLogFile *
requiredLogFileCount + approxBytesPerLogEvent - 1) / approxBytesPerLogEvent;
- for ( int x = 0; x < requiredLogEventCount; x++ )
+ for ( size_t x = 0; x < requiredLogEventCount; x++ )
{
LOG4CXX_INFO( logger, "This is test message " << x );
}
@@ -192,6 +201,10 @@ public:
}
helpers::FileOutputStream
output(LOG4CXX_STR("output/rolling/multiprocess-test4-child.log"), false);
auto thisProgram = GetExecutableFileName();
+ bool thisProgramExists = std::filesystem::exists(thisProgram);
+ if (!thisProgramExists && helpers::LogLog::isDebugEnabled())
+ helpers::LogLog::debug(LOG4CXX_STR("thisProgram: ") +
thisProgram);
+ LOGUNIT_ASSERT(thisProgramExists);
const char* args[] = {thisProgram.c_str(), "test3", 0};
helpers::Pool p;
apr_procattr_t* attr = NULL;
@@ -205,6 +218,16 @@ public:
int exitCode;
apr_exit_why_e reason;
apr_proc_wait(&pid[i], &exitCode, &reason, APR_WAIT);
+ if (exitCode != 0 && helpers::LogLog::isDebugEnabled())
+ {
+ LogString msg = LOG4CXX_STR("child: ");
+ helpers::StringHelper::toString(i, p, msg);
+ msg += LOG4CXX_STR("; exit code: ");
+ helpers::StringHelper::toString(exitCode, p,
msg);
+ msg += LOG4CXX_STR("; reason: ");
+ helpers::StringHelper::toString(reason, p, msg);
+ helpers::LogLog::debug(msg);
+ }
LOGUNIT_ASSERT_EQUAL(exitCode, 0);
}
if (helpers::LogLog::isDebugEnabled())
@@ -236,7 +259,7 @@ public:
{
try
{
- auto msgNumber =
std::stoi(line.substr(pos));
+ auto msgNumber =
std::stoull(line.substr(pos));
if (messageCount.size()
<= msgNumber)
messageCount.resize(msgNumber + 1);
++messageCount[msgNumber];
@@ -344,11 +367,11 @@ private:
{
static const int bufSize = 4096;
char buf[bufSize+1] = {0};
- uint32_t bufCount = 0;
+ [[maybe_unused]] uint32_t bufCount = bufSize;
#if defined(_WIN32)
- GetModuleFileName(NULL, buf, bufSize);
+ GetModuleFileName(NULL, buf, bufSize); // TODO handle failure,
e.g. ERROR_INSUFFICIENT_BUFFER
#elif defined(__APPLE__)
- _NSGetExecutablePath(buf, &bufCount);
+ _NSGetExecutablePath(buf, &bufCount); // TODO handle failure
#elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500) ||
(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L)
std::ostringstream exeLink;
exeLink << "/proc/" << getpid() << "/exe";
@@ -372,4 +395,3 @@ private:
};
LOGUNIT_TEST_SUITE_REGISTRATION(MultiprocessRollingTest);
-