Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Tests for I/O bindings
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 : #include <math.h>
10 : #include <stdio.h>
11 : #include <stdlib.h>
12 : #include <string.h>
13 : #include <time.h>
14 :
15 : #include <tests.h>
16 :
17 : #include <kdbhelper.h>
18 : #include <kdbio.h>
19 : #include <kdbiotest.h>
20 :
21 : /**
22 : * Get current time.
23 : * Use together with elektraIoTestSuite_getTimeDifference to measure time differences
24 : * @return timespec
25 : */
26 102 : unsigned int elektraIoTestSuiteUtilGetCurrentTime (struct timespec * ts)
27 : {
28 102 : if (clock_gettime (CLOCK_MONOTONIC, ts) == 0)
29 : {
30 : return 1;
31 : }
32 : else
33 : {
34 0 : return 0;
35 : }
36 : }
37 :
38 : /**
39 : * Get difference between measured times
40 : * @param start start measurement
41 : * @param stop end measurement
42 : * @return difference in milliseconds
43 : */
44 42 : long elektraIoTestSuiteUtilGetTimeDifference (struct timespec start, struct timespec stop)
45 : {
46 : struct timespec diff;
47 42 : diff.tv_sec = stop.tv_sec - start.tv_sec;
48 42 : diff.tv_nsec = stop.tv_nsec - start.tv_nsec;
49 :
50 42 : return (long) (diff.tv_sec * 1000 + round (diff.tv_nsec / 1.0e6));
51 : }
|