Author: kkolinko Date: Sat Jan 9 06:44:50 2016 New Revision: 1723829 URL: http://svn.apache.org/viewvc?rev=1723829&view=rev Log: Implement running the test with Apache Ant. The command is: ant download ant test
Remove unused test/build.xml Note: running with APR connector is supported, but usually results in a JVM crash. Removed: tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/build.xml Modified: tomcat/tc6.0.x/branches/tomcat6-testing_20160106/BUILDING.txt tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.properties.default tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.xml tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java Modified: tomcat/tc6.0.x/branches/tomcat6-testing_20160106/BUILDING.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/BUILDING.txt?rev=1723829&r1=1723828&r2=1723829&view=diff ============================================================================== --- tomcat/tc6.0.x/branches/tomcat6-testing_20160106/BUILDING.txt (original) +++ tomcat/tc6.0.x/branches/tomcat6-testing_20160106/BUILDING.txt Sat Jan 9 06:44:50 2016 @@ -172,3 +172,109 @@ For a quick rebuild of only modified cod cd ${tomcat.source} ant -f dist.xml release + +(8) Tests + +(8.1) Running Tomcat tests + +Tomcat 6 includes a small number of junit tests. (A lot more are available +with Tomcat 7 onwards). + +The tests are not run when a release is built. There is separate command to +run them. + +To run the testsuite use the following command: + + cd ${tomcat.source} + ant download + ant test + +It is advisable to redirect output of the above command to a file for later +inspection. + +The JUnit reports generated by the tests will be written to the following +directory: + + output/build/logs + +By default the testsuite is run three times to test 3 different +implementations of Tomcat connectors: BIO, NIO and APR. (If you are not +familiar with Tomcat connectors, see config/http.html in documentation for +details). + +The 3 runs are enabled and disabled individually by the following +properties, which all are "true" by default: + + execute.test.bio=true + execute.test.nio=true + execute.test.apr=true + +The APR connector can be tested only if Tomcat-Native library binaries are +found by the testsuite. The "test.apr.loc" property specifies the directory +where the library binaries are located. + +By default the "test.apr.loc" property specifies the following location: + + output/build/bin/native/ + +If you are on Windows and want to test the APR connector you can put the +tcnative-1.dll file into ${tomcat.source}/bin/native/ and it will be copied +into the above directory when the build runs. + + +(8.2) Running a single test + +It is possible to run a single JUnit test class by adding the "test.entry" +property to the build.properties file. The property specifies the name of +the test class. + +For example: + + test.entry=org.apache.catalina.util.TestServerInfo + +It is possible to further limit such run to a number of selected test +methods by adding "test.entry.methods" property. The property specifies a +comma-separated list of test case methods. + +For example: + + test.entry=org.apache.el.lang.TestELArithmetic + test.entry.methods=testMultiply01,testMultiply02 + + +(8.3) Other configuration options + + 1. It is possible to configure the directory where JUnit reports are + written to. It is configured by "test.reports" property. The default + value is + + output/build/logs + + 2. It is possible to enable generation of access log file when the tests + are run. This is off by default and can be enabled by the following + property: + + test.accesslog=true + + The "access_log.<date>" file will be written to the same directory as + JUnit reports, + + output/build/logs + + 3. The testsuite respects logging configuration as configured by + ${tomcat.source}/conf/logging.properties + + The log files will be written to the temporary directory used by the + tests, + + output/test-tmp/logs + + 4. It is possible to configure formatter used by JUnit reports. + Configuration properties are "junit.formatter.type", + "junit.formatter.extension" and "junit.formatter.usefile". + + For example the following property disables generation of separate report + files: + + junit.formatter.usefile=false + Modified: tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.properties.default URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.properties.default?rev=1723829&r1=1723828&r2=1723829&view=diff ============================================================================== --- tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.properties.default (original) +++ tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.properties.default Sat Jan 9 06:44:50 2016 @@ -29,6 +29,20 @@ version.build=45 version.patch=0 version.suffix=-dev +# ----- Build control flags ----- +execute.test.bio=true +execute.test.nio=true +# Still requires APR/native library to be present +execute.test.apr=true +# Stop testing if a failure occurs +test.haltonfailure=false +# Activate AccessLog during testing +test.accesslog=false + +# Some platforms (e.g. OSX El Capitan) require IPv4 to be the default for the +# multicast tests to work +java.net.preferIPv4Stack=false + # ----- Default Base Path for Dependent Packages ----- # Please note this path must be absolute, not relative, # as it is referenced with different working directory @@ -159,3 +173,15 @@ commons-daemon.native.src.loc.1=${base-c commons-daemon.native.src.loc.2=${base-commons.loc.2}/daemon/source/commons-daemon-${commons-daemon.version}-native-src.tar.gz commons-daemon.native.win.loc.1=${base-commons.loc.1}/daemon/binaries/windows/commons-daemon-${commons-daemon.version}-bin-windows-signed.zip commons-daemon.native.win.loc.2=${base-commons.loc.2}/daemon/binaries/windows/commons-daemon-${commons-daemon.version}-bin-windows-signed.zip + +# ----- JUnit Unit Test Suite, version 4.11 or later ----- +junit.version=4.11 +junit.home=${base.path}/junit-${junit.version} +junit.jar=${junit.home}/junit-${junit.version}.jar +junit.loc=${base-maven.loc}/junit/junit/${junit.version}/junit-${junit.version}.jar + +# ----- Hamcrest Library, used by JUnit, version 1.3 or later ---- +hamcrest.version=1.3 +hamcrest.home=${base.path}/hamcrest-${hamcrest.version} +hamcrest.jar=${hamcrest.home}/hamcrest-core-${hamcrest.version}.jar +hamcrest.loc=${base-maven.loc}/org/hamcrest/hamcrest-core/${hamcrest.version}/hamcrest-core-${hamcrest.version}.jar Modified: tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.xml?rev=1723829&r1=1723828&r2=1723829&view=diff ============================================================================== --- tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.xml (original) +++ tomcat/tc6.0.x/branches/tomcat6-testing_20160106/build.xml Sat Jan 9 06:44:50 2016 @@ -58,6 +58,10 @@ <property name="tomcat.classes" value="${tomcat.output}/classes"/> <property name="tomcat.dist" value="${tomcat.output}/dist"/> <property name="tomcat.manifests" value="${tomcat.output}/manifests"/> + <property name="test.classes" value="${tomcat.output}/testclasses"/> + <property name="test.temp" value="${tomcat.output}/test-tmp"/> + <property name="test.reports" value="${tomcat.build}/logs"/> + <property name="test.apr.loc" value="${tomcat.build}/bin/native"/> <!-- Can't be lower - jsp uses templates --> <property name="compile.source" value="1.5"/> @@ -91,11 +95,22 @@ <available property="tomcat-dbcp.present" file="${tomcat-dbcp.jar}" /> <available property="jdk16.present" classname="javax.sql.StatementEvent" /> + <!-- Tests To Run --> + <property name="test.name" value="**/Test*.java"/> + <property name="test.formatter" value="-Dorg.apache.juli.formatter=java.util.logging.SimpleFormatter"/> + <!-- Classpath --> <path id="tomcat.classpath"> <pathelement location="${ant.jar}"/> <pathelement location="${jdt.jar}"/> </path> + <path id="tomcat.test.classpath"> + <pathelement location="${tomcat.classes}"/> + <pathelement location="${test.classes}"/> + <pathelement location="${junit.jar}"/> + <pathelement location="${hamcrest.jar}"/> + <path refid="tomcat.classpath" /> + </path> <!-- Version info filter set --> <tstamp> @@ -672,10 +687,161 @@ <delete dir="${tomcat.classes}" /> <delete dir="${tomcat.build}" /> <delete dir="${tomcat.manifests}" /> + <delete dir="${test.classes}" /> + <delete dir="${test.temp}" /> <!-- Remove the copied catalina.properties --> <delete file="java/org/apache/catalina/startup/catalina.properties" /> </target> + <!-- ========================= Testing ========================== --> + + <target name="test-compile" depends="compile" > + <mkdir dir="${test.classes}"/> + <!-- Compile --> + <javac srcdir="test" destdir="${test.classes}" + debug="${compile.debug}" + deprecation="${compile.deprecation}" + source="${compile.source}" + target="${compile.target}" + encoding="ISO-8859-1" + includeantruntime="true"> + <classpath refid="tomcat.test.classpath" /> + <include name="org/apache/**" /> + <include name="javax/**" /> + </javac> + <copy todir="${test.classes}"> + <fileset dir="test"> + <include name="META-INF/**"/> + </fileset> + </copy> + </target> + + <!-- Default JUnit log output formatter --> + <property name="junit.formatter.type" value="plain" /> + <property name="junit.formatter.usefile" value="true" /> + <property name="junit.formatter.extension" value=".txt" /> + + <!-- Workaround against http://bugs.sun.com/view_bug.do?bug_id=6202721 --> + <available file="/dev/urandom" property="test.jvmarg.egd" value="-Djava.security.egd=file:/dev/./urandom"/> + <property name="test.jvmarg.egd" value="" /> + + <target name="test" description="Runs the JUnit test cases" + depends="test-bio,test-nio,test-apr" > + <fileset id="test.result.skippedtests" dir="${test.reports}" includes="*.txt"> + <not> + <contains text="Skipped: 0" /> + </not> + </fileset> + <fileset id="test.result.failedtests" dir="${test.reports}" includes="*.txt"> + <not> + <contains text="Failures: 0, Errors: 0" /> + </not> + </fileset> + <concat> + <header>Testsuites with skipped tests:${line.separator}</header> + <string>${toString:test.result.skippedtests}</string> + <filterchain> + <tokenfilter delimOutput="${line.separator}"> + <stringtokenizer delims=";"/> + </tokenfilter> + </filterchain> + </concat> + <concat> + <header>Testsuites with failed tests:${line.separator}</header> + <string>${toString:test.result.failedtests}</string> + <filterchain> + <tokenfilter delimOutput="${line.separator}"> + <stringtokenizer delims=";"/> + </tokenfilter> + </filterchain> + </concat> + + <fail if="test.result.error" message='Some tests completed with an Error. See ${tomcat.build}/logs for details, search for "ERROR".' /> + <fail if="test.result.failure" message='Some tests completed with a Failure. See ${tomcat.build}/logs for details, search for "FAILED".' /> + </target> + + <target name="test-bio" description="Runs the JUnit test cases for BIO. Does not stop on errors." + depends="test-compile,deploy" if="${execute.test.bio}"> + <runtests protocol="org.apache.coyote.http11.Http11Protocol" + extension=".BIO" /> + </target> + + <target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors." + depends="test-compile,deploy" if="${execute.test.nio}"> + <runtests protocol="org.apache.coyote.http11.Http11NioProtocol" + extension=".NIO" /> + </target> + + <target name="test-apr" description="Runs the JUnit test cases for APR. Does not stop on errors." + depends="test-compile,deploy,test-apr-exists" + if="${apr.exists}"> + <runtests protocol="org.apache.coyote.http11.Http11AprProtocol" + extension=".APR" /> + </target> + + <target name="test-apr-exists" description="Checks for APR lib" + if="${execute.test.apr}"> + <available file="${test.apr.loc}" property="apr.exists" /> + </target> + + <macrodef name="runtests" + description="Runs the unit tests using the specified connector. + Does not stop on errors, but sets 'test.result.error' and 'test.result.failure' properties."> + <attribute name="protocol" + description="The class name for the connector protocol"/> + <attribute name="extension" + description="The extension to use to distinguish the output"/> + + <sequential> + <mkdir dir="${test.reports}" /> + <junit printsummary="yes" fork="yes" dir="." showoutput="yes" + errorproperty="test.result.error" + failureproperty="test.result.failure" + haltonfailure="${test.haltonfailure}"> + + <jvmarg value="${test.jvmarg.egd}"/> + <jvmarg value="-Djava.library.path=${test.apr.loc}"/> + <jvmarg value="${test.formatter}"/> + <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/> + + <classpath refid="tomcat.test.classpath" /> + + <sysproperty key="tomcat.test.temp" value="${test.temp}" /> + <sysproperty key="tomcat.test.basedir" value="${test.basedir}" /> + <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" /> + <sysproperty key="tomcat.test.protocol" value="@{protocol}" /> + <sysproperty key="tomcat.test.accesslog" value="${test.accesslog}" /> + <sysproperty key="tomcat.test.reports" value="${test.reports}" /> + <sysproperty key="tomcat.test.openssl.path" value="${test.openssl.path}" /> + <sysproperty key="tomcat.test.relaxTiming" value="${test.relaxTiming}" /> + + <formatter type="${junit.formatter.type}" + usefile="${junit.formatter.usefile}" + extension="@{extension}${junit.formatter.extension}" /> + + <!-- If test.entry is defined, run a single test, otherwise run all valid tests --> + <test todir="${test.reports}" name="${test.entry}" + if="test.entry" unless="test.entry.methods" + /> + <test todir="${test.reports}" name="${test.entry}" methods="${test.entry.methods}" + if="test.entry.methods" + /> + <batchtest todir="${test.reports}" unless="test.entry"> + <fileset dir="test" > + <!-- Include all by default --> + <include name="${test.name}" /> + <!-- Exclude helper classes --> + <exclude name="**/Tester*.java" /> + <!-- Exclude the tests known to fail --> + <exclude name="org/apache/catalina/tribes/test/**" /> + <!-- Exclude performance tests. E.g. on systems with slow/inconsistent timing --> + <exclude name="**/*Performance.java" if="${test.excludePerformance}" /> + </fileset> + </batchtest> + </junit> + </sequential> + </macrodef> + <!-- ================ Download and dependency building =================== --> <target name="proxyflags"> @@ -856,6 +1022,19 @@ <param name="destdir" value="${nsis.home}/.."/> </antcall> + <!-- Libraries used for testing. JUnit, Hamcrest --> + <antcall target="downloadfile"> + <param name="sourcefile" value="${junit.loc}"/> + <param name="destfile" value="${junit.jar}"/> + <param name="destdir" value="${junit.home}"/> + </antcall> + + <antcall target="downloadfile"> + <param name="sourcefile" value="${hamcrest.loc}"/> + <param name="destfile" value="${hamcrest.jar}"/> + <param name="destdir" value="${hamcrest.home}"/> + </antcall> + </target> <target name="build-tomcat-dbcp" unless="jdk16.present" Modified: tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=1723829&r1=1723828&r2=1723829&view=diff ============================================================================== --- tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java (original) +++ tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java Sat Jan 9 06:44:50 2016 @@ -48,6 +48,8 @@ import org.junit.Before; import org.apache.catalina.Container; import org.apache.catalina.Engine; import org.apache.catalina.Host; +import org.apache.catalina.Lifecycle; +import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleException; import org.apache.catalina.Manager; import org.apache.catalina.Server; @@ -135,6 +137,8 @@ public abstract class TomcatBaseTest ext listener.setSSLRandomSeed("/dev/urandom"); server.addLifecycleListener(listener); connector.setAttribute("pollerThreadCount", Integer.valueOf(1)); + // FIXME: In Tomcat 6 Embedded.start() does not fire INIT_EVENT on Server + listener.lifecycleEvent(new LifecycleEvent(server, Lifecycle.INIT_EVENT)); } File catalinaBase = getTemporaryDirectory(); @@ -143,21 +147,21 @@ public abstract class TomcatBaseTest ext Host host = tomcat.createHost("localhost", appBase.getAbsolutePath()); engine.addChild(host); -//FIXME -// accessLogEnabled = Boolean.parseBoolean( -// System.getProperty("tomcat.test.accesslog", "false")); -// if (accessLogEnabled) { -// String accessLogDirectory = System -// .getProperty("tomcat.test.reports"); -// if (accessLogDirectory == null) { -// accessLogDirectory = new File(getBuildDirectory(), "logs") -// .toString(); -// } -// AccessLogValve alv = new AccessLogValve(); -// alv.setDirectory(accessLogDirectory); -// alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D"); -// tomcat.getHost().getPipeline().addValve(alv); -// } + accessLogEnabled = Boolean.parseBoolean( + System.getProperty("tomcat.test.accesslog", "false")); + if (accessLogEnabled) { + String accessLogDirectory = System + .getProperty("tomcat.test.reports"); + if (accessLogDirectory == null) { + accessLogDirectory = new File(getBuildDirectory(), "logs") + .toString(); + } + AccessLogValve alv = new AccessLogValve(); + alv.setDirectory(accessLogDirectory); + alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D"); + // tomcat.getHost().getPipeline().addValve(alv); + host.getPipeline().addValve(alv); + } // Cannot delete the whole tempDir, because logs are there, // but delete known subdirectories of it. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org