introduction of unit test on android kernel

53
Introduction of Unit Test on Android Kernel Jiahe Jou, 2012/11/22

Upload: johnson-chou

Post on 25-Jun-2015

2.952 views

Category:

Technology


12 download

DESCRIPTION

Android kernel unit testing

TRANSCRIPT

Page 1: Introduction of unit test on android kernel

Introduction of Unit Test on Android Kernel

Jiahe Jou, 2012/11/22

Page 2: Introduction of unit test on android kernel

Revisions

DATE AUTHOR DESCRIPTION

2012/11/13 Jiahe Jou Draft.

Page 3: Introduction of unit test on android kernel

Outlines● OMAP DDT Overview

● Compile and Installation

● Pre-requirement

● Run Test

● Automation Tool

● Customization

● Utilities

Page 4: Introduction of unit test on android kernel

OMAP DDT Overview● OMAP DDT(Device Driver Test)

○ Device driver testing framework for OMAP Linux kernel

○ Part of Linux OMAP Project

● Repository location○ Old: git://dev.omapzoom.org/pub/scm/richo/device_driver_test.git

○ New: git://gitorious.org/omap-ddt/omap-ddt.git

● Current branches○ master

○ ddt-2.6.35

○ ddt-2.6.39

○ ddt-3.0

Page 5: Introduction of unit test on android kernel

OMAP DDT Overview● First commit

Page 6: Introduction of unit test on android kernel

OMAP DDT Overview● Current owner

● Committer○ Leed Aguilar, [email protected]

○ Dmytro Kedrovskyi, [email protected]

○ Mariia Nagul, [email protected]

Page 7: Introduction of unit test on android kernel

OMAP DDT Overview● Every device has their own test code base

Page 8: Introduction of unit test on android kernel

● Compile

● Configuration

Compile and Installation

# Makefile / Place in the root of code base

KDIR:=$(PWD)/../kernel/android-3.0

CROSS_COMPILE:=arm-none-linux-gnueabi-

HOST:=x86_64

# Compile for g-sensor

$ make TESTSUITES=accelerometer

# For all devices

$ make

# A "build" folder will be created

Page 9: Introduction of unit test on android kernel

Compile and Installation● Install to device

# In OMAP DDT folder

$ adb push build /system/testsuites

# /system/testsuites is recommended

Page 10: Introduction of unit test on android kernel

Compile and Installation● Install to device

# In OMAP DDT folder

$ adb push build /system/testsuites

# /system/testsuites is recommended

Not Enough to

Run TEST!!

Page 11: Introduction of unit test on android kernel

Pre-requirement● Pre-requirement

○ Busybox

○ Bash

● Repository location○ git://busybox.net/busybox.git

○ git://git.savannah.gnu.org/bash.git

● Homepage○ http://www.busybox.net/

○ http://savannah.gnu.org/projects/bash

Page 12: Introduction of unit test on android kernel

Pre-requirement

Busybox Settings --> Build Options --> Build Busybox as a static binary (no shared libs) - Enable this option by pressing "Y"Busybox Settings --> Build Options --> Cross compiler prefix - Set this option equal to "arm-none-linux-gnueabi-"Busybox Settings --> General Configuration --> Don't use /usr - Enable this option by pressing "Y"Linux Module Utilities --> [ ] Simplified modutils [*] insmod [*] rmmod [*] lsmod [*] Pretty output [ ] modprobe [ ] depmodLinux Module Utilities --> [ ] Support version 2.2/2.4 Linux kernelsLinux Module Utilities --> [ ] Try to load module from a mmap'ed areaLinux Module Utilities --> [*] Support tainted module checking with new kernelsLinux Module Utilities --> () Default directory containing modules - Set this option to nothingLinux Module Utilities --> () Default name of modules.dep - Set this option to nothing

● Configuration for Busybox

Page 13: Introduction of unit test on android kernel

Pre-requirement● Install Busybox

$ adb push busybox /system/sbin

$ adb shell

$ cd /system/sbin

$ ./busybox --install .

# /system/sbin is recommended

Page 14: Introduction of unit test on android kernel

Pre-requirement

$ adb push busybox /system/sbin

$ adb shell

$ cd /system/sbin

$ ./busybox --install .

# /system/sbin is recommended

● Install Busybox

Don't forget the DOT

Page 15: Introduction of unit test on android kernel

Pre-requirement

$ CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/opt/arm_bash/

--host=arm-linux --enable-static-link --without-bash-malloc

$

$ make

$ adb push bash /system/sbin

$ adb shell

$ cd /system/sbin

$ mv sh sh.busybox

$ ln -s /system/sbin/bash sh

● Compile Bash

● Install Bash

Page 16: Introduction of unit test on android kernel

Run Test

# In /system/testsuites/accelerometer/test_code/script/

$ mkdir tmp test

○ /bin/sh: bad interpreter: No such file or directory# !/bin/sh

Modify to ...

# !/system/sbin/sh

● Troubleshooting○ tmp - cannot work as a temporary directory

○ test - cannot work as a test directory

● Run all test under device

