How to log to the fastlane screengrab output - android

I am using fastlanes screengrab to capture screenshots of an app. screengrab is utilizing androids ui testing framework espresso to navigate through the app. if one of my ui tests fails I want the other tests to continue capturing screenshots but at the same time I want to be notified about the failed test.
To prevent the test to fail and stopping the whole program I surrounded all my tests with try / catch. When a test fails I want the the exception to be logged to the screengrab output:
[10:24:37]: Running tests for locale: bs-BA
[10:24:37]: $ adb -s emulator-5554 shell am instrument --no-window-animation -w \
-e testLocale bs_BA \
-e endingLocale en_US \
-e class my.app.tests.MainLocationScreenshots \
-e isScreengrab true \
my.app.test/my.app.runners.RxTestRunner
[10:24:40]: ▸ my.app.tests.MainLocationScreenshots:
[10:24:41]: ▸ my.app.tests.MainLocationScreenshots:....
[10:25:37]: ▸ Time: 42.311
[10:25:37]: ▸ OK (7 tests)
I tried the following without success:
Log.d("", "Can you read this?????????")
Log.d("Screengrab", "Can you read this?")
Log.println(Log.ERROR,"Screengrab","What about this?")
System.out.print("But I bet this works")
All the Log calls appear in Logcat but not in the screengrab output, the System.out.print does not appear in either.
Is there a way to log the the screengrab output? Is it documented somewhere I haven't looked?
Thanks!

Related

how to execute individual Junit test in android using gradle

My project contains multiple test classes and each class contains some test methods.
I can run all the test using command line
gradlew testDebugUnitTest
Is there any gradlew command to run specific testMethod from a class?
Is there any gradlew command to run all test mmethods from a specific class?
Here is a class Foo2 and bar3 is the particular method you would like to test. This was taken from the Google developer Junit unit test command line documentation
$ adb shell am instrument -w \
> -e class com.android.demo.app.tests.Foo2#bar3 \
> com.android.demo.app.tests/android.support.test.runner.AndroidJUnitRunner

Native Code coverage with android soong build system

