-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser-tester.h
231 lines (212 loc) · 4.59 KB
/
parser-tester.h
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* Authored By Charlie Keaney */
/* parser-tester.h - Responsible for testing the
parser.
Temporarily defunct. */
#ifdef PARSER_TESTER_H
#define PARSER_TESTER_H 1
#include <fstream>
#include <sstream>
#include "tester-tools.h"
#include "lexer.h"
#include "parser.h"
#include "preprocessor.h"
#include "driver.h"
//////////////////////////////////////////////////////////////////
// Testing for the recognition of punctuator tokens //
//////////////////////////////////////////////////////////////////
#define NUM_MISRA_TESTS 133
static const char* misra_test_case_filenames[NUM_MISRA_TESTS] = {
"misra.h",
"misra1.c",
"misra10.c",
"misra100.c",
"misra101.c",
"misra102.c",
"misra103.c",
"misra104.c",
"misra105.c",
"misra106.c",
"misra107.c",
"misra108.c",
"misra109.c",
"misra11.c",
"misra110.c",
"misra111.c",
"misra112.c",
"misra113.c",
"misra114.c",
"misra115.c",
"misra117.c",
"misra118.c",
"misra119.c",
"misra12.c",
"misra120.c",
"misra121.c",
"misra122.c",
"misra123.c",
"misra124.c",
"misra125.h",
"misra126.c",
"misra127.c",
"misra13.c",
"misra14.c",
"misra15.c",
"misra16.c",
"misra17.c",
"misra18.c",
"misra19.c",
"misra1a.c",
"misra1b.c",
"misra1c",
"misra20.c",
"misra21.c",
"misra22.c",
"misra23.c",
"misra24.c",
"misra25a.c",
"misra25b.c",
"misra26a.c",
"misra26b.c",
"misra27.c",
"misra27.h",
"misra28.c",
"misra29.c",
"misra3.c",
"misra30.c",
"misra31.c",
"misra32.c",
"misra33.c",
"misra34.c",
"misra35.c",
"misra36.c",
"misra37.c",
"misra38.c",
"misra39.c",
"misra4.c",
"misra40.c",
"misra41.c",
"misra42.c",
"misra43.c",
"misra44.c",
"misra45.c",
"misra46.c",
"misra47.c",
"misra48.c",
"misra49.c",
"misra5.c",
"misra50.c",
"misra51.c",
"misra52.c",
"misra53.c",
"misra54.c",
"misra55.c",
"misra56.c",
"misra57.c",
"misra58.c",
"misra59.c",
"misra6.c",
"misra60.c",
"misra61.c",
"misra62.c",
"misra63.c",
"misra64.c",
"misra65.c",
"misra66.c",
"misra67.c",
"misra68.c",
"misra69.c",
"misra7.c",
"misra70.c",
"misra70a.c",
"misra71.c",
"misra72.c",
"misra73.c",
"misra74.c",
"misra75.c",
"misra76.c",
"misra77.c",
"misra78.c",
"misra79.c",
"misra8.c",
"misra80.c",
"misra81.c",
"misra82.c",
"misra83.c",
"misra84.c",
"misra85.c",
"misra86.c",
"misra87.c",
"misra88.c",
"misra89.c",
"misra9.c",
"misra90.c",
"misra91.c",
"misra92.c",
"misra93.c",
"misra94.c",
"misra95.c",
"misra96.c",
"misra97.c",
"misra98.c",
"misra99.c",
};
static inline TestResult test_misra_tests(
TestResult results[NUM_MISRA_TESTS])
{
bool all_tests_passed = true;
for (const char** testcase = misra_test_case_filenames;
testcase < misra_test_case_filenames + NUM_MISRA_TESTS;
testcase++) {
/* Get characters in the file. */
const char* filename = *testcase;
string filename_str = "./test-cases/misrul10/" + string(filename);
std::ifstream f(filename_str);
std::stringstream buffer;
buffer << f.rdbuf();
string buffer_str = buffer.str();
const char* file = buffer_str.c_str();
FileLocationDescriptor fld(*testcase, 0, 0);
KccExitCode exitcode;
drive(fld, input, CompilerFlags::OUTPUT_NOTHING);
/* Return results */
bool success_criteria = exitcode == KccExitCode::SUCCESS;
results[testcase - misra_test_case_filenames]
= success_criteria
? TestResult::SUCCESS
: TestResult::FAIL;
if (!success_criteria) {
all_tests_passed = false;
}
}
return all_tests_passed ? TestResult::SUCCESS : TestResult::FAIL;
}
//////////////////////////////////////////////////////////////////
// Code for running and presenting the results of tests //
//////////////////////////////////////////////////////////////////
#define NUM_PARSER_TESTS NUM_MISRA_TESTS
static inline TestResult test_parser(
TestResult results[NUM_PARSER_TESTS],
char*& output,
int indent = 0)
{
for (int i = 0; i < indent; i++) {
print_to_output("\t", output);
}
print_to_output("<-> ParserIntegrationTests", output);
print_to_output("\n", output);
TestResult misra_test_results[NUM_MISRA_TESTS];
TestResult misra_test_result = test_misra_tests(misra_test_results);
const char* misra_title = "MisraTests";
present_test_set_synopsis(
misra_title,
misra_test_result,
misra_test_results,
NUM_MISRA_TESTS,
output,
indent + 1
);
return (misra_test_result == TestResult::SUCCESS)
? TestResult::SUCCESS
: TestResult::FAIL;
}
#endif