forked from jefflieu/HLS-Tiny-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hier_func_test.cpp
101 lines (85 loc) · 2.3 KB
/
hier_func_test.cpp
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
/*
* Copyright 2021 Xilinx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hier_func.h"
int main() {
// Data storage
int a[NUM_TRANS], b[NUM_TRANS];
int c_expected[NUM_TRANS], d_expected[NUM_TRANS];
int c[NUM_TRANS], d[NUM_TRANS];
//Function data (to/from function)
int a_actual, b_actual;
int c_actual, d_actual;
// Misc
int retval=0, i, i_trans, tmp;
FILE *fp;
// Load input data from files
fp=fopen("tb_data/inA.dat","r");
for (i=0; i<NUM_TRANS; i++){
fscanf(fp, "%d", &tmp);
a[i] = tmp;
}
fclose(fp);
fp=fopen("tb_data/inB.dat","r");
for (i=0; i<NUM_TRANS; i++){
fscanf(fp, "%d", &tmp);
b[i] = tmp;
}
fclose(fp);
// Execute the function multiple times (multiple transactions)
for(i_trans=0; i_trans<NUM_TRANS-1; i_trans++){
//Apply next data values
a_actual = a[i_trans];
b_actual = b[i_trans];
hier_func(a_actual, b_actual, &c_actual, &d_actual);
//Store outputs
c[i_trans] = c_actual;
d[i_trans] = d_actual;
}
// Load expected output data from files
fp=fopen("tb_data/outC.golden.dat","r");
for (i=0; i<NUM_TRANS; i++){
fscanf(fp, "%d", &tmp);
c_expected[i] = tmp;
}
fclose(fp);
fp=fopen("tb_data/outD.golden.dat","r");
for (i=0; i<NUM_TRANS; i++){
fscanf(fp, "%d", &tmp);
d_expected[i] = tmp;
}
fclose(fp);
// Check outputs against expected
for (i = 0; i < NUM_TRANS-1; ++i) {
if(c[i] != c_expected[i]){
retval = 1;
}
if(d[i] != d_expected[i]){
retval = 1;
}
}
// Print Results
if(retval == 0){
printf(" *** *** *** *** \n");
printf(" Results are good \n");
printf(" *** *** *** *** \n");
} else {
printf(" *** *** *** *** \n");
printf(" Mismatch: retval=%d \n", retval);
printf(" *** *** *** *** \n");
}
// Return 0 if outputs are correct
return retval;
}