yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
manual/CHAPTER_StateOfTheArt/cmp_tbdata.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdbool.h>
4 #include <string.h>
5 
6 int line = 0;
7 char buffer1[1024];
8 char buffer2[1024];
9 
10 void check(bool ok)
11 {
12  if (ok)
13  return;
14  // fprintf(stderr, "Error in testbench output compare (line=%d):\n-%s\n+%s\n", line, buffer1, buffer2);
15  exit(1);
16 }
17 
18 int main(int argc, char **argv)
19 {
20  FILE *f1, *f2;
21  bool eof1, eof2;
22  int i;
23 
24  check(argc == 3);
25 
26  f1 = fopen(argv[1], "r");
27  f2 = fopen(argv[2], "r");
28 
29  check(f1 && f2);
30 
31  while (!feof(f1) && !feof(f2))
32  {
33  line++;
34  buffer1[0] = 0;
35  buffer2[0] = 0;
36 
37  eof1 = fgets(buffer1, 1024, f1) == NULL;
38  eof2 = fgets(buffer2, 1024, f2) == NULL;
39 
40  if (*buffer1 && buffer1[strlen(buffer1)-1] == '\n')
41  buffer1[strlen(buffer1)-1] = 0;
42 
43  if (*buffer2 && buffer2[strlen(buffer2)-1] == '\n')
44  buffer2[strlen(buffer2)-1] = 0;
45 
46  check(eof1 == eof2);
47 
48  for (i = 0; buffer1[i] || buffer2[i]; i++)
49  {
50  check(buffer1[i] != 0 && buffer2[i] != 0);
51 
52  // first argument is the reference. An 'z' or 'x'
53  // here means we don't care about the result.
54  if (buffer1[i] == 'z' || buffer1[i] == 'x')
55  continue;
56 
57  check(buffer1[i] == buffer2[i]);
58  }
59  }
60 
61  check(feof(f1) && feof(f2));
62 
63  fclose(f1);
64  fclose(f2);
65  return 0;
66 }
67 
int main(int argc, char **argv)
#define NULL