Files
Strata/terminal/tools/test_quant_header_names.py
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

66 lines
4.3 KiB
Python

"""The quant header is Strata's include/strata/quant/strata-quant-common.h (generated by tools/gen_quant_header.py, 0.2.16; tools/test_quant_header.py
checks its content); third_party/ggml/ggml-common.h only forwards to it (the dpct-migrated SYCL-mode copy, sycl/third_party/ggml, is gone since
0.2.15: the SYCL build includes the shared header). The Metal runtime reads the text under the new name, the Mac package ships both names (the old one for two releases).
python -m unittest tools.test_quant_header_names -v
"""
import shutil
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
NEW = ROOT.parent / "engine" / "include" / "strata" / "quant" / "strata-quant-common.h"
OLD = ROOT.parent / "engine" / "third_party" / "ggml" / "ggml-common.h"
class QuantHeaderNames(unittest.TestCase):
def test_the_text_is_in_the_new_file_and_the_old_path_forwards(self):
text = NEW.read_text(encoding="utf-8")
self.assertIn("\n#ifndef GGML_COMMON_DECL\n", text, "the new file is the header's text (the Metal runtime reads it as text)")
self.assertIn("GENERATED by tools/gen_quant_header.py", text)
self.assertIn("GGML_COMMON_IMPL_METAL", text)
self.assertGreater(text.count("\n"), 1900)
old = [ln for ln in OLD.read_text(encoding="utf-8").splitlines() if not ln.startswith("//") and ln.strip()]
self.assertEqual(old, ['#include "../../include/strata/quant/strata-quant-common.h"'])
# the SYCL build takes the shared header (sycl/CMakeLists.txt: ${STRATA_ROOT}/third_party/ggml), not a migrated copy of its own
self.assertFalse((ROOT.parent / "engine" / "sycl" / "third_party" / "ggml").exists(), "sycl/third_party/ggml is a dpct output copy no build reads")
self.assertIn("${STRATA_ROOT}/third_party/ggml", (ROOT.parent / "engine" / "sycl" / "CMakeLists.txt").read_text(encoding="utf-8"))
def test_the_metal_runtime_reads_the_new_name_and_the_old_one_second(self):
rp = (ROOT.parent / "engine" / "metal" / "src" / "resource_path.h").read_text(encoding="utf-8")
self.assertIn("resource2", rp)
rt = (ROOT.parent / "engine" / "metal" / "src" / "mtl_rt.mm").read_text(encoding="utf-8")
self.assertIn('resource2("STRATA_GGML_COMMON", "strata-quant-common.h", "ggml-common.h", STRATA_GGML_COMMON_DEFAULT)', rt)
cm = (ROOT.parent / "engine" / "metal" / "CMakeLists.txt").read_text(encoding="utf-8")
self.assertIn("${STRATA_ROOT}/include/strata/quant/strata-quant-common.h", cm)
def test_the_repo_mac_qwen_package_script_stages_the_real_header_under_both_names(self):
"""packaging/mac/build_engine.sh is the repo version of the release scripts' Mac stage (rel213/scripts/mac_rel213.sh copied third_party/ggml/ggml-common.h,
which is only a forwarder now: staged like that the Metal kernels would have no block layouts)."""
sh = (ROOT.parent / "tools" / "packaging" / "mac" / "build_engine.sh").read_text(encoding="utf-8")
self.assertIn('QUANT=engine/include/strata/quant/strata-quant-common.h', sh)
self.assertIn('cp "$QUANT" "$STAGE/metal/strata-quant-common.h"', sh)
self.assertIn('cp "$QUANT" "$STAGE/metal/ggml-common.h"', sh)
self.assertNotIn("cp third_party/ggml/ggml-common.h", sh)
self.assertIn('cmp "$PKG/metal/$n" "$QUANT"', sh)
self.assertNotIn("STRATA_GGML_DIR=$LL", sh)
@unittest.skipUnless(shutil.which("c++") or shutil.which("g++") or shutil.which("clang++"), "no C++ compiler")
def test_an_include_of_the_old_name_still_compiles(self):
cxx = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++")
with tempfile.TemporaryDirectory() as d:
src = Path(d) / "t.cpp"
src.write_text("#define GGML_COMMON_DECL_CPP\n#define GGML_COMMON_IMPL_CPP\n#include \"ggml-common.h\"\n"
"int main() { return sizeof(block_q4_K) == 144 ? 0 : 1; }\n", encoding="utf-8")
exe = Path(d) / "t"
done = subprocess.run([cxx, "-std=c++17", "-I", str(OLD.parent), str(src), "-o", str(exe)], capture_output=True, text=True)
self.assertEqual(done.returncode, 0, done.stderr[-800:])
self.assertEqual(subprocess.run([str(exe)]).returncode, 0)
if __name__ == "__main__":
unittest.main()