A press that lifts nothing no longer clears attempted_a, prior_a, the EV-69 carry or the new kept value; a held read no longer adopts (no taken, carry untouched, the owed 0 A is written); a refused 0 A no longer loses the untaken non-zero value. The kept value ends at a fresh own take, a different non-zero write, a lifting press, a hold or Solar's charger return. Existing tests edited only as the brief allows: test_ev69.py T12 (press alone) and T24 setup, test_ev69_fuzz.py N4, N1b user cause, I1, I2. Co-Authored-By: Claude <noreply@anthropic.com>
613 lines
29 KiB
Python
613 lines
29 KiB
Python
"""EV-71: Solar and Manual keep the add-on's own untaken non-zero write as
|
|
their own (the kept value), so the charger taking it late is never read as
|
|
another writer's value (no false CHARGER_OTHER, the peak cut never blocked).
|
|
`python3 -B test_ev71.py`
|
|
|
|
Rows T1-T19, T24-T39 and the Never rules N1-N15 of reports/EV-71-test-plan.md
|
|
(T20 and T21 are in test_ev69_fuzz.py, T22 is the existing suites CI runs, T23
|
|
is the formal check). Every check's label starts with its id. Writer level on
|
|
`tools/ev69_kit.py`: a `SolarWriter` / `ManualWriter` on a stub driver, a stub
|
|
tracker and a stub reading; one step per second on the model clock, which is
|
|
WRITER_S's clock.
|
|
|
|
Worlds (the charger's reading is a function of the second):
|
|
- C9: Solar at its own 0 A, taken; the plan is 12 A. The 12 A written at 200
|
|
returns False but the charger takes it. A held read at 201 shows 12 A and
|
|
`held_pause` writes 0 A (refused). The press comes at 202.
|
|
- F1a: as C9, but the held read at 201 shows 0 A (the :1345 adopt of base).
|
|
- F1b: Solar at its own 8 A; the held read at 201 shows 8 A, and the refused
|
|
0 A overwrites `attempted_a`.
|
|
- S1-adopt / S1-nt: EV-69's S1 shapes (see test_ev69.py).
|
|
|
|
Mutating a module this file grades? Read MUTATION.md first (purge __pycache__).
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, os.path.join(HERE, "tools"))
|
|
|
|
from app import carmode as CM # noqa: E402
|
|
from named_absence import nth, present # noqa: E402
|
|
from ev69_kit import (Drv, LOG, LOOP, Run, CLOCK, cap, check, chain, # noqa: E402,F401
|
|
done, evs, n_other, n_some, near, nev, press, show,
|
|
swriter)
|
|
|
|
START = {"c9": 0.0, "f1a": 0.0, "f1b": 8.0}
|
|
PRE = {"c9": 12.0, "f1a": 0.0, "f1b": 8.0} # what the held read at 201 shows
|
|
|
|
|
|
def held_wrap(w, held):
|
|
"""Run `held_pause` instead of `step` on the seconds in `held`: the charger
|
|
missed that read, the last reading stands in."""
|
|
orig = w.step
|
|
|
|
async def step(drv, rd, **kw):
|
|
if int(kw["now"]) in held:
|
|
await w.held_pause(
|
|
drv, rd, sun=CM.SunInputs(target_w=2000.0, silent=True,
|
|
unknown_s=1000.0),
|
|
now=kw["now"], tracker=kw["tracker"])
|
|
return
|
|
await orig(drv, rd, **kw)
|
|
w.step = step
|
|
|
|
|
|
def world(kind="c9", until=400, after=None, ev=(), press_at=202, held=(201,),
|
|
clamp=16.0, stale=None, gone=None, cls=None, take=None):
|
|
"""C9 / F1a / F1b: 12 A written at 200 (refused by the call, taken by the
|
|
charger), the held read(s), then the reading `after(t)` from 202."""
|
|
start = START[kind]
|
|
w = swriter(start, ph=1, cls=cls)
|
|
w.plan.a, w.plan.n = 12.0, 1
|
|
held_wrap(w, set(held))
|
|
drv = Drv(start, take or (lambda a, d: False), ph=1)
|
|
after = after or (lambda t: 12.0)
|
|
|
|
def cur(t, d):
|
|
if t <= 200:
|
|
return start
|
|
if t in held:
|
|
return PRE[kind]
|
|
return after(t)
|
|
pairs = list(ev)
|
|
if press_at is not None:
|
|
pairs.insert(0, (press_at, press)) # the press first, then ev
|
|
return Run(w, drv).go(200, until, ev=evs(*pairs), cur=cur, clamp=clamp,
|
|
stale=stale, gone=gone)
|
|
|
|
|
|
def calls0(r, lo, hi=10 ** 9):
|
|
return [(t, a) for t, a in r.calls_from(lo, hi) if a == 0.0]
|
|
|
|
|
|
def spaced(calls, lo=60, hi=10 ** 9):
|
|
ts = [t for t, _ in calls]
|
|
return all(lo <= b - a <= hi for a, b in zip(ts, ts[1:]))
|
|
|
|
|
|
def clamp_s1(t):
|
|
return 16.0 if t < 135 else 8.0
|
|
|
|
|
|
def clamp_16(t):
|
|
return 16.0
|
|
|
|
|
|
def s1w(until=400, ev=(), press_at=None, take=None, clamp=clamp_s1,
|
|
cur=None, stale=None, held=()):
|
|
"""EV-69's S1 world (own 3 -> 1 select taken, settle from 122, the close
|
|
tries at 132, 137, 142 refused), no take at 140."""
|
|
w = swriter(0.0, ph=3)
|
|
w.plan.a, w.plan.n = 12.0, 1
|
|
drv = Drv(0.0, take or (lambda a, d: False), ph=1)
|
|
w.seq = {"stage": "settle", "t0": 119.0, "t1": 122.0, "n": 1, "tries": 0,
|
|
"prev": None, "from": 3, "own": [0.0], "sel": True}
|
|
w.last_done = 122.0
|
|
w._own_n = 3
|
|
w._select_try(1, True)
|
|
if held:
|
|
held_wrap(w, set(held))
|
|
pairs = list(ev)
|
|
if press_at is not None:
|
|
pairs.append((press_at, press))
|
|
return Run(w, drv).go(123, until, ev=evs(*pairs), clamp=clamp, cur=cur,
|
|
stale=stale)
|
|
|
|
|
|
def s1_adopt(until=260, ev=(), press_at=None, clamp=clamp_s1):
|
|
"""The charger shows the 132 close of 12 A from 133 (adopted); the clamp
|
|
is 8 from 135, so the closes at 137 and 142 are 8 A, refused."""
|
|
return s1w(until, ev=[(133, show(12.0))] + list(ev), press_at=press_at,
|
|
clamp=clamp)
|
|
|
|
|
|
def snap(box):
|
|
def f(w, d, s):
|
|
box.update(att=w.attempted_a, prior=w.prior_a, last=w.last_a,
|
|
carry=list(w._carry), own=list(w._own_values()),
|
|
kept=getattr(w, "_kept", None))
|
|
return f
|
|
|
|
|
|
def man(until, ev=(), gone=None, last_switch=None, take=None, cur=None,
|
|
start_cur=8.0):
|
|
w = CM.ManualWriter()
|
|
w.last_switch = last_switch
|
|
drv = Drv(start_cur, take or (lambda a, d: False), ph=1)
|
|
st = {"a": 8.0, "n": 1, "rev": 1, "clamp": 16.0}
|
|
return Run(w, drv, kind="manual", st=st).go(
|
|
0, until, ev=evs(*ev), gone=gone, cur=cur)
|
|
|
|
|
|
def set_a(a):
|
|
return lambda w, d, s: s.__setitem__("a", a)
|
|
|
|
|
|
def set_n(n):
|
|
return lambda w, d, s: s.__setitem__("n", n)
|
|
|
|
|
|
# =========================================================================== #
|
|
print("C9 (the press), Solar")
|
|
# =========================================================================== #
|
|
box = {}
|
|
r = world(ev=[(202, snap(box))])
|
|
r2 = world(ev=[])
|
|
c1 = calls0(r, 202)
|
|
check(f"T1: C9, 12 A read from 202 to 400: no mismatch, hold or CHARGER_OTHER "
|
|
f"({r.first_ms(202)}, {r.first_hold()}, {n_other()}); the owed 0 A retry "
|
|
f"goes at 202 and 262 ({c1[:3]})",
|
|
r.clean(202, 400) and n_other() == 0 and (202, 0.0) in c1
|
|
and (262, 0.0) in c1)
|
|
nev("T1", r)
|
|
rr = world(ev=[(202, snap(box))])
|
|
check(f"T2: C9 end of 201: attempted_a {rr.att[201]}, prior_a "
|
|
f"{rr.prior[201]}, last_a {rr.last_a[201]}, sent_a {rr.sent_a[201]}, "
|
|
f"not taken ({rr.taken[201]})",
|
|
rr.att[201] == 0.0 and rr.prior[201] == 12.0 and rr.last_a[201] == 0.0
|
|
and rr.sent_a[201] == 0.0 and rr.taken[201] is False)
|
|
check(f"T2: just after the press at 202 (it lifts nothing) attempted_a, "
|
|
f"prior_a, last_a and the carry are what they were; 12.0 is own "
|
|
f"({box})",
|
|
box.get("att") == 0.0 and box.get("prior") == 12.0
|
|
and box.get("last") == 0.0 and box.get("carry") == []
|
|
and 12.0 in box.get("own", []))
|
|
|
|
rc = world(ev=[(202, cap(6.0))])
|
|
c3 = rc.calls_from(202)
|
|
check(f"T3: C9, cap 6 A from 202: the 0 A cut try goes at 202 ({c3[:3]}), "
|
|
f"retries at least 60 s apart, cut_fails at most 3 "
|
|
f"({rc.w.cut_fails}), no hold ({rc.first_hold()})",
|
|
c3 and near(c3[0][0], 202, 203) and c3[0][1] == 0.0
|
|
and spaced(c3) and rc.w.cut_fails <= 3 and rc.first_hold() is None
|
|
and rc.clean(202, 400))
|
|
nev("T3", rc)
|
|
|
|
r = world(press_at=None)
|
|
check(f"T4: C9-np (no press) as base: writes {r.calls_from(200, 300)}, no "
|
|
f"mismatch 200-400 ({r.first_ms(200)})",
|
|
r.calls_from(200, 300) == [(200, 12.0), (201, 0.0), (261, 0.0)]
|
|
and r.clean(200, 400))
|
|
|
|
r = world(after=lambda t: 16.0)
|
|
check(f"T5: C9, foreign 16 A from 202: mismatch {r.first_ms(202)}, hold "
|
|
f"{r.first_hold()}, 1 CHARGER_OTHER ({n_other()}), no non-zero write "
|
|
f"{r.calls_from(202, 400, True)}, no 0 A after 232 "
|
|
f"({r.calls_from(233, 400)})",
|
|
near(r.first_ms(202), 202, 203) and near(r.first_hold(), 232, 233)
|
|
and n_other() == 1 and not r.calls_from(202, 400, True)
|
|
and not r.calls_from(233, 400))
|
|
nev("T5", r)
|
|
|
|
r = world(after=lambda t: 12.0 if t < 210 or t >= 260 else 16.0)
|
|
check(f"T6: C9, own 12 A to 209, foreign 16 A 210-259, 12 A again from 260: "
|
|
f"clean 202-209 ({r.clean(202, 209)}), mismatch {r.first_ms(210)}, hold "
|
|
f"{r.first_hold()}, 1 line ({n_other()}); the kept value ended at the "
|
|
f"hold, so the hold stands 241-400 with no write "
|
|
f"({all(r.hold[t] for t in range(241, 401))}, "
|
|
f"{r.calls_from(210, 400)})",
|
|
r.clean(202, 209) and near(r.first_ms(210), 210, 211)
|
|
and near(r.first_hold(), 240, 241) and n_other() == 1
|
|
and all(r.hold[t] for t in range(241, 401))
|
|
and not r.calls_from(210, 400) and 12.0 not in r.own[300])
|
|
nev("T6", r)
|
|
|
|
r = world(after=lambda t: 0.0 if t < 210 else 12.0)
|
|
check(f"T7: C9, 0 A shown 202-209 (a fresh take of the owed 0 A), 12 A from "
|
|
f"210: taken at 202 ({r.taken[202]}), mismatch {r.first_ms(210)}, hold "
|
|
f"{r.first_hold()}, 1 line ({n_other()})",
|
|
r.taken[202] is True and near(r.first_ms(210), 210, 211)
|
|
and near(r.first_hold(), 240, 241) and n_other() == 1)
|
|
nev("T7", r)
|
|
|
|
r = world(after=lambda t: 12.0 if t < 230 else 0.0 if t < 240 else 12.0)
|
|
check(f"T8: C9, 12 A to 229, 0 A 230-239 (a fresh take), 12 A from 240: clean "
|
|
f"202-239 ({r.clean(202, 239)}), taken at 230 ({r.taken[230]}), "
|
|
f"mismatch {r.first_ms(230)}, hold {r.first_hold()}, 1 line "
|
|
f"({n_other()})",
|
|
r.clean(202, 239) and r.taken[230] is True
|
|
and near(r.first_ms(230), 240, 241) and near(r.first_hold(), 270, 271)
|
|
and n_other() == 1)
|
|
nev("T8", r)
|
|
|
|
r = world(after=lambda t: None if t < 270 else 12.0,
|
|
ev=[(262, lambda w, d, s: setattr(w.plan, "a", 10.0))])
|
|
w10 = [x for x in r.calls_from(262, 265)]
|
|
check(f"T9: C9, None reads 202-269, the plan raises to 10 A at 262 (written, "
|
|
f"refused), 12 A from 270: the write {w10[:2]}, own after it "
|
|
f"{r.own[263]} (10 replaced 12), mismatch {r.first_ms(270)}, hold "
|
|
f"{r.first_hold()}, 1 line ({n_other()})",
|
|
(262, 10.0) in w10 and 12.0 not in r.own[263] and 10.0 in r.own[263]
|
|
and near(r.first_ms(270), 270, 271) and near(r.first_hold(), 300, 301)
|
|
and n_other() == 1)
|
|
nev("T9", r)
|
|
|
|
r = world(after=lambda t: None if t < 207 else 12.0)
|
|
check(f"T10: C9, None 202-206, then 12 A from 207 (the same-value 0 A retry "
|
|
f"at 202 keeps the kept value): clean 202-400 ({r.clean(202, 400)}), "
|
|
f"retry {r.calls_from(202, 203)}",
|
|
r.clean(202, 400) and n_other() == 0 and (202, 0.0) in r.calls_from(202, 203)
|
|
and 12.0 in r.own[210])
|
|
nev("T10", r)
|
|
|
|
r = world(after=lambda t: 16.0 if t < 205 else None if t < 211 else 16.0)
|
|
check(f"T11: C9, 16 A 202-204, None 205-210, 16 A from 211: the count stands "
|
|
f"through None ({[r.ms[t] for t in range(205, 211)]}), hold "
|
|
f"{r.first_hold()}, 1 line ({n_other()})",
|
|
all(r.ms[t] == 202.0 for t in range(205, 211))
|
|
and near(r.first_hold(), 232, 233) and n_other() == 1)
|
|
|
|
r = world(after=lambda t: 12.0, stale=lambda t: 202 <= t <= 206)
|
|
check(f"T12: C9, stale reads 202-206, then 12 A: no mismatch 202-400 "
|
|
f"({r.first_ms(202)}), no CHARGER_OTHER ({n_other()})",
|
|
r.clean(202, 400) and n_other() == 0)
|
|
|
|
# T13 / T14: DA1, a press that lifts a hold or a count ends everything
|
|
def w8(until, ev, press_at):
|
|
w = swriter(8.0, ph=1)
|
|
w.plan.a, w.plan.n = 12.0, 1
|
|
drv = Drv(8.0, lambda a, d: False, ph=1)
|
|
box = {}
|
|
pairs = list(ev) + [(press_at, chain(press, snap(box)))]
|
|
r = Run(w, drv).go(199, until, ev=evs(*pairs),
|
|
cur=lambda t, d: 8.0 if t < 205 else 16.0)
|
|
return r, box
|
|
|
|
|
|
r, bx = w8(330, [], 250)
|
|
check(f"T13: Solar 8 A, 12 A refused at 199, foreign 16 A from 205 (hold "
|
|
f"{r.first_hold()}); a press at 250 lifts the hold: from 250 no "
|
|
f"mismatch or hold ({r.clean(251, 330)}), own right after the press "
|
|
f"{bx.get('own')} (empty: the lifting press ends everything), carry "
|
|
f"{bx.get('carry')}, kept {bx.get('kept')}, writes "
|
|
f"{r.calls_from(250, 330)}",
|
|
near(r.first_hold(), 235, 236) and r.clean(251, 330)
|
|
and bx.get("own") == [] and bx.get("carry") == []
|
|
and bx.get("kept") is None
|
|
and [x for x in r.calls_from(250, 330)] == [(250, 12.0), (310, 12.0)])
|
|
nev("T13", r)
|
|
r, bx = w8(330, [], 215)
|
|
check(f"T14: as T13, the press at 215 while the count runs (mismatch "
|
|
f"{r.first_ms(205)}): no count and no line from 216 "
|
|
f"({r.clean(216, 330)}), carry {r.carry[215]}, writes "
|
|
f"{r.calls_from(215, 330)}",
|
|
near(r.first_ms(205), 205, 206) and r.clean(216, 330)
|
|
and r.carry[215] == [] and n_other() == 0
|
|
and r.calls_from(215, 330) == [(215, 12.0), (275, 12.0)])
|
|
|
|
# =========================================================================== #
|
|
print("Manual")
|
|
# =========================================================================== #
|
|
cur12 = lambda t, d: 8.0 if t <= 100 else 12.0 # noqa: E731
|
|
r = man(200, ev=[(100, chain(set_a(12.0), press)),
|
|
(101, chain(set_n(3), press))], last_switch=50.0, cur=cur12)
|
|
check(f"T15: Manual 8 A, 12 A at 100 (refused by the call, taken), 3 phases "
|
|
f"pressed at 101 (lifts nothing): no mismatch, hold or 'Something "
|
|
f"else' line 100-200 ({r.first_ms(100)}, {r.first_hold()}, "
|
|
f"{n_some()}), no write 101-200 ({r.calls_from(101, 200)})",
|
|
r.clean(100, 200) and n_some() == 0 and not r.calls_from(101, 200))
|
|
nev("T15", r)
|
|
r = man(200, ev=[(100, chain(set_a(12.0), press))], last_switch=50.0,
|
|
cur=cur12)
|
|
check(f"T16 (a): T15 with no press: writes {r.calls_from(0)}, no mismatch",
|
|
r.calls_from(0) == [(100, 12.0)] and r.clean(100, 200))
|
|
r = man(260, ev=[(100, chain(set_a(12.0), press)),
|
|
(101, chain(set_n(3), press))],
|
|
take=lambda a, d: a == 0.0,
|
|
cur=lambda t, d: 8.0 if t <= 100 else 12.0 if t == 101 else d.cur)
|
|
check(f"T16 (b): last_switch None, 12 A read at 101: 0 A at 101, select at "
|
|
f"102 ({r.calls_from(100, 103)}, {r.drv.sel[:1]}), no mismatch at 101 "
|
|
f"({r.ms[101]})",
|
|
r.calls_from(100, 103) == [(100, 12.0), (101, 0.0)]
|
|
and r.drv.sel and near(r.drv.sel[0][0], 102, 103) and r.ms[101] is None)
|
|
|
|
# =========================================================================== #
|
|
print("Restart, press and S1")
|
|
# =========================================================================== #
|
|
r = world(gone=lambda t: 203 <= t <= 210,
|
|
after=lambda t: 12.0 if t < 203 else 16.0)
|
|
check(f"T17 (i): C9, the charger gone 203-210, back at 211 showing 16 A: no "
|
|
f"mismatch at 211 ({r.ms[211]}), the D2 0 A at 211 "
|
|
f"({r.calls_from(211, 212)}), the kept value is gone ({r.own[211]})",
|
|
r.ms[211] is None and (211, 0.0) in r.calls_from(211, 212)
|
|
and 12.0 not in r.own[211])
|
|
w2, m2 = CM.SolarWriter(), CM.ManualWriter()
|
|
src = open(os.path.join(HERE, "app", "carmode.py")).read()
|
|
others = [f for f in os.listdir(os.path.join(HERE, "app"))
|
|
if f.endswith(".py") and f != "carmode.py"
|
|
and "._kept" in open(os.path.join(HERE, "app", f)).read()]
|
|
check(f"T17 (ii): a new writer (a process restart) has no kept value and no "
|
|
f"carry ({getattr(w2, '_kept', None)}, {getattr(m2, '_kept', None)}, "
|
|
f"{w2._carry}); the kept value is in no other module (no store key) "
|
|
f"({others})",
|
|
getattr(w2, "_kept", None) is None
|
|
and getattr(m2, "_kept", None) is None and w2._carry == []
|
|
and not others)
|
|
|
|
# T18: S1-nt, the closes 12, 8, 8 refused, carry [0, 12, 8] at the end (142)
|
|
r = s1w(400, ev=[(145, press)], stale=lambda t: 145 <= t <= 149)
|
|
check(f"T18 (i): S1-nt, a press at 145 that lifts nothing, stale reads to 149: "
|
|
f"the carry is as at 144 ({r.carry[144]}) at every step 145-149 "
|
|
f"({[r.carry[t] for t in range(145, 150)]}), 12.0 is own "
|
|
f"({r.own[149]}), no write ({r.calls_from(145, 149)})",
|
|
r.carry[144] == [0.0, 12.0, 8.0, 8.0]
|
|
and all(r.carry[t] == r.carry[144] for t in range(145, 150))
|
|
and 12.0 in r.own[149] and not r.calls_from(145, 149))
|
|
r = s1w(400, ev=[(143, show(16.0)), (145, press)])
|
|
check(f"T18 (ii): foreign 16 A from 143, a press at 145 that lifts the count "
|
|
f"(mismatch {r.ms[144]}): the carry is empty after it "
|
|
f"({r.carry[145]}), 12.0 is no own value ({r.own[145]})",
|
|
r.ms[144] is not None and r.carry[145] == [] and 12.0 not in r.own[145])
|
|
nev("T18", r)
|
|
r = s1w(400, ev=[(145, press), (150, show(12.0))])
|
|
check(f"T18 (EV-69 T12 shape): press at 145, 12 A at 150: mismatch "
|
|
f"{r.first_ms(146)}, hold {r.first_hold()}, 1 line ({n_other()}), no "
|
|
f"write at or above 12 A",
|
|
near(r.first_ms(146), 150, 151) and near(r.first_hold(), 180, 181)
|
|
and n_other() == 1
|
|
and not [x for x in r.calls_from(145) if x[1] >= 12.0])
|
|
|
|
# T19: the T8 trace, labelled: the known limit
|
|
r = world(after=lambda t: 12.0 if t < 230 else 0.0 if t < 240 else 12.0)
|
|
check(f"T19: C9, the 12 A shown 202-229 may be another writer's 12 A exactly "
|
|
f"(the accepted limit, EV-67 class: it counts as own): no mismatch to "
|
|
f"229 ({r.clean(202, 229)}); after the fresh take at 230, 12 A at 240: "
|
|
f"mismatch {r.first_ms(230)}, hold {r.first_hold()}",
|
|
r.clean(202, 229) and near(r.first_ms(230), 240, 241)
|
|
and near(r.first_hold(), 270, 271))
|
|
|
|
# =========================================================================== #
|
|
print("F1: the held read and the 0 A overwrite")
|
|
# =========================================================================== #
|
|
r = world("f1a", press_at=None)
|
|
z = calls0(r, 201)
|
|
check(f"T24: F1a (the held read shows 0 A, the :1345 adopt of base), 12 A "
|
|
f"from 202: no mismatch, hold or CHARGER_OTHER ({r.first_ms(202)}, "
|
|
f"{n_other()}); the held read takes nothing (taken "
|
|
f"{set(r.taken[t] for t in range(201, 401))}); the owed 0 A goes out "
|
|
f"at 201-202 and is retried within RETRY_S+2 ({z[:4]})",
|
|
r.clean(202, 400) and n_other() == 0
|
|
and all(r.taken[t] is False for t in range(201, 401))
|
|
and z and near(z[0][0], 201, 202) and spaced(z, 60, 62))
|
|
nev("T24", r)
|
|
r = world("f1b", press_at=None)
|
|
z = calls0(r, 201)
|
|
check(f"T25: F1b (the refused 0 A overwrites attempted_a), 12 A from 202: no "
|
|
f"mismatch, hold or line ({r.first_ms(202)}, {n_other()}); attempted_a "
|
|
f"{r.att[201]}, prior_a {r.prior[201]}, 12.0 is own after the 0 A "
|
|
f"({r.own[201]}); the 0 A retry at 261 ({z[:3]})",
|
|
r.clean(202, 400) and n_other() == 0 and r.att[201] == 0.0
|
|
and r.prior[201] == 8.0 and 12.0 in r.own[201] and (261, 0.0) in z)
|
|
nev("T25", r)
|
|
r = world("f1a", press_at=None, ev=[(202, cap(6.0))])
|
|
c = r.calls_from(202)
|
|
# The held 0 A went at 201, before the cap; the cut try follows it RETRY_S
|
|
# later (the same spacing T27 has), not blocked by any hold.
|
|
check(f"T26: F1a, cap 6 A from 202: the 0 A cut try goes RETRY_S after the "
|
|
f"201 try ({c[:3]}), retries at least 60 s apart, cut_fails "
|
|
f"{r.w.cut_fails} at most 3, no hold",
|
|
c and c[0] == (261, 0.0) and spaced(c)
|
|
and r.w.cut_fails <= 3 and r.first_hold() is None)
|
|
nev("T26", r)
|
|
r = world("f1b", press_at=None, ev=[(202, cap(6.0))])
|
|
c = r.calls_from(202)
|
|
check(f"T27: F1b, cap 6 A from 202: the 0 A cut try at 261 ({c[:3]}), retries "
|
|
f"at least 60 s apart, cut_fails {r.w.cut_fails} at most 3, no hold",
|
|
c and c[0] == (261, 0.0) and spaced(c) and r.w.cut_fails <= 3
|
|
and r.first_hold() is None)
|
|
nev("T27", r)
|
|
for kind, tid in (("f1a", "T28"), ("f1b", "T29")):
|
|
r = world(kind, press_at=None, after=lambda t: 16.0)
|
|
check(f"{tid}: {kind.upper()}, foreign 16 A from 202: mismatch "
|
|
f"{r.first_ms(202)}, hold {r.first_hold()}, 1 CHARGER_OTHER "
|
|
f"({n_other()}), no non-zero write, no 0 A after 232 "
|
|
f"({r.calls_from(202, 400)})",
|
|
near(r.first_ms(202), 202, 203) and near(r.first_hold(), 232, 233)
|
|
and n_other() == 1 and not r.calls_from(202, 400, True)
|
|
and not r.calls_from(233, 400))
|
|
nev(tid, r)
|
|
r = world("f1b", press_at=None, after=lambda t: None if t < 270 else 12.0,
|
|
ev=[(261, lambda w, d, s: setattr(w.plan, "a", 10.0))])
|
|
check(f"T30: F1b, None 202-260, the plan raises to 10 A at 261 (written, "
|
|
f"refused), 12 A from 270: own {r.own[262]}, mismatch "
|
|
f"{r.first_ms(270)}, hold {r.first_hold()}, 1 line ({n_other()})",
|
|
(261, 10.0) in r.calls_from(261, 263) and 12.0 not in r.own[262]
|
|
and near(r.first_ms(270), 270, 271)
|
|
and near(r.first_hold(), 300, 301) and n_other() == 1)
|
|
nev("T30", r)
|
|
# T31: the ruled limit. A foreign value equal to our own untaken 12 A is taken
|
|
# as ours (EV-67 class, formal C9, E5): "it already stands" adopts it at 280
|
|
# and the clamp fall at 300 writes 8 A over it. Accepted by the PM (P3).
|
|
r = world("f1b", press_at=None,
|
|
after=lambda t: 8.0 if t < 210 else 12.0,
|
|
ev=[(280, lambda w, d, s: setattr(w.plan, "a", 12.0)),
|
|
(300, lambda w, d, s: setattr(w.plan, "a", 8.0))])
|
|
check(f"T31: F1b, 8 A (the taken last_a) 202-209, 12 A from 210: clean "
|
|
f"202-400 ({r.clean(202, 400)}); at 280 the 'it already stands' adopt "
|
|
f"takes the 12 A on show as Solar's own (last_a {r.last_a[280]}, taken "
|
|
f"{r.taken[280]}); at 300 8 A is written over it "
|
|
f"({r.calls_from(280, 303, True)}). The accepted limit (EV-67 class)",
|
|
r.clean(202, 400) and r.last_a[281] == 12.0 and r.taken[281] is True
|
|
and (300, 8.0) in r.calls_from(300, 303))
|
|
|
|
# T32-T34: Manual, the 0 A overwrite
|
|
gone32 = lambda t: 101 <= t <= 104 # noqa: E731
|
|
|
|
|
|
def man32(foreign=False):
|
|
return man(260, ev=[(100, chain(set_a(12.0), press)),
|
|
(101, lambda w, d, s: setattr(d, "ph", 3))],
|
|
gone=gone32,
|
|
cur=lambda t, d: 8.0 if t < 170 else (16.0 if foreign else 12.0))
|
|
|
|
|
|
r = man32()
|
|
check(f"T32: Manual 8 A, 12 A at 100 (the charger keeps 8), it is gone "
|
|
f"101-104 and back on 3 phases; _begin's 0 A at 160 refused "
|
|
f"({r.calls_from(100, 170)}); 12 A from 170: no mismatch, hold or "
|
|
f"'Something else' line 160-260 ({r.first_ms(160)}, {n_some()})",
|
|
(160, 0.0) in r.calls_from(160, 161) and r.clean(160, 260)
|
|
and n_some() == 0)
|
|
nev("T32", r)
|
|
r = man(200, ev=[(100, chain(set_a(12.0), press)),
|
|
(101, chain(set_n(3), press))],
|
|
cur=lambda t, d: 8.0 if t <= 101 else 12.0)
|
|
check(f"T33: Manual, 3 phases pressed at 101 (no gap block, the press lifts "
|
|
f"nothing), the read still 8 A: _begin's 0 A at 101 refused "
|
|
f"({r.calls_from(100, 103)}), 12 A from 102: clean 101-200 "
|
|
f"({r.first_ms(101)}, {n_some()})",
|
|
(101, 0.0) in r.calls_from(101, 102) and r.clean(101, 200)
|
|
and n_some() == 0)
|
|
nev("T33", r)
|
|
r = man32(foreign=True)
|
|
check(f"T34: Manual, T32 with a foreign 16 A from 170: mismatch "
|
|
f"{r.first_ms(170)}, hold {r.first_hold()}, 1 line ({n_some()})",
|
|
near(r.first_ms(170), 170, 171) and near(r.first_hold(), 200, 201)
|
|
and n_some() == 1)
|
|
|
|
# =========================================================================== #
|
|
print("The press and the held read in the S1 shapes")
|
|
# =========================================================================== #
|
|
r = s1_adopt(260, ev=[(150, press)])
|
|
check(f"T35: S1-adopt (12 A adopted, closes 12, 8, 8; state at 142 last_a "
|
|
f"{r.last_a[142]}, carry {r.carry[142]}, attempted_a {r.att[142]}, "
|
|
f"prior_a {r.prior[142]}, sent_a {r.sent_a[142]}), a press at 150 that "
|
|
f"lifts nothing, 12 A still shown: no mismatch, hold or line 150-260 "
|
|
f"({r.first_ms(150)}, {n_other()}), 12.0 is own at 150 ({r.own[150]}), "
|
|
f"writes {r.calls_from(143, 260)}",
|
|
r.last_a[142] is None and r.carry[142] == [0.0, 12.0, 8.0, 8.0]
|
|
and r.att[142] == 8.0 and r.prior[142] == 0.0 and r.sent_a[142] == 8.0
|
|
and r.clean(150, 260) and n_other() == 0 and 12.0 in r.own[150]
|
|
and r.calls_from(143, 260) == [(150, 8.0), (210, 8.0)])
|
|
nev("T35", r)
|
|
r = s1w(260, ev=[(145, press)], clamp=clamp_16,
|
|
cur=lambda t, d: 0.0)
|
|
check(f"T36: S1-nt with the clamp at 16 (closes 12, 12, 12 refused, the 0 A "
|
|
f"shown), a press at 145 that lifts nothing: no mismatch or hold "
|
|
f"145-260 ({r.first_ms(145)}), 0.0 is own ({r.own[145]}), writes "
|
|
f"{r.calls_from(143, 260)}",
|
|
r.clean(145, 260) and 0.0 in r.own[145]
|
|
and r.calls_from(143, 260) == [(145, 12.0), (205, 12.0)])
|
|
nev("T36", r)
|
|
# T37: a test-side spy on the writer's `_write` records the carry at its entry.
|
|
spy = []
|
|
w37 = swriter(0.0, ph=3)
|
|
w37.plan.a, w37.plan.n = 12.0, 1
|
|
drv37 = Drv(0.0, lambda a, d: False, ph=1)
|
|
w37.seq = {"stage": "settle", "t0": 119.0, "t1": 122.0, "n": 1, "tries": 0,
|
|
"prev": None, "from": 3, "own": [0.0], "sel": True}
|
|
w37.last_done = 122.0
|
|
w37._own_n = 3
|
|
w37._select_try(1, True)
|
|
held_wrap(w37, {143})
|
|
orig_w = w37._write
|
|
|
|
|
|
async def spy_w(*a, **k):
|
|
spy.append((CLOCK["t"], list(w37._carry), getattr(w37, "_kept", None)))
|
|
return await orig_w(*a, **k)
|
|
|
|
|
|
w37._write = spy_w
|
|
r = Run(w37, drv37).go(123, 260, ev=evs((150, show(12.0))), clamp=16.0)
|
|
at142 = r.carry[142]
|
|
at143 = [x for x in spy if x[0] == 143]
|
|
check(f"T37: S1-nt, clamp 16 (carry {at142} at 142), the held read at 143 "
|
|
f"shows 0 A: it takes nothing (taken {r.taken[143]}), the owed 0 A goes "
|
|
f"out at 143 ({r.calls_from(143, 143)}), the spy at the _write entry "
|
|
f"sees the carry as at 142 ({at143}), after the step it is "
|
|
f"{r.carry[143]} (the 0 A write ended it); the kept value is 12 A "
|
|
f"at the entry ({at143})",
|
|
at142 == [0.0, 12.0, 12.0, 12.0] and r.taken[143] is False
|
|
and (143, 0.0) in r.calls_from(143, 143) and len(at143) == 1
|
|
and at143[0][1] == at142 and at143[0][2] == 12.0
|
|
and r.carry[143] == [])
|
|
nev("T37", r)
|
|
|
|
# T37b: known limit, card EV-73. A refused non-zero value, then an acknowledged
|
|
# own 0 A (a taken write ends the kept value), then the charger takes the
|
|
# refused value late: today that is a count, then a hold at WRITER_S. This row
|
|
# pins it, so a later fix flips it on purpose.
|
|
r = world("f1a", press_at=None, take=lambda a, d: a == 0.0)
|
|
check(f"T37b [known limit, card EV-73]: the 12 A refused, the own 0 A taken "
|
|
f"(taken {r.taken[201]}), the charger shows 12 A from 202: mismatch "
|
|
f"{r.first_ms(202)}, hold {r.first_hold()}, 1 CHARGER_OTHER "
|
|
f"({n_other()}), kept value gone ({r.own[202]})",
|
|
r.taken[201] is True and near(r.first_ms(202), 202, 203)
|
|
and near(r.first_hold(), 232, 233) and n_other() == 1
|
|
and 12.0 not in r.own[202])
|
|
|
|
r = s1_adopt(260, ev=[(150, show(16.0))],
|
|
clamp=lambda t: 16.0 if t < 135 else 8.0 if t < 160 else 6.0)
|
|
check(f"T38: S1-adopt, foreign 16 A from 150, the clamp falls to 6 at 160 "
|
|
f"during the count: mismatch {r.first_ms(150)}, hold "
|
|
f"{r.first_hold()}, 1 CHARGER_OTHER ({n_other()}), no write 150-260 "
|
|
f"({r.calls_from(150, 260)}), state at 149: last_a {r.last_a[149]}, "
|
|
f"attempted_a {r.att[149]}, prior_a {r.prior[149]}, sent_a "
|
|
f"{r.sent_a[149]}",
|
|
near(r.first_ms(150), 150, 151) and near(r.first_hold(), 180, 181)
|
|
and n_other() == 1 and not r.calls_from(150, 260)
|
|
and r.last_a[149] is None and r.att[149] == 8.0 and r.prior[149] == 0.0
|
|
and r.sent_a[149] == 8.0)
|
|
nev("T38", r)
|
|
# T39: the accepted limit again (EV-67 class, E5): another writer's 8 A equal
|
|
# to our own untaken 8 A is taken as ours by the late read-back adopt, and the
|
|
# later own 12 A goes over it. No mutant: it documents the limit.
|
|
r = s1_adopt(260, ev=[(150, show(8.0)),
|
|
(200, lambda w, d, s: setattr(w.plan, "a", 12.0))],
|
|
clamp=lambda t: 16.0 if t < 135 else 8.0 if t < 200 else 16.0)
|
|
check(f"T39: S1-adopt, another writer's 8 A (= the kept 8 A) at 150, the clamp "
|
|
f"back to 16 and the plan 12 A at 200: not seen, no mismatch or hold "
|
|
f"150-260 ({r.first_ms(150)}); at 150 the read-back adopt takes it "
|
|
f"(last_a {r.last_a[150]}, taken {r.taken[150]}); 12 A is written over "
|
|
f"it at 200 and retried at 260 ({r.calls_from(200, 260)}). The accepted "
|
|
f"limit, EV-67",
|
|
r.clean(150, 260) and r.last_a[150] == 8.0 and r.taken[150] is True
|
|
and (200, 12.0) in r.calls_from(200, 201)
|
|
and (260, 12.0) in r.calls_from(260, 261))
|
|
|
|
# =========================================================================== #
|
|
print("Never rules not already inside a row")
|
|
# =========================================================================== #
|
|
# N4: the hole is no wider than EV-67: the own list holds only values the
|
|
# writer wrote, saw or had, never a made-up one, in the C9 and F1 traces.
|
|
for tag, r in (("C9", world()), ("F1a", world("f1a", press_at=None)),
|
|
("F1b", world("f1b", press_at=None))):
|
|
seen = {0.0, 8.0, 12.0} | {a for _, a in r.drv.calls}
|
|
stray = [(t, v) for t in r.own for v in r.own[t] if v not in seen]
|
|
check(f"N4 {tag}: every own value is one the writer wrote or had "
|
|
f"({stray[:2]})", not stray)
|
|
# N10: the kept value is never persisted (T17 ii names the modules); it is no
|
|
# key of the writer's own state dicts either.
|
|
check("N10: the kept value is not part of the carry list or the log",
|
|
all(not hasattr(CM, n) for n in ("KEY_KEPT", "KEY_OWN_KEPT")))
|
|
# N15: a kept value is never own after a hold (T6 reads it back from 260)
|
|
r = world(after=lambda t: 16.0 if t < 260 else 12.0)
|
|
check(f"N15: C9, a hold over 16 A (hold {r.first_hold()}), then the old 12 A "
|
|
f"from 260 does not lift it ({all(r.hold[t] for t in range(241, 401))})",
|
|
near(r.first_hold(), 232, 233)
|
|
and all(r.hold[t] for t in range(241, 401)))
|
|
done()
|