import copy import json import struct import tempfile import unittest from pathlib import Path from tools.coff_compare import build_coff from tools.regression_gate import ( BSS_SENTINEL, GateError, XDK_D3DINLINE_RECIPE, _capture_unit, _function_code_evidence, _json_hash, _object_fingerprint, compare_manifests, load_baseline, ) CODE_FLAGS = 0x60001020 BSS_FLAGS = 0xC0000080 class RegressionGateTests(unittest.TestCase): def setUp(self): self.temporary_directory = tempfile.TemporaryDirectory() self.root = Path(self.temporary_directory.name) self.target_path = self.root / "target.obj" self.base_path = self.root / "base.obj" self.unit_config = { "name": "source/example", "target_path": "target.obj", "base_path": "base.obj", } self.meaningful_sizes = {"_first": 3, "_second": 4} def tearDown(self): self.temporary_directory.cleanup() @staticmethod def _object( first=b"\x31\xc0\xc3", second=b"\x40\x48\x90\xc3", *, bss=True, common=False, first_storage=2, ): sections = [ { "name": ".text", "size": 16, "raw_data": first + b"\x90" * (16 - len(first)), "flags": CODE_FLAGS, }, { "name": ".text", "size": 16, "raw_data": second + b"\x90" * (16 - len(second)), "flags": CODE_FLAGS, }, ] symbols = [ { "name": "_first", "value": 0, "section": 1, "type": 0x20, "storage": first_storage, }, { "name": "_second", "value": 0, "section": 2, "type": 0x20, "storage": 2, }, ] if bss: sections.append( { "name": ".bss", "size": 8, "raw_data": b"\0" * 8, "flags": BSS_FLAGS, } ) symbols.append( { "name": "_queue", "value": 0, "section": 3, "type": 0, "storage": 3, } ) elif common: symbols.append( { "name": "_queue", "value": 8, "section": 0, "type": 0, "storage": 2, } ) result = bytearray(build_coff(sections=sections, symbols=symbols)) if bss: # IMAGE_SCN_CNT_UNINITIALIZED_DATA has a logical size but no raw # payload. Offset zero is the COFF header and must never be hashed. bss_header = 20 + 2 * 40 struct.pack_into("