PandA-2024.02
harness.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sys/stat.h>
7 #include <unistd.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  assert(argc < 3 && "Usage: ./benchmark <input_file>");
19  in_file = "input.data";
20  if(argc > 1)
21  in_file = argv[1];
22 
23  // Load input data
24  int in_fd;
25  char* data;
26  data = malloc(INPUT_SIZE);
27  assert(data != NULL && "Out of memory");
28  in_fd = open(in_file, O_RDONLY);
29  assert(in_fd > 0 && "Couldn't open input data file");
30  input_to_data(in_fd, data);
31 
32  // Unpack and call
33  run_benchmark(data);
34 
35 #ifdef WRITE_OUTPUT
36  int out_fd;
37  out_fd =
38  open("output.data", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
39  assert(out_fd > 0 && "Couldn't open output data file");
40  data_to_output(out_fd, data);
41  close(out_fd);
42 #endif
43 
44 // Validate benchmark results
45 #ifdef CHECK_OUTPUT
46  if(!check_data(data))
47  {
48  fprintf(stderr, "Benchmark results are incorrect\n");
49  return -1;
50  }
51 #endif
52  free(data);
53 
54  printf("Success.\n");
55  return 0;
56 }
#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 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