Skip to content

Commit beb694c

Browse files
committed
[test] Implement Sigterm-equivalent test for Unix
Fixes #13300
1 parent df677ad commit beb694c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "gtest/gtest.h"
66

77
#include "TFile.h"
8+
#include "TH1I.h"
89
#include "TMemFile.h"
910
#include "TDirectory.h"
1011
#include "TKey.h"
@@ -251,3 +252,25 @@ TEST(TFile, WalkTKeys)
251252
EXPECT_EQ(it->fKeyName, kLongerKey);
252253
EXPECT_EQ(it->fClassName, "string");
253254
}
255+
256+
// https://github.com/root-project/root/issues/13300
257+
TEST(TFile, Sigterm)
258+
{
259+
auto filename = "out13300.root";
260+
{
261+
TFile file(filename, "RECREATE");
262+
file.mkdir("subdir")->cd();
263+
TH1I hist("h", "h", 10, 0., 1.);
264+
hist.Fill(0.4);
265+
// Since the real behavior is save+close+crash which would make the test fail,
266+
// rather than calling directly std::raise(SIGTERM),
267+
// we emulate the response to SIGTERM in TerminalConfigUnix before crash:
268+
TROOT::WriteCloseAllFiles();
269+
TROOT::CleanUpROOTAtExit();
270+
}
271+
{
272+
TFile file(filename, "READ");
273+
ASSERT_EQ(file.Get<TH1I>("subdir/h")->GetBinContent(5), 1);
274+
}
275+
gSystem->Unlink(filename);
276+
}

0 commit comments

Comments
 (0)