-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.c
61 lines (45 loc) · 1.67 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "timer.h"
#ifndef UNITS
#define UNITS s
#endif
int main()
{
interval_t * a;
interval_t * b;
interval_t * c;
create_interval(&a, "Test 1", mono, UNITS);
create_interval(&b, "Test 2", mono, UNITS);
create_interval(&c, "Test 3", mono, UNITS);
printf("Running '%s'\n", a->name);
start(a);
nanosleep((struct timespec[]){{1, 0}}, NULL);
stop(a);
printf("RAW:\n START: %lld.%.9ld\n END: %lld.%.9ld\n", (long long) a->start.tv_sec, a->start.tv_nsec, (long long) a->stop.tv_sec, a->stop.tv_nsec);
printf("OUT: %.9f %s\n", elapsed_interval(a, none), print_unit(a->unit));
printf("EXPECTED: 1 sec\n");
printf("Running '%s'\n", b->name);
start(b);
nanosleep((struct timespec[]){{1, MILLI_TO_NSEC(500)}}, NULL);
stop(b);
printf("RAW:\n START: %lld.%.9ld\n END: %lld.%.9ld\n", (long long) b->start.tv_sec, b->start.tv_nsec, (long long) b->stop.tv_sec, b->stop.tv_nsec);
printf("OUT: %.9f %s\n", elapsed_interval(b, none), print_unit(b->unit));
printf("Running '%s'\n", c->name);
printf("EXPECTED: 1.5 sec\n");
start(c);
nanosleep((struct timespec[]){{2, MILLI_TO_NSEC(756)}}, NULL);
stop(c);
printf("RAW:\n START: %lld.%.9ld\n END: %lld.%.9ld\n", (long long) c->start.tv_sec, c->start.tv_nsec, (long long) c->stop.tv_sec, c->stop.tv_nsec);
printf("OUT: %.9f %s\n", elapsed_interval(c, none), print_unit(c->unit));
printf("EXPECTED: 2.756 sec\n");
printf("FINAL TEST\n");
print_results(3, a, b, c);
print_results_csv("#", 3, a, b, c);
free(a);
free(b);
free(c);
return EXIT_SUCCESS;
}