Skip to content

Commit 8f110d8

Browse files
committed
Option to log to a test case file based on failsfe test running
1 parent 6d82de4 commit 8f110d8

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

Code/ChroniclerJ/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@
7878
<includes>
7979
<include>**/*ITCase.java</include>
8080
</includes>
81-
<!-- <argLine>-Xbootclasspath/p:${project.build.directory}/${project.build.finalName}.jar
82-
-javaagent:${project.build.directory}/${project.build.finalName}.jar=enum,acmpeq,cacheDir=${project.build.directory}/cached-int-untaged,withSelectiveInst=${basedir}/resources/test-methods</argLine> -->
81+
<argLine>-Xbootclasspath/p:${project.build.directory}/${project.build.finalName}.jar
82+
-javaagent:${project.build.directory}/${project.build.finalName}.jar=failsafe,alwaysExport</argLine>
83+
<reuseForks>false</reuseForks>
8384
</configuration>
8485
<goals>
8586
<goal>integration-test</goal>

Code/ChroniclerJ/src/main/java/edu/columbia/cs/psl/chroniclerj/PreMain.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import java.io.FileInputStream;
55
import java.io.FileOutputStream;
66
import java.io.FileWriter;
7+
import java.io.IOException;
78
import java.io.PrintWriter;
89
import java.lang.instrument.ClassFileTransformer;
910
import java.lang.instrument.IllegalClassFormatException;
1011
import java.lang.instrument.Instrumentation;
1112
import java.security.ProtectionDomain;
13+
import java.util.Scanner;
1214

1315
import org.objectweb.asm.ClassReader;
1416
import org.objectweb.asm.ClassWriter;
@@ -33,7 +35,8 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
3335
ClassReader cr = new ClassReader(classfileBuffer);
3436
if (isIgnoredClass(cr.getClassName()))
3537
return null;
36-
System.out.println("Inst: " + cr.getClassName());
38+
if (DEBUG)
39+
System.out.println("Inst: " + cr.getClassName());
3740
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
3841
NonDeterministicReplayClassVisitor cv = new NonDeterministicReplayClassVisitor(Opcodes.ASM5, cw);
3942
cr.accept(cv, ClassReader.EXPAND_FRAMES);
@@ -54,7 +57,8 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
5457
ClassReader cr = new ClassReader(classfileBuffer);
5558
if (isIgnoredClass(cr.getClassName()))
5659
return null;
57-
System.out.println("Inst: " + cr.getClassName());
60+
if (DEBUG)
61+
System.out.println("Inst: " + cr.getClassName());
5862
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
5963
NonDeterministicLoggingClassVisitor cv = new NonDeterministicLoggingClassVisitor(new SerialVersionUIDAdder(cw));
6064
CallbackDuplicatingClassVisitor callbackDuplicator = new CallbackDuplicatingClassVisitor(cv);
@@ -124,6 +128,34 @@ public static void premain(String _args, Instrumentation inst) {
124128
ChroniclerJExportRunner.registerShutdownHook();
125129
} else if (d[0].equals("debug"))
126130
DEBUG = true;
131+
else if (d[0].equals("failsafe")) {
132+
try {
133+
// Read in the log file name based on the maven failsafe
134+
// config.
135+
File config = new File(System.getProperty("sun.java.command").split(" ")[1]);
136+
Scanner s = new Scanner(config);
137+
String testClass = null;
138+
while (s.hasNextLine()) {
139+
String line = s.nextLine();
140+
if (line.startsWith("tc.")) {
141+
testClass = line.split("=")[1];
142+
break;
143+
}
144+
}
145+
s.close();
146+
if (testClass == null)
147+
throw new IOException("Couldn't find test config");
148+
if (replay) {
149+
150+
} else {
151+
System.out.println("Overriding test class: " + testClass);
152+
ChroniclerJExportRunner.nameOverride = "target/"+testClass + ".crash";
153+
}
154+
} catch (IOException ex) {
155+
ex.printStackTrace();
156+
System.err.println("Unable to load in failsafe config");
157+
}
158+
}
127159
}
128160
}
129161
ClassFileTransformer transformer = new ChroniclerTransformer();

Code/ChroniclerJ/src/test/java/edu/columbia/cs/psl/test/chroniclerj/RandomITCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ public class RandomITCase {
66

77
public static void main(String[] args) {
88
System.out.println(Math.random());
9-
throw new NullPointerException();
109
}
1110

1211
@Test
1312
public void testRandom() throws Exception {
1413
System.out.println(Math.random());
14+
throw new NullPointerException();
15+
1516
}
1617
}

0 commit comments

Comments
 (0)