From d065db7d7143be50af96f1fa2c0460955e09bf10 Mon Sep 17 00:00:00 2001 From: ETWen Date: Fri, 21 Aug 2026 10:41:50 +0800 Subject: [PATCH] feat(ttl): Gate Script A on bcmcmd port-up count, not thermal sensors wait_init.ttl V2.0.0 now polls bcmcmd -n 0 -c ps | grep -w up | wc -l bcmcmd -n 1 -c ps | grep -w up | wc -l and proceeds only when BOTH exceed 216, so the baseline is taken with the data plane actually up rather than merely with pmon answering. V1.0.0 could use `wait "Thermal Not detected" prompt` because that was a string-presence test. Comparing a count needs the value captured, so the count is wrapped in an echo marker and read with waitregex + groupmatchstr1 + str2int. The command echo cannot false-match: it reads "PORTS0=$(bcmcmd ..." and the pattern requires a digit immediately after the "=". The optional-space allowance covers a wc that pads its output. The two thresholds are compared in nested ifs rather than with `and`, which is bitwise in TTL. WT_MIN and WT_INTERVAL are at the top of the file. The enter/exit prompt contract is unchanged, so Script A's surrounding waits still line up. Script A -> V1.0.4. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_014RetWKFZFG1ZHcitQAyhwM --- src/Script_ABC_Blanton/1_Blanton_Script_A.ttl | 4 +- src/Script_ABC_Blanton/utils/wait_init.ttl | 98 +++++++++++++------ 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/Script_ABC_Blanton/1_Blanton_Script_A.ttl b/src/Script_ABC_Blanton/1_Blanton_Script_A.ttl index 16ac2d1..53701f2 100644 --- a/src/Script_ABC_Blanton/1_Blanton_Script_A.ttl +++ b/src/Script_ABC_Blanton/1_Blanton_Script_A.ttl @@ -1,6 +1,6 @@ ; ============================================================================= ; Script A for Blanton -; Version : V1.0.3 +; Version : V1.0.4 ; Date : 2026-08-21 ; Author : ETWen ; ============================================================================= @@ -16,6 +16,8 @@ ; ScriptB/C Add Traffic Test ; V1.0.3 2026-08-21 utils/wait_init.ttl Created ; ScriptA Add Wait DUT Ready +; V1.0.4 2026-08-21 utils/wait_init.ttl Wait on bcmcmd port-up +; count (both units > 216) ; ============================================================================= include "config.ttl" diff --git a/src/Script_ABC_Blanton/utils/wait_init.ttl b/src/Script_ABC_Blanton/utils/wait_init.ttl index 207e2da..df53470 100644 --- a/src/Script_ABC_Blanton/utils/wait_init.ttl +++ b/src/Script_ABC_Blanton/utils/wait_init.ttl @@ -1,30 +1,68 @@ -; ============================================================================= -; File : utils/wait_init.ttl -; Version : V1.0.0 -; Date : 2026-08-21 -; Author : ETWen -; ============================================================================= -; Wait until "show platform temperature" is not "Thermal Not detected". -; Enter : prompt of the previous command is NOT consumed. -; Exit : "show platform temperature" is sent, prompt NOT consumed. -; -; Version History: -; V1.0.0 2026-08-21 Initial Version -; ============================================================================= -wt_interval = 10 -timeout = 30 -wait prompt_sonic_root - -:WAIT_THERMAL -sendln "show platform temperature" -wait "Thermal Not detected" prompt_sonic_root -if result = 2 then - goto THERMAL_OK -endif -wait prompt_sonic_root -pause wt_interval -goto WAIT_THERMAL - -:THERMAL_OK -timeout = 0 -sendln "show platform temperature" +; ============================================================================= +; File : utils/wait_init.ttl +; Version : V2.0.0 +; Date : 2026-08-21 +; Author : ETWen +; ============================================================================= +; Wait until BOTH switch units report more than WT_MIN ports up: +; bcmcmd -n 0 -c ps | grep -w up | wc -l +; bcmcmd -n 1 -c ps | grep -w up | wc -l +; +; Enter : prompt of the previous command is NOT consumed. +; Exit : a command has been sent, prompt NOT consumed (caller does the wait). +; +; Why the "PORTS0=" marker instead of reading the number straight off the +; screen: TTL can only test for a string, so counting requires capturing the +; output. Wrapping the count in an echo gives waitregex a unique anchor, and +; the ECHO of the command itself cannot false-match -- it reads +; "PORTS0=$(bcmcmd ..." and the regex demands a digit right after the "=". +; +; Version History: +; V1.0.0 2026-08-21 Initial Version (waited on "show platform temperature" +; until it stopped reporting "Thermal Not detected") +; V2.0.0 2026-08-21 Wait on the bcmcmd port-up count of BOTH switch units +; instead of the thermal sensors; proceed only when both +; are greater than WT_MIN (216). +; ============================================================================= +WT_MIN = 216 ; both units must report MORE than this many ports up +WT_INTERVAL = 10 ; seconds between polls + +timeout = 60 ; per-wait cap; bcmcmd ps is not instant +wait prompt_sonic_root + +:WAIT_PORTS +; --- unit 0 ----------------------------------------------------------------- +wt_up0 = 0 +sendln "echo PORTS0=$(bcmcmd -n 0 -c ps | grep -w up | wc -l)" +waitregex "PORTS0=[ ]*([0-9]+)" +if result = 1 then + str2int wt_up0 groupmatchstr1 +endif +wait prompt_sonic_root + +; --- unit 1 ----------------------------------------------------------------- +wt_up1 = 0 +sendln "echo PORTS1=$(bcmcmd -n 1 -c ps | grep -w up | wc -l)" +waitregex "PORTS1=[ ]*([0-9]+)" +if result = 1 then + str2int wt_up1 groupmatchstr1 +endif +wait prompt_sonic_root + +; --- both above the threshold? ---------------------------------------------- +; Nested ifs rather than "and": in TTL "and" is bitwise, so keeping the two +; comparisons separate leaves no room for precedence surprises. +if wt_up0 > WT_MIN then + if wt_up1 > WT_MIN then + goto PORTS_OK + endif +endif + +pause WT_INTERVAL +goto WAIT_PORTS + +:PORTS_OK +timeout = 0 +; Exit contract: send something without waiting, so the caller's next +; "wait prompt_sonic_root" has a prompt to match. +sendln ""