修复tcp测试时间停止过早问题
author孙春阳 <snickersun@163.com>
Mon, 6 Oct 2025 01:06:43 +0000 (09:06 +0800)
committer孙春阳 <snickersun@163.com>
Mon, 6 Oct 2025 01:06:43 +0000 (09:06 +0800)
code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c

index 0f62ad9..482482e 100644 (file)
@@ -28,6 +28,7 @@
     /* 使用嵌入式环境的简化定义 */
     #include "osal_mutex.h"
     #include "osal_task.h"
+    #include "osal_timer.h"  /* 用于osal_get_jiffies() */
     
     /* 简化的兼容性定义 */
     #define TCP_MUTEX_INIT(mutex)       osal_mutex_init(&(mutex))
@@ -793,28 +794,16 @@ static void tcp_test_stats_timer_callback(void *arg)
 
 /**
  * @brief 获取当前时间(毫秒) - 导出函数
+ * 
+ * 修复说明:监控线程使用osal_msleep(真实时间),工作线程也必须使用真实时间,
+ * 否则会导致时间不同步,300秒测试可能只跑80多秒就被监控线程停止。
  */
 uint32_t tcp_test_get_time_ms(void)
 {
 #ifdef USE_LWIP_SOCKET
-    /* 在lwIP环境中尝试使用真实的时间函数 */
-    #ifdef OSAL_TIME_AVAILABLE
-        /* 如果OSAL时间函数可用,使用它 */
-        return osal_get_jiffies();
-    #else
-        /* 否则使用简化的时间模拟 */
-        static uint32_t start_time = 0;
-        static uint32_t last_time = 0;
-        
-        if (start_time == 0) {
-            start_time = 1000; /* 从1秒开始 */
-            last_time = start_time;
-        }
-        
-        /* 每次调用增加约1-10ms的随机时间 */
-        last_time += (rand() % 10 + 1);
-        return last_time;
-    #endif
+    /* 在lwIP环境中直接使用OSAL时间函数 */
+    /* osal_get_jiffies()返回系统启动以来的毫秒数,是真实时间 */
+    return osal_get_jiffies();
 #else
     /* 在POSIX环境中使用标准gettimeofday */
     struct timeval tv;