Improve TLS WebSocket and network failure diagnostics

This commit is contained in:
chenjintao
2026-10-29 15:36:00 +08:00
parent 407051d420
commit b3e0b5bbb4
7 changed files with 147 additions and 24 deletions
+19 -5
View File
@@ -1,6 +1,7 @@
"""Test the actual timed handshake loop with scripted SDK steps and 5 ms ticks."""
from pathlib import Path
import subprocess
import os
root = Path(__file__).resolve().parents[1]
source = (root / 'ql-application/threadx/interface/custom_app/lib/librws/src/rws_socketpriv.c').read_bytes().decode('latin1')
@@ -15,7 +16,12 @@ typedef struct { int ret, next_state; unsigned int duration; } step;
static step steps[16];
static int count, calls, sleeps;
static unsigned int ticks;
static void test_log(const char *fmt, ...) { (void)fmt; }
static char diagnostic[1024];
static void test_log(const char *fmt, ...) {
va_list args;
if (!strstr(fmt, "[WSS-DIAG]")) return;
va_start(args, fmt); vsnprintf(diagnostic, sizeof(diagnostic), fmt, args); va_end(args);
}
#define LOG_I test_log
static unsigned int ql_rtos_get_systicks(void) { return ticks; }
static void rws_thread_sleep(unsigned int ms) { ticks += ms / 5; ++sleeps; }
@@ -52,8 +58,11 @@ int main(void) {
assert(rws_tls_handshake_timed(&ctx) == 0 && calls == 2 && sleeps == 0);
reset(&ctx); steps[0] = (step){-99, MBEDTLS_SSL_SERVER_CERTIFICATE, 1}; count = 1;
assert(rws_tls_handshake_timed(&ctx) == -99 && calls == 1 && sleeps == 0);
reset(&ctx);
assert(strstr(diagnostic, "result=failed phase=server certificate") && strstr(diagnostic, "ret=-99"));
reset(&ctx); ctx.state = MBEDTLS_SSL_SERVER_HELLO;
assert(rws_tls_handshake_timed(&ctx) == MBEDTLS_ERR_SSL_TIMEOUT && ticks == 4000 && calls < 2100);
assert(strstr(diagnostic, "result=timeout phase=server hello") && strstr(diagnostic, "elapsed_ms=20000"));
assert(strstr(diagnostic, "last_step=-26880") && strstr(diagnostic, "want_write=0"));
reset(&ctx); ticks = (unsigned int)-1000;
assert(rws_tls_handshake_timed(&ctx) == MBEDTLS_ERR_SSL_TIMEOUT && calls < 2100);
reset(&ctx); steps[0] = (step){0, MBEDTLS_SSL_SERVER_CERTIFICATE, 4001}; count = 1;
@@ -69,7 +78,12 @@ output.mkdir(parents=True, exist_ok=True)
cfile = output / 'test_wss_handshake.c'
cfile.write_text(harness, encoding='utf-8')
exe = output / 'test_wss_handshake.exe'
subprocess.run(['cl', '/nologo', '/W4', '/WX', '/TC', str(cfile),
'/I' + str(root / 'ql-application/threadx/common/include'),
'/Fo' + str(output / 'test_wss_handshake.obj'), '/Fe' + str(exe)], check=True)
if os.name == "nt":
subprocess.run(['cl', '/nologo', '/W4', '/WX', '/TC', str(cfile),
'/I' + str(root / 'ql-application/threadx/common/include'),
'/Fo' + str(output / 'test_wss_handshake.obj'), '/Fe' + str(exe)], check=True)
else:
subprocess.run(['cc', '-std=c99', '-Wall', '-Wextra', '-Werror',
'-I' + str(root / 'ql-application/threadx/common/include'),
str(cfile), '-o', str(exe)], check=True)
subprocess.run([str(exe)], check=True)