Skip to content

Commit 4aa5e2f

Browse files
committed
web: uniquify temp file paths in tests to avoid PID-collision races
tempHtml/tempPng wrote to /tmp/web_test_<label>.{html,png} with no per-process suffix. Concurrent invocations of the same gtest case (CI parallel jobs / retries / sharding) raced on the same path: one process's std::ofstream truncated another's in-flight write, producing a half-written file that was missing varying substrings depending on flush timing. Append getpid() to the filename so each process owns a private path. Verified by reproducing the race with 32 parallel runs of SaveReportTest.ContainsInlinedJS (100% failure before, 0% after). Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent 95bfbab commit 4aa5e2f

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/web/test/cpp/TestSaveImage.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2026, The OpenROAD Authors
33

4+
#include <unistd.h>
5+
46
#include <cstddef>
57
#include <cstring>
68
#include <filesystem>
@@ -79,8 +81,9 @@ class SaveImageTest : public tst::Nangate45Fixture
7981
// Save to a temp file and register for cleanup.
8082
std::string tempPng(const std::string& label)
8183
{
82-
std::string path = std::filesystem::temp_directory_path()
83-
/ ("web_test_" + label + ".png");
84+
std::string path
85+
= std::filesystem::temp_directory_path()
86+
/ ("web_test_" + label + "_" + std::to_string(::getpid()) + ".png");
8487
output_files_.push_back(path);
8588
return path;
8689
}

src/web/test/cpp/TestSaveReport.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2026, The OpenROAD Authors
33

4+
#include <unistd.h>
5+
46
#include <cstddef>
57
#include <filesystem>
68
#include <fstream>
@@ -59,8 +61,9 @@ class SaveReportTest : public tst::Nangate45Fixture
5961

6062
std::string tempHtml(const std::string& label)
6163
{
62-
std::string path = std::filesystem::temp_directory_path()
63-
/ ("web_test_" + label + ".html");
64+
std::string path
65+
= std::filesystem::temp_directory_path()
66+
/ ("web_test_" + label + "_" + std::to_string(::getpid()) + ".html");
6467
output_files_.push_back(path);
6568
return path;
6669
}

0 commit comments

Comments
 (0)