PandA-2024.02
local_support.c
Go to the documentation of this file.
1 #include "kmp.h"
2 #include <string.h>
3 
4 int INPUT_SIZE = sizeof(struct bench_args_t);
5 
6 void run_benchmark( void *vargs ) {
7  struct bench_args_t *args = (struct bench_args_t *)vargs;
8  kmp( args->pattern, args->input, args->kmpNext, args->n_matches );
9 }
10 
11 /* Input format:
12 %% Section 1
13 char[PATTERN_SIZE]: pattern
14 %% Section 2
15 char[STRING_SIZE]: text
16 */
17 
18 void input_to_data(int fd, void *vdata) {
19  struct bench_args_t *data = (struct bench_args_t *)vdata;
20  char *p, *s;
21  // Zero-out everything.
22  memset(vdata,0,sizeof(struct bench_args_t));
23  // Load input string
24  p = readfile(fd);
25 
26  s = find_section_start(p,1);
28 
29  s = find_section_start(p,2);
30  parse_string(s, data->input, STRING_SIZE);
31  free(p);
32 }
33 
34 void data_to_input(int fd, void *vdata) {
35  struct bench_args_t *data = (struct bench_args_t *)vdata;
36 
38  write_string(fd, data->pattern, PATTERN_SIZE);
39 
41  write_string(fd, data->input, STRING_SIZE);
42 }
43 
44 /* Output format:
45 %% Section 1
46 int[1]: number of matches
47 */
48 
49 void output_to_data(int fd, void *vdata) {
50  struct bench_args_t *data = (struct bench_args_t *)vdata;
51  char *p, *s;
52  // Zero-out everything.
53  memset(vdata,0,sizeof(struct bench_args_t));
54  // Load input string
55  p = readfile(fd);
56 
57  s = find_section_start(p,1);
58  parse_int32_t_array(s, data->n_matches, 1);
59  free(p);
60 }
61 
62 void data_to_output(int fd, void *vdata) {
63  struct bench_args_t *data = (struct bench_args_t *)vdata;
64 
65  write_section_header(fd); // No section header
66  write_int32_t_array(fd, data->n_matches, 1);
67 }
68 
69 int check_data( void *vdata, void *vref ) {
70  struct bench_args_t *data = (struct bench_args_t *)vdata;
71  struct bench_args_t *ref = (struct bench_args_t *)vref;
72  int has_errors = 0;
73 
74  has_errors |= (data->n_matches[0] != ref->n_matches[0]);
75 
76  // Return true if it's correct.
77  return !has_errors;
78 }
void data_to_input(int fd, void *vdata)
Definition: local_support.c:34
int32_t kmpNext[PATTERN_SIZE]
Definition: kmp.h:20
#define STRING_SIZE
Definition: kmp.h:11
int check_data(void *vdata, void *vref)
Definition: local_support.c:70
int write_int32_t_array(int fd, int32_t *arr, int n)
#define PATTERN_SIZE
Definition: kmp.h:10
int32_t n_matches[1]
Definition: kmp.h:21
int INPUT_SIZE
Definition: local_support.c:4
int parse_int32_t_array(char *s, int32_t *arr, int n)
int kmp(char pattern[PATTERN_SIZE], char input[STRING_SIZE], int32_t kmpNext[PATTERN_SIZE], int32_t n_matches[1])
Definition: kmp.c:24
int parse_string(char *s, char *arr, int n)
Definition: support.c:77
char pattern[PATTERN_SIZE]
Definition: kmp.h:18
int write_string(int fd, char *arr, int n)
void data_to_output(int fd, void *vdata)
Definition: local_support.c:63
int write_section_header(int fd)
void output_to_data(int fd, void *vdata)
Definition: local_support.c:49
char * readfile(int fd)
Definition: support.c:34
void input_to_data(int fd, void *vdata)
Definition: local_support.c:18
char * find_section_start(char *s, int n)
Definition: support.c:56
char input[STRING_SIZE]
Definition: kmp.h:19
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