-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracegenaoat.c
102 lines (79 loc) · 2.27 KB
/
tracegenaoat.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* tracegen.c - Running the binary tracegen with valgrind produces
* a memory trace of all of the registered aoatpose functions.
*
* The beginning and end of each registered aoatpose function's trace
* is indicated by reading from "marker" addresses. These two marker
* addresses are recorded in file for later use.
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <getopt.h>
#include "cachelab.h"
#include <string.h>
/* External variables declared in cachelab.c */
extern aoat_func_t func_list_aoat[MAX_AOAT_FUNCS];
extern int func_counter_aoat;
/* External function from aoat.c */
extern void registerAoatFunctions();
/* Markers used to bound trace regions of interest */
volatile char MARKER_START, MARKER_END;
static int A[256][256];
static int N;
int validate (int fn, int N, const int A[N][N], int grand_sum) {
int correct = correctAoat (N, A);
if (grand_sum != correct) {
printf ("Validation failed on function %d! Expected %d but got %d\n", fn, correct, grand_sum);
return 0;
}
return 1;
}
int main (int argc, char *argv[]) {
int i;
char c;
int selectedFunc = -1;
while ( (c = getopt (argc, argv, "N:F:")) != -1) {
switch (c) {
case 'N':
N = atoi (optarg);
break;
case 'F':
selectedFunc = atoi (optarg);
break;
case '?':
default:
printf ("./tracegen failed to parse its options.\n");
exit (1);
}
}
/* Register aoat functions */
registerAoatFunctions();
/* Fill A with data */
initMatrix (N, N, A, A);
/* Record marker addresses */
FILE *marker_fp = fopen (".marker", "w");
assert (marker_fp);
fprintf (marker_fp, "%llx %llx",
(unsigned long long int) &MARKER_START,
(unsigned long long int) &MARKER_END);
fclose (marker_fp);
if (-1 == selectedFunc) {
/* Invoke registered aoat functions */
for (i = 0; i < func_counter_aoat; i++) {
MARKER_START = 33;
int res = (*func_list_aoat[i].func_ptr) (N, A);
MARKER_END = 34;
if (!validate (i, N, A, res))
return i + 1;
}
} else {
MARKER_START = 33;
int res = (*func_list_aoat[selectedFunc].func_ptr) (N, A);
MARKER_END = 34;
if (!validate (selectedFunc, N, A, res))
return selectedFunc + 1;
}
return 0;
}