[Test] (MG_Test/Util): give each log level test process its own log file

This commit is contained in:
2026-10-15 12:22:36 -04:00
parent d3c10f15c3
commit 174a428e81
+18 -2
View File
@@ -30,6 +30,12 @@
#include <sstream>
#include <string>
#if defined(_WIN32)
#include <process.h>
#else
#include <unistd.h>
#endif
namespace {
// ---------------------------------------------------------------------------
@@ -77,6 +83,14 @@ namespace {
// line per level and then reads the file back.
std::string g_logPath;
int ProcessId() {
#if defined(_WIN32)
return _getpid();
#else
return static_cast<int>(getpid());
#endif
}
struct Emitted {
bool debug = false;
bool info = false;
@@ -186,9 +200,11 @@ namespace {
int main(int argc, char** argv) {
// Must happen before anything logs: MG_Util::Debug::InitFile() reads the variable
// once, on the first write, and caches the FILE*.
// once, on the first write, and caches the FILE*. The name carries the process id because
// ctest runs each case as its own process, in parallel.
namespace fs = std::filesystem;
const fs::path path = fs::temp_directory_path() / "mobilegl-loglevel-test.log";
const fs::path path =
fs::temp_directory_path() / ("mobilegl-loglevel-test-" + std::to_string(ProcessId()) + ".log");
std::error_code ec;
fs::remove(path, ec);
g_logPath = path.string();