Skip to content

Commit 2d37286

Browse files
youvedeep-singhAnas Nashif
authored andcommitted
tests: kernel: posix: clock: Add posix clock test.
Add posix clock API test. Signed-off-by: Youvedeep Singh <[email protected]>
1 parent 2e43d00 commit 2d37286

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
2+
project(NONE)
3+
4+
target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/include/posix)
5+
FILE(GLOB app_sources src/*.c)
6+
target_sources(app PRIVATE ${app_sources})

tests/kernel/posix/clock/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_TEST=y
2+
CONFIG_PTHREAD_IPC=y
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <tc_util.h>
8+
#include <pthread.h>
9+
10+
#define SLEEP_SECONDS 1
11+
12+
void main(void)
13+
{
14+
u32_t status;
15+
s64_t nsecs_elapsed, secs_elapsed;
16+
struct timespec ts, te;
17+
18+
TC_START("POSIX clock APIs\n");
19+
clock_gettime(CLOCK_MONOTONIC, &ts);
20+
/* 2 Sec Delay */
21+
sleep(SLEEP_SECONDS);
22+
usleep(SLEEP_SECONDS * USEC_PER_SEC);
23+
clock_gettime(CLOCK_MONOTONIC, &te);
24+
25+
if (te.tv_nsec >= ts.tv_nsec) {
26+
secs_elapsed = te.tv_sec - ts.tv_sec;
27+
nsecs_elapsed = te.tv_nsec - ts.tv_nsec;
28+
} else {
29+
nsecs_elapsed = NSEC_PER_SEC + te.tv_nsec - ts.tv_nsec;
30+
secs_elapsed = (te.tv_sec - ts.tv_sec - 1);
31+
}
32+
33+
status = secs_elapsed == (2 * SLEEP_SECONDS) ? TC_PASS : TC_FAIL;
34+
35+
TC_PRINT("POSIX clock APIs test done\n");
36+
TC_END_REPORT(status);
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tests:
2+
test:
3+
tags: core

0 commit comments

Comments
 (0)