[Android] Introduction to automated testing of andorid camera [2]

1 Overview

In the previous content we already know how to use adb and shell in python.

But in fact, every command has to be typed by hand, which is very troublesome.

Optimize the content of this section today.

2 Global variables for testing

See the previous article on reading the basic configuration:
getting started with python automation

We use it directly based on the read.py written above.

from read import readConfig   #导入包的操作
...
a = testInfo()
...
class testInfo:										   #testInfo 类用来存储测试模式/测试次数/测试设备
    def __init__(self):
        self.testCase = ""
        self.count    = 0
        self.devices  = ""
...
testInfo         =   readConfig()                      #读取config.txt文件
apk              =   testInfo[0]                       #测试apk名字
a.count          =   testInfo[1]                       #测试次数
a.testCase       =   testInfo[2]                       #测试模块    
a.devices        =   testInfo[3]                       #测试设备,这边测试设备是第三个字段.我第二个字段的内容是测试的模式/open/photo

3 ADB

Write an adb command operation function, this function needs to return the operation of adb related commands.
In essence, it is the splicing between characters.

#adb 命令函数
def adbCmd(cmd):
    global a
    ACmd = "adb -s "+a.devices +" "+ cmd
    print(ACmd)
    result = os.popen(ACmd)
    # print("执行命令后返回的内容为")
    #print(result.read())
    return result.read()

Write another adb operation function that does not return a value.

def adbCmd2(cmd):
    global a
    ACmd = "adb -s "+a.devices +" "+ cmd
    print(ACmd)
    os.system(ACmd)

The purpose of my writing two is just to make it easy to operate directly. After all, not every time you need to return the content of the operation.

Then write related functions such as taking pictures and returning to home

# 获取adb 设备信息
def getDevices():
    global a
    devices = os.popen("adb  devices|awk '{print $1}'|sed -n '2p'")
    a.devices = devices.read()
    a.devices = a.devices.replace("\n","")                                     #删掉换行符

# 获取hal的pid
def getPid():
    global halPid
    cmd = adbCmd("shell ps -A |grep \"camerahalserver\" |awk '{print $2}'|sed -n '1p'")      #获取camerahalserver的PID
    halPid = cmd.replace("\n","")
    print("halPid = ",cmd)
   
#返回home函数
def goHome():
    adbCmd("shell input keyevent 3")

#mode = 2 打开相机
def openCamera():
    cmd = "shell am start -W "+apk
    adbCmd(cmd)
#mode = 3 拍照
def photo():
    adbCmd2("shell input keyevent 27")

4 Memory Monitoring

After understanding the above situation, let's make an extension and write a program to monitor the content of the camera of the android device.

adb -s $devices shell dumpsys meminfo camerahalserver |grep -iE "TOTAL PSS"					#PSS
adb -s $devices shell cat sys/kernel/debug/ion/ion_mm_heap									#ION
adb -s $devices shell cat /proc/$pid/smaps													#SMAP

The entire test architecture is as follows: each part can be disassembled separately to write a package for inheritance and use.


The monitoring mobile phone was opened and tested 4469 times, as shown above, the memory is very good, and there is no obvious change. No memory leaks.

Guess you like

Origin blog.csdn.net/qq_38753749/article/details/128729445