安卓官方测试工具vts

安卓官方测试工具vts

之前在审计android hal层源码时注意到存在很多test文件,但是又不能直接使用。
谷歌肯定通过某种方式将他们集成到一起,通过搜索得知为vts

vts简介

vts是谷歌给vendor作测试用的,具体可以参阅官方文档。像我这样的安全研究员
可以用它来fuzz感兴趣的模块,它还提供了dashboard,通过google sdk显示测试
结果,覆盖率等情况,因为我对google sdk不是很熟,所以暂且搁置dashboard,
仅关注vts fuzz脚本编写。

使用方法

前置条件:已经成功编译aosp源码,并且成功刷机

$ make vts -j
$ vts-tradefed
> run vts-codelab -m VtsCodelabHelloWorldTest

Codelab给出示例代码,这里做一个简单介绍:

AndroidTest.xml

<configuration description="Config for VTS CodeLab HelloWorld test case">
    <option name="config-descriptor:metadata" key="plan" value="vts-codelab" />
    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
        <option name="push-group" value="HostDrivenTest.push" />
    </target_preparer>
    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
        <option name="test-module-name" value="VtsCodelabHelloWorldTest"/>
        <option name="test-case-path" value="vts/testcases/codelab/hello_world/VtsCodelabHelloWorldTest" />
    </test>
</configuration>

test名称为:VtsCodelabHelloWorldTest。
VtsFilePusher将所有需要的文件压入。
VtsMultiDeviceTest指定模块名称,也就是run vts-codelab -m <模块名称>


import logging

from vts.runners.host import asserts
from vts.runners.host import base_test
from vts.runners.host import const
from vts.runners.host import test_runner


class VtsCodelabHelloWorldTest(base_test.BaseTestClass):
    """Two hello world test cases which use the shell driver."""

    def setUpClass(self):
        self.dut = self.android_devices[0]
        self.shell = self.dut.shell

    def testEcho1(self):
        """A simple testcase which sends a command."""
        results = self.shell.Execute(
            "echo hello_world")  # runs a shell command.
        logging.info(str(results[const.STDOUT]))  # prints the stdout
        asserts.assertEqual(results[const.STDOUT][0].strip(),
                            "hello_world")  # checks the stdout
        asserts.assertEqual(results[const.EXIT_CODE][0],
                            0)  # checks the exit code

    def testEcho2(self):
        """A simple testcase which sends two commands."""
        results = self.shell.Execute(["echo hello", "echo world"])
        logging.info(str(results[const.STDOUT]))
        asserts.assertEqual(len(results[const.STDOUT]),
                            2)  # check the number of processed commands
        asserts.assertEqual(results[const.STDOUT][0].strip(), "hello")
        asserts.assertEqual(results[const.STDOUT][1].strip(), "world")
        asserts.assertEqual(results[const.EXIT_CODE][0], 0)
        asserts.assertEqual(results[const.EXIT_CODE][1], 0)

if __name__ == "__main__":
    test_runner.main()

VtsCodelabHelloWorldTest继承自BaseTestClass,它有四个默认方法:

  • setUpClass:在启动时调用
  • setUp:在执行每个测试用例前调用
  • tearDown:在执行完每个测试用例后调用
  • tearDownClass:在结束时清理

测试用例是一个以test开头的函数

有心情再写吧,估计接下来几天要忙成狗开始刚nfc了

参考文献

https://codelabs.developers.google.com/codelabs/android-vts

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,127评论 19 139
  • 很长时间没有认真的写篇文章,从今天开始正式学习PHP扩展开发,之前在Linux上也折腾过,只是认为在Linux上没...
    AllinGo阅读 1,087评论 2 2
  • 学的快最重要的是什么? 如果我说学的快最重要的是你已有的知识,你信吗?也就是说你原先知道的越多,你现在学的越快。 ...
    鸭梨山大哎阅读 2,941评论 1 4
  • 小明是我一个朋友的朋友,大学时候因为朋友的关系,我们常常聚会,后来也算成了朋友。还记得大学那会儿,每次大伙儿一起出...
    小斌Fiona阅读 361评论 0 0
  • 这次小组学习,看到我们小组成绩暂居第一,我当时心里由衷地高兴。取得这样的成绩并不是偶然,是因为我们组的家人多写多分...
    蜗牛的守望阅读 1,910评论 0 0