samples: posix: gettimeofday: incorporate libc time API tests
Use time(), localtime_r(), and asctime() to confirm that the declarations required for these (newlib) libc functions are made available in CONFIG_POSIX context. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
3cb353c09f
commit
1d026703c4
2 changed files with 11 additions and 6 deletions
|
|
@ -7,10 +7,11 @@ Overview
|
|||
********
|
||||
|
||||
This sample application demonstrates using the POSIX gettimeofday()
|
||||
function to display the absolute wall clock time every second. At
|
||||
system startup, the current time is queried using the SNTP networking
|
||||
protocol, enabled by setting the :option:`CONFIG_NET_CONFIG_CLOCK_SNTP_INIT`
|
||||
and :option:`CONFIG_NET_CONFIG_SNTP_INIT_SERVER` options.
|
||||
function to display the absolute wall clock time and local time every
|
||||
second. At system startup, the current time is queried using the SNTP
|
||||
networking protocol, enabled by setting the
|
||||
:option:`CONFIG_NET_CONFIG_CLOCK_SNTP_INIT` and
|
||||
:option:`CONFIG_NET_CONFIG_SNTP_INIT_SERVER` options.
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ int main(void)
|
|||
|
||||
while (1) {
|
||||
int res = gettimeofday(&tv, NULL);
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
localtime_r(&now, &tm);
|
||||
|
||||
if (res < 0) {
|
||||
printf("Error in gettimeofday(): %d\n", errno);
|
||||
|
|
@ -23,8 +26,9 @@ int main(void)
|
|||
}
|
||||
|
||||
printf("gettimeofday(): HI(tv_sec)=%d, LO(tv_sec)=%d, "
|
||||
"tv_usec=%d\n", (unsigned int)(tv.tv_sec >> 32),
|
||||
(unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec);
|
||||
"tv_usec=%d\n\t%s\n", (unsigned int)(tv.tv_sec >> 32),
|
||||
(unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec,
|
||||
asctime(&tm));
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue