summaryrefslogtreecommitdiff
path: root/tests/main.c
blob: ff7560dafd61137e80599ec20a5108eadfa2f4a2 (plain)
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
#include <stdio.h>
#include <stdbool.h>
#include <time.h>

#define TEST_MOD
#include "generated.c"

double diff_time(struct timespec a, struct timespec b) {
  double a_time = (double)a.tv_sec + a.tv_nsec * 1e-9;
  double b_time = (double)b.tv_sec + b.tv_nsec * 1e-9;

  return a_time - b_time;
}

int main() {
  int i = 0;
  int return_type = 0;
  while (i < total_test_count)  {
    char padded_testname[max_test_name_size + 2];
    int j = 0;
    while (test_names[i][j] != 0) {
      padded_testname[j] = test_names[i][j];
      j++;
    }
    while (j < max_test_name_size + 2 - 1) {
      padded_testname[j++] = ' ';
    }
    padded_testname[j] = 0;
    printf("%s", padded_testname);
    fflush(stdout);

    struct timespec begin, end;

    clock_gettime(CLOCK_MONOTONIC, &begin);
    bool result = tests[i]();
    clock_gettime(CLOCK_MONOTONIC, &end);

    return_type |= !result;

    printf(
      " %s %.2lfs\n",
      result ? "\x1b[32mP\x1b[0m" : "\x1b[31mF\x1b[0m",
      diff_time(end, begin)
    );
    i++;
  }

  return return_type;
}