存储测试通过
This commit is contained in:
@@ -51,15 +51,15 @@
|
||||
* =================================================================== */
|
||||
|
||||
#ifdef ENABLE_PHASE6_TESTS
|
||||
static void phase6_run(int sockfd) {
|
||||
static void phase6_run(int32_t sockfd) {
|
||||
/*
|
||||
* 单连接 TCP Echo:NET_MSG_DONTWAIT 非阻塞收,原样回显。
|
||||
* 连接断开由 net 层自动重监听(auto_relisten),应用层不维护生命周期;
|
||||
* 字节完整性由 PC 侧校验(data == test_data),固件不做每连接自检。
|
||||
*/
|
||||
int n = net_recv(sockfd, s_rx_buf, TEST_BUF_SIZE, NET_MSG_DONTWAIT);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf, TEST_BUF_SIZE, NET_MSG_DONTWAIT);
|
||||
if (n > 0) {
|
||||
int sent = net_send(sockfd, s_rx_buf, n, 0);
|
||||
int32_t sent = net_send(sockfd, s_rx_buf, n, 0);
|
||||
if (sent != n) {
|
||||
DBG_ERROR("echo: send %d != recv %d", sent, n);
|
||||
}
|
||||
@@ -119,9 +119,9 @@ static uint32_t phase7_cksum(const uint8_t *p, uint32_t n) {
|
||||
/* 单次 TCP Client 会话:对应 TC 701 主体 / TC 702 单轮。
|
||||
* 每轮使用不同本地端口 local_port 规避 TIME_WAIT。
|
||||
* 返回 1 表示全流程通过,0 表示中途失败(已记录 TEST_CHECK)。 */
|
||||
static int phase7_session(uint16_t local_port)
|
||||
static int32_t phase7_session(uint16_t local_port)
|
||||
{
|
||||
int sockfd = net_socket(NET_AF_INET, NET_SOCK_STREAM, 0);
|
||||
int32_t sockfd = net_socket(NET_AF_INET, NET_SOCK_STREAM, 0);
|
||||
if (sockfd < 0) {
|
||||
TEST_CHECK(0, "TC701 socket create");
|
||||
return 0;
|
||||
@@ -149,14 +149,14 @@ static int phase7_session(uint16_t local_port)
|
||||
|
||||
DBG_INFO("TC701 connecting %s:%d (local port %d)",
|
||||
PHASE7_REMOTE_IP, PHASE7_REMOTE_PORT, local_port);
|
||||
int rc = net_connect(sockfd, (struct net_sockaddr *)&raddr, sizeof(raddr));
|
||||
int32_t rc = net_connect(sockfd, (struct net_sockaddr *)&raddr, sizeof(raddr));
|
||||
TEST_CHECK(rc == 0, "TC701 connect issued (ret=%d)", rc);
|
||||
if (rc != 0) { net_close(sockfd); return 0; }
|
||||
|
||||
/* 等待连接建立:轮询 socket 状态(ESTABLISHED)。
|
||||
* 用 net_select 触发 net_poll 并作为 100ms 节拍,状态以 net_get_sock 为准。 */
|
||||
{
|
||||
int connected = 0;
|
||||
int32_t connected = 0;
|
||||
uint32_t tick = HAL_GetTick();
|
||||
while (HAL_GetTick() - tick < PHASE7_CONN_TIMEOUT_MS) {
|
||||
net_sock_t *sk = net_get_sock(sockfd);
|
||||
@@ -175,16 +175,16 @@ static int phase7_session(uint16_t local_port)
|
||||
/* 数据交换:64B 递增模式 */
|
||||
uint8_t tx[PHASE7_EXCH_SIZE];
|
||||
uint8_t rx[PHASE7_EXCH_SIZE];
|
||||
for (int i = 0; i < PHASE7_EXCH_SIZE; i++) tx[i] = (uint8_t)i;
|
||||
for (int32_t i = 0; i < PHASE7_EXCH_SIZE; i++) tx[i] = (uint8_t)i;
|
||||
|
||||
int sent = net_send(sockfd, tx, PHASE7_EXCH_SIZE, 0);
|
||||
int32_t sent = net_send(sockfd, tx, PHASE7_EXCH_SIZE, 0);
|
||||
TEST_CHECK(sent == PHASE7_EXCH_SIZE, "TC701 send %dB (sent=%d)", PHASE7_EXCH_SIZE, sent);
|
||||
if (sent != PHASE7_EXCH_SIZE) { net_close(sockfd); return 0; }
|
||||
|
||||
int recvd = 0;
|
||||
int32_t recvd = 0;
|
||||
uint32_t tick = HAL_GetTick();
|
||||
while (recvd < PHASE7_EXCH_SIZE) {
|
||||
int n = net_recv(sockfd, rx + recvd, PHASE7_EXCH_SIZE - recvd, NET_MSG_DONTWAIT);
|
||||
int32_t n = net_recv(sockfd, rx + recvd, PHASE7_EXCH_SIZE - recvd, NET_MSG_DONTWAIT);
|
||||
if (n > 0) {
|
||||
recvd += n;
|
||||
} else if (n == 0) {
|
||||
@@ -199,10 +199,10 @@ static int phase7_session(uint16_t local_port)
|
||||
if (HAL_GetTick() - tick > PHASE7_CONN_TIMEOUT_MS) break;
|
||||
}
|
||||
|
||||
int ok = (recvd == PHASE7_EXCH_SIZE);
|
||||
int32_t ok = (recvd == PHASE7_EXCH_SIZE);
|
||||
if (ok) {
|
||||
int bad = 0;
|
||||
for (int i = 0; i < PHASE7_EXCH_SIZE; i++) {
|
||||
int32_t bad = 0;
|
||||
for (int32_t i = 0; i < PHASE7_EXCH_SIZE; i++) {
|
||||
if (rx[i] != (uint8_t)i) { bad = 1; break; }
|
||||
}
|
||||
TEST_CHECK(!bad, "TC701 byte-compare %dB", PHASE7_EXCH_SIZE);
|
||||
@@ -220,7 +220,7 @@ static int phase7_session(uint16_t local_port)
|
||||
* 701/702 要求服务端在线,703 要求服务端离线,故 703 应在独立的一轮中运行)。 */
|
||||
static void phase7_test_timeout(void)
|
||||
{
|
||||
int sockfd = net_socket(NET_AF_INET, NET_SOCK_STREAM, 0);
|
||||
int32_t sockfd = net_socket(NET_AF_INET, NET_SOCK_STREAM, 0);
|
||||
if (sockfd < 0) { TEST_CHECK(0, "TC703 socket create"); return; }
|
||||
|
||||
struct net_sockaddr_in raddr;
|
||||
@@ -231,11 +231,11 @@ static void phase7_test_timeout(void)
|
||||
|
||||
DBG_INFO("TC703 connecting %s:%d (expect TIMEOUT, PC server must be OFF)",
|
||||
PHASE7_REMOTE_IP, PHASE7_REMOTE_PORT);
|
||||
int rc = net_connect(sockfd, (struct net_sockaddr *)&raddr, sizeof(raddr));
|
||||
int32_t rc = net_connect(sockfd, (struct net_sockaddr *)&raddr, sizeof(raddr));
|
||||
TEST_CHECK(rc == 0, "TC703 connect issued (ret=%d)", rc);
|
||||
if (rc != 0) { net_close(sockfd); return; }
|
||||
|
||||
int established = 0;
|
||||
int32_t established = 0;
|
||||
uint32_t tick = HAL_GetTick();
|
||||
while (HAL_GetTick() - tick < PHASE7_TIMEOUT_TEST_MS) {
|
||||
net_sock_t *sk = net_get_sock(sockfd);
|
||||
@@ -262,19 +262,19 @@ static void phase7_test_timeout(void)
|
||||
#define PHASE7_MULTI_BASE_PORT 51000
|
||||
#endif
|
||||
|
||||
static int phase7_session_multi(void)
|
||||
static int32_t phase7_session_multi(void)
|
||||
{
|
||||
int sockfd[PHASE7_MULTI_COUNT];
|
||||
int32_t sockfd[PHASE7_MULTI_COUNT];
|
||||
uint8_t tx[PHASE7_EXCH_SIZE];
|
||||
uint8_t rx[PHASE7_EXCH_SIZE];
|
||||
for (int i = 0; i < PHASE7_EXCH_SIZE; i++) tx[i] = (uint8_t)i;
|
||||
for (int32_t i = 0; i < PHASE7_EXCH_SIZE; i++) tx[i] = (uint8_t)i;
|
||||
|
||||
/* 1) 打开并连接所有 Socket(各自绑定不同本地端口规避 TIME_WAIT) */
|
||||
for (int i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
for (int32_t i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
sockfd[i] = net_socket(NET_AF_INET, NET_SOCK_STREAM, 0);
|
||||
if (sockfd[i] < 0) {
|
||||
TEST_CHECK(0, "TC704 socket create #%d", i);
|
||||
for (int j = 0; j < i; j++) net_close(sockfd[j]);
|
||||
for (int32_t j = 0; j < i; j++) net_close(sockfd[j]);
|
||||
return 0;
|
||||
}
|
||||
struct net_sockaddr_in laddr;
|
||||
@@ -284,7 +284,7 @@ static int phase7_session_multi(void)
|
||||
if (net_bind(sockfd[i], (struct net_sockaddr *)&laddr, sizeof(laddr)) < 0) {
|
||||
TEST_CHECK(0, "TC704 bind #%d port %d", i, PHASE7_MULTI_BASE_PORT + i);
|
||||
net_close(sockfd[i]);
|
||||
for (int j = 0; j < i; j++) net_close(sockfd[j]);
|
||||
for (int32_t j = 0; j < i; j++) net_close(sockfd[j]);
|
||||
return 0;
|
||||
}
|
||||
struct net_sockaddr_in raddr;
|
||||
@@ -292,11 +292,11 @@ static int phase7_session_multi(void)
|
||||
raddr.sin_family = NET_AF_INET;
|
||||
raddr.sin_port = net_htons((uint16_t)PHASE7_REMOTE_PORT);
|
||||
raddr.sin_addr.s_addr = net_inet_addr(PHASE7_REMOTE_IP);
|
||||
int rc = net_connect(sockfd[i], (struct net_sockaddr *)&raddr, sizeof(raddr));
|
||||
int32_t rc = net_connect(sockfd[i], (struct net_sockaddr *)&raddr, sizeof(raddr));
|
||||
TEST_CHECK(rc == 0, "TC704 connect #%d issued (ret=%d)", i, rc);
|
||||
if (rc != 0) {
|
||||
net_close(sockfd[i]);
|
||||
for (int j = 0; j < i; j++) net_close(sockfd[j]);
|
||||
for (int32_t j = 0; j < i; j++) net_close(sockfd[j]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -304,10 +304,10 @@ static int phase7_session_multi(void)
|
||||
/* 2) 等待所有连接建立(或超时) */
|
||||
{
|
||||
uint32_t tick = HAL_GetTick();
|
||||
int all_up = 0;
|
||||
int32_t all_up = 0;
|
||||
while (HAL_GetTick() - tick < PHASE7_CONN_TIMEOUT_MS) {
|
||||
all_up = 1;
|
||||
for (int i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
for (int32_t i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
net_sock_t *sk = net_get_sock(sockfd[i]);
|
||||
if (!sk || sk->state != NET_SOCK_STATE_ESTABLISHED) { all_up = 0; break; }
|
||||
}
|
||||
@@ -316,7 +316,7 @@ static int phase7_session_multi(void)
|
||||
}
|
||||
TEST_CHECK(all_up, "TC704 all %d sockets established within %dms", PHASE7_MULTI_COUNT, PHASE7_CONN_TIMEOUT_MS);
|
||||
if (!all_up) {
|
||||
for (int i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
for (int32_t i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
net_sock_t *sk = net_get_sock(sockfd[i]);
|
||||
if (sk) DBG_ERROR("TC704 socket #%d state=%d", i, sk->state);
|
||||
net_close(sockfd[i]);
|
||||
@@ -326,18 +326,18 @@ static int phase7_session_multi(void)
|
||||
}
|
||||
|
||||
/* 3) 每路独立收发回显 */
|
||||
int ok = 1;
|
||||
for (int i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
int sent = net_send(sockfd[i], tx, PHASE7_EXCH_SIZE, 0);
|
||||
int32_t ok = 1;
|
||||
for (int32_t i = 0; i < PHASE7_MULTI_COUNT; i++) {
|
||||
int32_t sent = net_send(sockfd[i], tx, PHASE7_EXCH_SIZE, 0);
|
||||
if (sent != PHASE7_EXCH_SIZE) {
|
||||
TEST_CHECK(0, "TC704 socket #%d send %dB (sent=%d)", i, PHASE7_EXCH_SIZE, sent);
|
||||
ok = 0;
|
||||
continue;
|
||||
}
|
||||
int recvd = 0;
|
||||
int32_t recvd = 0;
|
||||
uint32_t tick = HAL_GetTick();
|
||||
while (recvd < PHASE7_EXCH_SIZE) {
|
||||
int n = net_recv(sockfd[i], rx + recvd, PHASE7_EXCH_SIZE - recvd, NET_MSG_DONTWAIT);
|
||||
int32_t n = net_recv(sockfd[i], rx + recvd, PHASE7_EXCH_SIZE - recvd, NET_MSG_DONTWAIT);
|
||||
if (n > 0) recvd += n;
|
||||
else if (n == 0) break;
|
||||
else if (n < 0 && net_get_errno() == NET_ERR_WOULDBLOCK) {
|
||||
@@ -347,10 +347,10 @@ static int phase7_session_multi(void)
|
||||
} else break;
|
||||
if (HAL_GetTick() - tick > PHASE7_CONN_TIMEOUT_MS) break;
|
||||
}
|
||||
int sock_ok = (recvd == PHASE7_EXCH_SIZE);
|
||||
int32_t sock_ok = (recvd == PHASE7_EXCH_SIZE);
|
||||
if (sock_ok) {
|
||||
int bad = 0;
|
||||
for (int k = 0; k < PHASE7_EXCH_SIZE; k++) if (rx[k] != (uint8_t)k) { bad = 1; break; }
|
||||
int32_t bad = 0;
|
||||
for (int32_t k = 0; k < PHASE7_EXCH_SIZE; k++) if (rx[k] != (uint8_t)k) { bad = 1; break; }
|
||||
TEST_CHECK(!bad, "TC704 socket #%d echo %dB OK", i, PHASE7_EXCH_SIZE);
|
||||
} else {
|
||||
TEST_CHECK(0, "TC704 socket #%d recv %dB (expect %d)", i, recvd, PHASE7_EXCH_SIZE);
|
||||
@@ -359,7 +359,7 @@ static int phase7_session_multi(void)
|
||||
}
|
||||
|
||||
/* 4) 关闭所有 */
|
||||
for (int i = 0; i < PHASE7_MULTI_COUNT; i++) net_close(sockfd[i]);
|
||||
for (int32_t i = 0; i < PHASE7_MULTI_COUNT; i++) net_close(sockfd[i]);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -373,8 +373,8 @@ void net_layer_client_test_main(void)
|
||||
|
||||
DBG_INFO("--- TC 702: close/reconnect x%d ---", PHASE7_LOOP_COUNT);
|
||||
{
|
||||
int all_ok = 1;
|
||||
for (int i = 0; i < PHASE7_LOOP_COUNT; i++) {
|
||||
int32_t all_ok = 1;
|
||||
for (int32_t i = 0; i < PHASE7_LOOP_COUNT; i++) {
|
||||
if (!phase7_session((uint16_t)(PHASE7_LOCAL_PORT + 1 + i))) all_ok = 0;
|
||||
}
|
||||
TEST_CHECK(all_ok, "TC702 reconnect x%d all passed", PHASE7_LOOP_COUNT);
|
||||
@@ -445,7 +445,7 @@ static uint8_t s_tx_buf[TEST_BUF_SIZE];
|
||||
static uint32_t phase8_crc32_step(uint32_t crc, const uint8_t *data, uint32_t len) {
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
crc ^= data[i];
|
||||
for (int k = 0; k < 8; k++) {
|
||||
for (int32_t k = 0; k < 8; k++) {
|
||||
crc = (crc & 1u) ? (crc >> 1) ^ 0xEDB88320u : (crc >> 1);
|
||||
}
|
||||
}
|
||||
@@ -464,7 +464,7 @@ static void phase8_fill(uint8_t *buf, uint32_t size, uint32_t offset) {
|
||||
|
||||
/* 仅 ECHO/RECV 方向需要:逐字节校验接收数据 */
|
||||
#if PHASE8_DIRECTION != PHASE8_DIR_SEND
|
||||
static int phase8_verify(uint8_t *buf, uint32_t size, uint32_t offset) {
|
||||
static int32_t phase8_verify(uint8_t *buf, uint32_t size, uint32_t offset) {
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
if (buf[i] != (uint8_t)((offset + i) & 0xFF)) {
|
||||
DBG_ERROR("Phase8: mismatch at %lu (expect 0x%02X, got 0x%02X)",
|
||||
@@ -476,7 +476,7 @@ static int phase8_verify(uint8_t *buf, uint32_t size, uint32_t offset) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void phase8_run(int sockfd) {
|
||||
static void phase8_run(int32_t sockfd) {
|
||||
#if PHASE8_DIRECTION == PHASE8_DIR_RECV
|
||||
/* PC 发送文件(尾附 4B CRC32),MCU 接收并逐字节 + CRC32 校验 */
|
||||
DBG_INFO("Phase8[RECV]: receiving %d-byte file", PHASE8_FILE_SIZE);
|
||||
@@ -484,14 +484,14 @@ static void phase8_run(int sockfd) {
|
||||
uint32_t recvd = 0;
|
||||
uint32_t crc = 0xFFFFFFFFu;
|
||||
while (recvd < PHASE8_FILE_SIZE) {
|
||||
int to_read = (PHASE8_FILE_SIZE - recvd) > (TEST_BUF_SIZE - 4)
|
||||
int32_t to_read = (PHASE8_FILE_SIZE - recvd) > (TEST_BUF_SIZE - 4)
|
||||
? (TEST_BUF_SIZE - 4) : (int)(PHASE8_FILE_SIZE - recvd);
|
||||
int n = net_recv(sockfd, s_rx_buf, to_read, 0);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf, to_read, 0);
|
||||
if (n <= 0) {
|
||||
DBG_ERROR("Phase8[RECV]: recv fail at %lu (ret=%d)", recvd, n);
|
||||
return;
|
||||
}
|
||||
int ok = phase8_verify(s_rx_buf, (uint32_t)n, recvd);
|
||||
int32_t ok = phase8_verify(s_rx_buf, (uint32_t)n, recvd);
|
||||
TEST_CHECK(ok, "Phase8[RECV]: verify at %lu (%d bytes)", recvd, n);
|
||||
if (!ok) return;
|
||||
crc = phase8_crc32_step(crc, s_rx_buf, (uint32_t)n);
|
||||
@@ -502,7 +502,7 @@ static void phase8_run(int sockfd) {
|
||||
uint8_t foot[4];
|
||||
uint32_t got = 0;
|
||||
while (got < 4) {
|
||||
int n = net_recv(sockfd, foot + got, (int)(4 - got), 0);
|
||||
int32_t n = net_recv(sockfd, foot + got, (int)(4 - got), 0);
|
||||
if (n <= 0) {
|
||||
DBG_ERROR("Phase8[RECV]: footer recv fail (ret=%d)", n);
|
||||
return;
|
||||
@@ -527,7 +527,7 @@ static void phase8_run(int sockfd) {
|
||||
uint32_t chunk = (PHASE8_FILE_SIZE - sent) > (uint32_t)TEST_BUF_SIZE
|
||||
? (uint32_t)TEST_BUF_SIZE : (PHASE8_FILE_SIZE - sent);
|
||||
phase8_fill(s_tx_buf, chunk, sent);
|
||||
int n = net_send(sockfd, s_tx_buf, (int)chunk, 0);
|
||||
int32_t n = net_send(sockfd, s_tx_buf, (int)chunk, 0);
|
||||
if (n <= 0) {
|
||||
DBG_ERROR("Phase8[SEND]: send fail at %lu (ret=%d)", sent, n);
|
||||
return;
|
||||
@@ -547,7 +547,7 @@ static void phase8_run(int sockfd) {
|
||||
uint32_t chunk = (PHASE8_FILE_SIZE - sent) > (uint32_t)TEST_BUF_SIZE
|
||||
? (uint32_t)TEST_BUF_SIZE : (PHASE8_FILE_SIZE - sent);
|
||||
phase8_fill(s_tx_buf, chunk, sent);
|
||||
int n = net_send(sockfd, s_tx_buf, (int)chunk, 0);
|
||||
int32_t n = net_send(sockfd, s_tx_buf, (int)chunk, 0);
|
||||
if (n <= 0) {
|
||||
DBG_ERROR("Phase8[ECHO]: send fail at %lu (ret=%d)", sent, n);
|
||||
return;
|
||||
@@ -557,12 +557,12 @@ static void phase8_run(int sockfd) {
|
||||
|
||||
uint32_t recvd = 0;
|
||||
while (recvd < PHASE8_FILE_SIZE) {
|
||||
int n = net_recv(sockfd, s_rx_buf, TEST_BUF_SIZE, 0);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf, TEST_BUF_SIZE, 0);
|
||||
if (n <= 0) {
|
||||
DBG_ERROR("Phase8[ECHO]: recv fail at %lu (ret=%d)", recvd, n);
|
||||
return;
|
||||
}
|
||||
int ok = phase8_verify(s_rx_buf, (uint32_t)n, recvd);
|
||||
int32_t ok = phase8_verify(s_rx_buf, (uint32_t)n, recvd);
|
||||
TEST_CHECK(ok, "Phase8[ECHO]: verify at %lu (%d bytes)", recvd, n);
|
||||
if (!ok) return;
|
||||
recvd += (uint32_t)n;
|
||||
@@ -595,7 +595,7 @@ static void phase8_run(int sockfd) {
|
||||
#include "net_select.h"
|
||||
static uint32_t s_phase9_count = 0;
|
||||
|
||||
static void phase9_run(int sockfd) {
|
||||
static void phase9_run(int32_t sockfd) {
|
||||
net_fd_set readfds;
|
||||
net_timeval tv;
|
||||
|
||||
@@ -609,14 +609,14 @@ static void phase9_run(int sockfd) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 50000;
|
||||
|
||||
int nfds = net_select(sockfd + 1, &readfds, NULL, NULL, &tv);
|
||||
int32_t nfds = net_select(sockfd + 1, &readfds, NULL, NULL, &tv);
|
||||
if (nfds <= 0) return;
|
||||
|
||||
/* Socket 0 可读:非阻塞接收并回显 */
|
||||
if (NET_FD_ISSET(sockfd, &readfds)) {
|
||||
int n = net_recv(sockfd, s_rx_buf, TEST_BUF_SIZE, NET_MSG_DONTWAIT);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf, TEST_BUF_SIZE, NET_MSG_DONTWAIT);
|
||||
if (n > 0) {
|
||||
int sent = net_send(sockfd, s_rx_buf, n, 0);
|
||||
int32_t sent = net_send(sockfd, s_rx_buf, n, 0);
|
||||
if (sent == n) {
|
||||
s_phase9_count++;
|
||||
TEST_CHECK(1, "Phase9: select echo #%lu (%d bytes)", s_phase9_count, n);
|
||||
@@ -645,7 +645,7 @@ static void phase9_run(int sockfd) {
|
||||
* =================================================================== */
|
||||
|
||||
#ifdef ENABLE_PHASE10_TESTS
|
||||
static int s_phase10_stage = 0;
|
||||
static int32_t s_phase10_stage = 0;
|
||||
static uint32_t s_phase10_recv = 0;
|
||||
|
||||
static void phase10_fill(uint8_t *buf, uint32_t size, uint8_t seed) {
|
||||
@@ -654,19 +654,19 @@ static void phase10_fill(uint8_t *buf, uint32_t size, uint8_t seed) {
|
||||
}
|
||||
}
|
||||
|
||||
static int phase10_verify(uint8_t *buf, uint32_t size, uint8_t seed) {
|
||||
static int32_t phase10_verify(uint8_t *buf, uint32_t size, uint8_t seed) {
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
if (buf[i] != (uint8_t)(seed + i)) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void phase10_run(int sockfd) {
|
||||
static void phase10_run(int32_t sockfd) {
|
||||
/* 阶段 0 → 1:发送 4095B */
|
||||
if (s_phase10_stage == 0) {
|
||||
DBG_INFO("Phase10: 4095B (DMA-1)");
|
||||
phase10_fill(s_tx_buf, 4095, 0x10);
|
||||
int sent = net_send(sockfd, s_tx_buf, 4095, 0);
|
||||
int32_t sent = net_send(sockfd, s_tx_buf, 4095, 0);
|
||||
TEST_CHECK(sent == 4095, "Phase10: send 4095B (sent=%d)", sent);
|
||||
s_phase10_recv = 0;
|
||||
s_phase10_stage = 1;
|
||||
@@ -674,7 +674,7 @@ static void phase10_run(int sockfd) {
|
||||
}
|
||||
/* 阶段 1:接收并验证 4095B 回显 */
|
||||
if (s_phase10_stage == 1) {
|
||||
int n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(4095 - s_phase10_recv), 0);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(4095 - s_phase10_recv), 0);
|
||||
if (n > 0) {
|
||||
s_phase10_recv += (uint32_t)n;
|
||||
if (s_phase10_recv >= 4095) {
|
||||
@@ -688,7 +688,7 @@ static void phase10_run(int sockfd) {
|
||||
if (s_phase10_stage == 2) {
|
||||
DBG_INFO("Phase10: 4096B (DMA exact)");
|
||||
phase10_fill(s_tx_buf, 4096, 0x20);
|
||||
int sent = net_send(sockfd, s_tx_buf, 4096, 0);
|
||||
int32_t sent = net_send(sockfd, s_tx_buf, 4096, 0);
|
||||
TEST_CHECK(sent == 4096, "Phase10: send 4096B (sent=%d)", sent);
|
||||
s_phase10_recv = 0;
|
||||
s_phase10_stage = 3;
|
||||
@@ -696,7 +696,7 @@ static void phase10_run(int sockfd) {
|
||||
}
|
||||
/* 阶段 3:接收并验证 4096B 回显 */
|
||||
if (s_phase10_stage == 3) {
|
||||
int n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(4096 - s_phase10_recv), 0);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(4096 - s_phase10_recv), 0);
|
||||
if (n > 0) {
|
||||
s_phase10_recv += (uint32_t)n;
|
||||
if (s_phase10_recv >= 4096) {
|
||||
@@ -710,7 +710,7 @@ static void phase10_run(int sockfd) {
|
||||
if (s_phase10_stage == 4) {
|
||||
DBG_INFO("Phase10: 4097B (DMA+1, 2 SPI xacts)");
|
||||
phase10_fill(s_tx_buf, 4097, 0x30);
|
||||
int sent = net_send(sockfd, s_tx_buf, 4097, 0);
|
||||
int32_t sent = net_send(sockfd, s_tx_buf, 4097, 0);
|
||||
TEST_CHECK(sent == 4097, "Phase10: send 4097B (sent=%d)", sent);
|
||||
s_phase10_recv = 0;
|
||||
s_phase10_stage = 5;
|
||||
@@ -718,7 +718,7 @@ static void phase10_run(int sockfd) {
|
||||
}
|
||||
/* 阶段 5:接收并验证 4097B 回显 */
|
||||
if (s_phase10_stage == 5) {
|
||||
int n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(4097 - s_phase10_recv), 0);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(4097 - s_phase10_recv), 0);
|
||||
if (n > 0) {
|
||||
s_phase10_recv += (uint32_t)n;
|
||||
if (s_phase10_recv >= 4097) {
|
||||
@@ -731,7 +731,7 @@ static void phase10_run(int sockfd) {
|
||||
/* 阶段 6:零长度发送 —— 期望 net_send 返回 -1(NET_ERR_INVAL) */
|
||||
if (s_phase10_stage == 6) {
|
||||
DBG_INFO("Phase10: zero-length send");
|
||||
int sent = net_send(sockfd, s_tx_buf, 0, 0);
|
||||
int32_t sent = net_send(sockfd, s_tx_buf, 0, 0);
|
||||
TEST_CHECK(sent < 0, "Phase10: send 0B returns %d (expect <0)", sent);
|
||||
s_phase10_stage = 7;
|
||||
return;
|
||||
@@ -740,8 +740,8 @@ static void phase10_run(int sockfd) {
|
||||
if (s_phase10_stage == 7) {
|
||||
DBG_INFO("Phase10: 20x rapid sends (100B each)");
|
||||
phase10_fill(s_tx_buf, 100, 0x40);
|
||||
int all_ok = 1;
|
||||
for (int i = 0; i < 20; i++) {
|
||||
int32_t all_ok = 1;
|
||||
for (int32_t i = 0; i < 20; i++) {
|
||||
if (net_send(sockfd, s_tx_buf, 100, 0) != 100) {
|
||||
TEST_CHECK(0, "Phase10: rapid #%d fail", i + 1);
|
||||
all_ok = 0; break;
|
||||
@@ -759,7 +759,7 @@ static void phase10_run(int sockfd) {
|
||||
}
|
||||
/* 阶段 8:接收 2000B 回显总和并验证 */
|
||||
if (s_phase10_stage == 8) {
|
||||
int n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(2000 - s_phase10_recv), 0);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf + s_phase10_recv, (int)(2000 - s_phase10_recv), 0);
|
||||
if (n > 0) {
|
||||
s_phase10_recv += (uint32_t)n;
|
||||
if (s_phase10_recv >= 2000) {
|
||||
@@ -787,10 +787,10 @@ static void phase10_run(int sockfd) {
|
||||
* =================================================================== */
|
||||
|
||||
#ifdef ENABLE_PHASE11_TESTS
|
||||
static int s_phase11_armed = 0;
|
||||
static int32_t s_phase11_armed = 0;
|
||||
static uint32_t s_phase11_start = 0;
|
||||
|
||||
static void phase11_run(int sockfd) {
|
||||
static void phase11_run(int32_t sockfd) {
|
||||
/*
|
||||
* 第一次调用:记录开始时间并 arm。
|
||||
* 后续调用:非阻塞 recv,若返回 0 表示连接已断开(KeepAlive 触发)。
|
||||
@@ -803,7 +803,7 @@ static void phase11_run(int sockfd) {
|
||||
return;
|
||||
}
|
||||
|
||||
int n = net_recv(sockfd, s_rx_buf, 64, NET_MSG_DONTWAIT);
|
||||
int32_t n = net_recv(sockfd, s_rx_buf, 64, NET_MSG_DONTWAIT);
|
||||
if (n == 0) {
|
||||
uint32_t elapsed = HAL_GetTick() - s_phase11_start;
|
||||
TEST_CHECK(elapsed >= 60000,
|
||||
@@ -816,11 +816,11 @@ static void phase11_run(int sockfd) {
|
||||
|
||||
void net_layer_test_main(void)
|
||||
{
|
||||
int sockfd = -1;
|
||||
int phase_active = 0;
|
||||
int32_t sockfd = -1;
|
||||
int32_t phase_active = 0;
|
||||
uint32_t accept_retry = 0;
|
||||
struct net_sockaddr_in client_addr;
|
||||
int addrlen = sizeof(client_addr);
|
||||
int32_t addrlen = sizeof(client_addr);
|
||||
|
||||
sockfd = net_socket(NET_AF_INET, NET_SOCK_STREAM, 0);
|
||||
if (sockfd < 0) {
|
||||
@@ -855,7 +855,7 @@ void net_layer_test_main(void)
|
||||
*/
|
||||
for (;;) {
|
||||
if (!phase_active) {
|
||||
int acc = net_accept(sockfd, (struct net_sockaddr *)&client_addr, &addrlen);
|
||||
int32_t acc = net_accept(sockfd, (struct net_sockaddr *)&client_addr, &addrlen);
|
||||
if (acc < 0) {
|
||||
if (accept_retry % 100 == 0) {
|
||||
DBG_INFO("Test task: waiting for connection...");
|
||||
|
||||
Reference in New Issue
Block a user