Solar as a second writer next to Manual (carmode.SolarPlan, SolarWriter on ManualWriter's one write site, safe phase sequence and other-writer watch): signed spare, Batteries first on the batteries' ratings, the margin, whole amps rounded down, the 30 s / 1 A rule, start and pause dwells, auto phases, a one-phase car. Every way out ends at 0 A, retried by EV-04's rule; at shutdown before the inverters, three tries inside 15 s (D3); start-up and a returning charger or HA write 0 A first (D2); never over another writer's hold. The peak guard treats a Solar car as a Manual car (D1 wording). Solar kWh sensor and card line; select.goodwe_car_sun_first; ev_margin_w, ev_start_min, ev_pause_min with config, validator, translations, DOCS, DECISIONS and CHANGELOG. Checks: test_ev20.py, test_ev20_exits.py, test_ev20_writers.py, test_ev20_guard.py, test_ev20_long.py, test_ev20_long_car.py, test_ev20_fuzz.py (harness tools/ev20_sun.py, ev20_kit.py, ev20_day.py); test_ev03/test_ev04 no longer use Solar as the refused example. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
151 lines
7.2 KiB
Bash
Executable File
151 lines
7.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# CI-15: run the add-on's test_*.py files, in parallel, inside the CI container.
|
|
# Called by the step "the add-on's own tests" of .gitea/workflows/checks.yml as
|
|
# sh -eu /w/goodwe-addon/.gitea/ci/run-tests.sh
|
|
# and runnable the same way from a clone (see TESTS_DIR below).
|
|
#
|
|
# WHY: the serial loop ran past the runner's 60-minute limit (SAFETY-125: 85 files,
|
|
# 3 557 s of test time, run 1430 cut off at file 84). The host has 12 cores.
|
|
#
|
|
# SHAPE
|
|
# 1. A parallel batch: JOBS files at a time (xargs -P), longest first.
|
|
# 2. THEN the serial group, one at a time, after the batch has finished, so
|
|
# each runs on a machine with nothing else of ours on it.
|
|
# Every file writes to its own $RUN_DIR/<file>.out (there is no shared output
|
|
# file) and prints its result as ONE block under a lock, so the PASS/FAIL
|
|
# lines and the `CI: ` / tail -40 text of two files never interleave.
|
|
#
|
|
# THE FILE LIST IS STILL DERIVED FROM THE TREE (see checks.yml). The two typed
|
|
# lists below only SORT or SET ASIDE files that exist; a new test_*.py that is
|
|
# in neither list is run, in the parallel batch. A name that no longer exists
|
|
# in a list is harmless. Nothing can make a file silently not run.
|
|
#
|
|
# SERIAL GROUP: files whose assertions depend on the wall clock, so CPU load
|
|
# from siblings could flip them. Name and reason, one each:
|
|
# test_loop.py drives the real run_control() against a real wall-clock
|
|
# floor (~93 s on purpose); worst inter-cycle gap 3.0 s
|
|
# against a 4.5 s bound (TEST-30, CI-06).
|
|
# test_freeze.py part 3 runs the real sim/hwsim.py over a transport with a
|
|
# 16 s window, a 10 s hold and an alarm measured at 11.0 s:
|
|
# one poll of margin, and "failed 1 run in 3" on the rig
|
|
# transport (TEST-30, CI-06).
|
|
# test_safety87.py builds a controller (CH65) whose meter reading is stamped
|
|
# on the REAL clock, and section 8 asks its status page,
|
|
# which says "Not ready - Meter: no reading for N seconds,
|
|
# limit 30 seconds" once N passes 30. Measured by CI-15: N is
|
|
# about half the file's run time (N = 45 s in a 94 s run, 48 s
|
|
# in a 103 s run). The file takes ~25 s idle and took 45 s in
|
|
# CI's first parallel run, so N was ~20 s of the 30. It FAILED
|
|
# alone under --cpus 0.15 (94 s) and in a loaded parallel run
|
|
# (103 s). No test file is changed here, so it runs alone.
|
|
# Add a file here only with a measured reason, and say it in this list.
|
|
SERIAL="test_loop.py test_freeze.py test_safety87.py"
|
|
#
|
|
# LONGEST FIRST. With JOBS workers pulling from one queue, starting the longest
|
|
# files first keeps the tail short: the batch takes about as long as the longest
|
|
# file or the total work divided by JOBS, whichever is more. A sort order, not a
|
|
# selection. Seconds, CI-18 local runs at 10 workers on the 12-core host (one
|
|
# file's time grows with the load; the order is what matters): opt36 653,
|
|
# safety119 704, opt34 515, safety126 402, safety125 388, safety126b 364,
|
|
# modes_p3 377, safety94 360, modes_p4c 291, modes_p4b 238, tariff24_weather 235,
|
|
# modes_p4d 196, price_run_fixes 197, safety103 189, safety90 185, safety97 163.
|
|
# EV-20 (Solar), local runs at 8 workers: ev20_exits ~460, ev20_guard ~450,
|
|
# ev20 ~350, ev20_fuzz ~300, ev20_long_car ~280, ev20_long ~240, ev20_writers ~230.
|
|
# CI-18 split test_modes_p4, test_safety126 and test_safety125 so no one file
|
|
# is much over 400 s; test_opt34 and test_opt36 already fan out inside, and
|
|
# test_safety119 part 4 is one coupled block, so those three stay whole.
|
|
HEAVY="test_opt36.py test_safety119.py test_opt34.py test_ev20_exits.py test_ev20_guard.py test_safety126.py test_safety125.py test_safety126b.py test_modes_p3.py test_safety94.py test_ev20.py test_ev20_fuzz.py test_modes_p4c.py test_ev20_long_car.py test_ev20_long.py test_modes_p4b.py test_ev20_writers.py test_tariff24_weather.py test_modes_p4d.py test_safety125b.py test_price_run_fixes.py test_safety103.py test_safety90.py test_safety97.py test_peakguard.py test_opt20.py test_safety81.py"
|
|
#
|
|
JOBS=${CI_JOBS:-10}
|
|
cd "${TESTS_DIR:-/w/goodwe-addon/goodwe_controller}"
|
|
|
|
# one FILE: run it, keep its output in its own file, print its block whole.
|
|
if [ "${1:-}" = "--one" ]; then
|
|
f=$2
|
|
o="$RUN_DIR/$f.out"
|
|
start=$(date +%s)
|
|
if python3 "$f" > "$o" 2>&1; then rc=0; else rc=1; fi
|
|
secs=$(( $(date +%s) - start ))
|
|
{
|
|
if [ $rc = 0 ]; then
|
|
echo "PASS $f (${secs}s)"
|
|
grep "^CI: " "$o" || true
|
|
else
|
|
echo "FAIL $f (${secs}s)"
|
|
tail -40 "$o"
|
|
fi
|
|
} > "$RUN_DIR/$f.blk"
|
|
echo $rc > "$RUN_DIR/$f.rc"
|
|
flock "$RUN_DIR/print.lock" cat "$RUN_DIR/$f.blk"
|
|
exit 0
|
|
fi
|
|
|
|
set -- test_*.py
|
|
if [ "$1" = "test_*.py" ]; then
|
|
echo "NO test_*.py FOUND - the mount is empty or the layout moved. NOTHING has been checked."
|
|
exit 1
|
|
fi
|
|
ALL_COUNT=$#
|
|
# CI-18: CI_ONLY="test_a.py test_b.py" runs just those files, for a developer's
|
|
# local round (run-affected.sh sets it). checks.yml never sets it and
|
|
# test_affected_tests.py fails if it ever does: the merge gate is the glob above.
|
|
# Every name must be an existing test_*.py here, and the last line says PARTIAL.
|
|
PARTIAL=0
|
|
if [ -n "${CI_ONLY:-}" ]; then
|
|
PARTIAL=1
|
|
for f in $CI_ONLY; do
|
|
case "$f" in test_*.py) ;; *) echo "CI_ONLY: '$f' is not a test_*.py name"; exit 1 ;; esac
|
|
[ -f "$f" ] || { echo "CI_ONLY: '$f' does not exist in $(pwd)"; exit 1; }
|
|
done
|
|
set -- $CI_ONLY
|
|
echo "PARTIAL RUN (CI_ONLY): $# of $ALL_COUNT test files. NOT the merge gate."
|
|
fi
|
|
echo "$# test file(s) to run: $JOBS at a time, then the serial group"
|
|
|
|
RUN_DIR=$(mktemp -d /tmp/ci-tests.XXXXXX)
|
|
export RUN_DIR
|
|
: > "$RUN_DIR/par"
|
|
: > "$RUN_DIR/ser"
|
|
for f in $HEAVY; do
|
|
case " $SERIAL " in *" $f "*) continue ;; esac
|
|
case " $* " in *" $f "*) if [ -f "$f" ]; then echo "$f" >> "$RUN_DIR/par"; fi ;; esac
|
|
done
|
|
for f in "$@"; do
|
|
case " $SERIAL $HEAVY " in *" $f "*) continue ;; esac
|
|
echo "$f" >> "$RUN_DIR/par"
|
|
done
|
|
for f in $SERIAL; do
|
|
case " $* " in *" $f "*) if [ -f "$f" ]; then echo "$f" >> "$RUN_DIR/ser"; fi ;; esac
|
|
done
|
|
echo "parallel: $(wc -l < "$RUN_DIR/par") file(s); serial: $(wc -l < "$RUN_DIR/ser") file(s)"
|
|
|
|
t0=$(date +%s)
|
|
rc=0
|
|
# `exit 0` in the worker: a failing FILE is recorded in its .rc, so a non-zero
|
|
# from xargs itself means the machinery broke, which is a failure too.
|
|
xargs -n 1 -P "$JOBS" sh -eu "$0" --one < "$RUN_DIR/par" || rc=1
|
|
echo "parallel batch done in $(( $(date +%s) - t0 ))s; serial group next"
|
|
while read -r f; do
|
|
sh -eu "$0" --one "$f" || rc=1
|
|
done < "$RUN_DIR/ser"
|
|
|
|
# Every file that was meant to run has a verdict, and every verdict is PASS. A
|
|
# worker that died before writing its .rc leaves no file, which counts as a fail.
|
|
ran=0
|
|
bad=0
|
|
for f in "$@"; do
|
|
ran=$((ran + 1))
|
|
if [ ! -f "$RUN_DIR/$f.rc" ]; then
|
|
echo "FAIL $f (no result: the run never reported)"
|
|
bad=$((bad + 1))
|
|
elif [ "$(cat "$RUN_DIR/$f.rc")" != 0 ]; then
|
|
bad=$((bad + 1))
|
|
fi
|
|
done
|
|
echo "$ran file(s), $bad failed, $(( $(date +%s) - t0 ))s wall"
|
|
if [ "$PARTIAL" = 1 ]; then
|
|
echo "PARTIAL RUN: $ran of $ALL_COUNT test files ran. This is NOT the merge gate; CI runs all $ALL_COUNT."
|
|
fi
|
|
if [ "$bad" = 0 ] && [ "$rc" = 0 ]; then exit 0; fi
|
|
exit 1
|