测试:GoogleTest 全面单测(10工况设备表/故障检测/协议/消息/SQLite读回)+ UDP→SQLite 集成测试,src 零改动
build-test-deploy / ci (push) Failing after 11m45s

This commit is contained in:
zjk
2026-08-14 21:29:57 +08:00
parent f51a3ac750
commit de298414ff
14 changed files with 1286 additions and 13 deletions
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
#=======================================================================
# check_db.py: 校验 pPowerManger 写入的 power_data.db 是否有 CCU 反馈记录
#(验证 UDP 反馈 → SystemData → SQLite 全链路)。
#=======================================================================
import sys, os, sqlite3
def main():
db = os.environ.get('PM_DB', '/src/bin/power_data.db')
if not os.path.exists(db):
print(f"DB not found: {db}")
return 1
conn = sqlite3.connect(db)
cur = conn.cursor()
try:
cur.execute("SELECT COUNT(*) FROM ccuState")
n = cur.fetchone()[0]
except Exception as e: # noqa: BLE001
print(f"query failed: {e}")
conn.close()
return 1
conn.close()
print(f"ccuState rows = {n}")
return 0 if n > 0 else 1
if __name__ == '__main__':
sys.exit(main())
+54
View File
@@ -0,0 +1,54 @@
//=======================================================================
// udp_feeder.cpp: 集成测试用 — 向 pPowerManger 发送 CCU 状态反馈 UDP 消息。
// 直接使用真实 C++ 结构体构造消息(字节级与协议一致,无 Python 打包漂移)。
// 用法: udpFeeder [host] [port] [count]
//=======================================================================
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <thread>
#include <chrono>
#include "udpcomm/udpComm.h"
#include "udpcomm/ccuUdpMsg.h"
int main(int argc, char* argv[])
{
const char* host = (argc > 1) ? argv[1] : "127.0.0.1";
int port = (argc > 2) ? atoi(argv[2]) : 5001;
int count = (argc > 3) ? atoi(argv[3]) : 6;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) { perror("socket"); return 1; }
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_port = htons(static_cast<unsigned short>(port));
if (inet_pton(AF_INET, host, &addr.sin_addr) != 1) {
perror("inet_pton");
close(fd);
return 1;
}
udpComm u;
for (int i = 0; i < count; i++) {
msg_CcuStateFbMsg m;
memset(&m, 0, sizeof(m));
m.header.start1 = CCU_UDPMSG_START1;
m.header.start2 = CCU_UDPMSG_START2;
m.header.id = CCU_STATE_FB_ID;
m.data.ins_soc = 42;
m.data.dyn_soc = 66;
m.data.fc_status = 0x04;
m.data.heartbeat = i + 1;
m.checkCode = u.calculateChecksum(reinterpret_cast<unsigned char*>(&m), sizeof(m));
ssize_t n = sendto(fd, &m, sizeof(m), 0, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
if (n < 0) { perror("sendto"); close(fd); return 1; }
std::this_thread::sleep_for(std::chrono::milliseconds(300));
}
close(fd);
printf("sent %d CCU state msgs to %s:%d\n", count, host, port);
return 0;
}