HACK: don't even check for termiox
[libserialport/gsi.git] / test_timing.c
bloba24de5ea341ea353b5195578ff4e63b8c2c93be4
1 #include "config.h"
2 #include "libserialport.h"
3 #include "libserialport_internal.h"
4 #include <assert.h>
5 #include <unistd.h>
7 int main(int argc, char *argv[])
9 (void) argc;
10 (void) argv;
11 struct time a, b, c;
12 struct timeval tv;
13 struct timeout to;
15 printf("Testing arithmetic\n");
16 time_set_ms(&a, 10050);
17 time_set_ms(&b, 100);
18 assert(time_greater(&a, &b));
19 assert(!time_greater(&b, &a));
20 time_add(&a, &b, &c);
21 assert(time_as_ms(&c) == 10150);
22 time_sub(&a, &b, &c);
23 assert(time_as_ms(&c) == 9950);
24 time_as_timeval(&a, &tv);
25 assert(tv.tv_sec == 10);
26 assert(tv.tv_usec == 50000);
27 time_get(&a);
28 printf("Sleeping for 1s\n");
29 sleep(1);
30 time_get(&b);
31 time_sub(&b, &a, &c);
32 printf("Measured: %ums\n", time_as_ms(&c));
33 assert(time_as_ms(&c) >= 950);
34 assert(time_as_ms(&c) <= 1050);
35 printf("Starting 3s timeout\n");
36 timeout_start(&to, 3000);
37 printf("Time to wait: %dms\n", timeout_remaining_ms(&to));
38 printf("Sleeping for 1s\n");
39 sleep(1);
40 timeout_update(&to);
41 assert(!timeout_check(&to));
42 printf("Sleeping for 1s\n");
43 sleep(1);
44 timeout_update(&to);
45 assert(!timeout_check(&to));
46 printf("Remaining: %ums\n", timeout_remaining_ms(&to));
47 printf("Sleeping for 1s\n");
48 sleep(1);
49 timeout_update(&to);
50 assert(timeout_check(&to));
51 printf("Timeout expired\n");
52 printf("Starting 2s timeout\n");
53 timeout_start(&to, 2000);
54 printf("Limiting steps to 1s\n");
55 timeout_limit(&to, 1000);
56 printf("Time to wait: %ums\n", timeout_remaining_ms(&to));
57 printf("Sleeping for 1s\n");
58 sleep(1);
59 timeout_update(&to);
60 assert(!timeout_check(&to));
61 printf("Remaining: %ums\n", timeout_remaining_ms(&to));
62 printf("Sleeping for 1s\n");
63 sleep(1);
64 timeout_update(&to);
65 assert(timeout_check(&to));
66 printf("Timeout expired\n");
68 return 0;