Skip to content

Commit fb9ddad

Browse files
committed
Added logging and added support for valgrind strategy.
1 parent 6d11144 commit fb9ddad

File tree

10 files changed

+126
-60
lines changed

10 files changed

+126
-60
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/RunTestsLocallyAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import fi.helsinki.cs.tmc.model.ProjectMediator;
77
import fi.helsinki.cs.tmc.runners.CheckstyleRunHandler;
88
import fi.helsinki.cs.tmc.runners.TestRunHandler;
9+
import java.util.logging.Logger;
910
import org.netbeans.api.project.Project;
1011
import org.openide.nodes.Node;
1112
import org.openide.util.NbBundle.Messages;
1213
import org.openide.windows.WindowManager;
1314

1415
@Messages("CTL_RunTestsLocallyExerciseAction=Run &tests locally")
1516
public class RunTestsLocallyAction extends AbstractExerciseSensitiveAction implements Runnable {
17+
protected static final Logger log = Logger.getLogger(RunTestsLocallyAction.class.getName());
1618

1719
private CourseDb courseDb;
1820
private ProjectMediator projectMediator;
@@ -67,7 +69,6 @@ protected boolean enabledFor(Exercise exercise) {
6769

6870
@Override
6971
public void run() {
70-
7172
Exercise exercise = exerciseForProject(project);
7273
if (exercise != null) {
7374
ResultCollector resultCollector = new ResultCollector(exercise);

tmc-plugin/src/fi/helsinki/cs/tmc/data/Exercise.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@
77
public class Exercise implements Serializable {
88

99
private int id;
10-
10+
1111
private String name;
12-
12+
1313
private String courseName;
14-
14+
1515
/**
1616
* The URL this exercise can be downloaded from.
1717
*/
1818
@SerializedName("zip_url")
1919
private String downloadUrl;
20-
20+
2121
/**
2222
* The URL the solution can be downloaded from (admins only).
2323
*/
2424
@SerializedName("solution_zip_url")
2525
private String solutionDownloadUrl;
26-
26+
2727
/**
2828
* The URL where this exercise should be posted for review.
2929
*/
3030
@SerializedName("return_url")
3131
private String returnUrl;
32-
32+
3333
private boolean locked;
34-
34+
3535
@SerializedName("deadline_description")
3636
private String deadlineDescription;
37-
37+
3838
private Date deadline;
39-
39+
4040
private boolean returnable;
4141
@SerializedName("requires_review")
4242
private boolean requiresReview;
@@ -46,13 +46,24 @@ public class Exercise implements Serializable {
4646
@SerializedName("all_review_points_given")
4747
private boolean allReviewPointsGiven;
4848
private String checksum;
49-
49+
5050
@SerializedName("memory_limit")
5151
private Integer memoryLimit;
5252

5353
@SerializedName("runtime_params")
5454
private String[] runtimeParams;
5555

56+
57+
@SerializedName("valgrind_strategy")
58+
private ValgrindStrategy valgrindStrategy;
59+
60+
public enum ValgrindStrategy {
61+
@SerializedName("")
62+
NONE,
63+
@SerializedName("fail")
64+
FAIL
65+
}
66+
5667
public Exercise() {
5768
}
5869

@@ -72,7 +83,7 @@ public int getId() {
7283
public void setId(int id) {
7384
this.id = id;
7485
}
75-
86+
7687
public String getName() {
7788
return this.name;
7889
}
@@ -102,7 +113,7 @@ public String getDeadlineDescription() {
102113
public void setDeadlineDescription(String deadlineDescription) {
103114
this.deadlineDescription = deadlineDescription;
104115
}
105-
116+
106117
public boolean hasDeadlinePassed() {
107118
return hasDeadlinePassedAt(new Date());
108119
}
@@ -117,7 +128,7 @@ public boolean hasDeadlinePassedAt(Date time) {
117128
return false;
118129
}
119130
}
120-
131+
121132
public ExerciseKey getKey() {
122133
return new ExerciseKey(courseName, name);
123134
}
@@ -129,7 +140,7 @@ public String getCourseName() {
129140
public void setCourseName(String courseName) {
130141
this.courseName = courseName;
131142
}
132-
143+
133144
public String getDownloadUrl() {
134145
return this.downloadUrl;
135146
}
@@ -166,15 +177,15 @@ public void setReturnUrl(String returnAddress) {
166177
}
167178
this.returnUrl = returnAddress;
168179
}
169-
180+
170181
public Date getDeadline() {
171182
return deadline;
172183
}
173184

174185
public void setDeadline(Date deadline) {
175186
this.deadline = deadline;
176187
}
177-
188+
178189
public boolean isReturnable() {
179190
return returnable && !hasDeadlinePassed();
180191
}
@@ -247,6 +258,9 @@ public void setRuntimeParams(String[] runtimeParams) {
247258
this.runtimeParams = runtimeParams;
248259
}
249260

261+
public ValgrindStrategy getValgrindStrategy() {
262+
return valgrindStrategy;
263+
}
250264
@Override
251265
public String toString() {
252266
return name;

tmc-plugin/src/fi/helsinki/cs/tmc/data/TestCaseResult.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ public class TestCaseResult {
1515

1616
public TestCaseResult() {
1717
}
18-
18+
1919
public TestCaseResult(String name, boolean successful, String message) {
2020
this.name = name;
2121
this.successful = successful;
2222
this.message = message;
2323
}
24-
24+
2525
public TestCaseResult(String name, boolean successful, String message, String valgrindTrace) {
2626
this(name, successful, message);
2727
this.detailedMessage = valgrindTrace;
2828
}
29-
29+
3030
public String getName() {
3131
return name;
3232
}
@@ -44,12 +44,12 @@ public String getMessage() {
4444
public CaughtException getException() {
4545
return exception;
4646
}
47-
47+
4848
@CheckForNull
4949
public String getDetailedMessage() {
5050
return detailedMessage;
5151
}
52-
52+
5353
/**
5454
* Creates a TestCaseResult from a TestCase probably returned by a local run of tmc-junit-runner.
5555
*/

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import fi.helsinki.cs.tmc.data.Exercise.ValgrindStrategy;
56
import fi.helsinki.cs.tmc.data.TestCaseResult;
67
import fi.helsinki.cs.tmc.data.TestRunResult;
78
import fi.helsinki.cs.tmc.data.serialization.cresultparser.CTestResultParser;
@@ -37,9 +38,9 @@ public TestRunResult parseTestResults(String resultsJson) {
3738
return new TestRunResult(testCaseResults);
3839
}
3940

40-
public TestRunResult parseCTestResults(File resultsFile, File valgrindLog) throws Exception {
41+
public TestRunResult parseCTestResults(File resultsFile, File valgrindLog, ValgrindStrategy valgrindStrategy) throws Exception {
4142
// CTestResultParser could use refactoring. Duplicates parseTestResults and is kinda messy.
42-
CTestResultParser parser = new CTestResultParser(resultsFile, valgrindLog);
43+
CTestResultParser parser = new CTestResultParser(resultsFile, valgrindLog, valgrindStrategy);
4344
parser.parseTestOutput();
4445
return new TestRunResult(parser.getTestCaseResults());
4546
}

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,70 @@
11
package fi.helsinki.cs.tmc.data.serialization.cresultparser;
22

3+
import fi.helsinki.cs.tmc.data.Exercise.ValgrindStrategy;
34
import fi.helsinki.cs.tmc.data.TestCaseResult;
5+
import java.util.logging.Logger;
6+
import org.apache.commons.lang3.StringUtils;
7+
48

59
public class CTestCase {
10+
11+
private static final Logger log = Logger.getLogger(CTestCase.class.getName());
12+
13+
614
private String name;
715
private String result;
816
private String message;
917
private String points;
1018
private String valgrindTrace;
19+
private ValgrindStrategy valgrindStrategy;
1120
private boolean checkedForMemoryLeaks;
1221
private int maxBytesAllocated = -1;
1322

14-
public CTestCase(String name, String result, String message, String points, String valgrindTrace) {
23+
public CTestCase(String name, String result, String message, String points, String valgrindTrace, ValgrindStrategy valgrindStrategy) {
1524
this(name);
1625
this.result = result;
1726
this.message = message;
1827
this.points = points;
1928
this.valgrindTrace = valgrindTrace;
29+
this.valgrindStrategy = valgrindStrategy;
2030
this.checkedForMemoryLeaks = false;
2131
}
2232

23-
public CTestCase(String name, String result, String message) {
24-
this(name, result, message, null, null);
33+
public CTestCase(String name, String result, String message, ValgrindStrategy valgrindStrategy) {
34+
this(name, result, message, null, null, valgrindStrategy);
2535
}
2636

2737
public CTestCase(String name) {
2838
this.name = name;
2939
}
30-
40+
41+
private boolean failedDueToValgrind(String valgrindTrace) {
42+
if (ValgrindStrategy.FAIL == valgrindStrategy) {
43+
return StringUtils.isNotBlank(valgrindTrace);
44+
}
45+
return false;
46+
}
47+
3148
public TestCaseResult createTestCaseResult() {
32-
boolean successful = (result.equals("success"));
49+
boolean successful; // = valgrindPassedGivenStragegy(valgrindStrategy, valgrindTrace);
50+
3351
String msg = message;
52+
53+
if (ValgrindStrategy.FAIL == valgrindStrategy) {
54+
boolean valgrindFailed = failedDueToValgrind(valgrindTrace);
55+
successful = ((result.equals("success")) && !valgrindFailed);
56+
if (valgrindFailed) {
57+
if ("Passed".equals(msg)) {
58+
msg = "Failed due to errors in valgrind log; see log below";
59+
}
60+
61+
}
62+
} else {
63+
successful = result.equals("success");
64+
}
3465
return new TestCaseResult(name, successful, msg, valgrindTrace);
3566
}
36-
67+
3768
public String getName() {
3869
return name;
3970
}
@@ -73,15 +104,15 @@ public String getValgrindTrace() {
73104
public void setValgrindTrace(String valgrindTrace) {
74105
this.valgrindTrace = valgrindTrace;
75106
}
76-
107+
77108
public boolean isCheckedForMemoryLeaks() {
78109
return checkedForMemoryLeaks;
79110
}
80-
111+
81112
public boolean isCheckedForMemoryUsage() {
82113
return this.maxBytesAllocated >= 0;
83114
}
84-
115+
85116
public int getMaxBytesAllocated() {
86117
return maxBytesAllocated;
87118
}
@@ -93,5 +124,5 @@ public void setMaxBytesAllocated(int maxAllocations) {
93124
public void setCheckedForMemoryLeaks(boolean checkedForMemoryLeaks) {
94125
this.checkedForMemoryLeaks = checkedForMemoryLeaks;
95126
}
96-
97-
}
127+
128+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fi.helsinki.cs.tmc.data.serialization.cresultparser;
22

3+
import fi.helsinki.cs.tmc.data.Exercise;
4+
import fi.helsinki.cs.tmc.data.Exercise.ValgrindStrategy;
35
import fi.helsinki.cs.tmc.data.TestCaseResult;
46
import java.io.File;
57
import java.io.FileInputStream;
@@ -26,11 +28,13 @@ public class CTestResultParser {
2628

2729
private File testResults;
2830
private File valgrindOutput;
31+
private Exercise.ValgrindStrategy valgrindStrategy;
2932
private ArrayList<CTestCase> tests;
3033

31-
public CTestResultParser(File testResults, File valgrindOutput) {
34+
public CTestResultParser(File testResults, File valgrindOutput, ValgrindStrategy valgrindStrategy) {
3235
this.testResults = testResults;
3336
this.valgrindOutput = valgrindOutput;
37+
this.valgrindStrategy = valgrindStrategy;
3438
this.tests = new ArrayList<CTestCase>();
3539
}
3640

@@ -90,7 +94,7 @@ private ArrayList<CTestCase> parseTestCases(File testOutput) throws ParserConfig
9094
String result = node.getAttribute("result");
9195
String name = node.getElementsByTagName("description").item(0).getTextContent();
9296
String message = node.getElementsByTagName("message").item(0).getTextContent();
93-
cases.add(new CTestCase(name, result, message));
97+
cases.add(new CTestCase(name, result, message, valgrindStrategy));
9498
}
9599

96100
return cases;

tmc-plugin/src/fi/helsinki/cs/tmc/runners/AbstractExerciseRunner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fi.helsinki.cs.tmc.runners;
22

3-
import fi.helsinki.cs.tmc.actions.RunTestsLocallyAction;
43
import fi.helsinki.cs.tmc.data.Exercise;
54
import fi.helsinki.cs.tmc.data.serialization.TestResultParser;
65
import fi.helsinki.cs.tmc.events.TmcEventBus;

0 commit comments

Comments
 (0)