-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarFishTester.java
287 lines (239 loc) · 9.28 KB
/
StarFishTester.java
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
import com.sun.corba.se.impl.orbutil.concurrent.Mutex;
import java.lang.Exception;
import java.lang.Override;
import java.lang.Runnable;
import java.lang.System;
import java.lang.Thread;
import java.nio.file.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Date;
import java.io.File;
import java.util.Scanner;
import javax.annotation.processing.ProcessingEnvironment;
import javax.sound.midi.SysexMessage;
import sun.security.pkcs11.P11TlsKeyMaterialGenerator;
public class StarFishTester {
public static class TestResult {
String testName;
String status;
}
public static void main(String args[]) {
Boolean nw = false;
System.out.println("StarFish Tester Start");
try {
String testFile="";
if (args[0].equals("css1")) {
testFile = "tool/reftest/tclist/wpt_css1.res";
} else if (args[0].equals("css21")) {
testFile = "tool/reftest/tclist/wpt_css21.res";
} else if (args[0].equals("css3_backgrounds")) {
testFile = "tool/reftest/tclist/wpt_css3_backgrounds.res";
} else if (args[0].equals("css3_color")) {
testFile = "tool/reftest/tclist/wpt_css3_color.res";
} else if (args[0].equals("css3_transforms")) {
testFile = "tool/reftest/tclist/wpt_css3_transforms.res";
} else if (args[0].equals("css_rtl")) {
testFile = "tool/reftest/tclist/wpt_rtl_css.res";
} else if (args[0].equals("css1_rtl")) {
testFile = "tool/reftest/tclist/wpt_rtl_css1.res";
} else if (args[0].equals("css21_rtl")) {
testFile = "tool/reftest/tclist/wpt_rtl_css21.res";
} else if (args[0].equals("css3_backgrounds_rtl")) {
testFile = "tool/reftest/tclist/wpt_rtl_css3_backgrounds.res";
} else if (args[0].equals("css3_color_rtl")) {
testFile = "tool/reftest/tclist/wpt_rtl_css3_color.res";
} else if (args[0].equals("css3_transforms_rtl")) {
testFile = "tool/reftest/tclist/wpt_rtl_css3_transforms.res";
}
String fileContent = new String(Files.readAllBytes(Paths.get(testFile)));
String[] files = fileContent.split("\n");
final ArrayList<String> workQueue = new ArrayList<String>();
for (int i = 0; i < files.length; i ++) {
if (files[i].trim().length() != 0) {
workQueue.add(files[i]);
}
}
int cores = Runtime.getRuntime().availableProcessors();
// System.out.println("oh! rich guy you have " + cores + " processors!!! good!");
if (args.length >= 2 && args[1].equals("nw")) {
nw = true;
System.out.println("# pixel-test for Node-Webkit");
/*
String ss = "";
ss = "nw tool/pixel_test/nw_capture/ -l " + testFile + " pc";
System.out.println("# capture START:" + ss);
Process process = Runtime.getRuntime().exec(ss);
System.out.println("It may take a few minutes");
process.waitFor();
System.out.println("# capture COMPLETE");
*/
}
final Boolean enableNW = nw;
final Mutex workQueueMutex = new Mutex();
final Mutex printMutex = new Mutex();
final Mutex resultMutex = new Mutex();
final ArrayList<TestResult> testResult = new ArrayList<TestResult>();
for (int i = 0; i < workQueue.size(); i ++) {
TestResult rc = new TestResult();
rc.testName = workQueue.get(i);
rc.status = "";
testResult.add(rc);
}
File rm = new File("/tmp/StarFishTester/");
deleteDirectory(rm);
final String reftestFolder = "./out/x64/exe/debug/reftest/";
final String outFolder = "./out/x64/exe/debug/reftest/pixel_test/";
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < cores; i ++) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while(true) {
String workItem="";
boolean shouldBreak = false;
try {
workQueueMutex.acquire();
} catch (Exception e) {
}
if (workQueue.size() > 0) {
workItem = workQueue.get(0);
workQueue.remove(0);
} else {
shouldBreak = true;
}
workQueueMutex.release();
if (shouldBreak)
break;
Runtime runtime = Runtime.getRuntime();
// make temp dir
Date d = new Date();
String outputString = workItem + " ";
// System.out.println(tempDir);
String caseName = workItem;
String outFolderName = outFolder + caseName.replace("test/reftest", "");
String folderName = outFolderName.substring(0, outFolderName.lastIndexOf('/'));
File rDir = new File(folderName);
rDir.mkdirs();
caseName = caseName.substring(0, caseName.lastIndexOf('.'));
// excute runner
try {
String ss = "";
String pngFile = outFolderName + "_result.png";
String workingDir = workItem.substring(0, workItem.lastIndexOf('/') + 1);
File png = new File(pngFile);
if (png.exists()) { png.delete(); }
ss = "./StarFish " + workItem + " --pixel-test --width=" + 800 + " --height=" + 600 + " --screen-shot=" + pngFile;
// System.out.println(ss);
Process process = runtime.exec(ss);
process.waitFor();
} catch (Exception e) {
}
// take webkit screen shot
String expectedPNG = caseName.replace("_converted", "_result/font_independent/") + "_expected.png";
/* phantomjs regacy code
try {
File sc = new File(expectedPNG);
if (!sc.exists()) {
if (enableNW) {
System.out.println("File not Found : " + expectedPNG);
}
String ss = "tool/phantomjs/linux64/bin/phantomjs tool/pixel_test/capture.js -f " + workItem + " " + folderName + " pc";
// System.out.println(ss);
Process process = runtime.exec(ss);
process.waitFor();
}
} catch (Exception e) {
}
*/
// image diff
String testStatus="";
try {
String ss = "./tool/imgdiff/imgdiff " + outFolderName + "_result.png" + " " + expectedPNG;
// System.out.println(ss);
Process process = runtime.exec(ss);
process.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
// read the output from the command
String s = null;
String diffOut = "";
while ((s = stdInput.readLine()) != null) {
// System.out.println(s);
diffOut += s;
}
if (diffOut.trim().length() > 0) {
outputString += diffOut;
testStatus = diffOut;
} else {
outputString += "got error";
testStatus = "diff: 100.0% failed";
}
if (testStatus.contains("failed") || testStatus.contains("not exactly same")) {
ss = "test/tool/image_diff --diff " + outFolderName + "_result.png" + " " + expectedPNG + " " + outFolderName + "_diff.png";
process = runtime.exec(ss);
process.waitFor();
}
} catch (Exception e) {
}
try {
printMutex.acquire();
System.out.println(outputString);
System.out.flush();
} catch (Exception e) {
System.out.println(e.toString());
}
printMutex.release();
try {
resultMutex.acquire();
for (int i = 0; i < testResult.size(); i ++) {
if (testResult.get(i).testName.equals(workItem)) {
testResult.get(i).status = testStatus;
break;
}
}
} catch (Exception e) {
System.out.println(e.toString());
}
resultMutex.release();
}
}
});
threads.add(t);
t.start();
}
for (int i = 0; i < threads.size(); i++) {
threads.get(i).join();
}
System.err.println("======== test result ==================");
int good = 0;
int bad = 0;
for (int i = 0; i < testResult.size(); i ++) {
if (testResult.get(i).status.contains("passed"))
good++;
else {
bad++;
}
System.err.println(testResult.get(i).testName + " " + testResult.get(i).status);
}
System.err.println(" ====total : " + (good + bad) + " passed : " + good + " failed : " + bad);
} catch(Exception e) {
System.out.println(e.toString());
}
}
public static boolean deleteDirectory(File directory) {
if(directory.exists()){
File[] files = directory.listFiles();
if(null!=files){
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
deleteDirectory(files[i]);
}
else {
files[i].delete();
}
}
}
}
return(directory.delete());
}
}