From a1ba52d146af15b56b8c477f8c87c9621ec23b0b Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 6 Jan 2024 00:00:08 +0100 Subject: [PATCH] chore(dwarfsextract): use iolayer abstractions for mapping image --- src/dwarfsextract_main.cpp | 3 ++- test/tool_main_test.cpp | 16 +++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/dwarfsextract_main.cpp b/src/dwarfsextract_main.cpp index d1895e4d..dfbe4e9c 100644 --- a/src/dwarfsextract_main.cpp +++ b/src/dwarfsextract_main.cpp @@ -35,6 +35,7 @@ #include "dwarfs/logger.h" #include "dwarfs/mmap.h" #include "dwarfs/options.h" +#include "dwarfs/os_access.h" #include "dwarfs/performance_monitor.h" #include "dwarfs/tool.h" #include "dwarfs/util.h" @@ -137,7 +138,7 @@ int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) { std::shared_ptr perfmon = performance_monitor::create(perfmon_enabled); - filesystem_v2 fs(lgr, std::make_shared(filesystem), fsopts, perfmon); + filesystem_v2 fs(lgr, iol.os->map_file(filesystem), fsopts, perfmon); filesystem_extractor fsx(lgr); if (format.empty()) { diff --git a/test/tool_main_test.cpp b/test/tool_main_test.cpp index 39d5c238..a433040c 100644 --- a/test/tool_main_test.cpp +++ b/test/tool_main_test.cpp @@ -54,7 +54,6 @@ namespace { auto test_dir = fs::path(TEST_DATA_DIR).make_preferred(); auto audio_data_dir = test_dir / "pcmaudio"; -auto test_data_image = test_dir / "data.dwarfs"; enum class input_mode { from_file, @@ -429,14 +428,13 @@ TEST_F(dwarfsextract_main_test, cmdline_help_arg) { } #ifdef DWARFS_PERFMON_ENABLED -TEST_F(dwarfsextract_main_test, perfmon) { - // TODO: passing in test_data_image this way only only works because - // dwarfsextract_main does not currently use the os_access abstraction - auto exit_code = run({"-i", test_data_image.string(), "-f", "mtree", - "--perfmon", "filesystem_v2,inode_reader_v2"}); - EXPECT_EQ(exit_code, 0); - auto outs = out(); - auto errs = err(); +TEST(dwarfsextract_test, perfmon) { + auto t = dwarfsextract_tester::create_with_image(); + EXPECT_EQ(0, t.run({"-i", "image.dwarfs", "-f", "mtree", "--perfmon", + "filesystem_v2,inode_reader_v2"})) + << t.err(); + auto outs = t.out(); + auto errs = t.err(); EXPECT_GT(outs.size(), 100); EXPECT_FALSE(errs.empty()); EXPECT_THAT(errs, ::testing::HasSubstr("[filesystem_v2.readv_future]"));