Autotest添加测试用例小结

Autotest本身是一个自动化测试框架,可以在上面添加各种测试工具用于系统测试。前几天我在上面添加了几个基于龙芯桌面5.0系统的性能测试工具。现在做以下总结,大体写以下添加的过程。

以unixbench5为例,首先在client/tests目录下有一个文件夹:unixbench5,此文件夹有如下文件:
[root@Autotest-server unixbench5]# ls
control Makefile.patch UnixBench5.1.3.tgz unixbench5.py
其中control是控制文件,添加用例到autotest上时首先用到的,里面有测试名称NAME(很重要,添加新的用例时会修改这里的),测试属性、测试类、测试说明等,最后一行是测试执行的函数:

job.run_test('unixbench5',args='-c 1 -c 4', iterations=3)

run_test函数是job类里的一个方法,里面有很多参数,unixbench5是测试的用例,跟文件unixbench5.py直接对应,一般得相同才可以。"args"是执行参数,"iterations"是执行次数,一般是执行3次取平均值。

unixbench5.py文件是运行测试程序要用的脚本文件,里面有一个"unixbench5"的类,这个名词一般与外部的文件名相同,在这个类下有几个函数:

import os
import re
from autotest.client import test, utils
from autotest.client.shared import error #需要的模块 class unixbench5(test.test):#类,名词应该和外部的文件相同。 """
This test measure system wide performance by running the following tests:
- Dhrystone - focuses on string handling.
- Whetstone - measure floating point operations.
- Execl Throughput - measure the number of execl calls per second.
- File Copy
- Pipe throughput
- Pipe-based context switching
- Process creation - number of times a process can fork and reap
- Shell Scripts - number of times a process can start and reap a script
- System Call Overhead - estimates the cost of entering and leaving the
kernel.
- Graphical Tests - Both 2D and 3D graphical tests are provided. @see: http://code.google.com/p/byte-unixbench/
@author: Dale Curtis <dalecurtis@google.com>
""" #说明文件
version = 5 #版本 def initialize(self): #初始化函数,检查是否含有gcc,作用不是太大
self.job.require_gcc()
self.err = [] def setup(self, tarball='UnixBench5.1.3.tgz', args=''): #配置函数,创建源码目录,解压源码文件
"""
Compiles unixbench. @tarball: Path or URL to a unixbench tarball
@see: http://byte-unixbench.googlecode.com/files/unixbench-5.1.3.tgz
"""
tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
utils.extract_tarball_to_dir(tarball, self.srcdir)
os.chdir(self.srcdir)
if 'graphics' in args or 'gindex' in args:
utils.system('patch -p1 < %s/Makefile.patch' % self.bindir) #打patch包
utils.make() #编译安装 def run_once(self, args=''): #执行函数,用来执行测试用例,运行程序,收集结果到特定文件里。 vars = 'UB_TMPDIR="%s" UB_RESULTDIR="%s"' % (self.tmpdir,
self.resultsdir)
os.chdir(self.srcdir) self.report_data = utils.system_output('export DISPLAY=:0.0;'+ vars + ' ./Run ' + args)
self.results_path = os.path.join(self.resultsdir,
'raw_output_%s' % self.iteration)
utils.open_write_close(self.results_path, self.report_data)

Makefile.patch是一个patch包,非必须。UnixBench5.1.3.tgz是源码文件,一般会有。

以上就是一个测试用例的基本文件目录。如果要添加新的测试工具,需要修改control、unixbench5.py里的相关信息,还要替换源码目录。
修改完所有的信息后需要在auotest目录下执行:./utils/test_importer.py -t client/tests/test_tool/即可。test_tool是测试用例的名称。修改完后直接登录auotest服务器的网页即可看到用例已经更新到列表里,可以使用了。
总结:
可以看出添加一个测试用例不是很难,在原有的测试用例上简单修改即可,需要有一点的python知识,因为测试用例都是用python写的。

上一篇:【Android测试】【第十八节】Espresso——环境搭建


下一篇:利用DNSLOG获取看不到的信息(给盲注带上眼镜)