File tree Expand file tree Collapse file tree 2 files changed +18
-37
lines changed
Expand file tree Collapse file tree 2 files changed +18
-37
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- import gzip
43import importlib .util
54import pathlib
65import tempfile
@@ -627,31 +626,3 @@ def guarded_keychain() -> Iterator[None]:
627626 keychain .KEYCHAIN .clear ()
628627 yield
629628 keychain .KEYCHAIN .clear ()
630-
631-
632- @pytest .fixture (scope = "session" )
633- def path_debian_ext4_raw (tmp_path_factory : pytest .TempPathFactory ) -> Iterator [pathlib .Path ]:
634- """Fixture that provides a path to a Debian Trixie ext4 raw image.
635-
636- The image only contains a /bin directory with ~1000 files and an /etc directory with some configuration files.
637- The rest of the filesystem is not included.
638-
639- The /bin files are all sparse (filled with zeros).
640- The files in /etc do contain data.
641-
642- The source image is stored compressed in the test data directory to save space.
643- Compressed size is 100kb and decompresses to 5mb.
644- """
645- tmp_path = tmp_path_factory .mktemp ("data" )
646-
647- raw_path = tmp_path / "debian-trixie-bin-ext4.raw"
648- with gzip .open (absolute_path ("_data/filesystems/ext4/debian-trixie-bin-ext4.raw.gz" ), "rb" ) as fh :
649- raw_path .write_bytes (fh .read ())
650-
651- return raw_path
652-
653-
654- @pytest .fixture
655- def target_debian_ext4_raw (path_debian_ext4_raw : pathlib .Path ) -> Target :
656- """Fixture that provides a Target for a Debian Trixie ext4 raw image."""
657- return Target .open (path_debian_ext4_raw )
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import argparse
4+ import gzip
45import os
56import pathlib
67import platform
1314
1415import pytest
1516
17+ from dissect .target .containers .raw import RawContainer
1618from dissect .target .helpers .fsutil import TargetPath , normalize
19+ from dissect .target .target import Target
1720from dissect .target .tools .shell import (
1821 DebugMode ,
1922 ExtendedCmd ,
3336
3437 from pytest_benchmark .fixture import BenchmarkFixture
3538
36- from dissect .target .target import Target
37-
3839
3940try :
4041 import pexpect
@@ -617,16 +618,25 @@ def ansi_new_data(cls: pexpect.expect.Expecter, data: bytes) -> int | None:
617618 ],
618619)
619620def test_benchmark_ls_bin (
620- target_debian_ext4_raw : Target ,
621621 benchmark : BenchmarkFixture ,
622622 args : str ,
623623 capsys : pytest .CaptureFixture ,
624624) -> None :
625625 """Benchmark ls command with different parameters with a /bin directory containing ~1000 files."""
626+ with gzip .open (absolute_path ("_data/filesystems/ext4/debian-trixie-bin-ext4.raw.gz" ), "rb" ) as fh :
627+ container = RawContainer (fh )
628+
629+ t = Target ()
630+ t .disks .add (container )
631+ t .apply ()
632+
633+ def run_ls () -> None :
634+ target_cli = TargetCli (t )
635+ target_cli .onecmd (f"ls { args } /bin" )
626636
627- def run_ls () -> None :
628- target_cli = TargetCli (target_debian_ext4_raw )
629- target_cli .onecmd (f"ls { args } /bin" )
637+ benchmark (run_ls )
630638
631- benchmark (run_ls )
632- capsys .readouterr ()
639+ out , err = capsys .readouterr ()
640+ assert not err
641+ assert "bash" in out
642+ assert "zgrep" in out
You can’t perform that action at this time.
0 commit comments