Skip to content

Commit 80a705f

Browse files
committed
More CTestResultParser robustification (PR #98).
1 parent ddd49f4 commit 80a705f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/data/serialization/cresultparser/CTestResultParser.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ private void addValgrindOutput() throws FileNotFoundException {
136136
outputs[i] = "";
137137
}
138138

139-
Pattern errorPattern = Pattern.compile("ERROR SUMMARY: ([0-9]+)");
139+
Pattern errorPattern = Pattern.compile("==[0-9]+== ERROR SUMMARY: ([0-9]+)");
140140

141141
String line = scanner.nextLine();
142142
int firstPID = parsePID(line);
143143
parentOutput += "\n" + line;
144+
boolean warningLogged = false;
144145
while (scanner.hasNextLine()) {
145146
line = scanner.nextLine();
146147
int pid = parsePID(line);
@@ -150,10 +151,18 @@ private void addValgrindOutput() throws FileNotFoundException {
150151
if (pid == firstPID) {
151152
parentOutput += "\n" + line;
152153
} else {
153-
outputs[findIndex(pid, pids)] += "\n" + line;
154+
int outputIndex = findIndex(pid, pids);
155+
if (outputIndex == -1) {
156+
if (!warningLogged) {
157+
log.warning("Valgrind output has more PIDs than the expected (# of test cases + 1).");
158+
warningLogged = true;
159+
}
160+
continue;
161+
}
162+
outputs[outputIndex] += "\n" + line;
154163
Matcher m = errorPattern.matcher(line);
155164
if (m.find()) {
156-
errors[findIndex(pid, pids)] = Integer.parseInt(m.group(1));
165+
errors[outputIndex] = Integer.parseInt(m.group(1));
157166
}
158167
}
159168
}
@@ -162,7 +171,7 @@ private void addValgrindOutput() throws FileNotFoundException {
162171
for (int i = 0; i < outputs.length; i++) {
163172
if (errors[i] == 0) {
164173
// Workaround for a bug where any valgrind output is considered a potential error.
165-
outputs[i] = "";
174+
outputs[i] = null;
166175
}
167176
tests.get(i).setValgrindTrace(outputs[i]);
168177
}
@@ -178,7 +187,7 @@ private int findIndex(int pid, int[] pids) {
178187
return i;
179188
}
180189
}
181-
return 0;
190+
return -1;
182191
}
183192

184193
private int parsePID(String line) {

0 commit comments

Comments
 (0)