comparison mx/JUnitWrapper.java @ 16304:12f2b3baa163

JUnit Reporting
author Stefan Anzinger <stefan.anzinger@gmail.com>
date Sat, 19 Apr 2014 15:32:02 +0200
parents f38f746f4980
children 151fe6b1e511
comparison
equal deleted inserted replaced
16303:66c7e50a9a32 16304:12f2b3baa163
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 23
24
25 /* Execute testcases by reading names from a given file, due to limits of 24 /* Execute testcases by reading names from a given file, due to limits of
26 * the operating system regarding command line size (windows: 32k, 25 * the operating system regarding command line size (windows: 32k,
27 * linux [depending on the settings]: ~2097k) 26 * linux [depending on the settings]: ~2097k)
28 * see http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx 27 * see http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
29 */ 28 */
30 29
30 import org.apache.tools.ant.*;
31 import org.apache.tools.ant.taskdefs.optional.junit.*;
32 import org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.TypeAttribute;
33 import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.*;
34 import org.apache.tools.ant.types.*;
35 import org.apache.tools.ant.types.selectors.*;
31 import org.junit.runner.*; 36 import org.junit.runner.*;
37
32 import java.io.*; 38 import java.io.*;
33 import java.util.*; 39 import java.util.*;
34 40
35 public class JUnitWrapper { 41 public class JUnitWrapper {
36 42
37 /** 43 /**
38 * @param args 44 * @param args args[0] is the path where to read the names of the testclasses.
39 * args[0] is the path where to read the names of the testclasses. 45 * @throws Exception
40 */ 46 */
41 public static void main(String[] args) { 47 public static void main(String[] args) throws Exception {
42 if (args.length == 0) { 48 if (args.length == 0) {
43 System.err.printf("wrong usage. provide a filename\n"); 49 System.err.printf("wrong usage. provide a filename\n");
44 System.exit(1); 50 System.exit(1);
45 } 51 }
46 ArrayList<String> tests = new ArrayList<String>(1000); 52 ArrayList<String> tests = new ArrayList<String>(1000);
70 if (strargs.length == 1) { 76 if (strargs.length == 1) {
71 System.out.printf("executing junit test now... (%s)\n", strargs[0]); 77 System.out.printf("executing junit test now... (%s)\n", strargs[0]);
72 } else { 78 } else {
73 System.out.printf("executing junit tests now... (%d test classes)\n", strargs.length); 79 System.out.printf("executing junit tests now... (%d test classes)\n", strargs.length);
74 } 80 }
75 JUnitCore.main(strargs); 81
82 JUnitTask task = new JUnitTask();
83 task.setCloneVm(true);
84 task.setProject(new Project());
85 task.getProject().setSystemProperties();
86
87 task.getProject().setBasedir(".");
88 TypeAttribute ta = new TypeAttribute();
89 ta.setValue("xml");
90 FormatterElement fe = new FormatterElement();
91 fe.setType(ta);
92 task.addFormatter(fe);
93
94 File reportDir = new File("report");
95 reportDir.mkdirs();
96 File xmldir = new File(reportDir, "xml");
97 xmldir.mkdirs();
98 Set<String> ignore = new HashSet<>();
99 ignore.add("com.oracle.truffle.api.dsl.test.BinaryNodeTest");
100 ignore.add("com.oracle.truffle.api.dsl.test.ExecuteEvaluatedTest");
101 ignore.add("com.oracle.truffle.api.test.FrameTest");
102 ignore.add("com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTest");
103 ignore.add("com.oracle.truffle.sl.test.SLSimpleTestSuite");
104 ignore.add("com.oracle.graal.compiler.test.ea.UnsafeEATest");
105 ignore.add("com.oracle.graal.hotspot.test.HotSpotNmethodTest");
106 ignore.add("com.oracle.graal.hotspot.test.WriteBarrierAdditionTest");
107 ignore.add("com.oracle.graal.hotspot.test.CompressedOopTest");
108 ignore.add("com.oracle.graal.compiler.test.deopt.MonitorDeoptTest"); // Probably CString problem
109 for (String name : tests) {
110 JUnitTest t = new JUnitTest();
111 t.setName(name);
112 t.setTodir(xmldir);
113 if (new File(xmldir, "TEST-" + name + ".xml").exists() || ignore.contains(name)
114 ) {
115 System.out.println("Ignoring testclass " + name);
116 t.setIf("run.all");
117 }
118 t.setFork(false);
119 t.setHaltonerror(false);
120 t.setHaltonfailure(false);
121 task.addTest(t);
122 }
123 SummaryAttribute sa = new SummaryAttribute();
124 sa.setValue("withOutAndErr");
125 task.setPrintsummary(sa);
126 task.setFork(false);
127 task.setShowOutput(true);
128 task.setOutputToFormatters(true);
129 task.setHaltonerror(false);
130
131 task.execute();
132 XMLResultAggregator report = new XMLResultAggregator();
133 report.setProject(task.getProject());
134 report.setTofile(new File(reportDir, "unittest-report-merged.xml").getPath());
135 FileSet resultFileSet = new FileSet();
136 resultFileSet.setDir(xmldir);
137 resultFileSet.setIncludes("*");
138 report.addFileSet(resultFileSet);
139 report.execute();
140 AggregateTransformer at = report.createReport();
141 File htmlDir = new File(reportDir, "html");
142 htmlDir.mkdirs();
143 at.setTodir(htmlDir);
144 at.transform();
76 } 145 }
77 } 146 }