| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 1 | <?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 Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 6 | <property name="tested.project.absolute.dir" location="${tested.project.dir}" /> |
| Piotr Gurgul | e9e8f8c | 2009-09-14 20:42:13 -0700 | [diff] [blame] | 7 | <property name="instrumentation.dir" value="instrumented" /> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 8 | <property name="instrumentation.absolute.dir" location="${instrumentation.dir}" /> |
| 9 | |
| 10 | <property name="test.runner" value="android.test.InstrumentationTestRunner" /> |
| Piotr Gurgul | 0b61bf6 | 2009-09-21 21:40:15 -0700 | [diff] [blame] | 11 | <!-- Application package of the tested project extracted from its manifest file --> |
| 12 | <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml" |
| Piotr Gurgul | 41fb47d | 2009-09-22 17:28:26 -0700 | [diff] [blame] | 13 | expression="/manifest/@package" output="tested.manifest.package" /> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 14 | |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 15 | <!-- TODO: make it more configurable in the next CL's - now it is default for auto-generated |
| 16 | project --> |
| Piotr Gurgul | 0b61bf6 | 2009-09-21 21:40:15 -0700 | [diff] [blame] | 17 | <property name="emma.dump.file" |
| Piotr Gurgul | 41fb47d | 2009-09-22 17:28:26 -0700 | [diff] [blame] | 18 | value="/data/data/${tested.manifest.package}/files/coverage.ec" /> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 19 | |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 20 | <macrodef name="run-tests-helper"> |
| 21 | <attribute name="emma.enabled" default="false" /> |
| Piotr Gurgul | 47d7bdb | 2009-09-16 13:29:07 -0700 | [diff] [blame] | 22 | <element name="extra-instrument-args" optional="yes" /> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 23 | <sequential> |
| 24 | <echo>Running tests ...</echo> |
| 25 | <exec executable="${adb}" failonerror="true"> |
| 26 | <arg value="shell" /> |
| Piotr Gurgul | 47d7bdb | 2009-09-16 13:29:07 -0700 | [diff] [blame] | 27 | <arg value="am" /> |
| 28 | <arg value="instrument" /> |
| 29 | <arg value="-w" /> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 30 | <arg value="-e" /> |
| 31 | <arg value="coverage" /> |
| Piotr Gurgul | 47d7bdb | 2009-09-16 13:29:07 -0700 | [diff] [blame] | 32 | <arg value="@{emma.enabled}" /> |
| 33 | <extra-instrument-args /> |
| Piotr Gurgul | 41fb47d | 2009-09-22 17:28:26 -0700 | [diff] [blame] | 34 | <arg value="${manifest.package}/${test.runner}" /> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 35 | </exec> |
| 36 | </sequential> |
| 37 | </macrodef> |
| 38 | |
| Piotr Gurgul | e9e8f8c | 2009-09-14 20:42:13 -0700 | [diff] [blame] | 39 | <!-- 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 | |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 46 | <!-- Ensures that tested project is installed on the device before we run the tests. |
| 47 | Used for ordinary tests, without coverage measurement --> |
| 48 | <target name="-install-tested-project"> |
| Piotr Gurgul | 11a1b68 | 2009-09-24 18:17:22 -0700 | [diff] [blame] | 49 | <property name="do.not.compile.again" value="true" /> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 50 | <subant target="install"> |
| 51 | <fileset dir="${tested.project.absolute.dir}" includes="build.xml" /> |
| 52 | </subant> |
| 53 | </target> |
| 54 | |
| Piotr Gurgul | 11a1b68 | 2009-09-24 18:17:22 -0700 | [diff] [blame] | 55 | <target name="run-tests" depends="-install-tested-project, install" |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 56 | description="Runs tests from the package defined in test.package property"> |
| 57 | <run-tests-helper /> |
| 58 | </target> |
| 59 | |
| Piotr Gurgul | e9e8f8c | 2009-09-14 20:42:13 -0700 | [diff] [blame] | 60 | <target name="-install-instrumented"> |
| Piotr Gurgul | 11a1b68 | 2009-09-24 18:17:22 -0700 | [diff] [blame] | 61 | <property name="do.not.compile.again" value="true" /> |
| Piotr Gurgul | e9e8f8c | 2009-09-14 20:42:13 -0700 | [diff] [blame] | 62 | <subant target="-install-with-emma"> |
| 63 | <property name="out.absolute.dir" value="${instrumentation.absolute.dir}" /> |
| 64 | <fileset dir="${tested.project.absolute.dir}" includes="build.xml" /> |
| 65 | </subant> |
| 66 | </target> |
| 67 | |
| 68 | <target name="coverage" depends="-set-coverage-classpath, -install-instrumented, install" |
| 69 | description="Runs the tests against the instrumented code and generates |
| 70 | code coverage report"> |
| Piotr Gurgul | 47d7bdb | 2009-09-16 13:29:07 -0700 | [diff] [blame] | 71 | <run-tests-helper emma.enabled="true"> |
| 72 | <extra-instrument-args> |
| 73 | <arg value="-e" /> |
| 74 | <arg value="coverageFile" /> |
| 75 | <arg value="${emma.dump.file}" /> |
| 76 | </extra-instrument-args> |
| 77 | </run-tests-helper> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 78 | <echo>Downloading coverage file into project directory...</echo> |
| 79 | <exec executable="${adb}" failonerror="true"> |
| 80 | <arg value="pull" /> |
| 81 | <arg value="${emma.dump.file}" /> |
| 82 | <arg value="coverage.ec" /> |
| 83 | </exec> |
| 84 | <echo>Extracting coverage report...</echo> |
| 85 | <emma> |
| 86 | <report sourcepath="${tested.project.absolute.dir}/${source.dir}" |
| Piotr Gurgul | b11d00a | 2009-09-17 16:59:28 -0700 | [diff] [blame] | 87 | verbosity="${verbosity}"> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 88 | <!-- TODO: report.dir or something like should be introduced if necessary --> |
| 89 | <infileset dir="."> |
| 90 | <include name="coverage.ec" /> |
| 91 | <include name="coverage.em" /> |
| 92 | </infileset> |
| 93 | <!-- TODO: reports in other, indicated by user formats --> |
| 94 | <html outfile="coverage.html" /> |
| 95 | </report> |
| 96 | </emma> |
| Piotr Gurgul | 73b45f8 | 2009-09-16 10:43:19 -0700 | [diff] [blame] | 97 | <echo>Cleaning up temporary files...</echo> |
| 98 | <delete dir="${instrumentation.absolute.dir}" /> |
| 99 | <delete file="coverage.ec" /> |
| 100 | <delete file="coverage.em" /> |
| Piotr Gurgul | 7d63a4a | 2009-09-24 20:58:35 -0700 | [diff] [blame] | 101 | <echo>Saving the report file in ${basedir}/coverage/coverage.html</echo> |
| Piotr Gurgul | b0b6726 | 2009-09-01 21:58:52 -0700 | [diff] [blame] | 102 | </target> |
| 103 | |
| 104 | </project> |