Unverified 提交 c27bcf5a authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #791 from katzyn/coverage

Switch to JaCoCo code coverage
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
.settings .settings
benchmark.html benchmark.html
bin bin
coverage
data data
docs docs
ext ext
......
...@@ -63,7 +63,6 @@ To use this database, it is not required to install this software however. ...@@ -63,7 +63,6 @@ To use this database, it is not required to install this software however.
<a href="http://subclipse.tigris.org">Subclipse</a>, <a href="http://subclipse.tigris.org">Subclipse</a>,
<a href="http://eclipse-cs.sourceforge.net">Eclipse Checkstyle Plug-in</a>, <a href="http://eclipse-cs.sourceforge.net">Eclipse Checkstyle Plug-in</a>,
<a href="http://www.eclemma.org">EclEmma Java Code Coverage</a> <a href="http://www.eclemma.org">EclEmma Java Code Coverage</a>
</li><li><a href="http://emma.sourceforge.net">Emma Java Code Coverage</a>
</li><li><a href="http://www.mozilla.com/firefox">Mozilla Firefox</a> </li><li><a href="http://www.mozilla.com/firefox">Mozilla Firefox</a>
</li><li><a href="http://www.openoffice.org">OpenOffice</a> </li><li><a href="http://www.openoffice.org">OpenOffice</a>
</li><li><a href="http://nsis.sourceforge.net">NSIS</a> (Nullsoft Scriptable Install System) </li><li><a href="http://nsis.sourceforge.net">NSIS</a> (Nullsoft Scriptable Install System)
......
...@@ -303,11 +303,6 @@ java org.h2.test.TestAll timer ...@@ -303,11 +303,6 @@ java org.h2.test.TestAll timer
*/ */
public boolean memory; public boolean memory;
/**
* Whether the test is running with code coverage.
*/
public boolean coverage;
/** /**
* If code coverage is enabled. * If code coverage is enabled.
*/ */
...@@ -548,7 +543,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -548,7 +543,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
test.testEverything(); test.testEverything();
} else if ("codeCoverage".equals(args[0])) { } else if ("codeCoverage".equals(args[0])) {
test.codeCoverage = true; test.codeCoverage = true;
test.runTests(); test.runCoverage();
} else if ("multiThread".equals(args[0])) { } else if ("multiThread".equals(args[0])) {
new TestMulti().runTest(test); new TestMulti().runTest(test);
} else if ("halt".equals(args[0])) { } else if ("halt".equals(args[0])) {
...@@ -611,8 +606,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -611,8 +606,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
abbaLockingDetector = new AbbaLockingDetector().startCollecting(); abbaLockingDetector = new AbbaLockingDetector().startCollecting();
} }
coverage = isCoverage();
smallLog = big = networked = memory = ssl = false; smallLog = big = networked = memory = ssl = false;
diskResult = traceSystemOut = diskUndo = false; diskResult = traceSystemOut = diskUndo = false;
traceTest = stopOnError = false; traceTest = stopOnError = false;
...@@ -697,18 +690,24 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -697,18 +690,24 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
} }
} }
/** private void runCoverage() throws SQLException {
* Check whether this method is running with "Emma" code coverage turned on. smallLog = big = networked = memory = ssl = false;
* diskResult = traceSystemOut = diskUndo = false;
* @return true if the stack trace contains ".emma." traceTest = stopOnError = false;
*/ defrag = false;
private static boolean isCoverage() { traceLevelFile = throttle = 0;
for (StackTraceElement e : Thread.currentThread().getStackTrace()) { cipher = null;
if (e.toString().contains(".emma.")) {
return true; memory = true;
} multiThreaded = true;
} test();
return false; testUnit();
multiThreaded = false;
mvStore = false;
mvcc = false;
test();
// testUnit();
} }
/** /**
......
...@@ -40,7 +40,7 @@ public class TestMVStoreBenchmark extends TestBase { ...@@ -40,7 +40,7 @@ public class TestMVStoreBenchmark extends TestBase {
if (!config.big) { if (!config.big) {
return; return;
} }
if (config.coverage || config.codeCoverage) { if (config.codeCoverage) {
// run only when _not_ using a code coverage tool, // run only when _not_ using a code coverage tool,
// because the tool might instrument our code but not // because the tool might instrument our code but not
// java.util.* // java.util.*
......
...@@ -6,15 +6,22 @@ ...@@ -6,15 +6,22 @@
package org.h2.build; package org.h2.build;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.h2.build.code.SwitchSource; import org.h2.build.code.SwitchSource;
import org.h2.build.doc.XMLParser; import org.h2.build.doc.XMLParser;
...@@ -114,17 +121,67 @@ public class Build extends BuildBase { ...@@ -114,17 +121,67 @@ public class Build extends BuildBase {
javac(args, files); javac(args, files);
} }
private static void copy(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[8192];
int read;
while ((read = in.read(buffer, 0, buffer.length)) >= 0) {
out.write(buffer, 0, read);
}
}
/** /**
* Run the Emma code coverage. * Run the JaCoco code coverage.
*/ */
@Description(summary = "Run the Emma code coverage.") @Description(summary = "Run the JaCoco code coverage.")
public void coverage() { public void coverage() {
compile();
downloadTest(); downloadTest();
downloadUsingMaven("ext/emma-2.0.5312.jar", downloadUsingMaven("ext/org.jacoco.agent-0.8.0.jar",
"emma", "emma", "2.0.5312", "org.jacoco", "org.jacoco.agent", "0.8.0",
"30a40933caf67d88d9e75957950ccf353b181ab7"); "f2748b949b5fc661e089e2eeef39891dfd10a7e5");
String cp = "temp" + File.pathSeparator + "bin" + try (ZipFile zipFile = new ZipFile(new File("ext/org.jacoco.agent-0.8.0.jar"))) {
File.pathSeparator + "ext/emma-2.0.5312.jar" + final Enumeration<? extends ZipEntry> e = zipFile.entries();
while (e.hasMoreElements()) {
final ZipEntry zipEntry = e.nextElement();
final String name = zipEntry.getName();
if (name.equals("jacocoagent.jar")) {
try (InputStream in = zipFile.getInputStream(zipEntry);
FileOutputStream out = new FileOutputStream("ext/jacocoagent.jar")) {
copy(in, out);
}
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
downloadUsingMaven("ext/org.jacoco.cli-0.8.0.jar",
"org.jacoco", "org.jacoco.cli", "0.8.0",
"69e55ba110e6ffa91d72ed3df8e09aecf043b0ab");
downloadUsingMaven("ext/org.jacoco.core-0.8.0.jar",
"org.jacoco", "org.jacoco.core", "0.8.0",
"cc2ebdc1da53665ec788903bad65ee64345e4455");
downloadUsingMaven("ext/org.jacoco.report-0.8.0.jar",
"org.jacoco", "org.jacoco.report", "0.8.0",
"1bcab2a451f5a382bc674857c8f3f6d3fa52151d");
downloadUsingMaven("ext/asm-6.1-beta.jar",
"org.ow2.asm", "asm", "6.1-beta",
"bac2f84e42b7db902103a9ec8c4ca1293223e0ea");
downloadUsingMaven("ext/asm-commons-6.1-beta.jar",
"org.ow2.asm", "asm-commons", "6.1-beta",
"4ec77cde3be41559f92d25cdb39b9c55ee479253");
downloadUsingMaven("ext/asm-tree-6.1-beta.jar",
"org.ow2.asm", "asm-tree", "6.1-beta",
"539d3b0f5f7f5b04b1c286de8e76655b59ab2d43");
downloadUsingMaven("ext/args4j-2.33.jar",
"args4j", "args4j", "2.33",
"bd87a75374a6d6523de82fef51fc3cfe9baf9fc9");
delete(files("coverage"));
// Use own copy
copy("coverage/bin", files("temp"), "temp");
// JaCoCo does not support multiple versions of the same classes
delete(files("coverage/bin/META-INF/versions"));
String cp = "coverage/bin" +
File.pathSeparator + "ext/postgresql-9.4.1209.jre6.jar" + File.pathSeparator + "ext/postgresql-9.4.1209.jre6.jar" +
File.pathSeparator + "ext/servlet-api-3.1.0.jar" + File.pathSeparator + "ext/servlet-api-3.1.0.jar" +
File.pathSeparator + "ext/lucene-core-3.6.2.jar" + File.pathSeparator + "ext/lucene-core-3.6.2.jar" +
...@@ -135,17 +192,43 @@ public class Build extends BuildBase { ...@@ -135,17 +192,43 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/slf4j-nop-1.6.0.jar" + File.pathSeparator + "ext/slf4j-nop-1.6.0.jar" +
File.pathSeparator + javaToolsJar; File.pathSeparator + javaToolsJar;
// -XX:-UseSplitVerifier is for Java 7 compatibility // Run tests
execJava(args( execJava(args(
"-Xmx128m", "-Xmx128m",
"-XX:-UseSplitVerifier", "-javaagent:ext/jacocoagent.jar=destfile=coverage/jacoco.exec,"
"-cp", cp, "emma", "run", + "excludes=org.h2.test.*:org.h2.tools.*:org.h2.sample.*:android.*",
"-cp", "temp", "-cp", cp,
"-sp", "src/main", "org.h2.test.TestAll", "codeCoverage"));
"-r", "html,txt", // Remove classes that we don't want to include in report
"-ix", "-org.h2.test.*,-org.h2.dev.*," + delete(files("coverage/bin/android"));
"-org.h2.jaqu.*,-org.h2.mode.*,-org.h2.server.pg.*", delete(files("coverage/bin/org/h2/test"));
"org.h2.test.TestAll")); delete(files("coverage/bin/org/h2/tools"));
delete(files("coverage/bin/org/h2/sample"));
// Generate report
execJava(args("-cp",
"ext/org.jacoco.cli-0.8.0.jar" + File.pathSeparator
+ "ext/org.jacoco.core-0.8.0.jar" + File.pathSeparator
+ "ext/org.jacoco.report-0.8.0.jar" + File.pathSeparator
+ "ext/asm-6.1-beta.jar" + File.pathSeparator
+ "ext/asm-commons-6.1-beta.jar" + File.pathSeparator
+ "ext/asm-tree-6.1-beta.jar" + File.pathSeparator
+ "ext/args4j-2.33.jar",
"org.jacoco.cli.internal.Main", "report", "coverage/jacoco.exec",
"--classfiles", "coverage/bin",
"--html", "coverage/report", "--sourcefiles", "h2/src/main"));
try {
tryOpenCoverageInBrowser();
} catch (Throwable e) {
e.printStackTrace();
}
}
private static void tryOpenCoverageInBrowser() throws Exception {
Class<?> desktop = Class.forName("java.awt.Desktop");
Method m = desktop.getMethod("getDesktop");
Object d = m.invoke(null);
m = d.getClass().getMethod("open", File.class);
m.invoke(d, new File("coverage/report/index.html"));
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论