refactor: 把 run_hello.sh 合并进 run_tb.sh 的 'hello' 模块

新增 ./run_tb.sh hello [two],复用 'top' 的 RTL 编译列表 + hello_world/
two_inst 自检 TB,删除独立的 run_hello.sh。README 同步更新命令。
This commit is contained in:
2026-06-29 22:34:36 +08:00
parent 6b99e5abba
commit df4d5cd572
3 changed files with 41 additions and 28 deletions

View File

@@ -218,8 +218,8 @@ c' = K-PKE.Encrypt(ek_pke, m', r') ←── 复用整条 Encaps 流水
./run_tb.sh dec # Decaps含拒绝路径
./run_tb.sh dec 2 0 # 仅 K=2 用例 0
./run_hello.sh # hello_world 端到端(单实例)
./run_hello.sh two # hello_world 端到端双实例genenc + dec
./run_tb.sh hello # hello_world 端到端(单实例)
./run_tb.sh hello two # hello_world 端到端双实例genenc + dec
```
`hello_world` 硬件输出与 Rust 参考逐字节一致:`shared_key=ced0c031a4bee34a...``encrypted=a6b5ac5dcb9e9425b9e3b8``decrypted="hello world"`

View File

@@ -1,25 +0,0 @@
#!/usr/bin/env bash
# run_hello.sh - compile + run an ML-KEM hello_world hardware testbench.
# ./run_hello.sh single-instance protocol (default)
# ./run_hello.sh two two-instance (genenc + dec) protocol
set -e
cd "$(dirname "$0")"
source /opt/Xilinx/Vivado/2019.2/settings64.sh >/dev/null 2>&1
export LD_PRELOAD="/usr/lib64/libtinfo.so.5"
rm -rf xsim.dir .Xil
if [ "$1" = "two" ]; then
TB=tb_mlkem_two_inst_xsim; SNAP=mlkem_two
else
TB=tb_mlkem_hello_world_xsim; SNAP=mlkem_hello
fi
# compile the RTL (every non-TB xvlog line from the shared tcl)
grep -E '^xvlog ' sync_rtl/top/TB/xsim_run.tcl | grep -v 'TB/tb_' | while read -r cmd; do
eval "$cmd" >/dev/null
done
xvlog -sv --relax sync_rtl/top/TB/$TB.v >/dev/null
xelab $TB -s $SNAP --timescale 1ns/1ps >/dev/null 2>&1
xsim $SNAP -R 2>/dev/null | grep -vE '^(#|INFO|Time resolution|run -all|exit|xsim|Vivado|====.*Simulator|SW Build|IP Build|Copyright|Tool Version|Start of|source |## )' | sed '/^$/N;/^\n$/D'

View File

@@ -12,6 +12,8 @@
# ./run_tb.sh enc 4 1 # Encaps K=4, only CASE=1
# ./run_tb.sh dec # ML-KEM Decaps: all K, all cases (0..2)
# ./run_tb.sh dec 2 0 # Decaps K=2, only CASE=0
# ./run_tb.sh hello # hello_world end-to-end (single instance)
# ./run_tb.sh hello two # hello_world end-to-end (two instances)
# ./run_tb.sh --list
#
# 'top' (KeyGen), 'enc' (Encaps) and 'dec' (Decaps) share the same RTL datapath;
@@ -39,6 +41,7 @@ if [ "$1" = "--list" ]; then
done
echo " enc (ML-KEM Encaps; shares the 'top' RTL/tcl, enc testbench)"
echo " dec (ML-KEM Decaps; shares the 'top' RTL/tcl, dec testbench)"
echo " hello (ML-KEM hello_world end-to-end; 'hello two' for two instances)"
exit 0
fi
@@ -53,7 +56,7 @@ SEL_K="$2" # optional: 2/3/4 (top/enc modules only)
SEL_CASE="$3" # optional: KAT case index (top/enc modules only)
# 'enc' is not its own RTL dir; it reuses the 'top' KeyGen tcl compile list
# (same datapath) and swaps in the encaps testbench. 'dec' likewise (Decaps).
if [ "$MODULE" = "enc" ] || [ "$MODULE" = "dec" ]; then
if [ "$MODULE" = "enc" ] || [ "$MODULE" = "dec" ] || [ "$MODULE" = "hello" ]; then
TB_DIR="$SCRIPT_DIR/sync_rtl/top/TB"
else
TB_DIR="$SCRIPT_DIR/sync_rtl/$MODULE/TB"
@@ -281,4 +284,39 @@ if [ "$MODULE" = "top" ]; then
exit $?
fi
# ML-KEM hello_world end-to-end. Reuses the 'top' RTL compile list, then runs a
# self-checking protocol TB (no KAT vectors): single instance by default, or two
# instances (genenc + dec) with 'hello two'. Prints each step's inputs/outputs.
run_hello_selected() {
local tcl_file="$1" variant="$2"
set +e
rm -rf xsim.dir .Xil
local tb snap
if [ "$variant" = "two" ]; then
tb=tb_mlkem_two_inst_xsim; snap=mlkem_two
else
tb=tb_mlkem_hello_world_xsim; snap=mlkem_hello
fi
# compile RTL (every non-TB xvlog line from the shared tcl)
while read -r cmd; do
[[ "$cmd" == *"TB/tb_"* ]] && continue
eval "$cmd" || { echo "COMPILE FAILED: $cmd"; return 1; }
done < <(grep -E '^xvlog ' "$tcl_file")
echo " xvlog -sv --relax sync_rtl/top/TB/$tb.v"
xvlog -sv --relax "sync_rtl/top/TB/$tb.v" || { echo "HELLO TB COMPILE FAILED"; return 1; }
echo " xelab $tb -s $snap --timescale 1ns/1ps"
xelab "$tb" -s "$snap" --timescale 1ns/1ps || { echo "ELAB FAILED"; return 1; }
xsim "$snap" -R
}
if [ "$MODULE" = "hello" ]; then
run_hello_selected "$TCL_FILE" "$SEL_K" # SEL_K position carries the variant ('two')
exit $?
fi
execute_tcl "$TCL_FILE"