blob: 60518dff6cee6ba9e969de18091445c334bfb9a7 [file] [log] [blame]
Piotr Gurgulb0b67262009-09-01 21:58:52 -07001<?xml version="1.0" encoding="UTF-8"?>
2<project name="android_test_rules" default="run-tests">
3
4 <import file="android_rules.xml" />
5
Piotr Gurgulb0b67262009-09-01 21:58:52 -07006 <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -07007 <property name="instrumentation.dir" value="instrumented" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -07008 <property name="instrumentation.absolute.dir" location="${instrumentation.dir}" />
9
10 <property name="test.runner" value="android.test.InstrumentationTestRunner" />
Piotr Gurgul0b61bf62009-09-21 21:40:15 -070011 <!-- Application package of the tested project extracted from its manifest file -->
12 <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
13 expression="/manifest/@package" output="tested.application.package" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070014
Piotr Gurgulb0b67262009-09-01 21:58:52 -070015 <!-- TODO: make it more configurable in the next CL's - now it is default for auto-generated
16 project -->
Piotr Gurgul0b61bf62009-09-21 21:40:15 -070017 <property name="emma.dump.file"
18 value="/data/data/${tested.application.package}/files/coverage.ec" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070019
Piotr Gurgulb0b67262009-09-01 21:58:52 -070020 <macrodef name="run-tests-helper">
21 <attribute name="emma.enabled" default="false" />
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070022 <element name="extra-instrument-args" optional="yes" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070023 <sequential>
24 <echo>Running tests ...</echo>
25 <exec executable="${adb}" failonerror="true">
26 <arg value="shell" />
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070027 <arg value="am" />
28 <arg value="instrument" />
29 <arg value="-w" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070030 <arg value="-e" />
31 <arg value="coverage" />
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070032 <arg value="@{emma.enabled}" />
33 <extra-instrument-args />
Piotr Gurgul0b61bf62009-09-21 21:40:15 -070034 <arg value="${application.package}/${test.runner}" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -070035 </exec>
36 </sequential>
37 </macrodef>
38
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -070039 <!-- Invoking this target sets the value of extensible.classpath, which is being added to javac
40 classpath in target 'compile' (android_rules.xml) -->
41 <target name="-set-coverage-classpath">
42 <property name="extensible.classpath"
43 location="${instrumentation.absolute.dir}/classes" />
44 </target>
45
46 <!-- Invoking this target sets the value of extensible.classpath, which is being added to javac
47 classpath in target 'compile' (android_rules.xml) -->
48 <target name="-set-run-tests-classpath">
49 <property name="extensible.classpath"
50 location="${tested.project.absolute.dir}/bin/classes" />
51 </target>
52
Piotr Gurgulb0b67262009-09-01 21:58:52 -070053 <!-- Ensures that tested project is installed on the device before we run the tests.
54 Used for ordinary tests, without coverage measurement -->
55 <target name="-install-tested-project">
56 <subant target="install">
57 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
58 </subant>
59 </target>
60
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -070061 <target name="run-tests" depends="-set-run-tests-classpath, -install-tested-project, install"
Piotr Gurgulb0b67262009-09-01 21:58:52 -070062 description="Runs tests from the package defined in test.package property">
63 <run-tests-helper />
64 </target>
65
Piotr Gurgule9e8f8c2009-09-14 20:42:13 -070066 <target name="-install-instrumented">
67 <subant target="-install-with-emma">
68 <property name="out.absolute.dir" value="${instrumentation.absolute.dir}" />
69 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
70 </subant>
71 </target>
72
73 <target name="coverage" depends="-set-coverage-classpath, -install-instrumented, install"
74 description="Runs the tests against the instrumented code and generates
75 code coverage report">
Piotr Gurgul47d7bdb2009-09-16 13:29:07 -070076 <run-tests-helper emma.enabled="true">
77 <extra-instrument-args>
78 <arg value="-e" />
79 <arg value="coverageFile" />
80 <arg value="${emma.dump.file}" />
81 </extra-instrument-args>
82 </run-tests-helper>
Piotr Gurgulb0b67262009-09-01 21:58:52 -070083 <echo>Downloading coverage file into project directory...</echo>
84 <exec executable="${adb}" failonerror="true">
85 <arg value="pull" />
86 <arg value="${emma.dump.file}" />
87 <arg value="coverage.ec" />
88 </exec>
89 <echo>Extracting coverage report...</echo>
90 <emma>
91 <report sourcepath="${tested.project.absolute.dir}/${source.dir}"
Piotr Gurgulb11d00a2009-09-17 16:59:28 -070092 verbosity="${verbosity}">
Piotr Gurgulb0b67262009-09-01 21:58:52 -070093 <!-- TODO: report.dir or something like should be introduced if necessary -->
94 <infileset dir=".">
95 <include name="coverage.ec" />
96 <include name="coverage.em" />
97 </infileset>
98 <!-- TODO: reports in other, indicated by user formats -->
99 <html outfile="coverage.html" />
100 </report>
101 </emma>
Piotr Gurgul73b45f82009-09-16 10:43:19 -0700102 <echo>Cleaning up temporary files...</echo>
103 <delete dir="${instrumentation.absolute.dir}" />
104 <delete file="coverage.ec" />
105 <delete file="coverage.em" />
Piotr Gurgulb0b67262009-09-01 21:58:52 -0700106 </target>
107
108</project>