# In /system/testsuites/accelerometer/test_code/script/

$ ./run_all.sh

Page 17: Introduction of unit test on android kernel

Run Test

Page 18: Introduction of unit test on android kernel

Run Test

蝦毀!!

Page 19: Introduction of unit test on android kernel

Automation Tool● TITAN, TI Test AutomatioN tool

○ Control board through serial or telnet connection

○ Scheduling to run the test cases.

○ Auto boot support (Phidget board required)

● Repository location○ git://dev.omapzoom.org/pub/scm/cristopherson/titan-development.git

● Last commit

Page 20: Introduction of unit test on android kernel

Automation Tool● Recommended Environment

○ Netbeans

○ Java 1.6

● Project dependency○ Titan_Common

■ commons-net-1.4.1.jar

■ iText-2.1.0.jar

■ RXTXcomm.jar

■ ganymed-ssh2-build210.jar

■ poi-3.6-20091214.jar

Page 21: Introduction of unit test on android kernel

Automation Tool● Project dependency

○ Titan_DevelopmentBoard■ Phidget21.jar

○ Titan_GUI■ jcalendar.jar

■ RXTXcomm.jar

■ Phidget21.jar

■ iText-2.1.0.jar

■ poi-3.6-20091214.jar

Page 22: Introduction of unit test on android kernel

Automation Tool● Screenshot

Page 23: Introduction of unit test on android kernel

Automation Tool● Choose connection

Page 24: Introduction of unit test on android kernel

Automation Tool● Choose connection

Page 25: Introduction of unit test on android kernel

Automation Tool● Connection setting

Page 26: Introduction of unit test on android kernel

Automation Tool● Set test provider

Page 27: Introduction of unit test on android kernel

Automation Tool● Set test provider

Page 28: Introduction of unit test on android kernel

Automation Tool● Set test provider

Page 29: Introduction of unit test on android kernel

Automation Tool● Tests loaded

Page 30: Introduction of unit test on android kernel

Automation Tool● Check test cases

Page 31: Introduction of unit test on android kernel

Automation Tool● Schedule test

Page 32: Introduction of unit test on android kernel

Run Test

Page 33: Introduction of unit test on android kernel

Customization

main configuration file

run all tests

test runner

● Test code organization

Page 34: Introduction of unit test on android kernel

Customization

...

if [ `cat $SYSFS_BOARD_REV | grep -c "Tablet"` -ge 1 ]; then

# Specific to bma180 sensor

export ACCELEROMETER_SYSFS_PATH="/sys/bus/i2c/drivers/bma180_accel/4-0040"

export ACCELEROMETER_HW="bma180"

export ACCELEROMETER_POWERON_VAL=1

export ACCELEROMETER_POWEROFF_VAL=0

export ACCELEROMETER_ENABLE_POWER="$ACCELEROMETER_SYSFS_PATH/enable"

...

● Default device configuration in conf.sh○ BMA180

Page 35: Introduction of unit test on android kernel

Customization

...

elif [ `cat $SYSFS_BOARD_REV | grep -c "Panda"` -ge 1 ]; then

# Specific to bma250e sensor

export ACCELEROMETER_SYSFS_PATH="/sys/devices/accelerometer"

export ACCELEROMETER_HW="bma250e"

export ACCELEROMETER_POWERON_VAL=1

export ACCELEROMETER_POWEROFF_VAL=0

export ACCELEROMETER_ENABLE_POWER="$ACCELEROMETER_SYSFS_PATH/enable"

# Some extra configurations

...

● Add my device configuration to conf.sh ○ BMA250E

Page 36: Introduction of unit test on android kernel

Customization

#! /system/sbin/sh

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0001

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0002

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0003

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0004

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0005

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0006

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0007

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0008

./test_runner.sh -S L_DD_ACCELEROMETER_0000_0011

...

● run_all.sh

Scenarios

Page 37: Introduction of unit test on android kernel

Customization

Shell scripts

C code

● Test code structure

Page 38: Introduction of unit test on android kernel

Customization

C code

● Test code structure

Ctrl + C and Ctrl + V

Page 39: Introduction of unit test on android kernel

Customization

#####################################################################

# Scenario: L_DD_ACCELEROMETER_0000_0002

# Author : Hemanth V

# Date : Thu Jun 24 16:43:42 IST 2010

#####################################################################

# Begin L_DD_ACCELEROMETER_0000_0002

# FILE exists and is a symbolic link (same as -L)

01 set -x; test -h $ACCELEROMETER_SYSFS_PATH

# End L_DD_ACCELEROMETER_0000_0002

● Scenarios○ L_DD_ACCELEROMETER_0000_0002

Page 40: Introduction of unit test on android kernel

Customization

...

01 $ACCELEROMETER_DIR_HELPER/$ACCELEROMETER_HW/ACC_0000_0005

...

○ ACC_0000_0005

echo -n "1" > $ACCELEROMETER_SYSFS_PATH/enable

echo "Ensure board is Flat on the surface\n"

value=`$ACCELEROMETER_DIR_BINARIES/acctest $DEVFS_ACCELEROMETER Z

| grep Value | awk '{print $2}'`

