Skip to content

Commit b403d66

Browse files
committed
Merge pull request #99 from testmycode/valgrind-fix-and-release
Valgrind fix and release
2 parents ddd49f4 + ae7f4ae commit b403d66

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

tmc-plugin/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ OpenIDE-Module-Requires:
66
org.openide.windows.IOProvider,
77
org.openide.windows.WindowManager
88
OpenIDE-Module-Install: fi/helsinki/cs/tmc/actions/TmcModuleInstall.class
9-
OpenIDE-Module-Specification-Version: 0.8.6
9+
OpenIDE-Module-Specification-Version: 0.8.7

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) {

tmc-plugin/test/unit/src/fi/helsinki/cs/tmc/data/serialization/cresultparser/CTestResultParserTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void testParsingWithValgrindOutput() {
129129
CTestResultParser cpar = null;
130130
try {
131131
File ttmp = constructTestOutput(oneOfEachTest);
132-
File vtmp = constructNotMemoryFailingValgrindOutput(oneOfEachTest);
132+
File vtmp = constructMemoryFailingValgrindOutput();
133133

134134
cpar = new CTestResultParser(ttmp, vtmp, null);
135135
cpar.parseTestOutput();
@@ -140,11 +140,12 @@ public void testParsingWithValgrindOutput() {
140140
}
141141
List<TestCaseResult> results = cpar.getTestCaseResults();
142142
assertEquals("There should be two test results", 2, results.size());
143-
int i = 2;
144-
for (TestCaseResult r : results) {
145-
assertEquals("==" + i * 2 + "== " + (i - 1), r.getDetailedMessage().split("\n")[1]);
146-
i++;
147-
}
143+
assertNotNull("Valgrind errors should go in detailed message",
144+
results.get(0).getDetailedMessage());
145+
assertTrue("Valgrind errors should go in detailed message",
146+
results.get(0).getDetailedMessage().contains("==1== 1"));
147+
assertNull("Valgrind output should go into detailed message if there were not errors",
148+
results.get(1).getDetailedMessage());
148149
}
149150

150151
@Test
@@ -163,10 +164,9 @@ public void testTestsPassWhenNoMemoryErrors() {
163164
}
164165
List<TestCaseResult> results = cpar.getTestCaseResults();
165166
assertEquals("There should be two test results", 2, results.size());
166-
int i = 2;
167167
for (TestCaseResult r : results) {
168-
assertEquals("==" + i * 2 + "== " + (i - 1), r.getDetailedMessage().split("\n")[1]);
169-
i++;
168+
assertNull("Valgrind output should be empty when there was no error",
169+
r.getDetailedMessage());
170170
}
171171
}
172172

0 commit comments

Comments
 (0)