Index: build/build.bat =================================================================== --- build/build.bat (revision 480889) +++ build/build.bat (working copy) @@ -126,7 +126,7 @@ SET CLASSPATH=%CLASSPATH%;.\make\tmp\xalan.jar SET CLASSPATH=%CD%\make\tmp\cpptasks\patched.classes;%CLASSPATH% -SET CLASSPATH=.\make\tmp\ant-contrib.jar;%CLASSPATH% +SET CLASSPATH=%CD%\make\tmp;%CD%\make\tmp\ant-contrib.jar;%CLASSPATH% SET ANT_COMMAND=%ANT_HOME%\bin\ant.bat Index: build/build.sh =================================================================== --- build/build.sh (revision 480889) +++ build/build.sh (working copy) @@ -71,7 +71,7 @@ CLASSPATH=$CLASSPATH:`pwd`/make/tmp/junit.jar CLASSPATH=$CLASSPATH:`pwd`/make/tmp/xalan.jar CLASSPATH=`pwd`/make/tmp/cpptasks/patched.classes:$CLASSPATH -CLASSPATH=`pwd`/make/tmp/ant-contrib.jar:$CLASSPATH +CLASSPATH=`pwd`/make/tmp:`pwd`/make/tmp/ant-contrib.jar:$CLASSPATH export CLASSPATH ANT_COMMAND="$ANT_HOME/bin/ant --noconfig" Index: build/make/setup.xml =================================================================== --- build/make/setup.xml (revision 480889) +++ build/make/setup.xml (working copy) @@ -84,8 +84,25 @@ + + + + + + + + + + + + + + @@ -182,7 +200,7 @@ - + @@ -213,6 +231,16 @@ + + + + + + Error: +Could not find necessary resource: ${build.RESOURCE_HOME}/${check.file} + + + @@ -361,6 +389,7 @@ Index: build/make/win.properties =================================================================== --- build/make/win.properties (revision 480889) +++ build/make/win.properties (working copy) @@ -83,6 +83,7 @@ VM_HOME=..\..\vm PATCHES_HOME=../patches +HY_JUNIT_HOME=../../src/support/ant #proxy configuration # http.proxyHost= Index: build/make/targets/reg.test.xml =================================================================== --- build/make/targets/reg.test.xml (revision 480889) +++ build/make/targets/reg.test.xml (working copy) @@ -124,7 +124,7 @@ link="shared" outfile="${reg.test.native.path}/${outname}" objdir="${reg.test.native.path}/_obj"> - + Index: build/make/targets/reg.test.run.xml =================================================================== --- build/make/targets/reg.test.run.xml (revision 480889) +++ build/make/targets/reg.test.run.xml (working copy) @@ -17,29 +17,32 @@ - + + ================================== Run regression tests ================================== - + - - - - - + + + + + + + @@ -58,8 +61,8 @@ + Index: build/make/lnx.properties =================================================================== --- build/make/lnx.properties (revision 480889) +++ build/make/lnx.properties (working copy) @@ -85,6 +85,7 @@ # Location for VM sources (can be handy if building different versions of VM) VM_HOME=../../vm PATCHES_HOME=../patches +HY_JUNIT_HOME=../../src/support/ant #proxy configuration # http.proxyHost= Index: src/test/regression/H1694/H1694.java =================================================================== --- src/test/regression/H1694/H1694.java (revision 480889) +++ src/test/regression/H1694/H1694.java (working copy) @@ -1,7 +1,10 @@ package org.apache.harmony.drlvm.tests.regression.h1694; -class H1694 { - public int test() { +import junit.framework.TestCase; + +public class H1694 extends TestCase { + + public void test() { Object arrayOfObjects[] = new Object[10000]; // array of objects // padding memory @@ -18,12 +21,7 @@ } System.out.println("Test passed"); - return 104; // return pass } - - public static void main(String[] args) { - System.exit(new H1694().test()); - } } /* big padding object */ Index: src/support/ant/HYJunitTask.java =================================================================== --- src/support/ant/HYJunitTask.java (revision 0) +++ src/support/ant/HYJunitTask.java (revision 0) @@ -0,0 +1,271 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.support.ant.taskdef; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.optional.junit.FormatterElement; +import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter; +import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask; +import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest; +import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter; + +/** + * HYJunitTask extends Ant's JUnitTask task to handle JVM crash. + */ +public class HYJunitTask extends JUnitTask { + + /** + * Implementation of the result formatter to be used as a JVM crash handler. + */ + public static class JVMCrashHandler implements JUnitResultFormatter { + + private OutputStream out; + + /** + * Writes the name of the test to be executed + * to the crash handler file. + */ + public void startTest(junit.framework.Test test) { + try { + out.write(test.toString().getBytes()); + } catch (IOException e) { + throw new BuildException(e); + } + } + + /** + * Writes the new line character determining test finish + * to the crash handler file. + */ + public void endTest(junit.framework.Test test) { + try { + out.write('\n'); + } catch (IOException e) { + throw new BuildException(e); + } + } + + /** + * Does nothing. + */ + public void addFailure(junit.framework.Test test, + java.lang.Throwable t) { } + + /** + * Does nothing. + */ + public void addFailure(junit.framework.Test test, + junit.framework.AssertionFailedError t) { } + + /** + * Does nothing. + */ + public void addError(junit.framework.Test test, + java.lang.Throwable error) { } + + /** + * Does nothing. + */ + public void startTestSuite(JUnitTest suite) throws BuildException { + try { + out.write(suite.getName().getBytes()); + } catch (IOException e) { + throw new BuildException(e); + } + } + + /** + * Does nothing. + */ + public void endTestSuite(JUnitTest suite) throws BuildException { + try { + out.write('\n'); + } catch (IOException e) { + throw new BuildException(e); + } + } + + /** + * Does nothing. + */ + public void setOutput(java.io.OutputStream out) { + this.out = out; + } + + /** + * Does nothing. + */ + public void setSystemOutput(java.lang.String out) { } + + /** + * Does nothing. + */ + public void setSystemError(java.lang.String err) { } + } + + // checks whether the test execution is forked or not + private boolean fork; + // checks whether the build process should halt on error or not + private boolean haltOnError; + // determines should we report JVM crash to XML formatter or not + private boolean useXmlFormatter = false; + // formatter used as a crash handler + private FormatterElement crashHandler; + + /** + * Creates new instance of the task + */ + public HYJunitTask() throws Exception { + super(); + } + + @Override + public void setFork(boolean value) { + super.setFork(value); + fork = value; + } + + @Override + public void setForkMode(ForkMode mode) { + super.setForkMode(new ForkMode(ForkMode.PER_TEST)); + } + + @Override + public void setHaltonerror(boolean haltOnError) { + this.haltOnError = haltOnError; + super.setHaltonerror(haltOnError); + } + + @Override + protected void execute(JUnitTest test) throws BuildException { + if (fork) { + if (test.getOutfile() == null) { + test.setOutfile("TEST-" + test.getName()); + } + registerCrashHandler(); + } + super.execute(test); + } + + protected void actOnTestResult(int exitValue, boolean wasKilled, + JUnitTest test, String name) { + if (fork) { + File handlerFile = null; + try { + handlerFile = + new File(test.getTodir(), test.getOutfile() + ".chk"); + if (!handlerFile.exists()) { + reportJVMCrash(test, + "Forked JVM crashed during test launching: " + + test.getName()); + } else { + FileInputStream is = new FileInputStream(handlerFile); + if (is.available() == 0) { + is.close(); + reportJVMCrash(test, + "Forked JVM crashed during test launching: " + + test.getName()); + } else { + byte[] buff = new byte[is.available()]; + int num = is.read(buff); + is.close(); + if (buff[num-1] != '\n') { // test caused the JVM crash + // retrieve the name of the test + int pos = num-1; + while (pos > 0) { + pos--; + if (buff[pos] == '\n') { + break; + } + } + reportJVMCrash(test, + "Forked JVM crashed during the" + + " execution of the following test: " + + new String(buff, pos, num-pos) + + " (test suite is " + + test.getName() + + ")"); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + throw new BuildException(e); + } finally { + if (handlerFile != null) { + handlerFile.delete(); + } + } + } + super.actOnTestResult(exitValue, wasKilled, test, name); + } + + @Override + protected File getOutput(FormatterElement fe, JUnitTest test) { + // determine should we report JVM crash to XML formatter or not + if (FormatterElement.XML_FORMATTER_CLASS_NAME + .equals(fe.getClassname())) { + useXmlFormatter = true; + } + return super.getOutput(fe, test); + + } + + // Registeres the crash handler formatter + private void registerCrashHandler() { + if (crashHandler == null) { + crashHandler = new FormatterElement(); + crashHandler.setClassname(JVMCrashHandler.class.getName()); + crashHandler.setUseFile(true); + crashHandler.setExtension(".chk"); + addFormatter(crashHandler); + } + } + + // Reports JVM crash: + // - sets up the error property for crashed test + // - report crash to XML formatter if it was set for this test + // - throws BuildException if halt on error is true + private void reportJVMCrash(JUnitTest test, String message) throws IOException, BuildException { + String errorProperty = test.getErrorProperty(); + if (errorProperty != null) { + getProject().setNewProperty(errorProperty, "true"); + } + if (useXmlFormatter) { + // report JVM crash to XML formatter + JUnitResultFormatter fmter = new XMLJUnitResultFormatter(); + fmter.setOutput( + new FileOutputStream( + new File(test.getTodir(), test.getOutfile() + ".xml"))); + test.setCounts(1, 0, 1); + test.setProperties(System.getProperties()); + fmter.startTestSuite(test); + fmter.addError(null, new RuntimeException(message)); + fmter.endTestSuite(test); + } + if (haltOnError) { + throw new BuildException(message); + } + } +} +