"""RamSleuth 2.4.14 (MIT, github.com/MadGoatHaz/RamSleuth @ 115e99b) on a gamer's desktop, from a hardware-forum report (2026-10-10). Ground truth is upstream's 2.4.15 fixes: 71dcffd (collect_from reads /sys/firmware/dmi/entries/17-N itself, a directory, and `Err(_) => continue` swallows EISDIR, so the SMBIOS dual-channel override never fires) and d639c71 (decode_mclk takes Alder Lake's MC_BIOS_REQ ratio x refclk, already the data rate, as MCLK; the reporters double it to 7200 MT/s). The 17-N raw bytes and dmidecode output are a real dump with personal identifiers (serials) replaced by synthetic ones; everything else is verbatim.""" import io import os import subprocess import tarfile from bench.core import tools from bench.tasks import sleuth from bench.tasks.sleuth_cases import _home REPO = "https://github.com/MadGoatHaz/RamSleuth.git" COMMIT = "115e99bb3f73afd531297e9ba8ce358f8a992778" # tag v2.4.14 SRC = "home/user/src/RamSleuth/" HERE = os.path.dirname(os.path.abspath(__file__)) TYPE17 = bytes.fromhex( "115c0c000b00feff400040000040090001021a80006009030405060100000000100eb0044605b004030800" "0004ef0000000000000000000000000000000000000400000000000000000000000000000000000000000000" "0000000000436f6e74726f6c6c6572302d4368616e6e656c412d44494d4d300042414e4b2030005465616d" "2047726f757020496e630053455231303030310039383736353433323130005445414d47524f55502d5544" "342d3336303020200000") def _read(name): with open(os.path.join(HERE, name)) as f: return f.read() def source_tree(): """{path: bytes | Symlink} of RamSleuth at COMMIT, from a bare clone in the sleuth cache.""" repo = os.path.join(sleuth.CACHE_DIR, "RamSleuth.git") try: if not os.path.isdir(repo): subprocess.run(["git", "clone", "--quiet", "--bare", REPO, repo], check=True, capture_output=True, timeout=600) if subprocess.run(["git", "-C", repo, "cat-file", "-e", COMMIT + "^{commit}"], capture_output=True).returncode != 0: subprocess.run(["git", "-C", repo, "fetch", "--quiet", "origin", COMMIT], check=True, capture_output=True, timeout=600) tar = subprocess.run(["git", "-C", repo, "archive", "--format=tar", COMMIT], check=True, capture_output=True, timeout=120).stdout except (OSError, subprocess.SubprocessError) as e: raise tools.InfraError(f"fetching RamSleuth {COMMIT[:7]} failed: {e!r}") out = {} with tarfile.open(fileobj=io.BytesIO(tar)) as t: for m in t.getmembers(): if m.issym(): out[SRC + m.name] = tools.Symlink(m.linkname) elif m.isfile(): out[SRC + m.name] = t.extractfile(m).read() return out def _smbios(typ, handle, body, strings=()): s = b"".join(x.encode() + b"\0" for x in strings) + b"\0" if strings else b"\0\0" return bytes([typ, 4 + len(body), handle & 0xFF, handle >> 8]) + body + s def dmi_entries(): oem = "To Be Filled By O.E.M." t17b = TYPE17.replace(b"Controller0", b"Controller1").replace(b"SER10001", b"SER10002") entries = [ ("0-0", 0, _smbios(0, 0x0000, bytes([1, 2, 0x00, 0xF0, 3, 0xFF, 0x80, 0x98, 0x8B, 0x3F, 1, 0, 0, 0, 0x33, 0x0D, 5, 27, 0xFF, 0xFF, 0x20, 0x00]), ("American Megatrends International, LLC.", "21.01", "09/26/2025"))), ("1-0", 1, _smbios(1, 0x0001, bytes([1, 2, 3, 4]) + bytes(range(0x10, 0x20)) + bytes([6, 5, 6]), ("ASRock", "Z690M-ITX/ax", oem, oem, oem, oem))), ("2-0", 2, _smbios(2, 0x0002, bytes([1, 2, 3, 4, 5, 0x09, 6, 0x03, 0x00, 0x0A, 0]), ("ASRock", "Z690M-ITX/ax", oem, oem, oem, oem))), ("16-0", 16, _smbios(16, 0x000B, bytes([3, 3, 3]) + (0x08000000).to_bytes(4, "little") + bytes([0xFE, 0xFF, 2, 0]) + bytes(8))), ("17-0", 17, TYPE17), ("17-1", 17, t17b), ("127-0", 127, _smbios(127, 0xFFFE, b"")), ] files, table = {}, b"" for pos, (name, typ, raw) in enumerate(entries): d = f"sys/firmware/dmi/entries/{name}/" files.update({d + "raw": raw, d + "type": f"{typ}\n", d + "instance": name.split("-")[1] + "\n", d + "handle": f"{raw[2] | raw[3] << 8}\n", d + "length": f"{raw[1]}\n", d + "position": f"{pos}\n"}) table += raw ep = bytearray(b"_SM3_\0\x18\x03\x05\x00\x01\x00" + len(table).to_bytes(4, "little") + (0x69D0F000).to_bytes(8, "little")) ep[5] = -sum(ep) & 0xFF files.update({"sys/firmware/dmi/tables/DMI": table, "sys/firmware/dmi/tables/smbios_entry_point": bytes(ep)}) for f, v in (("bios_vendor", "American Megatrends International, LLC."), ("bios_version", "21.01"), ("bios_date", "09/26/2025"), ("board_vendor", "ASRock"), ("board_name", "Z690M-ITX/ax"), ("sys_vendor", "ASRock"), ("product_name", oem)): files["sys/class/dmi/id/" + f] = v + "\n" return files DMIDECODE_HEAD = """# dmidecode 3.7 Getting SMBIOS data from sysfs. SMBIOS 3.5.0 present. Table at 0x69D0F000. Handle 0x0000, DMI type 0, 26 bytes BIOS Information \tVendor: American Megatrends International, LLC. \tVersion: 21.01 \tRelease Date: 09/26/2025 \tROM Size: 32 MB \tBIOS Revision: 5.27 Handle 0x0001, DMI type 1, 27 bytes System Information \tManufacturer: ASRock \tProduct Name: Z690M-ITX/ax Handle 0x0002, DMI type 2, 15 bytes Base Board Information \tManufacturer: ASRock \tProduct Name: Z690M-ITX/ax Handle 0x000B, DMI type 16, 23 bytes Physical Memory Array \tLocation: System Board Or Motherboard \tUse: System Memory \tError Correction Type: None \tMaximum Capacity: 128 GB \tNumber Of Devices: 2 """ def context(): files, commands = _home.host(kernel="7.3.0-rc5-tkg-bore-llvm", cmdline="BOOT_IMAGE=/vmlinuz-7.3.0-rc5-tkg-bore-llvm " "root=UUID=6d3e0b6f-0b0c-4c51-9a3d-6c1a4b7e2f10 ro quiet") files.update(source_tree()) files.update(dmi_entries()) files["home/user/ramsleuth-probe.md"] = _read("_ramsleuth-probe.md") t17 = _read("_ramsleuth-dmidecode.txt") t17_blocks = t17[t17.index("Handle 0x000C"):] commands.update({"dmidecode": DMIDECODE_HEAD + t17_blocks, "dmidecode -t 17": t17, "dmidecode --type 17": t17, "dmidecode -t memory": DMIDECODE_HEAD[:DMIDECODE_HEAD.index("Handle 0x0000")] + DMIDECODE_HEAD[DMIDECODE_HEAD.index("Handle 0x000B"):] + t17_blocks}) commands["dmidecode --type memory"] = commands["dmidecode -t memory"] return sleuth.snapshot(files, commands) DOUBLED = r"half|/\s*2\b|÷\s*2|divid|doubl|twice|[x×*]\s*2(\.0)?\b|data[ -]?rate|1800" CASES = [ sleuth.Case( case_id="ramsleuth-channel", category="sleuth/code", context=context, complaint=("I'm testing RamSleuth 2.4.14, built from the checkout in /home/user/src/RamSleuth. It " "reports my memory as Single-Channel, but this is a 2x16 GB DDR4-3600 kit in both slots " "of a two-slot ITX board and the BIOS shows dual channel. The 2.4.14 release notes say a " "populated dual-channel kit reads as dual-channel again. The probe report it wrote is " "/home/user/ramsleuth-probe.md. Why is it still wrong?"), # Tightened 2026-10-12 after Opus passed `\braw file` / `\braw\b` with offhand mentions. culprit=[r"EISDIR|os error 21|\bis a director|\bare director|\bas (a )?director|\bon (a|the|each) director|" r"director(y|ies)[^.]{0,40}\b(instead of|not|rather than)\b[^.]{0,30}(file|raw)|" r"\b(instead of|rather than|not)\b[^.]{0,40}17-\S*/raw\b|join\(\s*[\"']raw[\"']", r"smbios|\bdmi\b|type[ -]?17|\b17-|collect_from|intel_smbios"], fix=[r"join\(\s*[\"']raw[\"']|\b(read|open|use|point)\w*\b[^.]{0,60}17-\S*/raw\b|" r"17-\S*/raw\b[^.]{0,40}\b(instead of|rather than)\b|\bappend\w*\b[^.]{0,20}/?raw\b"], key=["Err(_) => continue, // unreadable -> skip", "let bytes = match std::fs::read(&path)"], expert=["grep -rn 'dmi/entries' /home/user/src/RamSleuth/crates --include=*.rs", "sed -n 146,180p /home/user/src/RamSleuth/crates/ramsleuth-telemetry/src/intel_smbios.rs", "ls -l /sys/firmware/dmi/entries/17-0"], reference={"culprit": "intel_smbios::collect_from reads each /sys/firmware/dmi/entries/17-N with " "fs::read, but 17-N is a directory (the bytes are in 17-N/raw)", "root_cause": "fs::read fails on the directory, Err(_) => continue skips every entry, " "populated_count stays 0, so the SMBIOS dual-channel override never fires " "and the MCHBAR Single-Channel decode is reported.", "fix": "Read path.join(\"raw\") for each 17-N entry, then check the Type 17 parser " "offsets against the SMBIOS 3.5 layout."}, wrong=[{"culprit": "MCHBAR MAD_INTER_CHANNEL registers read as absent, so the MMIO decode says " "Single-Channel"}, {"culprit": "the SMBIOS Type 17 parser reads capacity at offset 0x28 instead of 0x0C"}, {"culprit": "channel_of cannot tell Controller0-ChannelA from Controller1-ChannelA"}, {"culprit": "intel_smbios.rs parse_type17() reads the Device Locator from 0x06/0x0C, not 0x10", "root_cause": "string_at assumes the string table starts with an empty string, which the " "kernel's raw file does not have, so both DIMMs get an empty locator"}]), sleuth.Case( case_id="ramsleuth-mts", category="sleuth/code", context=context, complaint=("RamSleuth 2.4.14 (source in /home/user/src/RamSleuth, probe report in " "/home/user/ramsleuth-probe.md) says my DDR4-3600 kit runs at 7200 MT/s. dmidecode and " "the BIOS say 3600. Where does the 7200 come from?"), culprit=[r"mclk|MC_BIOS_REQ|clk[_ ]?ratio|\bratio\b", DOUBLED], reject=[r"\bSPD\b|XMP|dmidecode|\bgear\b"], fix=[r"/\s*2\b|÷\s*2|\bhal(f|ve|ving)\b|divid|1800|" r"(drop|remove|don'?t|do not|stop)\b[^.\n]{0,40}(doubl|[x×*]\s*2)"], key=["clock_section(f64::from(ratio) * refclk)", '{:.0} MT/s", value * 2.0)', '{:.0} MT/s", mclk * 2.0)'], expert=["grep -rn 'MT/s\", ' /home/user/src/RamSleuth/crates --include=*.rs", "grep -n 'fn decode_mclk' -A 22 " "/home/user/src/RamSleuth/crates/ramsleuth-telemetry/src/intel_readout.rs"], reference={"culprit": "decode_mclk in intel_readout.rs takes MC_BIOS_REQ ratio x refclk " "(36 x 100 = 3600) as the DRAM clock", "root_cause": "On Alder Lake that product is already the DDR data rate (the real MCLK is " "1800 MHz), and the reporters then multiply MCLK by 2, giving 7200 MT/s.", "fix": "Divide by 2 for 11th-gen and later in decode_mclk (MCLK = ratio x refclk / 2) " "so the reported MT/s is 3600."}, wrong=[{"culprit": "SPD XMP profile decoded at the wrong speed"}, {"culprit": "UCLK reported equal to MCLK in gear 1"}]), ]