Running AOSP tests - android

I am trying to run some AOSP tests, but I can't run any test except for the cts. I mention that I am trying to do this with an emulator. This is the output from my terminal:
manuel#banstyle:~/aosp/development/testrunner$ ./runtest.py -v core
Building tests...
about to run adb shell cat /data/local.prop
about to run adb shell ls -l /data/local.prop
about to run adb root
ONE_SHOT_MAKEFILE="frameworks/base/tests/CoreTests/Android.mk" make -j16 -C "/home/manuel/aosp" all_modules
about to run adb shell pm list instrumentation | grep android.core/android.test.InstrumentationTestRunner
Error: adb shell pm list instrumentation | grep android.core/android.test.InstrumentationTestRunner returned 1 error code
Could not find instrumentation android.core/android.test.InstrumentationTestRunner on device. Try forcing a rebuild by updating a source file, and re-executing runtest.
Exiting due to AbortError...
manuel#banstyle:~/aosp/development/testrunner$ ./runtest.py -v calculator
Building tests...
about to run adb root
ONE_SHOT_MAKEFILE="packages/apps/Calculator/Android.mk" make -j16 -C "/home/manuel/aosp" all_modules
adb push /home/manuel/aosp/out/target/product/generic/data/app/CalculatorTests.odex data/app/CalculatorTests.odex
about to run adb push /home/manuel/aosp/out/target/product/generic/data/app/CalculatorTests.odex data/app/CalculatorTests.odex
adb install -r /home/manuel/aosp/out/target/product/generic/data/app/CalculatorTests.apk
about to run adb install -r /home/manuel/aosp/out/target/product/generic/data/app/CalculatorTests.apk
32 KB/s (2699 bytes in 0.080s)
pkg: /data/local/tmp/CalculatorTests.apk
Failure [INSTALL_FAILED_DEXOPT]
about to run adb shell pm list instrumentation | grep com.android.calculator2.tests/android.test.InstrumentationTestRunner
Error: adb shell pm list instrumentation | grep com.android.calculator2.tests/android.test.InstrumentationTestRunner returned 1 error code
Could not find instrumentation com.android.calculator2.tests/android.test.InstrumentationTestRunner on device. Try forcing a rebuild by updating a source file, and re-executing runtest.
Exiting due to AbortError...
manuel#banstyle:~/aosp/development/testrunner$
Can anyone help?

I also have the same issue when I try 4.2.2. However, I don't have the problem when I work on 4.3. After googling, I realize the problem is caused by apk and odex. In 4.2.2, tests are compiled into apk and odex, which means, the apk doesn't contain the classes.dex. The odex file contains all classes. This actually cause the failure when you only "adb install apk", because pm cannot find the classes.dex.
The way to solve this is to add LOCAL_DEX_PREOPT := false in the Android.mk. This will put the dex back to the apk. I have tried this in 4.2.2 full-eng.
This thread also gives some info. https://groups.google.com/forum/#!topic/android-building/OrBJsS2J3sw

Related

How to repair corrupted/obsolote Genymotion emulator via shell

I use a Genymotion android emulator for my automated Xamarin UI tests through the bash commands.
The issue is that the emulator is killed by the test runner app after tests are done. So this causes some kind of corruption on the emulator's virtual device file, I suppose.
When I try to start the emulator next time using the same script, I get the following error from Genymotion:
After clicking the update button, Genymotion dashboard opens. Then I can run the emulator by double clicking. But, I cannot do these steps through the shell.
If I could figure out what Genymotion does to repair the emulator, I would do the same thing in the shell script.
Here is my script to run the GM emulator;
cd $HOME
emulatorId=$(VBoxManage list vms | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})" | shuf -n 1)
open -a /Applications/Genymotion.app/Contents/MacOS/player.app --args --vm-name $emulatorId
sleep 5
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
After this command is executed I run my tests like following;
dotnet test Droid.UI.test.dll
Any solution or workaround for skipping this prompt is highly appreciated,
Thanks!
Your script completely overrides the launchpad; that's the problem. Why not use gmtool? It has been designed especially for this type of use.

Can't install apk on Android Things running on a Rasberry Pi 3B

I can install the apk and debug and everything works fine, but then (what seems randomly) it starts giving me the following error when I try to install/debug the app:
09/16 07:53:46: Launching app
$ adb push C:\Workspace\new-project-template-master\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.wolf.androidthings.autoherb
$ adb shell pm install -r "/data/local/tmp/com.wolf.androidthings.autoherb"
Error: android.os.ParcelableException: java.io.IOException: Requested internal only, but not enough space
$ adb shell pm uninstall com.wolf.androidthings.autoherb
$ adb shell pm install -r "/data/local/tmp/com.wolf.androidthings.autoherb"
Error: android.os.ParcelableException: java.io.IOException: Requested internal only, but not enough space
$ adb shell pm uninstall com.wolf.androidthings.autoherb
Unknown failure (at android.os.Binder.execTransact(Binder.java:674))
Error while Installing APK
The only way I can fix this problem at the moment is flashing the Android Things image again, which is not ideal..
Any ideas on why this is happening?
PS. This is when doing a debug install via Android Studio
I've seen this on Android Things with Raspberry Pi. As you have noticed, uninstalling the app via adb doesn't work. I connected with the console via serial and noticed that I was out of space on the filesystem. I had some big log files associated with my app (not sure where, somewhere in /data/...). I removed those (as in rm -f ...) and then my app installed fine.

