; ============================================================================= ; File : utils/wait_init.ttl ; Version : V3.0.0 ; Date : 2026-08-21 ; Author : ETWen ; ============================================================================= ; Wait until every switch unit ENABLED below reports at least WT_MIN ports up: ; bcmcmd -n -c ps | grep -w up | wc -l ; ; The DUT is not always fully populated. Which units exist is declared ONCE in ; config.ttl, so the traffic blocks in Script A/B/C and this wait agree: ; both units -> SWB_UNIT0 = 1 , SWB_UNIT1 = 1 ; unit 0 only -> SWB_UNIT0 = 1 , SWB_UNIT1 = 0 ; unit 1 only -> SWB_UNIT0 = 0 , SWB_UNIT1 = 1 ; no unit -> SWB_UNIT0 = 0 , SWB_UNIT1 = 0 (bypass, returns immediately) ; ; 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: TTL can only test for a string, so reading a count ; means capturing it. Wrapping the number in an echo gives waitregex a unique ; anchor, and the ECHO of the command cannot false-match -- it reads ; "PORTS0=$(bcmcmd ..." and the pattern requires 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). ; V3.0.0 2026-08-21 Add WT_UNIT0 / WT_UNIT1 so a partly populated DUT can ; be declared: wait on the enabled units only, and bypass ; entirely when neither is set. ; V3.1.0 2026-08-21 Take the population from SWB_UNIT0 / SWB_UNIT1 in ; config.ttl instead of local copies, so this wait and the ; traffic blocks cannot drift apart. ; V3.1.1 2026-08-25 WT_INTERVAL 10 -> 60. Fix the WT_MIN comments: the test ; has been `< WT_MIN` (at least) since the threshold was ; corrected, but the text still said "more than", which is ; the off-by-one that once hung Script A. ; ============================================================================= ; ---- which units to wait for: SWB_UNIT0 / SWB_UNIT1, set in config.ttl ------ WT_MIN = 216 ; an enabled unit must report AT LEAST this many ports up ; (216 = 108 loopback pairs x 2, i.e. every cabled port) WT_INTERVAL = 60 ; seconds between polls ; ----------------------------------------------------------------------------- timeout = 60 ; per-wait cap; bcmcmd ps is not instant wait prompt_sonic_root ; nothing declared -> bypass if SWB_UNIT0 = 0 then if SWB_UNIT1 = 0 then goto NO_UNITS endif endif :WAIT_PORTS wt_ok = 1 if SWB_UNIT0 = 1 then 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 if wt_up0 < WT_MIN then wt_ok = 0 endif endif if SWB_UNIT1 = 1 then 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 if wt_up1 < WT_MIN then wt_ok = 0 endif endif if wt_ok = 1 then goto PORTS_OK endif pause WT_INTERVAL goto WAIT_PORTS ; ---- exits ------------------------------------------------------------------ ; Both leave exactly one prompt unconsumed, so the caller's next ; "wait prompt_sonic_root" has something to match. :NO_UNITS sendln "echo wait_init:no-switch-unit-declared,bypassing-port-wait" goto DONE :PORTS_OK sendln "" :DONE timeout = 0