try new way to find classpath entries for travis ci

This commit is contained in:
Julian Dolby 2014-03-17 10:09:48 -04:00
parent 371695506d
commit b04a3f9b35
2 changed files with 41 additions and 37 deletions

View File

@ -37,31 +37,40 @@ import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.io.TemporaryFile;
public class DynamicCallGraphTests extends WalaTestCase {
public class DynamicCallGraphTest extends WalaTestCase {
private static URL testJarLocation;
static {
testJarLocation = DynamicCallGraphTests.class.getClassLoader().getResource("com.ibm.wala.core.testdata_1.0.0.jar");
if (testJarLocation == null) {
testJarLocation = DynamicCallGraphTests.class.getClassLoader().getResource("com.ibm.wala.core.testdata-1.3.4-SNAPSHOT.jar");
private static String getClasspathEntry(String elt) {
for (String s : System.getProperty("java.class.path").split(File.pathSeparator)) {
if (s.indexOf(elt) >= 0) {
File e = new File(s);
Assert.assertTrue(elt + " expected to exist", e.exists());
if (e.isDirectory() && !s.endsWith("/")) {
s = s + "/";
}
return s;
}
}
Assert.assertNotNull("cannot find test jar is classpath", testJarLocation);
Assert.assertFalse("cannot find " + elt, true);
return null;
}
private static String testJarLocation = getClasspathEntry("com.ibm.wala.core.testdata");
private boolean instrumentedJarBuilt = false;
private void instrument() throws IOException, ClassNotFoundException, InvalidClassFileException, FailureException {
if (! instrumentedJarBuilt) {
DynamicCallGraph.main(new String[]{testJarLocation.getPath(), "-o", "/tmp/test.jar"});
System.err.println("core data jar to instrument: " + testJarLocation);
DynamicCallGraph.main(new String[]{testJarLocation, "-o", "/tmp/test.jar"});
Assert.assertTrue("expected to create /tmp/test.jar", new File("/tmp/test.jar").exists());
instrumentedJarBuilt = true;
}
}
private void run(String exclusionsFile) throws IOException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
String shrikeBin = new File("../com.ibm.wala.shrike/bin/").getCanonicalPath();
String utilBin = new File("../com.ibm.wala.util/bin/").getCanonicalPath();
URLClassLoader jcl = new URLClassLoader(new URL[]{ new URL("file:///tmp/test.jar"), new URL("file://" + shrikeBin + "/"), new URL("file://" + utilBin + "/") }, DynamicCallGraphTests.class.getClassLoader().getParent());
String shrikeBin = getClasspathEntry("com.ibm.wala.shrike");
String utilBin = getClasspathEntry("com.ibm.wala.util");
URLClassLoader jcl = new URLClassLoader(new URL[]{ new URL("file:///tmp/test.jar"), new URL("file://" + shrikeBin), new URL("file://" + utilBin) }, DynamicCallGraphTest.class.getClassLoader().getParent());
Class<?> testClass = jcl.loadClass("dynamicCG.MainClass");
Assert.assertNotNull(testClass);
@ -76,7 +85,9 @@ public class DynamicCallGraphTests extends WalaTestCase {
try {
testMain.invoke(null, (Object)new String[0]);
} catch (Throwable e) {
// exceptions allowed here, just collecting CG
// exceptions here are from program being instrumented
// this is fine, since we are collecting its call graph
// and exceptions are possible behavior.
}
// the VM is not exiting, so stop tracing explicitly
@ -100,7 +111,9 @@ public class DynamicCallGraphTests extends WalaTestCase {
private void check(CallGraph staticCG) throws IOException {
BufferedReader dynamicEdgesFile = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(System.getProperty("dynamicCGFile")))));
String line;
int lines = 0;
while ((line = dynamicEdgesFile.readLine()) != null) {
lines++;
StringTokenizer edge = new StringTokenizer(line, "\t");
CGNode caller;
@ -125,6 +138,8 @@ public class DynamicCallGraphTests extends WalaTestCase {
}
dynamicEdgesFile.close();
Assert.assertTrue("more than one edge", lines > 0);
}
@Test

View File

@ -177,9 +177,11 @@ public abstract class OfflineInstrumenterBase {
*/
final class ClassInput extends Input {
final private File file;
final private File baseDirectory;
public ClassInput(File f) {
public ClassInput(File baseDirectory, File f) {
file = f;
this.baseDirectory = baseDirectory;
}
@Override
@ -194,7 +196,8 @@ public abstract class OfflineInstrumenterBase {
@Override
public String getInputName() {
return file.getPath();
int base = baseDirectory.getPath().length() + 1;
return file.getPath().substring(base);
}
}
@ -238,8 +241,8 @@ public abstract class OfflineInstrumenterBase {
/**
* Add a class file containing a source class to instrument.
*/
final public void addInputClass(File f) {
inputs.add(new ClassInput(f));
final public void addInputClass(File baseDirectory, File f) {
inputs.add(new ClassInput(baseDirectory, f));
}
/**
@ -247,7 +250,7 @@ public abstract class OfflineInstrumenterBase {
*
* @throws IllegalArgumentException if d is null
*/
final public void addInputDirectory(File d) throws IOException, IllegalArgumentException {
final public void addInputDirectory(File baseDirectory, File d) throws IOException, IllegalArgumentException {
if (d == null) {
throw new IllegalArgumentException("d is null");
}
@ -263,9 +266,9 @@ public abstract class OfflineInstrumenterBase {
for (int i = 0; i < fs.length; i++) {
File f = fs[i];
if (f.isDirectory()) {
addInputDirectory(f);
addInputDirectory(baseDirectory, f);
} else {
addInputClass(f);
addInputClass(baseDirectory, f);
}
}
}
@ -276,7 +279,7 @@ public abstract class OfflineInstrumenterBase {
*
* @throws IllegalArgumentException if a is null
*/
final public boolean addInputElement(String a) throws IOException {
final public boolean addInputElement(File baseDirectory, String a) throws IOException {
if (a == null) {
throw new IllegalArgumentException("a is null");
}
@ -288,11 +291,11 @@ public abstract class OfflineInstrumenterBase {
}
File f = new File(a);
if (f.isDirectory()) {
addInputDirectory(f);
addInputDirectory(baseDirectory, f);
return true;
} else if (f.exists()) {
if (a.endsWith(".class")) {
addInputClass(f);
addInputClass(baseDirectory, f);
return true;
} else if (a.endsWith(".jar") || a.endsWith(".zip")) {
addInputJar(new File(a));
@ -330,7 +333,7 @@ public abstract class OfflineInstrumenterBase {
i++;
continue;
} else if (!a.startsWith("-")) {
if (addInputElement(a)) {
if (addInputElement(new File(a), a)) {
continue;
}
} else if (a.startsWith("--")) {
@ -354,20 +357,6 @@ public abstract class OfflineInstrumenterBase {
return inputs.size();
}
/**
* Read a list of class file names from a stream and add them to the list of things to instrument.
*/
final public void readInputClasses(InputStream s) throws IOException, IllegalArgumentException {
if (s == null) {
throw new IllegalArgumentException("illegal null inputStream");
}
String str;
BufferedReader r = new BufferedReader(new InputStreamReader(s));
while ((str = r.readLine()) != null) {
addInputElement(str);
}
}
/**
* Start traversing the source class list from the beginning.
*/