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

@@ -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"