test: probe existing SYS clock access and AT time queries from APP

This commit is contained in:
chenjintao
2026-10-26 16:25:19 +08:00
parent 07525225cb
commit f8df812f45
7 changed files with 277 additions and 21 deletions
+18 -8
View File
@@ -32,7 +32,8 @@ int ql_rtc_get_time(ql_rtc_time_t *);
#include <assert.h>
#include <stdlib.h>
#include "APP_SOURCE"
static int mode, creates, queries, sets;
static int mode, creates, queries, sets, probes;
void app_sys_time_probe_run(void) {++probes;}
static unsigned int ticks=100;
static time_t app_epoch=100;
static int zone_minutes=480;
@@ -53,7 +54,10 @@ int ql_nw_get_nitz_time_info(QL_NW_NITZ_TIME_INFO_T *info) {
if (mode==3) return 0;
if (mode==4) {memset(info->nitz_time,'X',32); return 0;}
if (mode==5) {strcpy(info->nitz_time,"26/02/30 13:00:00 +32 00"); return 0;}
if (mode==6) {strcpy(info->nitz_time,"26/10/26 13:00:00 +32 00"); return 0;}
if (mode==6 || mode==22) {
strcpy(info->nitz_time,mode==22 ? "26/10/26 08:00:10 32 0" : "26/10/26 13:00:00 +32 00");
return 0;
}
if (mode==16 && queries==1) return 1;
if (mode==17) ticks+=600; /* slow query must be rejected */
if (mode==14) value=1793059198; /* near midnight UTC */
@@ -63,7 +67,7 @@ int ql_nw_get_nitz_time_info(QL_NW_NITZ_TIME_INFO_T *info) {
/* Compute relative elapsed correctly in wrap scenario. */
if (mode==13) value=1793019600+(unsigned int)(ticks-(UINT32_MAX-199U))/200U;
utc=gmtime(&value); assert(utc);
snprintf(info->nitz_time,32,"%02d/%02d/%02d %02d:%02d:%02d +32 00",
snprintf(info->nitz_time,32,mode==21 ? "%02d/%02d/%02d %02d:%02d:%02d 32 0" : "%02d/%02d/%02d %02d:%02d:%02d +32 00",
utc->tm_year%100,utc->tm_mon+1,utc->tm_mday,utc->tm_hour,utc->tm_min,utc->tm_sec);
return 0;
}
@@ -100,6 +104,11 @@ static void check_parser(void) {
assert(parse_nitz("26/10/26,13:00:00-22",&epoch,&zone)==0 &&
epoch==1793019600 && zone==-22);
assert(parse_nitz("26/10/26 13:00:00 +56 02",&epoch,&zone)==0);
assert(parse_nitz("26/10/26 08:00:10 32 0",&epoch,&zone)==0 && epoch==1793001610 && zone==32);
assert(parse_nitz("26/10/26 13:00:00 -22 0",&epoch,&zone)==0 && zone==-22);
assert(parse_nitz("26/10/26 13:00:00 0 0",&epoch,&zone)==0 && zone==0);
assert(parse_nitz("26/10/26 13:00:00 0",&epoch,&zone)!=0);
assert(parse_nitz("26/10/26 13:00:00 320 0",&epoch,&zone)!=0);
assert(parse_nitz("24/02/29 23:59:59 +00 00",&epoch,&zone)==0);
assert(parse_nitz("26/02/29 00:00:00 +00 00",&epoch,&zone)!=0);
assert(parse_nitz("38/01/19 03:14:07 +00 00",&epoch,&zone)==0 && epoch==2147483647);
@@ -110,7 +119,7 @@ static void check_parser(void) {
"26/10/26 24:00:00 +00 00", "26/10/26 13:60:00 +00 00",
"26/10/26 13:00:60 +00 00", "26/10/26 13:00:00 +57 00",
"26/10/26 13:00:00 -49 00", "26/10/26 13:00:00 +32 03",
"26/10/26 13:00:00 +32 0", "26/10/26 13:00:00 +32 junk",
"26/10/26 13:00:00 +32 junk",
"26/10/26 13:00:00 +32 00junk", "x6/10/26 13:00:00 +32 00"};
for (unsigned int i=0;i<sizeof(bad)/sizeof(bad[0]);++i)
assert(parse_nitz(bad[i],&epoch,&zone)!=0);
@@ -124,10 +133,11 @@ int main(int argc,char **argv) {
if (mode==13) ticks=UINT32_MAX-199U;
app_nitz_test_start(); app_nitz_test_start();
assert(creates==(mode==19 ? 2 : 1));
if ((mode>=1 && mode<=6) || mode==15 || mode==17 || mode==18 || mode==19 || mode==7)
if ((mode>=1 && mode<=6) || mode==15 || mode==17 || mode==18 || mode==19 || mode==7 || mode==22)
assert(sets==0);
else assert(sets==1);
assert(queries<=6);
assert(probes==(mode==19 ? 0 : 1));
return 0;
}
'''.replace('APP_SOURCE', str(APP / 'app_nitz_test.c'))
@@ -147,10 +157,10 @@ int main(int argc,char **argv) {
12: 'PASS source=nitz', 13: 'PASS source=nitz', 14: 'PASS source=nitz',
15: 'FAIL stage=no_fresh_nitz', 16: 'PASS source=nitz',
17: 'FAIL stage=no_fresh_nitz', 18: 'cached_or_inconsistent_nitz=1',
19: 'FAIL stage=create_task', 20: 'FAIL stage=app_clock_verification'}
19: 'FAIL stage=create_task', 20: 'FAIL stage=app_clock_verification', 21: 'PASS source=nitz', 22: 'FAIL stage=no_fresh_nitz'}
for mode, expected in cases.items():
log = subprocess.check_output([str(work / 'test'), str(mode)], text=True)
assert expected in log, log
if mode not in (0, 12, 13, 14, 16):
if mode not in (0, 12, 13, 14, 16, 21):
assert '[APP-NITZ-TEST] PASS ' not in log, log
print('PASS: Gregorian/parser validation and 21 API/freshness/RTC scenarios (ASan/UBSan)')
print('PASS: Gregorian/parser validation and 23 API/freshness/RTC scenarios (ASan/UBSan)')