-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_system_integration.sh
More file actions
executable file
·211 lines (169 loc) · 5.65 KB
/
test_system_integration.sh
File metadata and controls
executable file
·211 lines (169 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
# RV1106 AiCam 系统集成测试脚本
# 测试前后端功能和API接口
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 测试结果统计
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
# 函数定义
print_header() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}"
}
print_test() {
echo -e "${YELLOW}[测试] $1${NC}"
((TOTAL_TESTS++))
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
((PASSED_TESTS++))
}
print_error() {
echo -e "${RED}✗ $1${NC}"
((FAILED_TESTS++))
}
print_info() {
echo -e "${BLUE}[信息] $1${NC}"
}
# 测试API接口
test_api() {
local endpoint="$1"
local description="$2"
local expected_status="${3:-200}"
print_test "$description"
response=$(curl -s -w "%{http_code}" -o /tmp/api_response.json "http://localhost:8080$endpoint" 2>/dev/null || echo "000")
if [ "$response" = "$expected_status" ]; then
print_success "$description - 状态码: $response"
if [ -f /tmp/api_response.json ]; then
# 检查响应是否为有效JSON
if jq . /tmp/api_response.json >/dev/null 2>&1; then
print_info "响应格式: 有效JSON"
else
print_info "响应格式: 非JSON"
fi
fi
else
print_error "$description - 期望状态码: $expected_status, 实际: $response"
fi
}
# 测试MJPEG流
test_mjpeg_stream() {
print_test "MJPEG视频流测试"
# 测试MJPEG流头部
response=$(curl -s -I "http://localhost:8081/mjpeg" 2>/dev/null | head -1)
if echo "$response" | grep -q "200 OK"; then
print_success "MJPEG流可访问"
# 检查Content-Type
content_type=$(curl -s -I "http://localhost:8081/mjpeg" 2>/dev/null | grep -i "content-type" | cut -d: -f2 | tr -d ' \r\n')
if echo "$content_type" | grep -q "multipart/x-mixed-replace"; then
print_success "MJPEG Content-Type正确: $content_type"
else
print_error "MJPEG Content-Type错误: $content_type"
fi
else
print_error "MJPEG流不可访问: $response"
fi
}
# 测试前端页面
test_frontend() {
print_test "前端页面可访问性测试"
response=$(curl -s -w "%{http_code}" -o /tmp/frontend_response.html "http://localhost:3000" 2>/dev/null || echo "000")
if [ "$response" = "200" ]; then
print_success "前端页面可访问 - 状态码: $response"
# 检查页面内容
if grep -q "SmartCamera" /tmp/frontend_response.html; then
print_success "前端页面包含预期内容"
else
print_error "前端页面内容异常"
fi
else
print_error "前端页面不可访问 - 状态码: $response"
fi
}
# 主测试流程
main() {
print_header "RV1106 AiCam 系统集成测试"
print_info "开始时间: $(date)"
print_info "测试目标: 后端API (8080), MJPEG流 (8081), 前端 (3000)"
echo
# 1. 后端API测试
print_header "后端API接口测试"
test_api "/api/health" "健康检查接口"
test_api "/api/system/status" "系统状态接口"
test_api "/api/ai/config" "AI配置接口"
test_api "/api/alarm/statistics/overview" "报警统计概览接口"
test_api "/api/alarm/statistics/trend?days=7" "报警趋势接口"
test_api "/api/alarm/statistics/detection-types" "检测类型统计接口"
test_api "/api/cameras" "摄像头列表接口"
test_api "/api/auth/profile" "用户配置接口" "401" # 未登录应返回401
echo
# 2. MJPEG流测试
print_header "MJPEG视频流测试"
test_mjpeg_stream
echo
# 3. 前端测试
print_header "前端页面测试"
test_frontend
echo
# 4. 系统性能测试
print_header "系统性能检查"
print_test "后端进程检查"
if pgrep -f "smartcamera" >/dev/null; then
print_success "后端进程运行正常"
else
print_error "后端进程未运行"
fi
print_test "前端进程检查"
if pgrep -f "npm.*dev\|node.*dev" >/dev/null; then
print_success "前端进程运行正常"
else
print_error "前端进程未运行"
fi
print_test "端口监听检查"
if netstat -ln | grep -q ":8080.*LISTEN"; then
print_success "后端API端口8080监听正常"
else
print_error "后端API端口8080未监听"
fi
if netstat -ln | grep -q ":8081.*LISTEN"; then
print_success "MJPEG流端口8081监听正常"
else
print_error "MJPEG流端口8081未监听"
fi
if netstat -ln | grep -q ":3000.*LISTEN"; then
print_success "前端端口3000监听正常"
else
print_error "前端端口3000未监听"
fi
echo
# 5. 测试结果汇总
print_header "测试结果汇总"
print_info "总测试数: $TOTAL_TESTS"
print_success "通过测试: $PASSED_TESTS"
print_error "失败测试: $FAILED_TESTS"
success_rate=$((PASSED_TESTS * 100 / TOTAL_TESTS))
print_info "成功率: ${success_rate}%"
if [ $FAILED_TESTS -eq 0 ]; then
print_success "🎉 所有测试通过!系统运行正常"
exit 0
else
print_error "⚠️ 有 $FAILED_TESTS 个测试失败,请检查系统状态"
exit 1
fi
}
# 清理临时文件
cleanup() {
rm -f /tmp/api_response.json /tmp/frontend_response.html
}
# 设置清理函数
trap cleanup EXIT
# 运行主测试
main "$@"