1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.scalabench.plugins.dacapo;
19
20 import static java.lang.String.format;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.SortedMap;
27 import java.util.TreeMap;
28
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.scalabench.dacapo.callback.MarshallingSupport;
32 import org.scalabench.dacapo.callback.summary.Invocation;
33 import org.scalabench.dacapo.callback.summary.Iteration;
34 import org.scalabench.dacapo.callback.summary.Summary;
35 import org.scalabench.plugins.dacapo.util.SizeNameComparator;
36
37
38
39
40
41
42
43
44
45
46
47
48 public class VerifyMojo extends AbstractIntegrationTestMojo {
49
50
51
52
53
54
55
56 private boolean testFailureIgnore;
57
58
59
60
61
62
63 private File summaryFile;
64
65 public boolean isTestFailureIgnore() {
66 return testFailureIgnore;
67 }
68
69 @Override
70 public void execute() throws MojoExecutionException, MojoFailureException {
71 if (isSkipExecution()) {
72 logInfo("Tests are skipped.");
73 } else {
74 verifySummaryFile();
75 }
76 }
77
78 private void verifySummaryFile() throws MojoExecutionException, MojoFailureException {
79 final Summary summary = loadSummaryFromFile();
80 reportBenchmarkInvocations(summary);
81 }
82
83 private Summary loadSummaryFromFile() throws MojoExecutionException {
84 final Summary summary;
85
86 logInfo("Verifying DaCapo benchmark summary file: %s", summaryFile);
87
88 try {
89 summary = MarshallingSupport.loadSummary(summaryFile);
90 } catch (IOException e) {
91 throw new MojoExecutionException(format("Failed to load summary file: %s", summaryFile), e);
92 }
93
94 if (!getBenchmarkName().equals(summary.getBenchmark()))
95 throw new MojoExecutionException(format("Found summary for wrong benchmark: %s", summary.getBenchmark()));
96
97 return summary;
98 }
99
100 public void reportBenchmarkInvocations(Summary result) throws MojoFailureException {
101 final SortedMap<String, List<Invocation>> invocationsPerSize =
102 new TreeMap<String, List<Invocation>>(new SizeNameComparator());
103
104 for (Invocation invocation : result.getInvocations()) {
105 List<Invocation> invocations;
106 if ((invocations = invocationsPerSize.get(invocation.getSize())) == null)
107 invocationsPerSize.put(invocation.getSize(), invocations = new ArrayList<Invocation>());
108 invocations.add(invocation);
109 }
110
111 int failedInvocations = 0;
112
113 for (String size : invocationsPerSize.keySet()) {
114 for (Invocation invocation : invocationsPerSize.get(size)) {
115 final int failedIterations = countFailedIterations(invocation.getIterations());
116 if (failedIterations > 0) {
117 logError("Failed %2$d iterations of \"%1$s\" input size", size, failedIterations);
118 failedInvocations++;
119 }
120 }
121
122 if (failedInvocations > 0) {
123 logError("Failed %2$d invocations of \"%1$s\" input size", size, failedInvocations);
124 }
125 }
126
127 if (failedInvocations != 0) {
128 if (isTestFailureIgnore())
129 logError("There are test failures.");
130 else
131 throw new MojoFailureException("There are test failures.");
132 }
133 }
134
135 public static int countFailedIterations(List<? extends Iteration> iterations) {
136 int failedIterations = 0;
137
138 for (Iteration iteration : iterations)
139 if (!iteration.isValid())
140 failedIterations++;
141
142 return failedIterations;
143 }
144 }