Files
Strata/terminal/tools/test_setup_oldcpu.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

96 lines
4.0 KiB
Python

"""Tests for setup.py's experimental older-CPU build (#394 #595 #623): which floor a CPU without AVX2 gets, the CMake
definition, a build folder configured afresh when the floor changes, and the MCP server's note instead of a refusal.
No compiler, no GPU.
python -m unittest tools.test_setup_oldcpu
"""
from __future__ import annotations
import io
import os
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / "tools"))
import setup # noqa: E402
def cpuinfo(flags: str):
return mock.patch("builtins.open", lambda *a, **k: io.StringIO(f"model name\t: Old Xeon\nflags\t\t: {flags}\n"))
class FloorTest(unittest.TestCase):
def setUp(self):
self.env = mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": ""})
self.env.start()
def tearDown(self):
self.env.stop()
def test_avx2_cpu_gets_the_normal_engine(self):
self.assertEqual(setup.cpu_floor(True), "")
def test_linux_flags(self):
with mock.patch.object(setup, "WIN", False):
with cpuinfo("fpu sse4_1 sse4_2 popcnt avx xsave"):
self.assertEqual(setup.cpu_floor(False), "avx")
with cpuinfo("fpu sse4_1 sse4_2 popcnt"):
self.assertEqual(setup.cpu_floor(False), "none")
with cpuinfo("fpu sse3 ssse3"):
self.assertEqual(setup.cpu_floor(False), "unsupported")
def test_windows_probe(self):
with mock.patch.object(setup, "WIN", True):
for probe, want in (("avx", "avx"), ("sse4.2", "none"), ("", "unsupported")):
with mock.patch.object(setup, "_cpuid_floor", lambda p=probe: p):
self.assertEqual(setup.cpu_floor(False), want)
def test_env_asks_for_a_floor_build_on_any_cpu(self):
for v in ("avx", "none", "AVX"):
with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": v}):
self.assertEqual(setup.cpu_floor(True), v.lower())
with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": "bogus"}):
self.assertEqual(setup.cpu_floor(True), "")
@unittest.skipUnless(os.name == "nt", "the CPUID stub runs on Windows")
def test_this_pc_probe(self):
self.assertIn(setup._cpuid_floor(), ("avx", "sse4.2")) # any x86-64 PC that runs the tests
class DefsTest(unittest.TestCase):
def test_defs_and_fresh_configure(self):
with tempfile.TemporaryDirectory() as d:
b = Path(d)
cache = b / "CMakeCache.txt"
self.assertEqual(setup.isa_floor_defs("", b, {}), []) # the normal build: nothing added
cache.write_text("x")
self.assertEqual(setup.isa_floor_defs("avx", b, {"isa_floor": "avx"}), ["-DSTRATA_ISA_FLOOR=avx"])
self.assertTrue(cache.exists()) # same floor: the folder is kept
self.assertEqual(setup.isa_floor_defs("none", b, {"isa_floor": "avx"}), ["-DSTRATA_ISA_FLOOR=none"])
self.assertFalse(cache.exists()) # another floor: configured afresh
cache.write_text("x")
self.assertEqual(setup.isa_floor_defs("", b, {"isa_floor": "none"}), [])
self.assertFalse(cache.exists()) # back to the normal build
cache.write_text("x")
setup.isa_floor_defs("", b, {})
self.assertTrue(cache.exists()) # the normal build's folder untouched
class McpTest(unittest.TestCase):
def test_no_avx2_is_a_note_not_a_refusal(self):
import strata_mcp as M
s = M.Strata(ROOT)
gpu = [{"index": 0, "name": "x", "vram_gb": 24.0, "usable": True, "vendor": "nvidia"}]
r = s.recommend({"ram_gb": 64, "gpus": gpu, "cpu": {"avx2": False}})
self.assertIsNotNone(r["model"])
self.assertTrue(any("no AVX2" in n and "EXPERIMENTAL" in n for n in r["notes"]))
if __name__ == "__main__":
unittest.main()