1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 08:38:51 -05:00

summary: updated build scripts for testing.

.gitignore:
  added files created by new targets.

build.xml:
  removed targets install and reinstall.
  modified target help to depend on android_rules.help and only explain targets defined here.
  updated target javadoc.
  added targets lint-xml, lint-html, and monkey.
  added private target -pre-clean to remove files created by new targets.

tests/AndroidManifest.xml:
  updated note on running the tests.

tests/ant.properties:
  removed test.runner as target test is now overridden.

tests/build.xml:
  removed target test-report as it is now integrated with overridden target test.
  overrode target test to disable deleting coverage.em and use the new test runner.
  overrode target help to depend on android_rules.help and only explain targets defined here.
  added targets javadoc, lint-xml, lint-html, and artifacts.
  added private target -pre-clean to remove files created by new targets.

tests/clean-tests.sh:
  new sh script to run through all the tests.
This commit is contained in:
ashley willis 2012-05-30 18:02:57 -05:00
parent 982f78fcc9
commit a0ee0b1561
6 changed files with 374 additions and 63 deletions

14
.gitignore vendored
View File

@ -1,5 +1,13 @@
local.properties
bin
gen
.settings
bin
coverage
coverage.ec
coverage.em
gen
javadoc
junit-report.xml
lint-results.*ml
lint-results_files
local.properties
monkey.txt
*~

150
build.xml
View File