android espresso: running test from command line

I have a test.espresso package with all the test classes.
I am trying to run a single test class from the command line, however it ends up running all the test classes.
adb shell am instrument -w \
com.demo.app.test/android.support.test.runner.AndroidJUnitRunner
How do I just run a single test class. I want to use bamboo(which is like jenkins) to run all the test classes individually in separate jobs.
This worked for me (the change is in bold:
adb shell am instrument -w-e class full.path.and.TestClassName\ com.demo.app.test/android.support.test.runner.AndroidJUnitRunner
Based on: https://developer.android.com/studio/test/command-line.html#AMOptionsSyntax (look under options for "class").
If you're using gradle, then there is gradle task you can directly use to achieve it. It would be something like this:
./gradlew connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
To run on specific flavor:
./gradlew connectedMyAppFlavorDebugAndroidTest
It does everything for you, right from building the app, installing on the connected device, run the tests and finally uninstall the app.
If you're not sure about the exact gradle task you need to execute the tests, run the following to get the all available gradle tasks:
./gradlew tasks
You'll get the list of all the tasks with the short description.
To run via command line
Start device. I use Genymotion so I would do
gmtool admin start DeviceName
Install via command line
For ADB
for ADB is should be exactly what the console outputs from Android studio when you start .
$ adb push /Users/x/x-android/app/build/outputs/apk/x-debug.apk
$ adb shell pm install -r "/data/local/tmp/com.x"
$ adb push /x/x/x-android/app/build/outputs/apk/x-debug-androidTest.apk /data/local/tmp/com.x.test
$ adb shell pm install -r "/data/local/tmp/com.x.test"
For Genymotion it is
gmtool device install ~/Desktop/x.apk
gmtool device install ~/Desktop/x-androidTest.apk
For Genymotion connect Genymotion to ADB
gmtool device adbconnect
Start your tests. This is for both ADB and Geny
adb shell am instrument -w -r -e debug false -e class com.x.MyTest com.x.test/android.support.test.runner.AndroidJUnitRunner
I'm adding also how to run it from Gradle here.
./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.MyClassTest#myFunctionTest

Android UI testing: "adb shell uiautomator" throws error, "uiautomator" in "adb shell" works

I would like to compile and run Android UI black-box tests using only command-line tools on Windows. I wrote an UiAutomatorTestCase, built it, and uploaded it into /data/local/tmp/. I verified that the jar file was copied into the latter directory.
If I type
adb shell
and then type
uiautomator runtest MyTest.jar –c com.example.MyTest
at the adb shell prompt, the test runs successfully. So far so good.
The problem is if I combine these two steps and type
adb shell uiautomator runtest MyTest.jar –c com.example.MyTest
then I get the following error:
Error: /data/local/tmp/ľc does not exist
According to the documentation, this should work. The error is the same on Windows 7 Pro 32-bit HUN and on Windows 8.1 Pro 64-bit ENG. The device is a Samsung Galaxy S3 Mini (GT-I8190), running Android 4.1.2 (API level 16).
What am I doing wrong?
I strongly suppose,
adb shell
$ <command> is same as adb shell <command>. I've never encountered any discrepancy in this regards.
Please try adb kill-server and adb start-server
Please also try adb -s <device_id> shell <command> you can find <device_id> from adb devices
Can you also please let us know what is the output of adb version?

adb and multiple device simultaneously

I am automating some test on android devices.
I am using Jenkins in order to run the tests (via jobs)
each job runs with a 95% success rate when only 1 device is connected to the machine
but when I plug 2 android devices or more, it seems adb has some trouble and I get a 5% success rate.
is it ok to run multiple instances of adb command?
here is the command I run for each job:
adb -s DEVICESERIAL shell am force-stop com.myapp.test
adb -s DEVICESERIAL shell am force-stop com.myapp
adb -s DEVICESERIAL uninstall com.myapp adb -s DEVICESERIAL uninstall com.myapp.test
adb -s DEVICESERIAL install -r com.myapp adb -s DEVICESERIAL install -r com.myapp.test
adb -s DEVICESERIAL shell am instrument -w TESTNAME/android.test.InstrumentationTestRunner
adb -s DEVICESERIAL logcat -d -v time
all command run with success but when the test starts and when I have multiple devices connected i get errors like for example:
- Unable to find instrumentation target package
- INSTRUMENTATION_STATUS_CODE: 0
- Failure [INSTALL_FAILED_INVALID_URI]
at first I thought the test apk was not installed correctly, but when trying manually after the failure, it worked fine (so the test file is installed)
again. Using 1 device only, everything is stable.
Is there something special to do in order to install and run the test on different devices simultaneously?
note that I have tried different usb ports, different cables etc...
thanks

Categories

Resources