-
Notifications
You must be signed in to change notification settings - Fork 1
/
tester.cpp
195 lines (174 loc) · 6.95 KB
/
tester.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Copyright (c) 2018-2020, High Performance Computing Architecture and System
* research laboratory at University of North Carolina at Charlotte (HPCAS@UNCC)
* and Lawrence Livermore National Security, LLC.
*
* SPDX-License-Identifier: (BSD-3-Clause)
*/
#include <stdio.h>
#include <OpenMPIR.h>
#include <string.h>
#include <iostream>
#include <regex>
extern OpenMPDirective* parseOpenMP(const char*, void *_exprParse(const char*));
void output(OpenMPDirective*);
std::string test(OpenMPDirective*);
int openFile(std::ifstream&, const char*);
void output(OpenMPDirective* node) {
if (node) {
std::string unparsing_string = node->generatePragmaString();
std::cout << unparsing_string << "\n";
node->generateDOT();
};
}
std::string test(OpenMPDirective* node) {
std::string unparsing_string;
if (node) {
unparsing_string = node->generatePragmaString();
}
return unparsing_string;
}
int openFile(std::ifstream& file, const char* filename) {
file.exceptions (std::ifstream::failbit | std::ifstream::badbit);
try {
file.open(filename);
}
catch (std::ifstream::failure const&) {
std::cerr << "Exception caused by opening the given file\n";
return -1;
}
return 0;
}
int main( int argc, const char* argv[] ) {
const char* filename = NULL;
const char* mode = "string";
int result;
if (argc > 1) {
filename = argv[1];
};
if (argc > 2) {
mode = argv[2];
};
std::ifstream input_file;
std::ofstream output_file;
if (filename != NULL) {
result = openFile(input_file, filename);
//}
//else {
// std::cout << "No specific testing file is provided, use the default PARALLEL testing instead.\n";
// result = openFile(input_file, "../tests/parallel.txt");
};
if (result) {
std::cout << "No testing file is available.\n";
return -1;
};
// open the result table file
output_file.open("./results.md", ios_base::app);
if (result) {
std::cout << "No output file is available.\n";
return -1;
};
std::string input_pragma;
std::string output_pragma;
std::string validation_string;
std::string pass = "true";
std::map<std::string, std::string> processed_data;
int total_amount = 0;
int passed_amount = 0;
int failed_amount = 0;
int invalid_amount = 0;
int line_no = 0;
int current_pragma_line_no = 1;
char current_char = input_file.peek();
std::string current_line;
OpenMPBaseLang base_lang = Lang_C;
std::regex fortran_regex ("[!][$][Oo][Mm][Pp]");
bool is_fortran = false;
std::string filename_string = std::string(filename);
filename_string = filename_string.substr(filename_string.rfind("/")+1);
while (!input_file.eof()) {
line_no += 1;
switch (current_char) {
case '\n':
input_file.seekg(1, ios_base::cur);
break;
default:
std::getline(input_file, current_line);
current_line = std::regex_replace(current_line, std::regex("^\\s+"), std::string(""));
if (std::regex_match(current_line.substr(0, 5), fortran_regex)) {
is_fortran = true;
base_lang = Lang_Fortran;
}
else {
base_lang = Lang_C;
};
if (current_line.substr(0, 7) == "#pragma" || is_fortran) {
total_amount += 1;
if (input_pragma.size()) {
std::cout << "======================================\n";
std::cout << "Line: " << current_pragma_line_no << "\n";
std::cout << "GIVEN INPUT: " << input_pragma << "\n";
std::cout << "GENERATED OUTPUT: " << output_pragma << "\n";
std::cout << "Missing the output for validation.\n";
std::cout << "======================================\n";
invalid_amount += 1;
};
current_pragma_line_no = line_no;
input_pragma = current_line;
auto search_pragma = processed_data.find(input_pragma);
if (search_pragma != processed_data.end()) {
output_pragma = processed_data[input_pragma];
break;
};
OpenMPDirective* openMPAST = parseOpenMP(current_line.c_str(), NULL);
output_pragma = test(openMPAST);
if (output_pragma.size() == 0) {
pass = "false";
};
output_file << filename_string.c_str() << " | ` " << current_line.c_str() << " ` | ` " << output_pragma.c_str() << " ` | " << pass.c_str() << "\n";
processed_data[input_pragma] = output_pragma;
pass = "true";
is_fortran = false;
}
else if (current_line.substr(0, 6) == "PASS: ") {
validation_string = current_line.substr(6);
if (input_pragma.size() == 0) {
validation_string.clear();
}
else if (output_pragma != validation_string) {
std::cout << "======================================\n";
std::cout << "Line: " << current_pragma_line_no << "\n";
std::cout << "FAILED INPUT: " << input_pragma << "\n";
std::cout << "WRONG OUTPUT: " << output_pragma << "\n";
std::cout << "EXPECTED OUTPUT: " << validation_string << "\n";
std::cout << "======================================\n";
failed_amount += 1;
}
else {
passed_amount += 1;
}
input_pragma.clear();
validation_string.clear();
}
};
current_char = input_file.peek();
};
if (input_pragma.size()) {
std::cout << "======================================\n";
std::cout << "Line: " << current_pragma_line_no << "\n";
std::cout << "GIVEN INPUT: " << input_pragma << "\n";
std::cout << "GENERATED OUTPUT: " << output_pragma << "\n";
std::cout << "Missing the output for validation.\n";
std::cout << "======================================\n";
invalid_amount += 1;
};
input_pragma.clear();
std::cout << "=================== SUMMARY ===================\n";
std::cout << "TOTAL TESTS : " << total_amount << "\n";
std::cout << "PASSED TESTS : " << passed_amount << "\n";
std::cout << "FAILED TESTS : " << failed_amount << "\n";
std::cout << "INVALID TESTS: " << invalid_amount << "\n";
input_file.close();
output_file.close();
return 0;
}