mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-27 11:42:15 +09:00
[Test] (MG_Test/Util): give each log level test process its own log file
This commit is contained in:
1 parent
d3c10f15c3
commit
174a428e81
1 file changed
+18
-2
@@ -30,6 +30,12 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <process.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -77,6 +83,14 @@ namespace {
|
|||||||
// line per level and then reads the file back.
|
// line per level and then reads the file back.
|
||||||
std::string g_logPath;
|
std::string g_logPath;
|
||||||
|
|
||||||
|
int ProcessId() {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
return _getpid();
|
||||||
|
#else
|
||||||
|
return static_cast<int>(getpid());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct Emitted {
|
struct Emitted {
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
bool info = false;
|
bool info = false;
|
||||||
@@ -186,9 +200,11 @@ namespace {
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
// Must happen before anything logs: MG_Util::Debug::InitFile() reads the variable
|
// 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;
|
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;
|
std::error_code ec;
|
||||||
fs::remove(path, ec);
|
fs::remove(path, ec);
|
||||||
g_logPath = path.string();
|
g_logPath = path.string();
|
||||||
|
|||||||
Reference in new issue
Block a user