[ $value -ge 900 ]

● Scenarios with helper○ L_DD_ACCELEROMETER_0000_0005

Page 41: Introduction of unit test on android kernel

Customization

○ run_all.sh

#! /system/sbin/sh

....

/test_runner.sh -S L_DD_ACCELEROMETER_0000_0099

...

...

01 $ACCELEROMETER_DIR_HELPER/$ACCELEROMETER_HW/ACC_0000_0099

...

● Add scenarios○ L_DD_ACCELEROMETER_0000_0099

Page 42: Introduction of unit test on android kernel

Customization

# Test the enable/disable function of accelerometer

handlerSysFs.sh "set" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWERON_VAL

handlerSysFs.sh "compare" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWERON_VAL || exit 1

handlerSysFs.sh "set" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWEROFF_VAL

handlerSysFs.sh "compare" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWEROFF_VAL || exit 100

exit 0

● ACC_0000_0099

Page 43: Introduction of unit test on android kernel

Customization

# In /system/testsuites/accelerometer/test_code/script/

$ ./test_runner.sh -S L_DD_ACCELEROMETER_0000_0099

# Or

$ ./run_all.sh

● Run it!○ L_DD_ACCELEROMETER_0000_0099

Page 44: Introduction of unit test on android kernel

Customization● Run by Titan

○ omap-ddt/automation/test_descriptors/accelerometer/teststitan-

testdescriptor.xml

<test id="L_DD_ACCELEROMETER_0000_0001"><information>

<autor>Jiahe Jou</autor><description>Test enable/disable feature of accelerometer.</description><dateofcreation>21/11/2012</dateofcreation>

</information><run>

<action><command>/testsuites/accelerometer/scripts/test_runner.sh

L_DD_ACCELEROMETER_0000_0099</command></action><action>

<command>rm /testsuites/accelerometer/scripts/log.*</command></action>

</run>

Page 45: Introduction of unit test on android kernel

Customization● Run by Titan

○ omap-ddt/automation/test_descriptors/accelerometer/teststitan-

testdescriptor.xml

<pass><output>

<value>stat=0</value></output>

</pass>

<fail><timeout time="15"/><output>

<regularexpression>stat=[^0]\d*</regularexpression></output>

</fail>

</test>

Page 46: Introduction of unit test on android kernel

Utilities● Under "omap-ddt/utils/*"● PAN tool

○ A test driver integrated from LTP

○ Execute listed test cases, report 0 for all passed, or number of failed

○ Ex. scenarios

● akey○ Listen KEY_ENTER, KEY_SELECT and KEY_OK from kaypad

● waitkey○ Listen any one key event

● BC tool○ For "bc programming language" for math

○ Syntax is similar to C

Page 47: Introduction of unit test on android kernel

Utilities● evtest

○ Event listener, exit by interrupt

● handlers○ A collection of useful helpers, such as operating on sysfs

○ handlerActivityManager.sh

○ handlerAndroidMonkey.sh

○ handlerAndroidPM.sh

○ handlerAndroidSqlite3.sh

○ handlerCpuFreqScalFrequencies.sh

○ handlerSysFs.sh

○ ...

○ About 4x helpers

Page 48: Introduction of unit test on android kernel

Utilities● memtester tool

○ Memoey testing tool

● microcom tool○ Minicom-like serial terminal emulator

● priority○ Get and set processes' priority

● schedutils tool○ Control processes's scheduling

Page 49: Introduction of unit test on android kernel

Utilities● scripts

○ A collection of useful scripts and monkey scripts

○ android_display_switch.sh

○ is_android_ready.sh

○ display.live.wallpaper.menu

○ display.system.wallpaper.menu

○ ics.set.max.screen.timeout.value

○ t2.ics.unlock.screen

○ ...

○ About 2x scripts

Page 50: Introduction of unit test on android kernel

Utilities

# Test the enable/disable function of accelerometer

handlerSysFs.sh "set" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWERON_VAL

handlerSysFs.sh "compare" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWERON_VAL || exit 1

handlerSysFs.sh "set" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWEROFF_VAL

handlerSysFs.sh "compare" $ACCELEROMETER_SYSFS_PATH/enable

$ACCELEROMETER_POWEROFF_VAL || exit 100

exit 0

● Usage

Page 51: Introduction of unit test on android kernel

Utilities● Usage

#####################################################################

# Scenario: L_DD_ACCELEROMETER_0000_0005

# Author : Hemanth V

# Date : Thu Jun 24 16:43:42 IST 2010

#####################################################################

# Begin L_DD_ACCELEROMETER_0000_0005

echo -n "1" > $ACCELEROMETER_SYSFS_PATH/enable

echo "Ensure board is Flat on the surface\n"

value=`$ACCELEROMETER_DIR_BINARIES/acctest $DEVFS_ACCELEROMETER Z

| grep Value | awk '{print $2}'`

[ $value -ge 900 ]

Page 52: Introduction of unit test on android kernel

Q & A

Page 53: Introduction of unit test on android kernel

End