Skip to content

Commit 571cd12

Browse files
committed
[test] Implement Sigterm-equivalent test for Unix
Fixes #13300
1 parent efc88a7 commit 571cd12

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

io/io/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# For the list of contributors see $ROOTSYS/README/CREDITS.
66

77
ROOT_ADD_GTEST(RRawFile RRawFile.cxx LIBRARIES RIO)
8-
ROOT_ADD_GTEST(TFile TFileTests.cxx LIBRARIES RIO)
8+
ROOT_ADD_GTEST(TFile TFileTests.cxx LIBRARIES RIO Hist)
99
ROOT_ADD_GTEST(TBufferFile TBufferFileTests.cxx LIBRARIES RIO)
1010
ROOT_ADD_GTEST(TBufferMerger TBufferMerger.cxx LIBRARIES RIO Imt Tree)
1111
ROOT_ADD_GTEST(TBufferJSON TBufferJSONTests.cxx LIBRARIES RIO)

io/io/test/TFileTests.cxx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include <memory>
22
#include <vector>
33
#include <string>
4+
#include <csignal>
45

56
#include "gtest/gtest.h"
67

78
#include "TFile.h"
9+
#include "TH1I.h"
810
#include "TMemFile.h"
911
#include "TDirectory.h"
1012
#include "TKey.h"
@@ -251,3 +253,31 @@ TEST(TFile, WalkTKeys)
251253
EXPECT_EQ(it->fKeyName, kLongerKey);
252254
EXPECT_EQ(it->fClassName, "string");
253255
}
256+
257+
void handle_sigterm(int signum)
258+
{
259+
terminated = 1;
260+
std::cout << "handled signal " << strsignal(signum) << " on PID " << getpid() << std::endl;
261+
}
262+
263+
// https://github.com/root-project/root/issues/13300
264+
TEST(TFile, Sigterm)
265+
{
266+
auto filename = "out13300.root";
267+
{
268+
TFile file(filename, "RECREATE");
269+
file.mkdir("subdir")->cd();
270+
TH1I hist("h", "h", 10, 0., 1.);
271+
hist.Fill(0.4);
272+
// Since the real behavior is save+close+crash which would make the test fail,
273+
// rather than calling directly std::raise(SIGTERM),
274+
// we emulate the response to SIGTERM in TerminalConfigUnix before crash:
275+
TROOT::WriteCloseAllFiles();
276+
TROOT::CleanUpROOTAtExit();
277+
}
278+
{
279+
TFile file(filename, "READ");
280+
ASSERT_EQ(file.Get<TH1I>("subdir/h")->GetBinContent(5), 1);
281+
}
282+
gSystem->Unlink(filename);
283+
}

0 commit comments

Comments
 (0)