Files
Willi Ballenthin 9a8aad5e37 Share the handler test harness
Move the helpers that call a handler with a dispatch context into
tests/handler_harness.py and the emulator fixtures into conftest.py, so
handler tests in other files can use them. Add start_process for handlers
that need the current process and thread, and an x64 driver fixture.
2026-10-08 20:09:30 +01:00

71 lines
1.8 KiB
Python

import copy
import json
import lzma
from collections.abc import Callable, Iterator
from functools import cache
from pathlib import Path
from typing import Any
import pytest
from speakeasy import Speakeasy
from tests.handler_harness import load_emu
TESTS_DIR = Path(__file__).resolve().parent
BINS_DIR = TESTS_DIR / "bins"
@pytest.fixture(scope="session")
def base_config():
with (TESTS_DIR / "test.json").open() as f:
return json.load(f)
@pytest.fixture
def config(base_config):
return copy.deepcopy(base_config)
@pytest.fixture(scope="session")
def load_test_bin():
@cache
def _load(bin_name: str) -> bytes:
with lzma.open(BINS_DIR / bin_name) as f:
return f.read()
return _load
@pytest.fixture
def run_test():
def _run(cfg, target, argv=None):
se = Speakeasy(config=cfg, argv=argv or [])
try:
module = se.load_module(data=target)
se.run_module(module, all_entrypoints=True)
return se.get_report()
finally:
se.shutdown()
return _run
@pytest.fixture
def dll_emu(config: dict[str, Any], load_test_bin: Callable[[str], bytes]) -> Iterator[Speakeasy]:
yield from load_emu(config, load_test_bin("dll_test_x86.dll.xz"))
@pytest.fixture
def dll64_emu(config: dict[str, Any], load_test_bin: Callable[[str], bytes]) -> Iterator[Speakeasy]:
yield from load_emu(config, load_test_bin("dll_test_x64.dll.xz"))
@pytest.fixture
def driver_emu(config: dict[str, Any], load_test_bin: Callable[[str], bytes]) -> Iterator[Speakeasy]:
yield from load_emu(config, load_test_bin("wdm_test_x86.sys.xz"))
@pytest.fixture
def driver64_emu(config: dict[str, Any], load_test_bin: Callable[[str], bytes]) -> Iterator[Speakeasy]:
yield from load_emu(config, load_test_bin("wdm_test_x64.sys.xz"))