NAC_Blockchain/scripts/test_all.sh

96 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# NAC区块链统一测试脚本
# 作者NAC公链开发小组
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "========================================="
echo " NAC区块链统一测试脚本"
echo "========================================="
echo ""
SUCCESS=0
FAILED=0
TOTAL_TESTS=0
TOTAL_PASSED=0
TOTAL_FAILED=0
# 测试模块函数
test_module() {
local module=$1
local name=$2
if [ -d "$module" ]; then
echo -e "${YELLOW}正在测试 ${name}...${NC}"
cd "$module"
if cargo test 2>&1 | tee /tmp/test_${name}.log; then
# 提取测试统计
TESTS=$(grep "test result:" /tmp/test_${name}.log | tail -1 || echo "")
echo -e "${GREEN}${name} 测试通过${NC}"
if [ -n "$TESTS" ]; then
echo " $TESTS"
fi
((SUCCESS++))
else
echo -e "${RED}${name} 测试失败${NC}"
echo "错误日志: /tmp/test_${name}.log"
((FAILED++))
fi
cd ..
echo ""
else
echo -e "${YELLOW}跳过 ${name}(目录不存在)${NC}"
echo ""
fi
}
# 开始测试
START_TIME=$(date +%s)
# 1. 测试nac-udm核心模块
test_module "nac-udm" "NAC统一数据模型"
# 2. 测试charter-compiler
test_module "charter-compiler" "Charter编译器"
# 3. 测试nvm_v2
test_module "nvm_v2" "NAC虚拟机v2"
# 4. 测试其他模块(如果存在)
test_module "nac-nvm" "NAC虚拟机"
test_module "nac-cbpp" "CBPP共识协议"
test_module "nac-gnacs" "GNACS资产分类"
test_module "nac-acc" "ACC协议"
test_module "nac-acc20c" "ACC-20C合规协议"
test_module "nac-rpc" "NAC RPC接口"
test_module "nac-storage" "NAC存储层"
# 计算耗时
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# 输出统计
echo "========================================="
echo "测试完成"
echo "========================================="
echo -e "成功: ${GREEN}${SUCCESS}${NC}"
echo -e "失败: ${RED}${FAILED}${NC}"
echo "耗时: ${DURATION}"
echo ""
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}✓ 所有模块测试通过!${NC}"
exit 0
else
echo -e "${RED}✗ 部分模块测试失败,请检查错误日志${NC}"
exit 1
fi