Repository navigation
Expand file tree
/
Copy pathrlregr.cpp
More file actions
426 lines (340 loc) · 11.7 KB
/
Copy pathrlregr.cpp
File metadata and controls
426 lines (340 loc) · 11.7 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// rlregr.c
//
// assembly regression worker for rl.c
#include "rl.h"
#define TMP_PREFIX "di" // 2 characters
// Currently not overridable
#define REGR_PERL "perl"
#define DIR_START_CMD "startdir.cmd"
#define DIR_END_CMD "enddir.cmd"
// <rl> ... </rl> directives:
//
// PassFo
// Doesn't add -FoNUL. to the command line; allows passing of -Fo
// explicitly.
//
// NoAsm
// Disables asm file generation.
#define PASS_FO_CMD "PassFo"
#define NO_ASM_CMD "NoAsm"
//
// Global variables set before worker threads start, and only accessed
// (not set) by the worker threads.
//
static BOOL NoMasterCompare;
LOCAL int
DoCommand(
const char *path, // full path of directory to run command in
const char *cmdbuf,
bool displayError = true
)
{
int rtncode;
rtncode = ExecuteCommand(path, cmdbuf);
if (rtncode && displayError) {
LogOut("ERROR: Command had a return code of %d:", rtncode);
LogOut(" %s", cmdbuf);
}
return rtncode;
}
LOCAL void __cdecl
RegrCleanUp(void)
{
}
// One-time assembly regression initialization.
void
RegrInit(
void
)
{
atexit(RegrCleanUp);
if (getenv_unsafe("REGR_NOMASTERCMP") != NULL) {
if (FBaseline) {
Fatal("-baseline conflicts with environment variable REGR_NOMASTERCMP.");
}
NoMasterCompare = TRUE;
}
else {
NoMasterCompare = FALSE;
}
}
// Called at the start of each directory.
BOOL
RegrStartDir(
char *path
)
{
char full[MAX_PATH];
// Execute directory setup command script if present.
sprintf_s(full, "%s\\%s", path, DIR_START_CMD);
if (GetFileAttributes(full) != INVALID_FILE_ATTRIBUTES) {
Message(""); // newline
Message("Executing %s", DIR_START_CMD);
if (DoCommand(path, DIR_START_CMD))
return FALSE;
Message(""); // newline
}
return TRUE;
}
// Called at the end of each directory.
BOOL
RegrEndDir(
char* path
)
{
char full[MAX_PATH];
// Execute directory shutdown command script if present.
sprintf_s(full, "%s\\%s", path, DIR_END_CMD);
if (GetFileAttributes(full) != INVALID_FILE_ATTRIBUTES) {
Message(""); // newline
Message("Executing %s", DIR_END_CMD);
if (DoCommand(path, DIR_END_CMD))
return FALSE;
Message("");
}
return TRUE;
}
// Called to perform assembly regressions on one file.
// Returns -1 for failure, 1 for diff, 0 for okay.
int
RegrFile(
CDirectory* pDir,
Test * pTest,
TestVariant * pTestVariant
)
{
FILE *fp;
char *p;
const char *opts;
int x;
int rc;
int retval;
char full[MAX_PATH]; // temporary place for full paths
char basename[MAX_PATH]; // base filename
const char *asmdir; // dir of generated asm file
char masterasmbuf[MAX_PATH]; // name of master asm file
char asmbuf[MAX_PATH]; // name of generated asm file
char diffbuf[MAX_PATH]; // name of generated diff file
char objbuf[MAX_PATH]; // name of generated obj file
char fullmasterasmbuf[MAX_PATH]; // path of master asm file
char fullasmbuf[MAX_PATH]; // path of generated asm file
char fulldiffbuf[MAX_PATH]; // path of generated diff file
char fullobjbuf[MAX_PATH]; // path of generated obj file
char standardoptbuf[BUFFER_SIZE]; // standard compilation options (-Fa..)
char cmdbuf[BUFFER_SIZE]; // compilation command
char compilerbuf[BUFFER_SIZE]; // compiler name buffer
char buf[BUFFER_SIZE];
char tmp_file1[BUFFER_SIZE];
char tmp_file2[BUFFER_SIZE];
char tmp_file3[BUFFER_SIZE];
BOOL passFo = FALSE;
BOOL noAsm = FALSE;
// We don't allow non-target conditions for ASM currently, so we should
// never see a conditionNodeList.
ASSERTNR(pTest->conditionNodeList == NULL);
// Check the directives.
if (HasInfo(pTest->defaultTestInfo.data[TIK_RL_DIRECTIVES], XML_DELIM,
PASS_FO_CMD))
{
passFo = TRUE;
}
if (HasInfo(pTest->defaultTestInfo.data[TIK_RL_DIRECTIVES], XML_DELIM,
NO_ASM_CMD))
{
noAsm = TRUE;
}
// Base file name (name.* -> name)
strcpy_s(basename, pTest->name);
for(p = basename; *p != '.' && *p != '\0'; p++);
*p = '\0';
// Determine the standard options.
asmdir = pDir->IsBaseline() ? MASTER_DIR : DIFF_DIR;
sprintf_s(standardoptbuf, "-AsmDumpMode:%s\\%s.asm",
asmdir, basename);
switch (TargetMachine) {
case TM_WVM:
case TM_WVMX86:
case TM_WVM64:
strcat_s(standardoptbuf, " /BC ");
break;
}
if (BaseCompiler || DiffCompiler) {
char *b2;
if (pDir->IsBaseline())
b2 = BaseCompiler;
else
b2 = DiffCompiler;
ASSERTNR(b2);
sprintf_s(compilerbuf, " -B2 %s", b2);
}
else
{
*compilerbuf = '\0';
}
// Try to open the source file.
sprintf_s(full, "%s\\%s", pDir->GetDirectoryPath(), pTest->name);
fp = fopen_unsafe(full, "r");
if (fp == NULL) {
LogError("ERROR: Could not open '%s' with error '%s'", pTest->name, strerror_unsafe(errno));
return -1;
}
fclose(fp);
ASSERTNR(pTestVariant->optFlags == NULL);
ASSERTNR(pTestVariant->testInfo.data[TIK_LINK_FLAGS] == NULL);
opts = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
if (opts == NULL)
{
opts = "";
}
// Compute the object name if passing -Fo through.
if (passFo)
sprintf_s(objbuf, "%s.obj", basename);
else
sprintf_s(objbuf, "%s\\%s.obj", asmdir, basename);
sprintf_s(fullobjbuf, "%s\\%s", pDir->GetDirectoryPath(), objbuf);
// Compute the names for the assembly and diff files.
sprintf_s(masterasmbuf, "%s\\%s.asm", MASTER_DIR, basename);
sprintf_s(asmbuf, "%s\\%s.asm", asmdir, basename);
sprintf_s(diffbuf, "%s\\%s.d", DIFF_DIR, basename);
sprintf_s(fullmasterasmbuf, "%s\\%s", pDir->GetDirectoryPath(), masterasmbuf);
sprintf_s(fullasmbuf, "%s\\%s", pDir->GetDirectoryPath(), asmbuf);
sprintf_s(fulldiffbuf, "%s\\%s", pDir->GetDirectoryPath(), diffbuf);
// There could be a diff file from previous regressions. Remove it now.
if (!pDir->IsBaseline())
DeleteFileIfFound(fulldiffbuf);
// Create the compiler command and do the compile.
sprintf_s(cmdbuf, "%s%s %s %s %s %s 2>nul 1>nul",
JCBinary, compilerbuf, standardoptbuf, opts, EXTRA_CC_FLAGS,
pTest->name);
if (FVerbose) {
strcpy_s(buf, cmdbuf);
}
else {
// For non-verbose, don't display the standard options
sprintf_s(buf, "%s%s %s %s %s",
JCBinary, compilerbuf, opts, EXTRA_CC_FLAGS, pTest->name);
}
Message("%s", buf);
if (FTest)
{
return 0;
}
// There could be a diff file from previous regressions. Remove it now.
if (!pDir->IsBaseline())
{
DeleteFileIfFound(fulldiffbuf);
}
if (DoCommand(pDir->GetDirectoryPath(), cmdbuf))
{
DeleteFileIfFound(fullasmbuf);
return -1;
}
// If we are passing -Fo through to the compiler, remove the generated
// object file.
if (passFo)
DeleteFileRetryMsg(fullobjbuf);
// See if we generated an assembly file.
if (GetFileAttributes(fullasmbuf) == INVALID_FILE_ATTRIBUTES) {
LogOut("ERROR: Assembly file %s not generated", asmbuf);
return -1;
}
// Create the assembler command and do the asm if necessary.
if (REGR_ASM && !noAsm) {
sprintf_s(cmdbuf, "%s %s", REGR_ASM, asmbuf);
Message("%s", cmdbuf);
// ignore the REGR_ASM return code; we still want to do diffs or
// update the master with the generated asm file.
if (DoCommand(pDir->GetDirectoryPath(), cmdbuf)) {
retval = -1;
}
else {
retval = 0;
DeleteFileRetryMsg(fullobjbuf);
}
} else {
retval = 0;
}
// Exit if not comparing to master or doing baselines.
if (NoMasterCompare || pDir->IsBaseline())
return retval;
// FYI: Up to this point we haven't used fullmasterasmbuf.
ASSERTNR(!strcmp(asmdir, DIFF_DIR));
// If the master doesn't exist, consider this a failure.
if (GetFileAttributes(fullmasterasmbuf) == INVALID_FILE_ATTRIBUTES) {
LogOut("ERROR: %s doesn't exist", fullmasterasmbuf);
return -1;
}
x = DoCompare(fullasmbuf, fullmasterasmbuf, pTestVariant->testInfo.hasData[TIK_EOL_NORMALIZATION]);
if (x < 0)
return -1;
// If the files differ, remove potential bogus differences and try again.
rc = retval;
if (x) {
// Remove the possible bogus diffs.
// Generate some temporary file names.
// Note: these are full pathnames, not relative pathnames.
// NOTE: BE VERY CAREFUL TO CLEAN THESE UP!
if (mytmpnam(pDir->GetDirectoryPath(), TMP_PREFIX, tmp_file1) == NULL ||
mytmpnam(pDir->GetDirectoryPath(), TMP_PREFIX, tmp_file2) == NULL ||
mytmpnam(pDir->GetDirectoryPath(), TMP_PREFIX, tmp_file3) == NULL) {
Fatal("Unable to create temporary files");
}
ThreadInfo[ThreadId].AddToTmpFileList(tmp_file1);
ThreadInfo[ThreadId].AddToTmpFileList(tmp_file2);
ThreadInfo[ThreadId].AddToTmpFileList(tmp_file3);
sprintf_s(cmdbuf, "%s %s %s %s",
REGR_SHOWD, REGR_PERL, fullasmbuf, tmp_file1);
if (DoCommand(pDir->GetDirectoryPath(), cmdbuf)) {
rc = -1;
}
else {
sprintf_s(cmdbuf, "%s %s %s %s",
REGR_SHOWD, REGR_PERL, fullmasterasmbuf, tmp_file2);
if (DoCommand(pDir->GetDirectoryPath(), cmdbuf)) {
rc = -1;
}
else {
// Compare again.
x = DoCompare(tmp_file1, tmp_file2, pTestVariant->testInfo.hasData[TIK_EOL_NORMALIZATION]);
if (x < 0) {
rc = -1;
}
else if (x) {
// They still differ, make a diff file.
sprintf_s(cmdbuf, "%s %s %s > %s",
REGR_DIFF, tmp_file1, tmp_file2, tmp_file3);
DoCommand(pDir->GetDirectoryPath(), cmdbuf, false);
sprintf_s(cmdbuf,"%s -p -e \"s/^[<>-].*\\r?\\n//\" < %s > %s",
REGR_PERL, tmp_file3, fulldiffbuf);
if (DoCommand(pDir->GetDirectoryPath(), cmdbuf)) {
rc = -1;
}
else {
Message("%s and %s differ", asmbuf, masterasmbuf);
WriteLog("%s has diffs", pTest->name);
rc = 1;
}
}
else {
// Move the new asm into the master directory
DeleteFileRetryMsg(fullmasterasmbuf);
if (!MoveFile(fullasmbuf, fullmasterasmbuf)) {
LogOut("ERROR: MoveFile(%s, %s) failed with error %d",
fullasmbuf, fullmasterasmbuf, GetLastError());
rc = -1;
}
}
}
}
ThreadInfo[ThreadId].DeleteTmpFileList();
}
else {
// They don't differ, so delete the assembly file we just created.
DeleteFileRetryMsg(fullasmbuf);
}
return rc;
}