p3p implementation
This commit is contained in:
+24
-6
@@ -31,6 +31,7 @@ class TestRecord:
|
||||
priority: int
|
||||
victim_band: str | None
|
||||
config: dict[str, dict[str, str | None]]
|
||||
throttled: bool
|
||||
estimated_minutes: int
|
||||
status: str = "pending"
|
||||
excluded: bool = False
|
||||
@@ -81,6 +82,7 @@ def init_db(db_path: str | Path = DB_PATH) -> None:
|
||||
priority INTEGER NOT NULL CHECK (priority BETWEEN 1 AND 5),
|
||||
victim_band TEXT,
|
||||
config_json TEXT,
|
||||
throttled INTEGER NOT NULL DEFAULT 0,
|
||||
estimated_minutes INTEGER NOT NULL,
|
||||
status TEXT NOT NULL CHECK (status IN ('pending', 'completed', 'failed', 'invalid')),
|
||||
excluded INTEGER NOT NULL DEFAULT 0,
|
||||
@@ -137,6 +139,7 @@ def init_db(db_path: str | Path = DB_PATH) -> None:
|
||||
_ensure_column(conn, "tests", "config_json", "TEXT")
|
||||
_ensure_column(conn, "tests", "victim_band", "TEXT")
|
||||
_ensure_column(conn, "tests", "excluded", "INTEGER NOT NULL DEFAULT 0")
|
||||
_ensure_column(conn, "tests", "throttled", "INTEGER NOT NULL DEFAULT 0")
|
||||
|
||||
# Seed runtime defaults for schedule estimation.
|
||||
conn.execute(
|
||||
@@ -159,9 +162,9 @@ def upsert_tests(records: list[TestRecord], db_path: str | Path = DB_PATH) -> in
|
||||
"""
|
||||
INSERT INTO tests(
|
||||
test_id, device, test_type, rotation, rx_tx, has_coe_pair,
|
||||
coe_pairing_json, config_json, priority, victim_band, estimated_minutes, status, excluded, raw_payload
|
||||
coe_pairing_json, config_json, priority, victim_band, throttled, estimated_minutes, status, excluded, raw_payload
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(test_id, device) DO UPDATE SET
|
||||
test_type = excluded.test_type,
|
||||
device = excluded.device,
|
||||
@@ -172,6 +175,7 @@ def upsert_tests(records: list[TestRecord], db_path: str | Path = DB_PATH) -> in
|
||||
config_json = excluded.config_json,
|
||||
priority = excluded.priority,
|
||||
victim_band = excluded.victim_band,
|
||||
throttled = excluded.throttled,
|
||||
estimated_minutes = excluded.estimated_minutes,
|
||||
status = excluded.status,
|
||||
excluded = excluded.excluded,
|
||||
@@ -190,6 +194,7 @@ def upsert_tests(records: list[TestRecord], db_path: str | Path = DB_PATH) -> in
|
||||
json.dumps(r.config),
|
||||
r.priority,
|
||||
r.victim_band,
|
||||
int(r.throttled),
|
||||
r.estimated_minutes,
|
||||
r.status,
|
||||
int(r.excluded),
|
||||
@@ -260,13 +265,24 @@ def _entry_value(entry: dict[str, str | None], key: str) -> str:
|
||||
return _normalize_text(entry.get(key) or entry.get(key.capitalize()) or entry.get(key.upper()))
|
||||
|
||||
|
||||
def _record_power_mode(record: TestRecord) -> str:
|
||||
power_mode = _entry_value(_band_entry(record.config, "6G"), "power_mode")
|
||||
if power_mode:
|
||||
return power_mode
|
||||
|
||||
raw_payload = record.raw_payload or {}
|
||||
return _normalize_text(raw_payload.get("6GHz Power Mode"))
|
||||
|
||||
|
||||
def _match_any_band_value(record: TestRecord, key: str, token_suffix: str) -> bool:
|
||||
if not token_suffix:
|
||||
return False
|
||||
|
||||
target_num = _extract_signed_int(token_suffix)
|
||||
target_compact = _normalize_compact(token_suffix)
|
||||
for band in ("5G", "6G", "2G"):
|
||||
keys = ("Station 1", "Station 2", "Station 3") if record.test_type == "P3P" else ("5G", "6G", "2G")
|
||||
|
||||
for band in keys:
|
||||
entry = _band_entry(record.config, band)
|
||||
value = _entry_value(entry, key)
|
||||
if not value:
|
||||
@@ -289,7 +305,7 @@ def _matches_atomic_exclusion_token(record: TestRecord, token: str) -> bool:
|
||||
test_type = _normalize_text(record.test_type)
|
||||
rotation = _normalize_text(record.rotation)
|
||||
victim_band = _normalize_text(record.victim_band)
|
||||
power_mode = _entry_value(_band_entry(record.config, "6G"), "power_mode")
|
||||
power_mode = _record_power_mode(record)
|
||||
known_devices = {_normalize_text(DUT), _normalize_text(REF)}
|
||||
|
||||
if token in {"LPI", "SP"}:
|
||||
@@ -343,7 +359,7 @@ def list_schedulable_tests(db_path: str | Path = DB_PATH, rule: str = "") -> lis
|
||||
SELECT
|
||||
test_id, device, test_type, rotation, rx_tx, has_coe_pair,
|
||||
config_json, victim_band,
|
||||
coe_pairing_json, priority, estimated_minutes,
|
||||
coe_pairing_json, priority, throttled, estimated_minutes,
|
||||
excluded, status, raw_payload
|
||||
FROM tests
|
||||
WHERE excluded = 0
|
||||
@@ -365,6 +381,7 @@ def list_schedulable_tests(db_path: str | Path = DB_PATH, rule: str = "") -> lis
|
||||
priority=int(row["priority"]),
|
||||
victim_band=row["victim_band"],
|
||||
config=json.loads(row["config_json"] or "{}"),
|
||||
throttled=bool(row["throttled"]),
|
||||
estimated_minutes=int(row["estimated_minutes"]),
|
||||
status=row["status"],
|
||||
excluded=bool(row["excluded"]),
|
||||
@@ -384,7 +401,7 @@ def list_tests_for_device(device: str, db_path: str | Path = DB_PATH) -> list[Te
|
||||
SELECT
|
||||
test_id, device, test_type, rotation, rx_tx, has_coe_pair,
|
||||
config_json, victim_band,
|
||||
coe_pairing_json, priority, estimated_minutes,
|
||||
coe_pairing_json, priority, throttled, estimated_minutes,
|
||||
excluded, status, raw_payload
|
||||
FROM tests
|
||||
WHERE device = ?
|
||||
@@ -406,6 +423,7 @@ def list_tests_for_device(device: str, db_path: str | Path = DB_PATH) -> list[Te
|
||||
priority=int(row["priority"]),
|
||||
victim_band=row["victim_band"],
|
||||
config=json.loads(row["config_json"] or "{}"),
|
||||
throttled=bool(row["throttled"]),
|
||||
estimated_minutes=int(row["estimated_minutes"]),
|
||||
status=row["status"],
|
||||
excluded=bool(row["excluded"]),
|
||||
|
||||
Reference in New Issue
Block a user