Skip to content

Commit b80ead8

Browse files
committed
Merge bitcoin/bitcoin#32890: bench: Avoid tmp files in pwd
fa2fbaa bench: Avoid tmp files in pwd (MarcoFalke) Pull request description: It is a bit confusing that one bench run, when aborted, could leave behind temp files in the current working directory. It is similarly confusing to delete those files in the next run of bench. Fix all issues by using `BasicTestingSetup`, which provides a proper temp folder to use and also cleans up after itself. Can be tested via: ``` ( echo 'my file content' > streams_tmp ) && ls streams_tmp && ./bld-cmake/bin/bench_bitcoin --filter=FindByte && ls streams_tmp ``` Previously the file would be deleted, now it is kept. ACKs for top commit: stickies-v: ACK fa2fbaa Tree-SHA512: 33798030f990d1b4c95be4682d8dbfad95e8716d5fc0b99d65937196f2ced1ba649193c2adba4155f4eec9fd06e16be6667f3c3705af1880f47b2ff57a76243b
2 parents c4f9090 + fa2fbaa commit b80ead8

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/bench/streams_findbyte.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <bench/bench.h>
6-
76
#include <streams.h>
7+
#include <test/util/setup_common.h>
88
#include <util/fs.h>
99

1010
#include <cstddef>
@@ -13,11 +13,11 @@
1313

1414
static void FindByte(benchmark::Bench& bench)
1515
{
16-
// Setup
17-
AutoFile file{fsbridge::fopen("streams_tmp", "w+b")};
16+
const auto testing_setup{MakeNoLogFileContext<const BasicTestingSetup>(ChainType::REGTEST)};
17+
AutoFile file{fsbridge::fopen(testing_setup->m_path_root / "streams_tmp", "w+b")};
1818
const size_t file_size = 200;
1919
uint8_t data[file_size] = {0};
20-
data[file_size-1] = 1;
20+
data[file_size - 1] = 1;
2121
file << data;
2222
file.seek(0, SEEK_SET);
2323
BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size};
@@ -27,9 +27,7 @@ static void FindByte(benchmark::Bench& bench)
2727
bf.FindByte(std::byte(1));
2828
});
2929

30-
// Cleanup
3130
assert(file.fclose() == 0);
32-
fs::remove("streams_tmp");
3331
}
3432

3533
BENCHMARK(FindByte, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)