From a7a82ffee5539917e55f13855ab449f8d4a291fd Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 29 Sep 2026 02:41:15 -0400 Subject: [PATCH] [Test] (MG_Remote): P9 W3 - LogForwardTest leaves no role logs in /tmp on a green run --- MobileGL/MG_Test/Wire/LogForwardTest.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/MobileGL/MG_Test/Wire/LogForwardTest.cpp b/MobileGL/MG_Test/Wire/LogForwardTest.cpp index 7977c5c3..57d74af5 100644 --- a/MobileGL/MG_Test/Wire/LogForwardTest.cpp +++ b/MobileGL/MG_Test/Wire/LogForwardTest.cpp @@ -239,17 +239,32 @@ namespace { // ---- 2. the logger ------------------------------------------------------------------------ // One log base for the whole binary: the file sinks latch their path on first use, and gtest - // may run every case in one process. + // may run every case in one process. A green run leaves nothing in /tmp (the environment below); + // a red one keeps both role files for the triage. + bool g_logBaseMade = false; const std::string& LogBase() { static const std::string base = [] { const std::string path = "/tmp/mgl-logforward-" + std::to_string(::getpid()) + ".log"; ::setenv("MOBILEGL_LOG_FILE_PATH", path.c_str(), 1); Debug::TruncateRoleLogs(path.c_str()); + g_logBaseMade = true; return path; }(); return base; } + class RemoveRoleLogsIfGreen final : public ::testing::Environment { + public: + void TearDown() override { + if (!g_logBaseMade || !::testing::UnitTest::GetInstance()->Passed()) return; + for (const auto role : {Debug::LogRole::Client, Debug::LogRole::Server}) { + ::unlink(Debug::RoleLogPath(LogBase().c_str(), role).c_str()); + } + } + }; + [[maybe_unused]] ::testing::Environment* const g_removeRoleLogs = + ::testing::AddGlobalTestEnvironment(new RemoveRoleLogsIfGreen); + std::string ReadWhole(const std::string& path) { std::string all; if (FILE* file = std::fopen(path.c_str(), "rb")) {