@ -160,50 +160,29 @@
</exec>
</target>
<!-- Install the package on the default emulator -->
<target name="install" depends="debug">
<echo>Installing ${out.final.file} onto default emulator...</echo>
<exec executable="${adb}" failonerror="true">
<arg value="install" />
<arg path="${out.final.file}" />
</exec>
</target>
<!-- Re-Install the package on the default emulator -->
<target name="reinstall" depends="debug">
<echo>Reinstalling ${out.final.file} onto default emulator...</echo>
<exec executable="${adb}" failonerror="true">
<arg value="install" />
<arg value="-r" />
<arg path="${out.final.file}" />
</exec>
</target>
<target name="astyle">
<exec executable="astyle" failonerror="true">
<arg line="--style=java --indent=spaces=4 --indent-switches --max-instatement-indent=4 --brackets=attach --add-brackets --convert-tabs --unpad-paren --pad-header --pad-oper --suffix=none --recursive 'src/com/fsck/k9/*.java' 'tests/src/com/fsck/k9/*.java'"/>
</exec>
</target>
<target name="help">
<target name="help" depends="android_rules.help">
<!-- displays starts at col 13
|13 80| -->
<echo>Android Ant Build. Available targets:</echo>
<echo> help: Displays this help.</echo>
<echo> debug: Builds the application and sign it with a debug key.</echo>
<echo> release: Builds the application. The generated apk file must be</echo>
<echo> signed before it is published.</echo>
<echo> install: Installs the debug package onto a running emulator or</echo>
<echo> device. This can only be used if the application has </echo>
<echo> not yet been installed.</echo>
<echo> reinstall: Installs the debug package on a running emulator or</echo>
<echo> device that already has the application.</echo>
<echo> The signatures must match.</echo>
<echo> uninstall: uninstall the application from a running emulator or</echo>
<echo> device.</echo>
<echo> bump-version: ant -Dversion-name=3.123</echo>
<echo> Bumps the project version to 3.123,tags and commits it</echo>
<echo> astyle: Make K-9's source look like it's supposed to</echo>
<echo> eclipse: Apply template Eclipse settings</echo>
<echo> javadoc: Create javadoc. Requires ANDROID_HOME environment</echo>
<echo> variable to be set (i.e. /opt/android-sdk-update-manager/)</echo>
<echo>Additional targets:</echo>
<!--echo> bump-version: ant -Dversion-name=3.123</echo>
<echo> Bumps the project version to 3.123,tags and commits it.</echo>
<echo> upload: Uploads a new release to google code.</echo-->
<echo> rclib: Creates library for remote control applications.</echo>
<echo> astyle: Make K-9's source look like it's supposed to.</echo>
<echo> eclipse: Apply template Eclipse settings.</echo>
<echo> javadoc: Javadoc output to javadoc/. ANDROID_HOME environment</echo>
<echo> variable must be set (i.e. /opt/android-sdk-linux/).</echo>
<echo> lint-xml: Lint output lint-results.xml.</echo>
<echo> lint-html: Lint output to lint-results.html.</echo>
<echo> monkey: Runs monkey on the running emulator. Change the</echo>
<echo> defaults -Dmonkey.seed=NUM and -Dmonkey.count=NUM</echo>
<echo> from 0 and 200, respectively.</echo>
</target>
<target name="eclipse" description="Apply template Eclipse settings">
@ -213,19 +192,110 @@
</target>
<property environment="env" />
<property name="javadoc-dir" location="javadoc" />
<target name="javadoc" description="build javadoc">
<mkdir dir="javadoc"/>
<mkdir dir="${javadoc-dir}"/>
<javadoc
destdir="javadoc"
destdir="${javadoc-dir}"
doctitle="K-9 Mail"
verbose="on"
use="true"
classpath="${env.ANDROID_HOME}/platforms/android-15/android.jar"
classpath="${env.ANDROID_HOME}/platforms/${target}/android.jar"
sourcepath="gen;src"
linkoffline="http://d.android.com/reference ${env.ANDROID_HOME}/docs/reference/"
/>
</target>
<target name="lint-xml">
<exec executable="lint" failonerror="true">
<arg value="--xml" />
<arg value="lint-results.xml" />
<arg path="." />
</exec>
</target>
<target name="lint-html">
<exec executable="lint" failonerror="true">
<arg value="--html" />
<arg value="lint-results.html" />
<arg path="." />
</exec>
</target>
<target name="monkey">
<xpath input="AndroidManifest.xml" expression="/manifest/@package" output="manifest.package" />
<if condition="monkey.count">
<else>
<property name="monkey.count" value="200" />
</else>
</if>
<if condition="monkey.seed">
<else>
<property name="monkey.seed" value="0" />
</else>
</if>
<exec executable="${adb}" output="monkey.txt" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="-e" />
<arg value="shell" />
<arg value="monkey" />
<arg value="-p" />
<arg value="${manifest.package}" />
<arg value="-v" />
<arg value="-s" />
<arg value="${monkey.seed}" />
<arg value="${monkey.count}" />
</exec>
</target>
<scriptdef name="lastindexplus1" language="javascript">
<attribute name="text" />
<attribute name="substring" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var substring = attributes.get("substring");
project.setProperty(attributes.get("property"), text.lastIndexOf(substring) + 1);
]]>
</scriptdef>
<scriptdef name="substring" language="javascript">
<attribute name="text" />
<attribute name="start" />
<attribute name="end" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var start = attributes.get("start");
var end = attributes.get("end") || text.length();
project.setProperty(attributes.get("property"), text.substring(start, end));
]]>
</scriptdef>
<!-- this, and the two scriptdefs above, are for CloudBees. see tests/build.xml -->
<target name="-artifactd" depends="-set-debug-files, -artifact" />
<target name="-artifacti" depends="-set-instrumented-mode, -artifact" />
<target name="-artifact">
<lastindexplus1 text="${env.GIT_BRANCH}" substring="/" property="lastindexof" />
<substring text="${env.GIT_BRANCH}" start="${lastindexof}" property="branch" />
<substring text="${env.GIT_COMMIT}" start="0" end="10" property="commit" />
<copy file="${out.final.file}"
tofile="${out.dir}/K9-${branch}-${env.BUILD_ID}-${commit}-${env.BUILD_NUMBER}.apk"
verbose="on"
/>
</target>
<target name="-pre-clean" description="Removes testing output and javadoc">
<delete file="monkey.txt" verbose="${verbose}" />
<delete file="lint-results.xml" verbose="${verbose}" />
<delete file="lint-results.html" verbose="${verbose}" />
<delete dir="lint-results_files" verbose="${verbose}" />
<delete dir="${javadoc-dir}" verbose="${verbose}" />
</target>
<!-- END K-9 STUFF-->
<import file="${sdk.dir}/tools/ant/build.xml" />

View File

@ -13,7 +13,7 @@
<!--
This declares that this application uses the instrumentation test runner targeting
the package of com.fsck.k9. To run the tests use the command:
"adb shell am instrument -w com.fsck.k9.tests/android.test.InstrumentationTestRunner"
"adb shell am instrument -w com.fsck.k9.tests/com.zutubi.android.junitreport.JUnitReportTestRunner"
-->
<instrumentation android:name="com.zutubi.android.junitreport.JUnitReportTestRunner"
android:targetPackage="com.fsck.k9"

View File

@ -16,4 +16,3 @@
# The password will be asked during the build when you use the 'release' target.
tested.project.dir=../
test.runner=com.zutubi.android.junitreport.JUnitReportTestRunner

View File