I'm trying to generate code coverage report for my native components with AOSP source code using soong build system.
I have extended aosp vhal but unit test cases are same as in below link.
http://androidxref.com/8.1.0_r33/xref/hardware/interfaces/automotive/vehicle/2.0/default/tests/
Tried adding below to cc_test, cc_binary in Android.bp
native_coverage : true,
cflags: [
"-g",
"-O0",
"-fprofile-arcs",
"-ftest-coverage",
],
ldflags : [
"-fprofile-arcs",
"-ftest-coverage",
],
Native binary unit-tests-coverage is generated in out/target/product but I can't find gcno intermediates for this.
Running below command gives me *.gcda files for each test files.
adb shell \
GCOV_PREFIX=/data/local/tmp \
GCOV_PREFIX_STRIP=`echo $ANDROID_BUILD_TOP | grep -o / | wc -l` \
/data/local/tmp/unit-tests-coverage
I have tried below links but not sure how to proceed :(
http://logan.tw/posts/2015/04/28/check-code-coverage-with-clang-and-lcov/
https://android.googlesource.com/platform/bionic.git/+/master-soong
https://android.googlesource.com/platform/build/soong/+/581341d%5E%21/
https://android.googlesource.com/platform/external/e2fsprogs/+/fedfb27%5E%21/
https://android.googlesource.com/platform/development/+/master/scripts/acov#23
http://androidxref.com/9.0.0_r3/xref/bionic/README.md#293
I'm not sure if google's vts framework can be used here to generate native code coverage.
https://codelabs.developers.google.com/codelabs/android-vts-8/#6
"gcnodir" is generated but not sure how to make use of it.
/coverage/data/nativetest64/vehicle-unit-tests-coverage/unit-tests-coverage.gcnodir
Posting answer to my question for other users on SO.
Install coverage tool :
sudo apt-get install lcov (This should install lcov-1.12)
sudo apt-get install gcc-4.6 (Clang generates .gcno approximately equal to gcc 4.2 that aren't compatible
with gcov-4.8. Installing gcc-4.6 to get gcov-4.6 and invoking lcov with '--gcov-tool /usr/bin/gcov-4.6')
Download LLVM 3.8 for llvm-cov to work : http://releases.llvm.org/download.html
All native unit test cases i.e instrumented binary needs to be executed on target. To build and emit clang's instrumentation based profiling. Example: http://androidxref.com/9.0.0_r3/xref/hardware/interfaces/automotive/vehicle/2.0/default/Android.bp#82 (Renamed to vehicle-manager-unit-test for shorter name)
export NATIVE_COVERAGE=true
Add native_coverage: true to test module in Android.bp
Go to: module-name/test
Use mm or make command to build native binary
Ex: For hardware/interfaces/automotive/vehicle/2.0/default/tests/ :
mma or make vehicle-manager-unit-test -j32
Copy coverage enabled instrumented binary to target
adb push out/target/product/product_name/data/nativetest64/vendor/vehicle-manager-unit-test /data/nativetest64/vehicle-manager-unit-test
adb shell chmod +x /data/nativetest64/vehicle-manager-unit-test
Run test cases and generate .gcda files
adb shell \
GCOV_PREFIX=/data/local/tmp \
GCOV_PREFIX_STRIP=echo $ANDROID_BUILD_TOP | grep -o / | wc -l \
/data/nativetest64/vehicle-manager-unit-test
adb shell find -iname *.gcda
adb pull /data/local/tmp/proc/self/cwd/out/soong/.intermediates/hardware/interfaces/automotive/vehicle/2.0/default/vehicle-manager-unit-test/android_x86_64_silvermont_vendor_cov/obj/hardware/interfaces/automotive/vehicle/2.0/default/tests/ .(Destination folder)
Extract GCNO files from GCNODIR (archive file generated at
out/overage/data/nativetest64/vendor/vehicle-manager-unit-test ) to
same folder with GCDA files
llvm-cov gcov -f -b *.gcda (https://llvm.org/docs/CommandGuide/llvm-cov.html )
lcov --directory . --base-directory . --gcov-tool /usr/bin/gcov-4.6 --capture -o cov.info (http://ltp.sourceforge.net/coverage/lcov.php)
genhtml cov.info -o output
Here's the script which wraps all these commands:
https://gist.github.com/pankajgangwar/f070b8b54e83543f8e3638dcd2cae1b8
here it is explaned how to generate coverage reports, which do require GTest:
these flags enable the generation of test coverage: -fprofile-arcs -ftest-coverage
then one has to use gcov: gcov main_test.cpp
which's output then can be passed on to lcov (for reference):
$ lcov --coverage --directory . --output-file main_coverage.info
from which one can generate an lcov coverage report in HTML format:
$ genhtml main_coverage.info --output-directory out
these .gcda files in .gcnodir are gcov data files. gcov also has an output option --json-format, which might come handy when wanting to consume the coverage data with a web-service.
one of the examples from the links you've provided can be used to generate it for a whole project:
Collect the code coverage results:
$ lcov --directory . \
--base-directory . \
--gcov-tool gcov.sh \
--capture -o cov.info
Generate HTML files:
$ genhtml cov.info -o output
where the only difference is, that the wrapper script would need to be adjusted to call gcov. probably one could even omit the wrapper passed with option --gcov-tool, since it should be directly called.
since one can only prepare the coverage report by adding the compiler flags, the gcov and lcov commands should be setup as post-build script, so that they would automatically generate the report.

Time cannot run brunch?

I'm having an issue with the time command.
I use /usr/bin/time so i can use the -f and -o modifiers.
My script is:
make clean
repo sync -j5
. ./platform_manifest/manual_add_kernel_manifest.sh \
&& . build/envsetup.sh \
&& /usr/bin/time -o log$day$month.log -f "Buildtime: %E" brunch aokp_mako-eng
The script is part of an automated build system for an android ROM.
When it gets to the time part, i get:
/usr/bin/time: cannot run brunch: No such file or directory
Command exited with non-zero status 127
Buildtime: 0:00.00
Brunch works fine with the regular time command, but I cannot route its output to a file, which is why I am using /usr/bin/time in the first place. If there is a way to do this, that is fine for me as I can trim off the real: header with | awk '{ print $2 }'.
Any help is appreciated!
Ubuntu 12.04, all updates installed
I don't know what brunch is, but the most likely reason that a non-builtin time program can't find it, even when the built-in time can, is that it's a shell function or a Bash alias.
Whether or not that's the case . . .
[…] I cannot route [the regular time command's] output to a file […]
You can write:
{ time brunch aokp_mako-eng ; } 2>"log$day$month.log"
to wrap time (and everything else) into a command-list whose STDERR has already been redirected to the file.

android monkey runner scripts

I was trying to run a a sample python program using monkey runner but unfortunately throwing an error of this type :
Can't open specified script file
Usage: monkeyrunner [options] SCRIPT_FILE
-s MonkeyServer IP Address.
-p MonkeyServer TCP Port.
-v MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)
Exception in thread "main" java.lang.NullPointerException
so any one can guide me how to resolve this and how to use monkey runner to execute this type of things
I've found that making the path to the script absolute helped monkeyrunner.
I am invoking the runner from a Python script where a helper class has a startMonkey method:
def startMonkey(self, monkeyScript):
command = [ self.env + '\\tools\\monkeyrunner.bat' ]
command.append( os.path.abspath( monkeyScript ) )
return startProcess( command )
This seems to be working for me.
Script file should be a full path file name try below monkeyrunner c:\test_script\first.py
So go to the folder \ sdk \ tools
and press shift and right click to open command prompt and type monkeyrunner c:\test_script\python_file_name.py

color the lines of logcat on Linux [android]

The Logcat in Eclipse has colors for errors, warning, debug, ...
How can I do to get the same result on Linux (Ubuntu) when I run the command 'adb -e logcat' in a terminal to get it colored?
adb logcat -v color
from developer.android.com
Link with script
I think it will be useful for you and you can change script by yourself;)
This is my view of "colorizing" the logcat:
https://bitbucket.org/brunobraga/logcat-colorize
My favourite is pidcat, maintained by Jake Wharton based off of Jeff Sharkey's script (mentioned by Yaroslav Boichuk).
I have also used logcat-color, maintained by Marshall Culpepper, (also based off of Jeff's script) which allows you to create profiles you can activate (log per task, or per application, etc).
I have preferred pidcat because at the time logcat-color wouldn't filter by package name, and I never went back to try again once it was added. Seems to be reasonably popular still as well.
And yet another script:
#!/bin/sh
while :; do
adb $# logcat | sed \
-e 's:^V/:\x00\x1b[0;35m:g' \
-e 's:^D/:\x00\x1b[0;36m:g' \
-e 's:^I/:\x00\x1b[0;32m:g' \
-e 's:^W/:\x00\x1b[0;33m:g' \
-e 's:^E/:\x00\x1b[0;31m:g' \
-e 's:^F/:\x00\x1b[0;31m:g' \
-e '/Unexpected value from nativeGetEnabledTags/d' \
-e '/The application may be/d'
sleep 1
done
If you use Python, PyLogAnalyser can filter, colorize and analyse all type of logs in Linux, Windows and Mac (and Cygwin).
You can install it directly from PyPI:
python -m pip install pyloganalyser
And call it in order to print the log for the standard output (also, for text or HTML output):
adb logcat -v threadtime | python -m loganalyser --stdin --stdout -c Android_logcat_threadtime.conf
The file 'Android_logcat_threadtime.conf' is included in the module directory. So the actual invocation could be:
CONFPATH="$(python -c 'import loganalyser;print loganalyser.__file__.replace("/__init__.pyc","")')";
adb logcat -v threadtime | python -m loganalyser --stdin --stdout -c "$CONFPATH"/android/Android_logcat_threadtime.conf
Website: http://pyloganalyser.sourceforge.net
Have a try with lnav , add logcat config from here

Categories

Resources