Skip to content

Commit 2c7da01

Browse files
committed
[io] add test for adding object close to 1GiB
1 parent 8db960b commit 2c7da01

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

io/io/test/TFileTests.cxx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,35 @@ TEST(TFile, DeleteKey)
452452
// Same as before the recovery
453453
EXPECT_EQ(4, fnCountGaps(fileGuard.GetPath()));
454454
}
455+
456+
TEST(TFile, KeySizeLimit)
457+
{
458+
// The following tests run out of memory on 32bit platforms
459+
if (sizeof(std::size_t) == 4) {
460+
GTEST_SKIP() << "Skipping test on 32bit platform.";
461+
}
462+
463+
ROOT::TestSupport::FileRaii fileGuard("tfile_test_key_size_limit.root");
464+
465+
auto f = std::unique_ptr<TFile>(TFile::Open(fileGuard.GetPath().c_str(), "RECREATE"));
466+
f->SetCompressionSettings(0);
467+
468+
// Check that we can add keys >1GB (but smaller than 1GiB, obviously) in small and large files.
469+
// This does work even though the last, virtual free segment is 1GB (and not 1GiB). The code looking for a
470+
// free segment, however, does not check the size of the last virtual gap in this case.
471+
472+
std::vector<char> v;
473+
v.resize(1000 * 1000 * 1000 + 100, 'x'); // more than 1GB but less the 1GiB
474+
f->WriteObject(&v, "v0");
475+
EXPECT_LT(f->GetEND(), TFile::kStartBigFile);
476+
f->WriteObject(&v, "v1");
477+
EXPECT_GT(f->GetEND(), TFile::kStartBigFile);
478+
f->Write();
479+
f->Close();
480+
481+
f = std::unique_ptr<TFile>(TFile::Open(fileGuard.GetPath().c_str(), "UPDATE"));
482+
EXPECT_GT(f->GetEND(), TFile::kStartBigFile);
483+
f->WriteObject(&v, "v2");
484+
f->Write();
485+
f->Close();
486+
}

0 commit comments

Comments
 (0)