1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include "nsutils.c"
4 #include "t-utils.h"
5 #include <sys/time.h>
6 #include <time.h>
7
main(int argc,char ** argv)8 int main(int argc, char **argv)
9 {
10 struct timeval start, stop;
11 float f_delta;
12 int msec_delta;
13 char *s1;
14 const char *s2;
15
16 t_set_colors(0);
17 t_verbose = 1;
18 t_start("tv_delta tests");
19
20 stop.tv_sec = start.tv_sec = time(NULL);
21 stop.tv_usec = 2500;
22 start.tv_usec = 0;
23 msec_delta = tv_delta_msec(&start, &stop);
24 t_ok(msec_delta == 2, "tv_delta_msec()");
25 f_delta = tv_delta_f(&start, &stop) * 1000;
26 t_ok((double)f_delta == (double)2.5, "tv_delta_f() * 1000 is %.2f and should be 2.5", f_delta);
27 gettimeofday(&start, NULL);
28 memcpy(&stop, &start, sizeof(start));
29 stop.tv_sec += 100;
30
31 asprintf(&s1, "arg varg foo %d", 12);
32 s2 = mkstr("arg varg foo %d", 12);
33 ok_str(s1, s2, "mkstr() must build proper strings");
34 if (real_online_cpus() > 0) {
35 t_pass("%d online cpus detected", real_online_cpus());
36 } else {
37 t_fail("Can't determine the number of online cpus");
38 }
39
40 return t_end();
41 }
42