Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc2b529c3a |
+6
-3
@@ -188,6 +188,8 @@ Blanton_TTL_Script/
|
||||
│ # eth0→TARGET_10G、eth1→TARGET_1G,兩張卡同時持續 ping
|
||||
├── port_prbs_monitor.sh # 100G uplink PRBS 測試(bcmcmd phy diag)
|
||||
├── blanton_ber.sh # 全機 SerDes BER 掃描(phydiag prbs / prbsstat)
|
||||
├── nfc_polling.sh # NFC tag 背景輪詢 + PASS/FAIL 統計
|
||||
├── blantons_nfc_validate.py # NFC/NCI 驗證工具(廠商提供,未修改)
|
||||
├── blanton_tr518.sh # TR518 封包測試,量功耗前的負載來源
|
||||
├── TH6_SWB0_power_readback.sh # SWB0 19 條軌 V×I + 總功耗
|
||||
├── TH6_SWB1_power_readback.sh # SWB1 同上
|
||||
@@ -342,9 +344,9 @@ PROFILE_CHANNELS=( "0:high:8" "1:low:8" ... ) # "channel:operation:change_perc
|
||||
|
||||
| 模組 | 進入點 | 功能 |
|
||||
|------|--------|------|
|
||||
| **Script A(Pre-test)** | `1_Blanton_Script_A.ttl` V1.1.1 | root 登入 → `date -s` 對時 → 清 job log → **收掉前一輪殘留**(`hw-test-session finish` → `bgctl reset --yes` → `bgctl stop --all` → `bgctl list` 確認清空)→ `hw-test-session start` → **設定風扇轉速** → **等資料面就緒**(`wait_init.ttl`)→ DUT 清單(boot/version/fwutil/syseeprom/ssdhealth/TPM/NVMe)→ BMC enroll + version/status → source bash 工具 → 清/讀 7 組 PCIe AER + `ras-mc-ctl --summary` → `lspci` → margin → PMON → dmesg → **10G/1G 管理網路 ping** → 100G uplink 設定與狀態 → **一輪流量基線** → `show uptime` |
|
||||
| **Script B(Stress)** | `2_Blanton_Script_B.ttl` | `mlucas-avx2 -cpu 0:15` + `bgctl run` 的 `memtester` / SSD / USB 壓力 + BMC DDR(`bmc-manager run memtester`)→ BMC USB net test(探測 cdc_ncm 介面,`systemd-run` 掛 4 小時 ping)→ 啟動 mgmt ping 監控 → `jobs` / `bgctl list` → traffic(依 `SWB_UNIT`)→ `while 1` 每輪完整 PMON + margin |
|
||||
| **Script C(Post-test)** | `3_Blanton_Script_C.ttl` | `kill $(jobs -p)` + `bgctl stop --all` / `reset` + 停 BMC USB unit 與 mgmt ping → PMON + dmesg → 7 組 AER + `ras-mc-ctl` → BMC USB `journalctl` → `ip -s link show eth0/eth1` → `cat` mlucas log → traffic `stop` + `report` → **BER 掃描**(依 `SWB_UNIT`)→ NVMe 健康 → `show reboot-cause` / `uptime` → **job log 複製到 USB(帶時戳)** → `hw-test-session finish` |
|
||||
| **Script A(Pre-test)** | `1_Blanton_Script_A.ttl` V1.1.2 | root 登入 → `date -s` 對時 → 清 job log → **收掉前一輪殘留**(`hw-test-session finish` → `bgctl reset --yes` → `bgctl stop --all` → `bgctl list` 確認清空)→ `hw-test-session start` → **設定風扇轉速** → **等資料面就緒**(`wait_init.ttl`)→ DUT 清單(boot/version/fwutil/syseeprom/ssdhealth/TPM/NVMe)→ BMC enroll + version/status → source bash 工具 → 清/讀 7 組 PCIe AER + `ras-mc-ctl --summary` → `lspci` → margin → PMON → dmesg → **10G/1G 管理網路 ping** → **NFC 基線**(start → 30s → stop → report)→ 100G uplink 設定與狀態 → **一輪流量基線** → `show uptime` |
|
||||
| **Script B(Stress)** | `2_Blanton_Script_B.ttl` | `mlucas-avx2 -cpu 0:15` + `bgctl run` 的 `memtester` / SSD / USB 壓力 + BMC DDR(`bmc-manager run memtester`)→ BMC USB net test(探測 cdc_ncm 介面,`systemd-run` 掛 4 小時 ping)→ 啟動 mgmt ping 監控 → **啟動 NFC 輪詢** → `jobs` / `bgctl list` → traffic(依 `SWB_UNIT`)→ `while 1` 每輪完整 PMON + margin |
|
||||
| **Script C(Post-test)** | `3_Blanton_Script_C.ttl` | `kill $(jobs -p)` + `bgctl stop --all` / `reset` + 停 BMC USB unit、mgmt ping 與 **NFC 輪詢** → PMON + dmesg → 7 組 AER + `ras-mc-ctl` → BMC USB `journalctl` → `ip -s link show eth0/eth1` → `cat` mlucas log → **NFC `report`** → traffic `stop` + `report` → **BER 掃描**(依 `SWB_UNIT`)→ NVMe 健康 → `show reboot-cause` / `uptime` → **job log 複製到 USB(帶時戳)** → `hw-test-session finish` |
|
||||
| **SWB loopback 流量** | `blanton_traffic_linespeed <sub> [-u 0\|1\|all]` | `init`(VLAN 30..137,成對 `cdN`/`cdN+32`)→ `clear` → `start`(`tx 100 length=512`)→ `stop` → `report`(per-pair TX/RX 交叉比對 PASS/FAIL);另有 `ps`(link/speed)與 `run`(一條龍)。**V0.6.0 起含 100G uplink `ce0`**(VLAN 138):它沒有 loopback 對象,靠 **ingress mirror 打回自己**維持循環,`report` 最後一列就是它,底下再接一份跨 unit summary |
|
||||
| **FPGA 暫存器存取** | `cb_fpga <fn> <addr> [data]`、`fpga_rescan` | pcimem 打 `resource0` + BAR 相對 offset,32-bit word;BDF 於 source 時自動偵測;`pmc/icb/swb0/swb1_fpga` 走 VSPI 窗口 |
|
||||
| **CB I2C / PMBus** | `cb_i2c_init/scan/read/write`、`cb_pmbus_read/write/linear16` | FPGA F3 OpenCores master,**讀用 Repeated START**(SMBus/PMBus 裝置必需) |
|
||||
@@ -360,6 +362,7 @@ PROFILE_CHANNELS=( "0:high:8" "1:low:8" ... ) # "channel:operation:change_perc
|
||||
| **SerDes BER 掃描** | `blanton_ber.sh {init\|clear\|start\|stop\|report} [-u 0\|1\|all]` | 全機每個對接 port 的 PRBS BER:`prbs set p=3` + `prbs get`(確認每條 lane 都鎖上)→ `prbsstat STArt Interval=30` →(等一個 interval)→ `prbsstat Ber` → `STOp` → `prbs clear`。`report` 一列一條 lane,**BER < 1e-6 才 PASS**,最後跨 unit 的 summary 帶最差 lane。⚠️ PRBS 期間 link 顯示 DOWN、不過流量 |
|
||||
| **TR518 負載** | `blanton_tr518.sh {start\|stop} [-u 0\|1\|all]` | `port cd lb=mac` → `l2 learn off` → `test mode nr=yes` → `tr 518 ... testphase=1`,然後 settle `TR_SETTLE_SEC`(120s)再讓人量功耗。`stop` 只送 `port cd lb=none`(照 `TR518.txt`),L2 學習與 test mode **不會還原**,`TR_RESTORE_*=1` 才會 |
|
||||
| **SWB 軌功耗** | `TH6_SWB{0,1}_power_readback.sh` | 讀 `show platform voltage/current` **各一次**,19 條軌 V×I 與總功耗。舊版每軌各讀一次(38 次呼叫、每軌不同時刻),總和是不同瞬間的加總 |
|
||||
| **NFC 讀取輪詢** | `nfc_polling.sh {start\|stop\|status\|tail\|report\|clear\|fg}` | 背景重複跑 `blantons_nfc_validate.py`,每輪追加一行機器可讀的 `RESULT=`(PASS/FAIL 取自工具自己的摘要行,兩者皆無則 **ERROR**,與 FAIL 分開計數)。`start` 會先清空 log;`report` **只讀 log,polling 中隨時可跑**,並標示 `RUNNING` 免得快照被當最終結果。`tail` **不 follow** |
|
||||
| **USB 目標偵測** | `usb_target.sh [-o dev\|mnt\|both\|id] [-n] [-r sec]` | 找出插入的 USB 儲存裝置,排除 `/` 與 `/host` 的底層碟(本平台可能從 USB DOM 開機),多顆時拒絕猜;掛載時會驗證真的可寫 |
|
||||
| **打包交付** | `publish/publish.sh [-v Ver] [-f] [-z] [-n]` | 版號讀 Script A 檔頭,複製成 `publish/Script_ABC_Blanton_<Ver>/`,排除 `*.log`,可另出 zip |
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ DUT 端的取數能力由一組 **bash 工具庫** 提供(CB FPGA `pcimem` →
|
||||
|
||||
完整架構見 [ARCHITECTURE.md](ARCHITECTURE.md)。
|
||||
|
||||
**目前狀態(2026-08-28)**:Script A 為 **V1.1.1**(A 集中記錄 A/B/C 三支的變更)。涵蓋
|
||||
**目前狀態(2026-08-28)**:Script A 為 **V1.1.2**(A 集中記錄 A/B/C 三支的變更)。涵蓋
|
||||
PCIe AER / DDR EDAC / PMON+TPM / 電壓 margin(9 顆 LTC2980)/ SWB loopback 線速流量 /
|
||||
10G+1G 管理網路 ping / BMC DDR 與 USB / NVMe 健康,壓力層走平台的 `bgctl`。
|
||||
switch unit 數量由 `config.ttl` 的 `SWB_UNIT0` / `SWB_UNIT1` 宣告,風扇轉速由 `FAN_SPEED` 指定
|
||||
@@ -22,7 +22,8 @@ TR518 負載(`blanton_tr518.sh`,**TTL 尚未接**)、SWB 軌功耗(`TH6_
|
||||
線速流量也納入 100G `ce0`(VLAN 138,靠 ingress mirror 維持循環)。
|
||||
Script A 開頭會先收掉前一輪殘留(`hw-test-session finish` + `bgctl reset/stop --all`),
|
||||
再 `bgctl list` 確認沒有 job 留著佔資源。
|
||||
最後一次發布是 **V1.1.0**;SWB 的 I2C 通道與位址已於 2026-08-19 上機驗證。
|
||||
NFC tag 讀取由 `nfc_polling.sh` 背景輪詢(A 做基線、B 起、C 停並 report)。
|
||||
最後一次發布是 **V1.1.1**;SWB 的 I2C 通道與位址已於 2026-08-19 上機驗證。
|
||||
交付用 `./publish/publish.sh` 打包。
|
||||
|
||||
## 技術棧
|
||||
@@ -129,6 +130,16 @@ sleep 30 # 至少等一個 interval 再 rep
|
||||
./Blanton_Script/blanton_tr518.sh stop # 只送 port cd lb=none
|
||||
# ⚠️ stop 不還原 l2 learn / test mode(TR_RESTORE_LEARN=1 / _TESTMODE=1 才會)
|
||||
|
||||
# ── NFC tag 輪詢 ────────────────────────────────────
|
||||
~/Blanton_Script/nfc_polling.sh start # 背景,start 會先清空 log
|
||||
~/Blanton_Script/nfc_polling.sh status # pid、已跑幾輪、最後一筆結果
|
||||
~/Blanton_Script/nfc_polling.sh report # PASS/FAIL/ERROR 統計,polling 中也能跑
|
||||
~/Blanton_Script/nfc_polling.sh tail 50 # 最後 50 行(不 follow,不會卡住)
|
||||
~/Blanton_Script/nfc_polling.sh stop
|
||||
# log: ~/Blanton_Script/log/nfc_poll.log
|
||||
# ERROR = 工具沒印出 [PASS]/[FAIL](或逾時),跟「tag 讀不到」分開算
|
||||
# NFC_INTERVAL_SEC / NFC_TIMEOUT_SEC / NFC_ARGS 可調(要每個子指令都帶)
|
||||
|
||||
# ── USB 目標偵測 ────────────────────────────────────
|
||||
bash ~/Blanton_Script/usb_target.sh -o dev # /dev/sdX1
|
||||
bash ~/Blanton_Script/usb_target.sh -o mnt # 掛好並回傳掛載點
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# v1.1.2 — NFC tag reads are now watched for the whole soak, not sampled once
|
||||
|
||||
## ✨ New features
|
||||
|
||||
**Background NFC polling**
|
||||
* New `nfc_polling.sh` runs `blantons_nfc_validate.py` over and over in the background and keeps score. `start` / `stop` / `status` / `tail` / `report` / `clear` / `fg`.
|
||||
* **`report` works while the poll is still running.** It only reads the log, so it never disturbs the run — and it labels itself `RUNNING` so a mid-soak snapshot is not mistaken for the final answer:
|
||||
|
||||
```
|
||||
state : RUNNING (pid=2240323) -- this is a snapshot, the count is still moving
|
||||
rounds : 240
|
||||
PASS : 238
|
||||
FAIL : 2
|
||||
ERROR : 0 (tool did not produce a verdict)
|
||||
RESULT : FAIL
|
||||
|
||||
--- tags seen ---
|
||||
046F7BD2142290 238
|
||||
```
|
||||
* **`ERROR` is counted apart from `FAIL`.** A round where the tool printed neither `[PASS]` nor `[FAIL]` — it crashed, the file was missing, it hung past the timeout — did not measure anything. That is a different problem from a tag that would not read, and rolling the two together hides whichever one you are not looking for.
|
||||
* `report` also lists which NFCID1s were seen and how often, and the last ten failures with their timestamps and reasons.
|
||||
* `start` clears the log first, so a report always describes the run you just did rather than everything since the DUT was built.
|
||||
* Script A takes a 30-second NFC baseline, Script B starts the poll for the soak, Script C stops it with the other monitors and reports.
|
||||
|
||||
## 🐛 Bug fixes
|
||||
|
||||
**The NFC log never reached the USB stick**
|
||||
* Script C copied `nfc_polling.log`; the file is `nfc_poll.log`. The `cp` failed, nothing checked it, and the run finished looking fine — you would only notice back at the desk with a job archive that had no NFC log in it.
|
||||
|
||||
## 📦 Downloads
|
||||
|
||||
| File | Contents |
|
||||
|---|---|
|
||||
| `Script_ABC_Blanton_V1.1.2.zip` | The full Tera Term working directory, including `Blanton_Script/` to copy onto the DUT |
|
||||
|
||||
**After copying to the DUT:**
|
||||
|
||||
```bash
|
||||
chmod +x ~/Blanton_Script/*.sh # see below
|
||||
grep -rlU $'\r' ~/Blanton_Script # expect no output
|
||||
```
|
||||
|
||||
`blanton_ber.sh` and `nfc_polling.sh` are invoked by the macros through `./` or `~/`, so they need the execute bit along with `bmc_monitor.sh` and `usb_target.sh` — neither git nor a Windows/USB copy carries it reliably. `blantons_nfc_validate.py` does **not** need it: `nfc_polling.sh` calls it through `python3` precisely so one more `chmod` cannot be forgotten.
|
||||
|
||||
## ⚠️ Before you run
|
||||
|
||||
* **`nfc_polling.sh start` clears the log.** Script B starts a fresh poll for the soak, which wipes Script A's baseline log — the baseline numbers are already in the master console log by then, but the file is gone.
|
||||
* **NFC log path is `~/Blanton_Script/log/nfc_poll.log`** and it is copied into the job directory by Script C for the USB archive.
|
||||
* **These three tests cannot share the switch.** `blanton_ber.sh`, `blanton_tr518.sh` and `blanton_traffic_linespeed` all take over port loopback and L2 learning. Script C already orders BER after the traffic report.
|
||||
* **PRBS takes the links down** while `blanton_ber.sh` is armed. That is the test working, not a fault.
|
||||
* **`ce0` keeps running until you stop it.** An interrupted run leaves the 100G port saturated with nothing in `show interfaces status` to hint at it.
|
||||
* **Two numbers must stay in step**: Script C's `sleep 30` and `blanton_ber.sh`'s `BER_INTERVAL`.
|
||||
* **`FAN_SPEED` is 100** — the fans run flat out unless you change `config.ttl`.
|
||||
* **Declare the switch population** with `SWB_UNIT0` / `SWB_UNIT1`.
|
||||
* **PRBS on the two 100G uplinks (`port_prbs_monitor.sh`) is still not wired into the macros.**
|
||||
* **The three items listed as unverified in v1.1.0 are still unverified**: the `ce0` ingress mirror, the 120s settle in `blanton_tr518.sh`, and `test mode nr=no` on stop. See [v1.1.0](https://etgit.et-wen.com/etwen/Blanton_TTL_Script/releases/tag/V1.1.0) for the one-command check on each.
|
||||
|
||||
## 🔗 Links
|
||||
|
||||
* [ARCHITECTURE.md](https://etgit.et-wen.com/etwen/Blanton_TTL_Script/src/branch/main/ARCHITECTURE.md) — test flow, data models, constraints
|
||||
* [CLAUDE.md](https://etgit.et-wen.com/etwen/Blanton_TTL_Script/src/branch/main/CLAUDE.md) — commands and the bench gotchas
|
||||
|
||||
**Full changelog:** [V1.1.1...V1.1.2](https://etgit.et-wen.com/etwen/Blanton_TTL_Script/compare/V1.1.1...V1.1.2)
|
||||
@@ -1,6 +1,6 @@
|
||||
; =============================================================================
|
||||
; Script A for Blanton
|
||||
; Version : V1.1.1
|
||||
; Version : V1.1.2
|
||||
; Date : 2026-08-28
|
||||
; Author : ETWen
|
||||
; =============================================================================
|
||||
@@ -138,6 +138,29 @@
|
||||
; A run that ended badly leaves jobs holding CPU and a
|
||||
; session open; the next run used to inherit both, and
|
||||
; the stress numbers were quietly wrong because of it
|
||||
; V1.1.2 2026-08-28 Blanton_Script/nfc_polling.sh Add background NFC tag polling
|
||||
; start / stop / status / tail / report / clear / fg
|
||||
; wraps blantons_nfc_validate.py; start clears the log
|
||||
; first, so a report covers this run only
|
||||
; report works WHILE polling - it only reads the log,
|
||||
; and says RUNNING so a snapshot is not read as final
|
||||
; Each round appends a machine-readable RESULT line, so
|
||||
; the tally never depends on the tool's wording
|
||||
; PASS / FAIL come from the tool's own summary; ERROR
|
||||
; means it produced neither, which is a different fault
|
||||
; from a tag that would not read - counted separately
|
||||
; tail does NOT follow (tail -f never returns, and a
|
||||
; macro waiting on the prompt would hang there)
|
||||
; Runs the .py through python3, not ./ - the file is
|
||||
; mode 100644 and a USB copy carries no execute bit
|
||||
; Blanton_Script/blantons_nfc_validate.py Vendor NFC/NCI validation tool (unmodified)
|
||||
; ScriptA NFC baseline: start -> status -> 30s -> stop -> report
|
||||
; ScriptB Start NFC polling for the soak, then status
|
||||
; ScriptC Stop NFC polling with the other monitors, report it
|
||||
; next to the mgmt ping log, and copy nfc_poll.log to
|
||||
; the job dir for the USB archive
|
||||
; Fix: that cp said nfc_polling.log - the file is
|
||||
; nfc_poll.log, so the NFC log never reached the USB
|
||||
; =============================================================================
|
||||
include "config.ttl"
|
||||
|
||||
@@ -306,6 +329,18 @@ sendln "cat ~/Blanton_Script/log/mgmt_ping.log"
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/mgmt_ping_monitor.sh clear"
|
||||
|
||||
; ========== NFC Test ==========
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh start"
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh status"
|
||||
wait prompt_sonic_root
|
||||
sendln "sleep 30"
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh stop"
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh report"
|
||||
|
||||
|
||||
; ========== 100G Port Status ==========
|
||||
wait prompt_sonic_root
|
||||
|
||||
@@ -100,6 +100,12 @@ wait prompt_sonic_root
|
||||
pause 3
|
||||
sendln "./Blanton_Script/mgmt_ping_monitor.sh status"
|
||||
|
||||
; ========== NFC Test ==========
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh start"
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh status"
|
||||
|
||||
|
||||
; ========== 100G Port ==========
|
||||
wait prompt_sonic_root
|
||||
|
||||
@@ -25,6 +25,8 @@ wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/mgmt_ping_monitor.sh status"
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/mgmt_ping_monitor.sh stop"
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh stop"
|
||||
|
||||
;=============================================================================================================
|
||||
; 100G PRBS STOP
|
||||
@@ -92,6 +94,10 @@ sendln "cat /host/hw-eval/jobs/qfx5252-stress-usb.log"
|
||||
wait prompt_sonic_root
|
||||
sendln "cat ~/Blanton_Script/log/mgmt_ping.log"
|
||||
|
||||
; ========== NFC Test result ==========
|
||||
wait prompt_sonic_root
|
||||
sendln "~/Blanton_Script/nfc_polling.sh report"
|
||||
|
||||
; ========== 100G Port ==========
|
||||
wait prompt_sonic_root
|
||||
sendln "show interfaces status Ethernet513,Ethernet514"
|
||||
@@ -201,6 +207,8 @@ wait prompt_sonic_root
|
||||
sendln "cp ./Blanton_Script/log/bmc_poll.log /host/hw-eval/jobs/"
|
||||
wait prompt_sonic_root
|
||||
sendln "cp ./Blanton_Script/log/mgmt_ping.log /host/hw-eval/jobs/"
|
||||
wait prompt_sonic_root
|
||||
sendln "cp ./Blanton_Script/log/nfc_poll.log /host/hw-eval/jobs/"
|
||||
|
||||
wait prompt_sonic_root
|
||||
getdate ts_date "%Y%m%d"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,314 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# nfc_polling.sh -- keep reading the NFC tag in the background, and tally it
|
||||
# =============================================================================
|
||||
# Version History:
|
||||
# V1.0.0 2026-08-28 First version. start/stop/status/tail/report/clear/fg,
|
||||
# wraps blantons_nfc_validate.py. 'report' works while the
|
||||
# poll is still running.
|
||||
# =============================================================================
|
||||
#
|
||||
# Each round runs blantons_nfc_validate.py once and appends a machine-readable
|
||||
# verdict line, so 'report' never has to parse the tool's prose:
|
||||
#
|
||||
# [2026-08-28 15:04:11] NFC poll #000001 START
|
||||
# ... the tool's own output ...
|
||||
# [2026-08-28 15:04:14] NFC poll #000001 RESULT=PASS tag=046F7BD2142290
|
||||
#
|
||||
# The verdict comes from the tool's own [PASS] / [FAIL] summary line. If neither
|
||||
# appears the round is ERROR, not FAIL -- "the tool did not run" and "the tag was
|
||||
# not read" are different problems and get counted separately.
|
||||
#
|
||||
# Usage:
|
||||
# ./nfc_polling.sh start # background, CLEARS the log first
|
||||
# ./nfc_polling.sh status # running? pid, rounds so far, log size
|
||||
# ./nfc_polling.sh tail [n] # last n lines (default 50) -- does NOT follow
|
||||
# ./nfc_polling.sh report # PASS/FAIL tally; safe to run WHILE polling
|
||||
# ./nfc_polling.sh stop
|
||||
# ./nfc_polling.sh clear # delete the log (must be stopped)
|
||||
# ./nfc_polling.sh fg # run in the foreground, Ctrl-C to stop
|
||||
#
|
||||
# Environment overrides:
|
||||
# NFC_INTERVAL_SEC=10 NFC_TIMEOUT_SEC=60 NFC_MAX_ROUNDS=0 (0 = forever)
|
||||
# NFC_ARGS="test --debug" NFC_LOG_DIR=<dir> NFC_BIN=<python3>
|
||||
# =============================================================================
|
||||
|
||||
# --- User Configurable Section ----------------------------------------------
|
||||
NFC_INTERVAL_SEC="${NFC_INTERVAL_SEC:-10}" # gap between rounds
|
||||
NFC_TIMEOUT_SEC="${NFC_TIMEOUT_SEC:-60}" # kill a round that hangs (0 = never)
|
||||
NFC_MAX_ROUNDS="${NFC_MAX_ROUNDS:-0}" # 0 = until 'stop'
|
||||
|
||||
# Called through python3 on purpose: blantons_nfc_validate.py arrives from git
|
||||
# (mode 100644) and a Windows/USB copy does not carry the execute bit either, so
|
||||
# "./blantons_nfc_validate.py" would fail with Permission denied on a fresh DUT.
|
||||
NFC_PY="${NFC_PY:-python3}"
|
||||
NFC_SCRIPT_NAME="${NFC_SCRIPT_NAME:-blantons_nfc_validate.py}"
|
||||
|
||||
# --debug is kept because that is the output that has been seen on the bench.
|
||||
# It costs ~1.5 KB per round (~13 MB/day at a 10s interval), which is fine for a
|
||||
# soak; drop it to "test" if you want a smaller log.
|
||||
NFC_ARGS="${NFC_ARGS:-test --debug}"
|
||||
|
||||
NFC_LOG_DIR="${NFC_LOG_DIR:-}" # empty = <script dir>/log
|
||||
NFC_LOG_NAME="${NFC_LOG_NAME:-nfc_poll.log}"
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
SCRIPT_NAME="$(basename -- "${BASH_SOURCE[0]}")"
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPT_PATH="${SCRIPT_DIR}/${SCRIPT_NAME}"
|
||||
NFC_SCRIPT="${NFC_SCRIPT:-${SCRIPT_DIR}/${NFC_SCRIPT_NAME}}"
|
||||
[ -n "${NFC_LOG_DIR}" ] || NFC_LOG_DIR="${SCRIPT_DIR}/log"
|
||||
LOG_FILE="${NFC_LOG_DIR}/${NFC_LOG_NAME}"
|
||||
PID_FILE="${NFC_LOG_DIR}/${NFC_LOG_NAME%.log}.pid"
|
||||
|
||||
STOP=0
|
||||
SLEEP_PID=""
|
||||
|
||||
ts() { date '+%Y-%m-%d %H:%M:%S'; }
|
||||
die() { printf '[ERROR] %s\n' "$*" >&2; exit 1; }
|
||||
|
||||
on_signal() {
|
||||
STOP=1
|
||||
[ -n "${SLEEP_PID}" ] && kill "${SLEEP_PID}" 2>/dev/null
|
||||
return 0
|
||||
}
|
||||
|
||||
# sleep that a signal can cut short, so 'stop' does not wait out the interval
|
||||
interruptible_sleep() {
|
||||
local sec="$1"
|
||||
[ "${sec}" -le 0 ] 2>/dev/null && return 0
|
||||
sleep "${sec}" &
|
||||
SLEEP_PID=$!
|
||||
wait "${SLEEP_PID}" 2>/dev/null
|
||||
SLEEP_PID=""
|
||||
return 0
|
||||
}
|
||||
|
||||
is_running() {
|
||||
local pid
|
||||
[ -f "${PID_FILE}" ] || return 1
|
||||
pid="$(cat "${PID_FILE}" 2>/dev/null)"
|
||||
[ -n "${pid}" ] || return 1
|
||||
kill -0 "${pid}" 2>/dev/null || return 1
|
||||
printf '%s' "${pid}"
|
||||
return 0
|
||||
}
|
||||
|
||||
# --- one round ---------------------------------------------------------------
|
||||
# Appends START, the tool output, then a RESULT line. Everything about a round
|
||||
# lands in the log even when the tool dies, so 'report' can still account for it.
|
||||
run_one_round() {
|
||||
local n="$1" out rc verdict tag reason
|
||||
printf '[%s] NFC poll #%06d START\n' "$(ts)" "${n}"
|
||||
|
||||
if [ -n "${NFC_TIMEOUT_SEC}" ] && [ "${NFC_TIMEOUT_SEC}" -gt 0 ] 2>/dev/null \
|
||||
&& command -v timeout >/dev/null 2>&1; then
|
||||
out="$(timeout "${NFC_TIMEOUT_SEC}" "${NFC_PY}" "${NFC_SCRIPT}" ${NFC_ARGS} 2>&1)"; rc=$?
|
||||
else
|
||||
out="$("${NFC_PY}" "${NFC_SCRIPT}" ${NFC_ARGS} 2>&1)"; rc=$?
|
||||
fi
|
||||
printf '%s\n' "${out}"
|
||||
|
||||
# The tool's own summary decides. Exit status is only the fallback, because
|
||||
# a tool that never printed a summary did not measure anything.
|
||||
if printf '%s\n' "${out}" | grep -q '^\[PASS\]'; then
|
||||
verdict="PASS"
|
||||
elif printf '%s\n' "${out}" | grep -q '^\[FAIL\]'; then
|
||||
verdict="FAIL"
|
||||
elif [ "${rc}" -eq 124 ]; then
|
||||
verdict="ERROR"; reason="round exceeded NFC_TIMEOUT_SEC=${NFC_TIMEOUT_SEC}s"
|
||||
else
|
||||
verdict="ERROR"; reason="no [PASS]/[FAIL] summary, exit=${rc}"
|
||||
fi
|
||||
|
||||
tag="$(printf '%s\n' "${out}" | sed -n 's/.*NFCID1=\([0-9A-Fa-f]*\).*/\1/p' | tail -1)"
|
||||
[ -n "${reason}" ] || reason="$(printf '%s\n' "${out}" | grep -m1 '^\[\(PASS\|FAIL\)\]' | cut -c8-)"
|
||||
|
||||
printf '[%s] NFC poll #%06d RESULT=%s tag=%s reason=%s\n' \
|
||||
"$(ts)" "${n}" "${verdict}" "${tag:--}" "${reason:--}"
|
||||
}
|
||||
|
||||
main_loop() {
|
||||
local n=0
|
||||
trap on_signal INT TERM
|
||||
printf '[%s] ===== nfc_polling start : %s %s (interval %ss) =====\n' \
|
||||
"$(ts)" "${NFC_PY}" "${NFC_SCRIPT}" "${NFC_INTERVAL_SEC}"
|
||||
while [ "${STOP}" -eq 0 ]; do
|
||||
n=$(( n + 1 ))
|
||||
run_one_round "${n}"
|
||||
if [ "${NFC_MAX_ROUNDS}" -gt 0 ] 2>/dev/null && [ "${n}" -ge "${NFC_MAX_ROUNDS}" ]; then
|
||||
break
|
||||
fi
|
||||
[ "${STOP}" -eq 0 ] && interruptible_sleep "${NFC_INTERVAL_SEC}"
|
||||
done
|
||||
printf '[%s] ===== nfc_polling stop : %d round(s) =====\n' "$(ts)" "${n}"
|
||||
}
|
||||
|
||||
# --- sub-commands ------------------------------------------------------------
|
||||
do_start() {
|
||||
local pid
|
||||
pid="$(is_running)" && die "already running (pid=${pid})"
|
||||
[ -r "${NFC_SCRIPT}" ] || die "cannot read ${NFC_SCRIPT}"
|
||||
command -v "${NFC_PY}" >/dev/null 2>&1 || die "${NFC_PY} not found"
|
||||
mkdir -p "${NFC_LOG_DIR}" || die "cannot create ${NFC_LOG_DIR}"
|
||||
|
||||
# start always begins a fresh log, so a report is about THIS run only
|
||||
: > "${LOG_FILE}" || die "cannot write ${LOG_FILE}"
|
||||
|
||||
if command -v setsid >/dev/null 2>&1; then
|
||||
setsid "${SCRIPT_PATH}" __daemon >/dev/null 2>&1 &
|
||||
else
|
||||
nohup "${SCRIPT_PATH}" __daemon >/dev/null 2>&1 &
|
||||
disown 2>/dev/null
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
pid="$(is_running)" || die "start failed, check ${LOG_FILE}"
|
||||
printf 'started (pid=%s)\nlog: %s\n' "${pid}" "${LOG_FILE}"
|
||||
}
|
||||
|
||||
do_daemon() {
|
||||
mkdir -p "${NFC_LOG_DIR}" || die "cannot create ${NFC_LOG_DIR}"
|
||||
exec >>"${LOG_FILE}" 2>&1
|
||||
printf '%d\n' "$$" > "${PID_FILE}"
|
||||
trap 'rm -f "${PID_FILE}"' EXIT
|
||||
main_loop
|
||||
}
|
||||
|
||||
do_stop() {
|
||||
local pid i
|
||||
pid="$(is_running)" || { printf 'not running\n'; rm -f "${PID_FILE}"; return 0; }
|
||||
kill -TERM -"${pid}" 2>/dev/null || kill -TERM "${pid}" 2>/dev/null
|
||||
for (( i = 0; i < 20; i++ )); do
|
||||
kill -0 "${pid}" 2>/dev/null || break
|
||||
sleep 0.5
|
||||
done
|
||||
if kill -0 "${pid}" 2>/dev/null; then
|
||||
printf 'SIGTERM ignored, sending SIGKILL\n'
|
||||
kill -KILL -"${pid}" 2>/dev/null || kill -KILL "${pid}" 2>/dev/null
|
||||
fi
|
||||
rm -f "${PID_FILE}"
|
||||
printf 'stopped (pid=%s)\n' "${pid}"
|
||||
}
|
||||
|
||||
# counts straight out of the log, so it is the same answer running or stopped
|
||||
_tally() {
|
||||
local f="$1"
|
||||
[ -r "${f}" ] || { printf '0 0 0 0\n'; return; }
|
||||
awk '
|
||||
/RESULT=PASS/ { p++ }
|
||||
/RESULT=FAIL/ { f++ }
|
||||
/RESULT=ERROR/ { e++ }
|
||||
/ START$/ { s++ }
|
||||
END { printf "%d %d %d %d\n", s+0, p+0, f+0, e+0 }
|
||||
' "${f}"
|
||||
}
|
||||
|
||||
do_status() {
|
||||
local pid started passed failed errored size
|
||||
if pid="$(is_running)"; then
|
||||
printf 'status : running (pid=%s)\n' "${pid}"
|
||||
else
|
||||
printf 'status : stopped\n'
|
||||
fi
|
||||
printf 'log : %s\n' "${LOG_FILE}"
|
||||
if [ -r "${LOG_FILE}" ]; then
|
||||
size="$(du -h "${LOG_FILE}" 2>/dev/null | cut -f1)"
|
||||
read -r started passed failed errored <<< "$(_tally "${LOG_FILE}")"
|
||||
printf 'size : %s\n' "${size:-?}"
|
||||
printf 'rounds : %s started (PASS %s / FAIL %s / ERROR %s)\n' \
|
||||
"${started}" "${passed}" "${failed}" "${errored}"
|
||||
printf 'last : %s\n' "$(grep -a 'RESULT=' "${LOG_FILE}" | tail -1)"
|
||||
else
|
||||
printf 'size : (no log yet)\n'
|
||||
fi
|
||||
}
|
||||
|
||||
do_report() {
|
||||
local pid started passed failed errored inflight verdict first last
|
||||
[ -r "${LOG_FILE}" ] || die "no log at ${LOG_FILE} -- has it been started?"
|
||||
read -r started passed failed errored <<< "$(_tally "${LOG_FILE}")"
|
||||
inflight=$(( started - passed - failed - errored ))
|
||||
|
||||
echo "===== NFC polling report ====="
|
||||
printf 'log : %s\n' "${LOG_FILE}"
|
||||
if pid="$(is_running)"; then
|
||||
printf 'state : RUNNING (pid=%s) -- this is a snapshot, the count is still moving\n' "${pid}"
|
||||
else
|
||||
printf 'state : stopped\n'
|
||||
fi
|
||||
first="$(grep -a -m1 ' START$' "${LOG_FILE}" | sed -n 's/^\[\([^]]*\)\].*/\1/p')"
|
||||
last="$(grep -a 'RESULT=' "${LOG_FILE}" | tail -1 | sed -n 's/^\[\([^]]*\)\].*/\1/p')"
|
||||
printf 'window : %s -> %s\n' "${first:-?}" "${last:-?}"
|
||||
echo ""
|
||||
printf 'rounds : %d\n' "${started}"
|
||||
printf 'PASS : %d\n' "${passed}"
|
||||
printf 'FAIL : %d\n' "${failed}"
|
||||
printf 'ERROR : %d (tool did not produce a verdict)\n' "${errored}"
|
||||
[ "${inflight}" -gt 0 ] && printf 'in flight: %d (round started, no result yet)\n' "${inflight}"
|
||||
|
||||
if [ "${started}" -eq 0 ]; then
|
||||
verdict="NO DATA"
|
||||
elif [ "${failed}" -gt 0 ] || [ "${errored}" -gt 0 ]; then
|
||||
verdict="FAIL"
|
||||
else
|
||||
verdict="PASS"
|
||||
fi
|
||||
printf 'RESULT : %s\n' "${verdict}"
|
||||
|
||||
echo ""
|
||||
echo "--- tags seen ---"
|
||||
grep -a 'RESULT=PASS' "${LOG_FILE}" \
|
||||
| sed -n 's/.* tag=\([0-9A-Fa-f]*\) .*/\1/p' \
|
||||
| sort | uniq -c | sort -rn | awk '{printf " %-20s %s\n", $2, $1}'
|
||||
grep -aq 'RESULT=PASS.* tag=[0-9A-Fa-f]' "${LOG_FILE}" || echo " (none)"
|
||||
|
||||
if [ "$(( failed + errored ))" -gt 0 ]; then
|
||||
echo ""
|
||||
echo "--- last 10 FAIL / ERROR ---"
|
||||
grep -aE 'RESULT=(FAIL|ERROR)' "${LOG_FILE}" | tail -10 | sed 's/^/ /'
|
||||
fi
|
||||
echo ""
|
||||
[ "${verdict}" = "FAIL" ] && return 2
|
||||
return 0
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
${SCRIPT_NAME} - background NFC tag polling (wraps ${NFC_SCRIPT_NAME})
|
||||
|
||||
start run in the background; CLEARS the log first
|
||||
stop stop it
|
||||
status running? pid, rounds so far, last result
|
||||
tail [n] last n lines of the log (default 50) -- does NOT follow
|
||||
report PASS/FAIL tally -- safe to run WHILE polling
|
||||
clear delete the log (must be stopped)
|
||||
fg run in the foreground, Ctrl-C to stop
|
||||
|
||||
interval ${NFC_INTERVAL_SEC}s per-round timeout ${NFC_TIMEOUT_SEC}s rounds ${NFC_MAX_ROUNDS} (0 = forever)
|
||||
log ${LOG_FILE}
|
||||
|
||||
A round is PASS or FAIL from the tool's own summary line; ERROR means it
|
||||
produced neither, which is a different problem from a tag that would not read.
|
||||
USAGE
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
start) do_start ;;
|
||||
stop) do_stop ;;
|
||||
status) do_status ;;
|
||||
report) do_report ;;
|
||||
# deliberately NOT 'tail -f': that never returns, and a TTL macro waiting on
|
||||
# the prompt would hang there forever.
|
||||
tail) [ -r "${LOG_FILE}" ] || die "no log at ${LOG_FILE}"
|
||||
tail -n "${2:-50}" "${LOG_FILE}" ;;
|
||||
clear)
|
||||
is_running >/dev/null && die "still running, stop it first"
|
||||
rm -f "${LOG_FILE}"
|
||||
printf 'log cleared\n'
|
||||
;;
|
||||
fg) main_loop ;;
|
||||
__daemon) do_daemon ;;
|
||||
-h|--help|"") usage ;;
|
||||
*) printf '[ERROR] unknown sub-command: %s\n\n' "$1" >&2; usage; exit 1 ;;
|
||||
esac
|
||||
Reference in New Issue
Block a user