@ -81,19 +81,194 @@
-->
<!-- version-tag: custom -->
<target name="test-report">
<xpath input="${tested.project.dir}/AndroidManifest.xml"
expression="/manifest/@package" output="tested.manifest.package" />
<xpath input="AndroidManifest.xml"
expression="/manifest/@package" output="manifest.package" />
<echo>Downloading XML test report...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}"/>
<arg value="pull" />
<arg value="/data/data/${tested.manifest.package}/files/junit-report.xml" />
<arg value="junit-report.xml" />
<!-- K-9 CUSTOM STUFF -->
<property environment="env" />
<property name="javadoc-dir" location="javadoc" />
<target name="javadoc" description="build javadoc">
<mkdir dir="${javadoc-dir}"/>
<javadoc
destdir="${javadoc-dir}"
doctitle="K-9 Mail"
verbose="on"
use="true"
classpath="${env.ANDROID_HOME}/platforms/${target}/android.jar"
sourcepath="gen;src"
linkoffline="http://d.android.com/reference ${env.ANDROID_HOME}/docs/reference/"
/>
</target>
<target name="lint-xml">
<exec executable="lint" failonerror="true">
<arg value="--xml" />
<arg value="lint-results.xml" />
<arg path="." />
</exec>
</target>
<target name="lint-html">
<exec executable="lint" failonerror="true">
<arg value="--html" />
<arg value="lint-results.html" />
<arg path="." />
</exec>
</target>
<property name="junit-file" location="junit-report.xml" />
<!-- This is overridden because otherwise it deletes coverage.em after extraction, requiring
another compile. Also, test.runner can be changed here instead of in ant.properties, and
the code to pull the results is integrated. Changes are commented because from looking at
r20-preview, this might break and need to be redone. -->
<target name="test" depends="-test-project-check"
description="OVERRIDE: Runs tests from the package defined in test.package property">
<property name="tested.project.absolute.dir" location="${tested.project.dir}" />
<property name="test.runner" value="com.zutubi.android.junitreport.JUnitReportTestRunner" /><!-- changed from original -->
<!-- Application package of the tested project extracted from its manifest file -->
<xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
expression="/manifest/@package" output="tested.manifest.package" />
<xpath input="AndroidManifest.xml"
expression="/manifest/@package" output="manifest.package" />
<property name="emma.dump.file"
value="/data/data/${tested.manifest.package}/coverage.ec" />
<if condition="${emma.enabled}">
<then>
<echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
<run-tests-helper emma.enabled="true">
<extra-instrument-args>
<arg value="-e" />
<arg value="coverageFile" />
<arg value="${emma.dump.file}" />
</extra-instrument-args>
</run-tests-helper>
<echo>Downloading coverage file into project directory...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="pull" />
<arg value="${emma.dump.file}" />
<arg value="coverage.ec" />
</exec>
<echo>Extracting coverage report...</echo>
<emma>
<report sourcepath="${tested.project.absolute.dir}/${source.dir}"
verbosity="${verbosity}">
<!-- TODO: report.dir or something like should be introduced if necessary -->
<infileset dir=".">
<include name="coverage.ec" />
<include name="coverage.em" />
</infileset>
<!-- TODO: reports in other, indicated by user formats -->
<html outfile="coverage.html" />
</report>
</emma>
<!-- commented out from original
<echo>Cleaning up temporary files...</echo>
<delete file="coverage.ec" />
<delete file="coverage.em" />
-->
<echo>Saving the report file in ${basedir}/coverage/coverage.html</echo>
</then>
<else>
<run-tests-helper />
</else>
</if>
<!-- added for JUnitReportTestRunner: -->
<echo>Saving the JUnit test report as ${junit-file}</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}"/>
<arg value="pull" />
<arg value="/data/data/${tested.manifest.package}/files/junit-report.xml" />
<arg value="${junit-file}" />
</exec>
</target>
<scriptdef name="lastindexplus1" language="javascript">
<attribute name="text" />
<attribute name="substring" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var substring = attributes.get("substring");
project.setProperty(attributes.get("property"), text.lastIndexOf(substring) + 1);
]]>
</scriptdef>
<scriptdef name="substring" language="javascript">
<attribute name="text" />
<attribute name="start" />
<attribute name="end" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var start = attributes.get("start");
var end = attributes.get("end") || text.length();
project.setProperty(attributes.get("property"), text.substring(start, end));
]]>
</scriptdef>
<target name="artifacts" description="Copies the apks as unique CloudBees artifacts">
<lastindexplus1 text="${env.GIT_BRANCH}" substring="/" property="lastindexof" />
<substring text="${env.GIT_BRANCH}" start="${lastindexof}" property="branch" />
<substring text="${env.GIT_COMMIT}" start="0" end="10" property="commit" />
<!-- calls ../build.xml -->
<property name="tested.project.absolute.dir" location="${tested.project.dir}" />
<condition property="my.project.target" value="-artifacti" else="-artifactd">
<isset property="emma.enabled" />
</condition>
<subant target="${my.project.target}" failonerror="true">
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
</subant>
<!-- define out.final.file if not already defined (if calling without debug, for instance) -->
<condition property="out.final.file.isset" value="true" else="false">
<isset property="out.final.file" />
</condition>
<if condition="${out.final.file.isset}">
<else>
<property name="out.final.file"
location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
</else>
</if>
<copy file="${out.final.file}"
tofile="${out.dir}/K9-${branch}-${env.BUILD_ID}-${commit}-${env.BUILD_NUMBER}-tests.apk"
verbose="on"
/>
</target>
<target name="-pre-clean" description="Removes testing output">
<delete file="${junit-file}" verbose="${verbose}" />
<delete file="lint-results.xml" verbose="${verbose}" />
<delete file="lint-results.html" verbose="${verbose}" />
<delete dir="lint-results_files" verbose="${verbose}" />
<delete file="coverage.ec" verbose="${verbose}" />
<delete file="coverage.em" verbose="${verbose}" />
<delete dir="coverage" verbose="${verbose}" />
<delete dir="${javadoc-dir}" verbose="${verbose}" />
</target>
<target name="help" depends="android_rules.help">
<!-- displays starts at col 13
|13 80| -->
<echo>Additional targets:</echo>
<echo> javadoc: Javadoc output to javadoc/. ANDROID_HOME environment</echo>
<echo> variable must be set (i.e. /opt/android-sdk-linux/).</echo>
<echo> lint-xml: Lint output lint-results.xml.</echo>
<echo> lint-html: Lint output to lint-results.html.</echo>
<echo> test: Overridden -- also outputs junit-report.xml.</echo>
<echo> artifacts: Copies the apks as unique CloudBees artifacts. Usage:</echo>
<echo> ant [emma] [debug] artifacts</echo>
</target>
<!-- END K-9 CUSTOM STUFF -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

