mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
scripts: game-abba.ps1 takes a value the settings line hides as an arm, keeps a name's last value, refuses a checkout in -Out (review)
- arm_settings applies the space and length rules only to a value the runtime's settings line shows as it is:
one of ASCII letters, digits and " ._,:+=*-", the `plain` test of d3d12/apps/leonida/src/leonida.rs line 65,
mirrored and quoted in d3d12_ab_compare.py's new SOURCES, which a contract test checks against leonida.rs.
Any other value (a folder with a space, a long path) shows as "<hidden, N chars>", which `check` takes as
shown, so it can be an arm.
- A name given twice in one arm counts with its last value, as the gate keeps it.
- `settings` names an item by its position (and its LEONIDA_ name), never by its text, so no path is said back.
- The runner refuses a checkout inside -Out, where a re-run's clean-up could reach it.
- The files the runner writes are written beside themselves and moved over, so abba.json, rewritten after every
run, is never found cut short; an -Out whose abba.json exists but is not readable as this runner's is refused
as such ("no readable abba.json of this runner").
- docs/measuring_fps.md and the script's header say the same.
This commit is contained in:
@ -80,18 +80,21 @@ A change of code, or a switch that cannot be turned in play, needs separate runs
|
||||
checked. `-Pairs` is 4, and 3 at least: 2 pairs are 2 runs a side, which `abba` can never compare (it needs 3 runs a
|
||||
side, or 4 pairs for a verdict from the pairs themselves), so they are refused before any run. At 4 pairs and 300 s
|
||||
in the world it is 11 or 12 runs, about an hour.
|
||||
- Refused before any run, besides the above: an `-Out` inside a checkout, or the same folder as `-Game`,
|
||||
`-DataTemplate` or a data folder, inside one or holding one; a `-MoreA`/`-MoreB` item the settings line could never
|
||||
show, read the way the gate reads `-More` (split at `;`, name and value trimmed): anything but
|
||||
`LEONIDA_NAME=value` with the name in capitals, digits and `_`, a value with a space, or one longer than the 120
|
||||
characters the line shows (`d3d12_ab_compare.py settings --more=<text>` says which); a missing `-Game`,
|
||||
`-DataTemplate` or data folder.
|
||||
- Refused before any run, besides the above: an `-Out` inside a checkout or holding one, or the same folder as
|
||||
`-Game`, `-DataTemplate` or a data folder, inside one or holding one; a `-MoreA`/`-MoreB` item the settings line
|
||||
could never show, read the way the gate reads `-More` (split at `;`, name and value trimmed, a name's last value
|
||||
kept): anything but `LEONIDA_NAME=value` with the name in capitals, digits and `_`, or a value the line shows as
|
||||
it is (ASCII letters, digits and ` ._,:+=*-` only) with a space in it or longer than its 120 characters
|
||||
(`d3d12_ab_compare.py settings --more=<text>` says which item, by its position). A value with any other character,
|
||||
such as a folder (`LEONIDA_DLSS_DIR=C:\Program Files\NVIDIA`), shows as hidden, which counts as shown, so it can
|
||||
be an arm. Also refused: a missing `-Game`, `-DataTemplate` or data folder.
|
||||
- `<Out>\abba.json` records the arms' inputs (`more`, `more_a`, `more_b`, `play_args`, `world_seconds`, `max_minutes`,
|
||||
`retry`, `pairs`, and this machine's `game`, `data_template`, `checkout_a`, `checkout_b`, `data_a`, `data_b`) and each
|
||||
run: its folder, exe, commit and why it was left out. It is written at the start and after each run, so a run that
|
||||
stops on an error leaves it as far as it went. A run into an `-Out` whose `abba.json` this runner wrote first deletes
|
||||
what the earlier one wrote there (`runs`, `abba.json`, `comparison.txt`, `comparison.json`), and nothing else; an
|
||||
`-Out` holding any of those without such an `abba.json` is refused. The files it writes are LF text. Exit code 0 with
|
||||
`-Out` holding any of those without a readable `abba.json` of the runner is refused. The files it writes are LF
|
||||
text, each written beside itself and moved over it, so none is ever found cut short. Exit code 0 with
|
||||
a comparison ("no clear difference" is one); 1 without one: too few runs left or unbalanced pairs (the comparison
|
||||
files say why), or an error (a refusal, a failed warm-up, a gate that did not start, a comparator that failed),
|
||||
which writes no comparison.
|
||||
|
||||
@ -16,10 +16,11 @@
|
||||
# slot runs again, -Retry times (1). Runs go to <Out>\runs; <Out> gets abba.json (the arms' inputs, then each run as it
|
||||
# ends, what was left out and why), comparison.txt and comparison.json.
|
||||
#
|
||||
# Refused before any run: -Out in a checkout, or one folder with, inside or around -Game, -DataTemplate or a data
|
||||
# folder; a -MoreA/-MoreB item the settings line could never show (`d3d12_ab_compare.py settings`); a missing folder
|
||||
# or a checkout without scripts\game-gate.ps1. A run into an -Out whose abba.json this runner wrote first deletes what
|
||||
# the earlier run wrote there (runs, abba.json, comparison.*); an -Out holding any of those without it is refused.
|
||||
# Refused before any run: -Out in a checkout or holding one, or one folder with, inside or around -Game,
|
||||
# -DataTemplate or a data folder; a -MoreA/-MoreB item the settings line could never show (`d3d12_ab_compare.py
|
||||
# settings`; a value the line hides, such as a folder, counts as shown); a missing folder or a checkout without
|
||||
# scripts\game-gate.ps1. A run into an -Out whose abba.json this runner wrote first deletes what the earlier run wrote
|
||||
# there (runs, abba.json, comparison.*); an -Out holding any of those without a readable one is refused.
|
||||
# Exit code: 0 with a comparison ("no clear difference" is one); 1 without one, either because the runs left do not
|
||||
# give one (comparison.txt says why) or on an error (nothing compared).
|
||||
# Options: -Pairs (4; 3 at least: the comparison needs 3 runs a side, or 4 pairs for a verdict from the pairs
|
||||
@ -60,7 +61,10 @@ $sep = [IO.Path]::DirectorySeparatorChar
|
||||
function Test-Within([string]$Inner, [string]$Outer) { ($Inner + $sep).StartsWith($Outer + $sep, $pathCase) }
|
||||
# The text files this runner writes: UTF-8 without a byte order mark, LF line ends, one final newline.
|
||||
function Write-TextFile([string]$Path, [string]$Content) {
|
||||
[IO.File]::WriteAllText($Path, ((($Content -replace "`r`n", "`n") -replace '\n+\z', '') + "`n"))
|
||||
# Written beside the file and moved over it: a reader, or a run stopped halfway, never finds it cut short.
|
||||
$part = "$Path.$PID.part"
|
||||
[IO.File]::WriteAllText($part, ((($Content -replace "`r`n", "`n") -replace '\n+\z', '') + "`n"))
|
||||
[IO.File]::Move($part, $Path, $true)
|
||||
}
|
||||
|
||||
foreach ($need in 'Game', 'DataTemplate', 'Out') {
|
||||
@ -89,6 +93,8 @@ $Out = Get-FolderPath $Out
|
||||
# This runner's own checkout too: in two-build mode it is neither arm's.
|
||||
foreach ($checkout in $CheckoutA, $CheckoutB, (Get-FolderPath $repo)) {
|
||||
if (Test-Within $Out $checkout) { throw "-Out is inside a checkout: $Out" }
|
||||
# A checkout inside -Out (at <Out>\runs, say) could be deleted by a re-run's clean-up.
|
||||
if (Test-Within $checkout $Out) { throw "a checkout is inside -Out: $checkout" }
|
||||
}
|
||||
# The folders every gate run reads or writes: the runs' folders would mix with them, and a re-run's clean-up with them.
|
||||
$inputs = [ordered]@{ '-Game' = (Get-FolderPath $Game); '-DataTemplate' = (Get-FolderPath $DataTemplate) }
|
||||
@ -154,7 +160,8 @@ if (-not $DryRun) {
|
||||
$held = @($outputs | Where-Object { Test-Path -LiteralPath $_ } |
|
||||
Where-Object { $_ -ne $root -or @(Get-ChildItem -LiteralPath $_ -Force).Count })
|
||||
if ($held.Count) {
|
||||
throw "-Out holds runs, abba.json or comparison files that this runner did not write (no abba.json of its own): $Out"
|
||||
$whose = if (Test-Path -LiteralPath $recordFile) { 'no readable abba.json of this runner' } else { 'no abba.json of this runner' }
|
||||
throw "-Out holds runs, abba.json or comparison files that this runner did not write ($whose): $Out"
|
||||
}
|
||||
}
|
||||
foreach ($old in $outputs) {
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
@ -157,14 +158,39 @@ class Runs(unittest.TestCase):
|
||||
_items, unshowable = ab.arm_settings("leonida_x=1;OTHER=1;LEONIDA_X;LEONIDA_E=;LEONIDA_S=a b;LEONIDA_L="
|
||||
+ "1" * (ab.SHOWN + 1))
|
||||
self.assertEqual(unshowable, [
|
||||
"leonida_x is not a LEONIDA_ name in capitals", "OTHER is not a LEONIDA_ name in capitals",
|
||||
"LEONIDA_X is not NAME=value", "LEONIDA_E has no value", "LEONIDA_S's value has a space",
|
||||
f"LEONIDA_L's value is longer than the {ab.SHOWN} characters the settings line shows"])
|
||||
"item 1's name is not LEONIDA_ in capitals, digits and _",
|
||||
"item 2's name is not LEONIDA_ in capitals, digits and _", "item 3 is not NAME=value",
|
||||
"item 4 (LEONIDA_E) has no value", "item 5 (LEONIDA_S) has a space in a value the line shows",
|
||||
f"item 6 (LEONIDA_L) is longer than the {ab.SHOWN} characters the line shows"])
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
self.assertEqual(ab.main(["settings", "--more=LEONIDA_X=1;LEONIDA_S=a b"]), 0)
|
||||
self.assertEqual(json.loads(out.getvalue()),
|
||||
{"settings": [["LEONIDA_X", "1"]], "unshowable": ["LEONIDA_S's value has a space"]})
|
||||
self.assertEqual(json.loads(out.getvalue()), {
|
||||
"settings": [["LEONIDA_X", "1"]], "unshowable": ["item 2 (LEONIDA_S) has a space in a value the line shows"]})
|
||||
|
||||
def test_a_value_the_line_hides_counts_as_shown(self):
|
||||
# leonida.rs hides a value with any character but ASCII letters, digits and " ._,:+=*-": a folder with a space
|
||||
# or a long one shows as "<hidden, N chars>", which `check` takes as shown. A plain value is cut or split.
|
||||
spaced, long = "C:\\Program Files\\NVIDIA", "D:\\" + "dlss\\" * 30
|
||||
items, unshowable = ab.arm_settings(f"LEONIDA_DLSS_DIR={spaced};LEONIDA_LONG_DIR={long};LEONIDA_T=a\tb")
|
||||
self.assertEqual(unshowable, [])
|
||||
self.assertEqual(items, [("LEONIDA_DLSS_DIR", spaced), ("LEONIDA_LONG_DIR", long), ("LEONIDA_T", "a\tb")])
|
||||
self.assertGreater(len(long), ab.SHOWN)
|
||||
d = self.summary_run("hidden", settings={"LEONIDA_DLSS_DIR": f"<hidden, {len(spaced)} chars>"})
|
||||
self.assertEqual(ab.check_run(d, more=f"LEONIDA_DLSS_DIR={spaced}"), (None, "1" * 16))
|
||||
|
||||
def test_the_last_value_of_a_name_counts_as_the_gate_keeps_it(self):
|
||||
self.assertEqual(ab.arm_settings("LEONIDA_X=0;LEONIDA_Y=2;LEONIDA_X=1"), ([("LEONIDA_Y", "2"), ("LEONIDA_X", "1")], []))
|
||||
self.assertEqual(ab.arm_settings("LEONIDA_X=a b;LEONIDA_X=1"), ([("LEONIDA_X", "1")], []))
|
||||
d = self.summary_run("twice", settings={"LEONIDA_X": "1"})
|
||||
self.assertEqual(ab.check_run(d, more="LEONIDA_X=0;LEONIDA_X=1"), (None, "1" * 16))
|
||||
|
||||
def test_an_item_is_named_by_its_position_not_its_text(self):
|
||||
# What an arm gives can hold a folder (a user's name): `settings` never says it back.
|
||||
_items, unshowable = ab.arm_settings("C:\\Users\\someone\\x;someone=1;LEONIDA_X=some one")
|
||||
self.assertEqual(unshowable, ["item 1 is not NAME=value", "item 2's name is not LEONIDA_ in capitals, digits and _",
|
||||
"item 3 (LEONIDA_X) has a space in a value the line shows"])
|
||||
self.assertNotIn("some", json.dumps(unshowable))
|
||||
|
||||
def test_check_prints_json(self):
|
||||
out = io.StringIO()
|
||||
@ -243,5 +269,17 @@ class Plan(unittest.TestCase):
|
||||
self.assertEqual(ab.plan(2, switch=True)["warm_up_and_discarded"], ["warm-up A", "warm-up B", "discarded A"])
|
||||
|
||||
|
||||
class Contract(unittest.TestCase):
|
||||
def test_the_runtime_still_writes_settings_by_the_rules_mirrored_here(self):
|
||||
for words, path in ab.SOURCES.items():
|
||||
with open(os.path.join(ROOT, path), encoding="utf-8") as f:
|
||||
# Rust strings continued over lines (a backslash at the end of a line) read as one.
|
||||
text = re.sub(r"\\\r?\n\s*", "", f.read())
|
||||
self.assertIn(words, text, f"{path} no longer says {words!r}: update tools/d3d12_ab_compare.py")
|
||||
# The rules here are the ones quoted: the same plain characters, the same length.
|
||||
self.assertIn(f'c.is_ascii_alphanumeric() || "{ab.PLAIN}".contains(c)', "".join(ab.SOURCES))
|
||||
self.assertIn(f"SHOWN: usize = {ab.SHOWN};", "".join(ab.SOURCES))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@ -49,6 +49,11 @@ exit $(if ($result -eq 'PASS') { 0 } else { 1 })
|
||||
FAILING_COMMAND = '@echo off\r\nif /i "%~3"=="{command}" exit /b 3\r\n"{python}" %*\r\n'
|
||||
|
||||
|
||||
def unwrapped(err):
|
||||
"""PowerShell's error text with the lines it wraps at the console width ("\n | ") joined again."""
|
||||
return re.sub(r"\s*\n\s*\|\s?", " ", err)
|
||||
|
||||
|
||||
def write(path, text):
|
||||
with open(path, "w", encoding="utf-8", newline="\n") as f:
|
||||
f.write(text)
|
||||
@ -81,6 +86,17 @@ class Script(unittest.TestCase):
|
||||
self.assertNotIn("'\\'", line)
|
||||
self.assertIn("[IO.Path]::DirectorySeparatorChar", text)
|
||||
|
||||
def test_files_are_written_beside_and_moved_over(self):
|
||||
# A file written in place is cut short for a moment (and for good if the run stops then): abba.json is
|
||||
# rewritten after every run. The move is not seen by a test run, so the text says it.
|
||||
with open(SCRIPT, encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
body = text[text.index("function Write-TextFile"):]
|
||||
body = body[:body.index("\n}")]
|
||||
self.assertIn("[IO.File]::WriteAllText($part,", body)
|
||||
self.assertIn("[IO.File]::Move($part, $Path, $true)", body)
|
||||
self.assertNotIn("WriteAllText($Path", body)
|
||||
|
||||
|
||||
@unittest.skipUnless(os.name == "nt" and PWSH, "needs Windows and pwsh")
|
||||
class DryRun(unittest.TestCase):
|
||||
@ -93,7 +109,7 @@ class DryRun(unittest.TestCase):
|
||||
r = subprocess.run([PWSH, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", SCRIPT, "-Game", game,
|
||||
"-DataTemplate", template, "-Out", out or os.path.join(self.dir, "out"), "-Python",
|
||||
sys.executable, "-DryRun", *args], capture_output=True, text=True, timeout=120)
|
||||
return r.returncode, r.stdout, r.stderr
|
||||
return r.returncode, r.stdout, unwrapped(r.stderr)
|
||||
|
||||
def slots(self, out):
|
||||
return [re.match(r"(\d+) (\S+) ([AB]): (.*)$", line).groups() for line in out.splitlines()
|
||||
@ -148,17 +164,36 @@ class DryRun(unittest.TestCase):
|
||||
("-Pairs is 3 or more", ("-Data", same, "-MoreB", "LEONIDA_X=1", "-Pairs", "2")),
|
||||
("-Retry is 0 or more", ("-Data", same, "-MoreB", "LEONIDA_X=1", "-Retry", "-1")),
|
||||
# What the runtime's settings line can never show, so that no run of the arm could pass its check.
|
||||
("-MoreB: LEONIDA_X's value has a space", one + ("-MoreB", "LEONIDA_X=a b")),
|
||||
("-MoreB: leonida_x is not a LEONIDA_ name in capitals", one + ("-MoreB", "leonida_x=1")),
|
||||
("-MoreB: LEONIDA_X is not NAME=value", one + ("-MoreB", "LEONIDA_X")),
|
||||
("-MoreA: LEONIDA_X's value is longer than the 120 characters", ("-Data", same, "-MoreA",
|
||||
"LEONIDA_X=" + "1" * 121)),
|
||||
("-MoreB: item 1 (LEONIDA_X) has a space in a value the line shows", one + ("-MoreB", "LEONIDA_X=a b")),
|
||||
("-MoreB: item 1's name is not LEONIDA_", one + ("-MoreB", "leonida_x=1")),
|
||||
("-MoreB: item 2 is not NAME=value", one + ("-MoreB", "LEONIDA_Y=1;LEONIDA_X")),
|
||||
("-MoreA: item 1 (LEONIDA_X) is longer than the 120 characters", ("-Data", same, "-MoreA",
|
||||
"LEONIDA_X=" + "1" * 121)),
|
||||
]
|
||||
for message, args in cases:
|
||||
code, _out, err = self.run_script(*args)
|
||||
self.assertNotEqual(code, 0, args)
|
||||
self.assertIn(message, err)
|
||||
|
||||
def test_a_value_the_line_hides_is_an_arm(self):
|
||||
# Per-arm DLL folders: shown as "<hidden, N chars>", which the check takes as shown, however long or spaced.
|
||||
code, out, err = self.run_script("-Data", os.path.join(self.dir, "data"),
|
||||
"-MoreA", "LEONIDA_DLSS_DIR=C:\\Program Files\\NVIDIA",
|
||||
"-MoreB", "LEONIDA_DLSS_DIR=D:\\" + "dlss\\" * 30, "-Pairs", "3")
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("mode: one exe, two settings; 9 runs, 3 pairs", out)
|
||||
|
||||
def test_no_checkout_is_inside_the_output(self):
|
||||
# A checkout at <Out>\runs\a would go with a re-run's clean-up.
|
||||
out = os.path.join(self.dir, "out")
|
||||
a, b = os.path.join(out, "runs", "a"), os.path.join(self.dir, "b")
|
||||
os.makedirs(os.path.join(a, "scripts"))
|
||||
os.makedirs(os.path.join(b, "scripts"))
|
||||
code, _out, err = self.run_script("-CheckoutA", a, "-DataA", os.path.join(self.dir, "da"), "-CheckoutB", b,
|
||||
"-DataB", os.path.join(self.dir, "db"), out=out)
|
||||
self.assertNotEqual(code, 0)
|
||||
self.assertIn("a checkout is inside -Out", err)
|
||||
|
||||
def test_the_output_is_not_in_a_checkout(self):
|
||||
for root in (ROOT, ROOT.swapcase()): # Windows paths ignore case
|
||||
code, out, err = self.run_script("-Data", "D", "-MoreB", "LEONIDA_X=1", out=os.path.join(root, "abba-out"))
|
||||
@ -292,6 +327,9 @@ class StubGate(unittest.TestCase):
|
||||
self.assertNotIn(b"\r", data, name)
|
||||
self.assertFalse(data.startswith(b"\xef\xbb\xbf"), name)
|
||||
self.assertTrue(data.endswith(b"\n") and not data.endswith(b"\n\n"), name)
|
||||
# Each was written beside itself and moved over: no part is left.
|
||||
parts = [os.path.join(base, n) for base, _dirs, names in os.walk(self.out) for n in names if n.endswith(".part")]
|
||||
self.assertEqual(parts, [])
|
||||
|
||||
def test_a_run_into_the_same_out_starts_clean(self):
|
||||
# The first run leaves 06-measured-B out; in the second it passes and must count, with nothing kept from the
|
||||
@ -323,18 +361,19 @@ class StubGate(unittest.TestCase):
|
||||
|
||||
def test_an_out_the_runner_did_not_write_is_refused_and_kept(self):
|
||||
# Without an abba.json of its own, what -Out holds is someone else's: nothing is deleted and nothing runs.
|
||||
held = {
|
||||
os.path.join("runs", "other-tool", "keep.txt"): "keep\n",
|
||||
"abba.json": json.dumps({"schema": "another-tool/1"}),
|
||||
"comparison.txt": "keep\n",
|
||||
}
|
||||
for name, text in held.items():
|
||||
held = [
|
||||
(os.path.join("runs", "other-tool", "keep.txt"), "keep\n", "(no abba.json of this runner)"),
|
||||
("abba.json", json.dumps({"schema": "another-tool/1"}), "(no readable abba.json of this runner)"),
|
||||
("abba.json", '{"schema": "leonida-abba-run/1", "runs": [', "(no readable abba.json of this runner)"),
|
||||
("comparison.txt", "keep\n", "(no abba.json of this runner)"),
|
||||
]
|
||||
for name, text, whose in held:
|
||||
shutil.rmtree(self.out, ignore_errors=True)
|
||||
os.makedirs(os.path.dirname(os.path.join(self.out, name)), exist_ok=True)
|
||||
write(os.path.join(self.out, name), text)
|
||||
r, made = self.run_abba("refused")
|
||||
self.assertNotEqual(r.returncode, 0, name)
|
||||
self.assertIn("that this runner did not write", r.stderr)
|
||||
self.assertIn(f"that this runner did not write {whose}", unwrapped(r.stderr))
|
||||
self.assertEqual(made, [], name)
|
||||
with open(os.path.join(self.out, name), encoding="utf-8") as f:
|
||||
self.assertEqual(f.read(), text, name)
|
||||
@ -354,7 +393,7 @@ class StubGate(unittest.TestCase):
|
||||
finally:
|
||||
os.rename(moved, path)
|
||||
self.assertNotEqual(r.returncode, 0, message)
|
||||
self.assertIn(message, r.stderr)
|
||||
self.assertIn(message, unwrapped(r.stderr))
|
||||
self.assertEqual(made, [], message)
|
||||
self.assertEqual(sorted(os.listdir(os.path.join(self.out, "runs"))), before, message)
|
||||
self.assertEqual(self.read_json("comparison.json")["verdict"], "B slower", message)
|
||||
@ -389,7 +428,7 @@ class StubGate(unittest.TestCase):
|
||||
for slot, count in (("01-warm-up-A", 1), ("02-warm-up-B", 2), ("03-discarded-A", 3)):
|
||||
r, made = self.run_abba("stop", {slot: "FAIL"})
|
||||
self.assertNotEqual(r.returncode, 0, slot)
|
||||
self.assertIn(f"{slot} failed its gate", r.stderr)
|
||||
self.assertIn(f"{slot} failed its gate", unwrapped(r.stderr))
|
||||
self.assertEqual(len(made), count, slot)
|
||||
self.assertFalse(os.path.exists(os.path.join(self.out, "comparison.json")), slot)
|
||||
# The record says what ran before the stop.
|
||||
@ -402,7 +441,7 @@ class StubGate(unittest.TestCase):
|
||||
write(wrapper, FAILING_COMMAND.format(command=command, python=sys.executable))
|
||||
r, made = self.run_abba("first", python=wrapper)
|
||||
self.assertNotEqual(r.returncode, 0, r.stdout)
|
||||
self.assertIn(f"{command} failed", r.stderr)
|
||||
self.assertIn(f"{command} failed", unwrapped(r.stderr))
|
||||
self.assertEqual(len(made), count, command)
|
||||
self.assertEqual(len(self.read_json("abba.json")["runs"]), count, command)
|
||||
for name in ("comparison.json", "comparison.txt"):
|
||||
|
||||
@ -35,12 +35,14 @@ as shown). A run folder with an ab-excluded.txt (written by the runner) is left
|
||||
why.
|
||||
|
||||
`settings` reads an arm's settings the way `check` does, which is the way scripts/game-gate.ps1 reads -More (split
|
||||
at ";", name and value trimmed), and says which of them the settings line could never show: an item without "="
|
||||
(the gate drops it), a name that is not LEONIDA_ in capitals, digits and "_", or a value that is empty, has a space
|
||||
or is longer than the line shows. The runner refuses those before its first run.
|
||||
at ";", name and value trimmed, the last value of a name kept), and says which of them the settings line could never
|
||||
show: an item without "=" (the gate drops it), a name that is not LEONIDA_ in capitals, digits and "_", an empty
|
||||
value, or a value the line shows (one of plain characters, see SOURCES) with a space in it or longer than it shows.
|
||||
A value the line hides (a folder, a file) shows as hidden, which counts as shown. The runner refuses those before
|
||||
its first run.
|
||||
|
||||
Standard library only; reads files, never runs them; prints no log line and no path (`check` and `settings` name the
|
||||
LEONIDA_ settings they were given).
|
||||
Standard library only; reads files, never runs them; prints no log line and no path (`check` names the LEONIDA_
|
||||
settings it was given, `settings` the position of an item and its LEONIDA_ name, never a value or other text).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@ -63,10 +65,20 @@ T95 = [12.706, 4.303, 3.182, 2.776, 2.571, 2.447, 2.365, 2.306, 2.262, 2.228, 2.
|
||||
WORLD_DRAWS = 1000
|
||||
# Written by scripts/game-abba.ps1 in a run folder it leaves out.
|
||||
EXCLUDED = "ab-excluded.txt"
|
||||
# The runtime's settings line (d3d12/apps/leonida/src/leonida.rs, settings_line) lists LEONIDA_ names only, and cuts
|
||||
# a value longer than SHOWN; tools/game_gate.py reads a value up to the first space.
|
||||
# The runtime's settings line (d3d12/apps/leonida/src/leonida.rs, settings_line) lists LEONIDA_ names only. A value
|
||||
# of plain characters (leonida.rs line 65: ASCII letters and digits and PLAIN) shows as it is, cut when longer than
|
||||
# SHOWN; any other shows as "<hidden, N chars>". tools/game_gate.py reads a shown value up to the first space.
|
||||
SETTING_NAME = re.compile(r"LEONIDA_[A-Z0-9_]+")
|
||||
PLAIN = " ._,:+=*-"
|
||||
SHOWN = 120
|
||||
# The runtime's own words these rules mirror, and where they are written: tests/test_d3d12_ab_compare.py checks that
|
||||
# each is still there, so a changed rule fails the test, not an hour of runs.
|
||||
SOURCES = {
|
||||
'k.starts_with("LEONIDA_")': "d3d12/apps/leonida/src/leonida.rs",
|
||||
'v.chars().all(|c| c.is_ascii_alphanumeric() || " ._,:+=*-".contains(c))': "d3d12/apps/leonida/src/leonida.rs",
|
||||
"const SHOWN: usize = 120;": "d3d12/apps/leonida/src/leonida.rs",
|
||||
'format!("<hidden, {n} chars>")': "d3d12/apps/leonida/src/leonida.rs",
|
||||
}
|
||||
PHASE = re.compile(r"A/B phase (\d+) bits (\d+) on \[[^\]]*\]: (\d+) frames, mean ([\d.]+) ms, median ([\d.]+), "
|
||||
r"p90 ([\d.]+), ([\d.]+) draws a frame")
|
||||
COUNTERS = re.compile(r"A/B counters phase (\d+) bits (\d+): (.*)$")
|
||||
@ -259,26 +271,38 @@ def phase_effects(phases, keep_jumps=False):
|
||||
|
||||
|
||||
def arm_settings(more):
|
||||
"""([(name, value)], [why each other item could never show in the settings line]) of an arm's -More text."""
|
||||
items, unshowable = [], []
|
||||
for item in (more or "").split(";"):
|
||||
"""([(name, value)], [why an item could never show in the settings line]) of an arm's -More text. A name's last
|
||||
value counts, as the gate keeps it. An item is named by its position and its LEONIDA_ name, never by its text."""
|
||||
last, unshowable = {}, []
|
||||
for position, item in enumerate((more or "").split(";"), 1):
|
||||
if not item.strip():
|
||||
continue
|
||||
if "=" not in item:
|
||||
unshowable.append(f"{item.strip()} is not NAME=value")
|
||||
unshowable.append((position, f"item {position} is not NAME=value"))
|
||||
continue
|
||||
name, value = (part.strip() for part in item.split("=", 1))
|
||||
if not SETTING_NAME.fullmatch(name):
|
||||
unshowable.append(f"{name or 'a setting with no name'} is not a LEONIDA_ name in capitals")
|
||||
elif not value:
|
||||
unshowable.append(f"{name} has no value")
|
||||
elif any(c.isspace() for c in value):
|
||||
unshowable.append(f"{name}'s value has a space")
|
||||
elif len(value) > SHOWN:
|
||||
unshowable.append(f"{name}'s value is longer than the {SHOWN} characters the settings line shows")
|
||||
unshowable.append((position, f"item {position}'s name is not LEONIDA_ in capitals, digits and _"))
|
||||
continue
|
||||
last.pop(name, None)
|
||||
last[name] = (position, value)
|
||||
items = []
|
||||
for name, (position, value) in last.items():
|
||||
where = f"item {position} ({name})"
|
||||
if not value:
|
||||
unshowable.append((position, f"{where} has no value"))
|
||||
elif shows_as_it_is(value) and " " in value:
|
||||
unshowable.append((position, f"{where} has a space in a value the line shows"))
|
||||
elif shows_as_it_is(value) and len(value) > SHOWN:
|
||||
unshowable.append((position, f"{where} is longer than the {SHOWN} characters the line shows"))
|
||||
else:
|
||||
items.append((name, value))
|
||||
return items, unshowable
|
||||
return items, [why for _position, why in sorted(unshowable)]
|
||||
|
||||
|
||||
def shows_as_it_is(value):
|
||||
"""Whether the settings line shows `value` itself (cut past SHOWN), not "<hidden, N chars>": leonida.rs line 65."""
|
||||
return all((c.isascii() and c.isalnum()) or c in PLAIN for c in value)
|
||||
|
||||
|
||||
def check_run(path, exe=None, more=""):
|
||||
|
||||
Reference in New Issue
Block a user