Update provider for EMMA from CTS
The provider now accepts a "secret" request to dump EMMA coverage
data.
The commands in tests/EMMA_README were updated for the new world
order, in which the tests live in CTS rather than being one with
the provider itself. This also converts the commands from direct
execution to a shell function, and adds a second function that can
be used to de-EMMA the provider.
Bug 2361048
Change-Id: I38b494cc65a15523207f95d2e622756cc393b665
diff --git a/tests/EMMA_README b/tests/EMMA_README
index 1a2a35d..d3f4e89 100644
--- a/tests/EMMA_README
+++ b/tests/EMMA_README
@@ -1,27 +1,93 @@
-#TODO Modify when we move CTS tests to frameworks
+# This defines a shell function called run_emma_calp() that rebuilds
+# the Calendar provider with EMMA coverage, executes the Calendar CTS
+# tests, and generates results into ~/emmaReport/. The previous emmaReport
+# directory, if any, will be removed.
+#
+# This expects that ". build/envsetup.sh" and an appropriate "lunch"
+# command have already been issued.
+#
+# Also, since we're doing this "the hard way", it's necessary to have
+# /system/framework/emma.jar in BOOTCLASSPATH. Basic steps:
+# - edit system/core/rootdir/init.rc
+# - insert "/system/framework/emma.jar" right before framework.jar
+# - mm -j8 external/emma
+# - make -j8
+# - adb reboot-bootloader
+# - fastboot flashall
+#
+# This also defines a no_emma_calp() function that rebuilds the provider
+# without emma.
+#
+# NOTE: interrupting execution may leave you in a different directory
-#These are instructions for generating code coverage for the provider
-#for only the CalendarCts.java set of tests. This file can be sourced
-#directly from the command line to generate the coverage results in
-#your home directory.
+function run_emma_calp()
+{
+ # rebuild provider with emma coverage
+ _build_install_calp true
+ if [ $? -ne 0 ]; then
+ echo Build failed.
+ return 1
+ fi
-adb root;
-cd ${ANDROID_BUILD_TOP}/packages/providers/CalendarProvider;
-export EMMA_INSTRUMENT=true;
-rm -R ${ANDROID_BUILD_TOP}/out/target/common/obj/APPS/CalendarProvider_intermediates
-rm -R ${ANDROID_BUILD_TOP}/out/target/common/obj/APPS/CalendarProviderTests_intermediates
-mm;
-adb remount;
-adb push ${ANDROID_PRODUCT_OUT}/system/app/CalendarProvider.apk system/app/CalendarProvider.apk;
-adb push ${ANDROID_PRODUCT_OUT}/data/app/CalendarProviderTests.apk data/app/CalendarProviderTests.apk;
-sleep 2;
-adb shell am instrument -w -e coverage true -e class com.android.providers.calendar.CalendarCts com.android.providers.calendar.tests/android.test.InstrumentationTestRunner;
-if [ -d ~/emmaReport ]; then
- rm -R ~/emmaReport;
-fi
-mkdir ~/emmaReport;
-pushd ~/emmaReport;
-adb pull /data/user/0/com.android.providers.calendar/files/coverage.ec coverage.ec;
-java -cp ${ANDROID_BUILD_TOP}/external/emma/lib/emma.jar emma report -r html -in coverage.ec -sp ${ANDROID_BUILD_TOP}/packages/providers/CalendarProvider/src -in ${ANDROID_BUILD_TOP}/out/target/common/obj/APPS/CalendarProvider_intermediates/coverage.em;
-popd;
-export EMMA_INSTRUMENT=false;
+ # run the CTS tests; note we can't get success/failure result in $?
+ adb shell am instrument -w -e coverage true \
+ -e class android.provider.cts.CalendarTest \
+ -w 'com.android.cts.provider/android.provider.cts.CalendarTest\$CalendarEmmaTestRunner'
+
+ # this path is hard-coded into the CalendarEmmaTestRunner
+ output=/sdcard/calendar-provider.ec
+
+ # extract and generate the report
+ rm -rf ~/emmaReport
+ mkdir ~/emmaReport
+ pushd ~/emmaReport
+ adb pull $output coverage.ec
+ adb shell rm $output
+ java -cp ${ANDROID_BUILD_TOP}/external/emma/lib/emma.jar \
+ emma report -r html -in coverage.ec \
+ -sp ${ANDROID_BUILD_TOP}/packages/providers/CalendarProvider/src \
+ -in ${ANDROID_BUILD_TOP}/out/target/common/obj/APPS/CalendarProvider_intermediates/coverage.em
+ popd
+
+ echo "Report is in $HOME/emmaReport"
+
+ return 0
+}
+
+function no_emma_calp()
+{
+ # rebuild provider without emma coverage
+ _build_install_calp false
+}
+
+function _build_install_calp()
+{
+ emma=$1
+
+ # switch to root on userdebug builds - this may take a second to finish
+ adb root
+
+ pushd $ANDROID_BUILD_TOP
+
+ # force rebuild
+ rm -rf out/target/common/obj/APPS/CalendarProvider_intermediates
+ ##rm -rf out/target/common/obj/APPS/CalendarProviderTests_intermediates
+ rm -rf out/target/common/obj/APPS/CtsProviderTestCases_intermediates
+ EMMA_INSTRUMENT=$emma mmm -j4 packages/providers/CalendarProvider \
+ && EMMA_INSTRUMENT=$emma mmm -j4 cts/tests/tests/provider
+ if [ $? -ne 0 ]; then
+ popd
+ return 1
+ fi
+
+ # copy the instrumented APKs to the device
+ adb remount
+ adb push ${ANDROID_PRODUCT_OUT}/system/app/CalendarProvider.apk /system/app/
+ ##adb push ${ANDROID_PRODUCT_OUT}/data/app/CalendarProviderTests.apk /data/app/
+ adb push ${ANDROID_PRODUCT_OUT}/data/app/CtsProviderTestCases.apk /data/app/
+ popd
+
+ # give the device a couple of seconds to install the packages
+ sleep 2
+}
+