59
tests/clean-tests.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/sh
# clean and run all the tests on an emulator -- only one emulator should be running (a device can be attached).
# will start and stop an emulator if no emulator is running.
# name of emulator is given as an argument (no spaces in the name!), or "api7" if not given.
# starting the emulator requires daemonize which requires a Unix-like system: http://software.clapper.org/daemonize/
# clean
ant all clean || exit 99
# see if emulator is running, and uninstall package if so
EMULATOR_ALREADY_RUNNING=false
if adb devices | grep emulator | grep device$; then
ant -Dadb.device.arg=-e uninstall || exit 98
EMULATOR_ALREADY_RUNNING=true
fi
# build project and test project
time ant emma debug artifacts || exit 1
# start emulator if not running, and uninstall package
if [ $EMULATOR_ALREADY_RUNNING == false ] ; then
if [ -z $1 ]; then
AVD_NAME=api7
else
AVD_NAME=$1
fi
echo starting emulator ${AVD_NAME}
daemonize -o /tmp/${AVD_NAME}.stdout -e /tmp/${AVD_NAME}.stderr -p /tmp/${AVD_NAME}.pid -l /tmp/${AVD_NAME}.lock \
$ANDROID_HOME/tools/emulator-arm -avd ${AVD_NAME} -no-audio -no-window -no-snapshot-save || exit 97
ps ux | grep -f /tmp/${AVD_NAME}.pid | grep emulator || exit 96
adb kill-server
time adb start-server
adb devices
#sleep 7
adb devices | grep emulator || exit 95
echo adb -e wait-for-device
time adb -e wait-for-device
adb devices | grep device$ || exit 94
ant -Dadb.device.arg=-e uninstall || exit 98
fi
# install project and test project, run tests
time ant -Dadb.device.arg=-e emma installd test || exit 2
# lint, javadoc, monkey
cd ..
time ant lint-xml || exit 3
time ant javadoc || exit 4
time ant -Dmonkey.count=200 -Dmonkey.seed=0 monkey || exit 5
# kill emulator if this script started it
if [ $EMULATOR_ALREADY_RUNNING == false ] ; then
adb emu kill || exit 93
sleep 1
! ps ux | grep -f /tmp/${AVD_NAME}.pid | grep emulator || exit 92
rm -f /tmp/${AVD_NAME}.stdout /tmp/${AVD_NAME}.stderr /tmp/${AVD_NAME}.pid /tmp/${AVD_NAME}.lock
fi