PandA-2024.02
harness.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <sys/stat.h>
7 #include <assert.h>
8 
9 #define WRITE_OUTPUT
10 #define CHECK_OUTPUT
11 
12 #include "support.h"
13 
14 int main(int argc, char **argv)
15 {
16  // Parse command line.
17  char *in_file;
18  #ifdef CHECK_OUTPUT
19  char *check_file;
20  #endif
21  assert( argc<4 && "Usage: ./benchmark <input_file> <check_file>" );
22  in_file = "input.data";
23  #ifdef CHECK_OUTPUT
24  check_file = "check.data";
25  #endif
26  if( argc>1 )
27  in_file = argv[1];
28  #ifdef CHECK_OUTPUT
29  if( argc>2 )
30  check_file = argv[2];
31  #endif
32 
33  // Load input data
34  int in_fd;
35  char *data;
36  data = malloc(INPUT_SIZE);
37  assert( data!=NULL && "Out of memory" );
38  in_fd = open( in_file, O_RDONLY );
39  assert( in_fd>0 && "Couldn't open input data file");
40  input_to_data(in_fd, data);
41 
42  // Unpack and call
43  run_benchmark( data );
44 
45  #ifdef WRITE_OUTPUT
46  int out_fd;
47  out_fd = open("output.data", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
48  assert( out_fd>0 && "Couldn't open output data file" );
49  data_to_output(out_fd, data);
50  close(out_fd);
51  #endif
52 
53  // Load check data
54  #ifdef CHECK_OUTPUT
55  int check_fd;
56  char *ref;
57  ref = malloc(INPUT_SIZE);
58  assert( ref!=NULL && "Out of memory" );
59  check_fd = open( check_file, O_RDONLY );
60  assert( check_fd>0 && "Couldn't open check data file");
61  output_to_data(check_fd, ref);
62  #endif
63 
64  // Validate benchmark results
65  #ifdef CHECK_OUTPUT
66  if( !check_data(data, ref) ) {
67  fprintf(stderr, "Benchmark results are incorrect\n");
68  return -1;
69  }
70  #endif
71  free(data);
72  free(ref);
73 
74  printf("Success.\n");
75  return 0;
76 }
#define NULL
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
int INPUT_SIZE
Definition: local_support.c:4
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
void input_to_data(int fd, void *vdata)
Definition: local_support.c:18
int main(int argc, char **argv)
Definition: harness.c:14
void run_benchmark(void *vargs)
Definition: local_support.c:6

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13