1 | /* |
---|
2 | * Copyright (c) 2017 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <time.h> |
---|
20 | #include <rtems.h> |
---|
21 | #include <rtems/test-info.h> |
---|
22 | #include <rtems/timespec.h> |
---|
23 | |
---|
24 | #include "tmacros.h" |
---|
25 | |
---|
26 | const char rtems_test_name[] = "SPTIMECOUNTER 4"; |
---|
27 | |
---|
28 | static void Init(rtems_task_argument arg) |
---|
29 | { |
---|
30 | struct timespec real_start; |
---|
31 | struct timespec mono_start; |
---|
32 | struct timespec real_end; |
---|
33 | struct timespec mono_end; |
---|
34 | struct timespec real_elapsed; |
---|
35 | struct timespec mono_elapsed; |
---|
36 | |
---|
37 | struct timespec min; |
---|
38 | struct timespec max; |
---|
39 | |
---|
40 | int rv; |
---|
41 | |
---|
42 | TEST_BEGIN(); |
---|
43 | |
---|
44 | rtems_timespec_set(&min, 1, 980000000); |
---|
45 | rtems_timespec_set(&max, 2, 20000000); |
---|
46 | |
---|
47 | rv = clock_gettime(CLOCK_REALTIME, &real_start); |
---|
48 | rtems_test_assert(rv == 0); |
---|
49 | rv = clock_gettime(CLOCK_MONOTONIC, &mono_start); |
---|
50 | rtems_test_assert(rv == 0); |
---|
51 | |
---|
52 | rtems_task_wake_after(2 * rtems_clock_get_ticks_per_second()); |
---|
53 | |
---|
54 | rv = clock_gettime(CLOCK_REALTIME, &real_end); |
---|
55 | rtems_test_assert(rv == 0); |
---|
56 | rv = clock_gettime(CLOCK_MONOTONIC, &mono_end); |
---|
57 | rtems_test_assert(rv == 0); |
---|
58 | |
---|
59 | rtems_timespec_subtract(&real_start, &real_end, &real_elapsed); |
---|
60 | rtems_timespec_subtract(&mono_start, &mono_end, &mono_elapsed); |
---|
61 | |
---|
62 | rtems_test_assert(rtems_timespec_greater_than(&real_elapsed, &min)); |
---|
63 | rtems_test_assert(rtems_timespec_greater_than(&max, &real_elapsed)); |
---|
64 | rtems_test_assert(rtems_timespec_greater_than(&mono_elapsed, &min)); |
---|
65 | rtems_test_assert(rtems_timespec_greater_than(&max, &mono_elapsed)); |
---|
66 | |
---|
67 | TEST_END(); |
---|
68 | rtems_test_exit(0); |
---|
69 | } |
---|
70 | |
---|
71 | #define CONFIGURE_MICROSECONDS_PER_TICK 10000 |
---|
72 | |
---|
73 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
74 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
75 | |
---|
76 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
77 | |
---|
78 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
79 | |
---|
80 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
81 | |
---|
82 | #define CONFIGURE_INIT |
---|
83 | |
---|
84 | #include <rtems/confdefs.h> |
---|