`
lhq1013
  • 浏览: 87537 次
  • 性别: Icon_minigender_2
  • 来自: 丽水
社区版块
存档分类
最新评论

Android CTS的TCL/Expect交互式自动化脚本

阅读更多
runCTS.exp脚本主要是连接Android系统真机后运行Android cts测试计划用的,过程中对部分异常情况做的处理,脚本尚不完善,仅供参考。
(脚本中的内容的解释请参考 http://lhq1013.iteye.com/blog/907633)

#!/usr/bin/expect

set force_conservative 0  ;# set to 1 to force conservative mode even if
  ;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

set timeout -1
spawn $env(SHELL)     ;#启动一个SHELL进程
match_max 2000   ;#设置最大匹配的字符数
expect "*"

# proc: reboot telephone
proc restartPhone {} {
spawn ./adb shell
expect "# "
sleep 5
send "reboot\r"
sleep 5
expect "*"
puts "-------------reboot ok"
}

# proc: set permissions for device
set passwords {rxyrxy vmkid} ;   #list of passwords.You have three chances at most to enter the right password.

proc setPermissions {} {
puts "-----------setPermissions"
set count 0
global passwords    ;#global 用于在过程中引用全局变量

send "sudo -s\r"
expect {          ;#开始循环匹配send后输出的结果
"*# " { send "./adb kill-server\r" }    ;#双引号中为要求匹配的字符,“*”为通配符,花括号中未匹配上后需要做的动作
"Sorry, try again." {sleep 2; incr count 1; set password [lindex $passwords $count]; send "${password}\r"; exp_continue }
"*password*" { set password [lindex $passwords $count]; send "${password}\r"; exp_continue }     ;#exp_continue表示跳出此次循环,继续下次;如果不写在匹配上后,直接跳出循环
}
expect "*# "
send -- "./adb devices\r"
expect {
"*List of devices attached \r*device\r" { puts "------------------connect device ok"; sleep 2; }
"*List of devices attached *" { sleep 5; setPermissions; exp_continue}
}
}

# proc: start to run the test plan
proc executePlan {plan} {
set cmd "start --plan "
lappend cmd $plan       ;#在变量cmd后面追加变量plan的值
set timeout 2400       ;#设置超时时间为40分钟

send $cmd
send "\r"
    expect {
"*Choose a session" {sleep 1; send "1\r"; exp_continue}
"Test summary:*pass*fail*timeOut*notExecuted*Total" {puts "----------$plan.------run--over"; sleep 8 }
"offline" {puts "----------$plan.offline----"; restartPhone; sleep 13; exp_continue}
#"Installing met timeout due to Unknown reason." {sleep 10; puts "----------$plan.offline----"; restartPhone; exp_continue}
"*\r" {sleep 20; exp_continue}
timeout {puts "--------timeout--------"; restartPhone; exp_continue}
}
}

#prepare for start run plans, connect to telephone

# how to catch the ANDROID_BUILD_TOP no defined error.?
puts "----------------------------------------------------"
set status [catch { set dirPath $env(ANDROID_BUILD_TOP) } result ]   
if { $status != 0 } {
puts stderr "Please run 'build/envsetup.sh' first!"
exit 1
}

setPermissions     ;#调用前面定义好的setPermissions过程

send "cd ${dirPath}/out/host/linux-x86/cts/android-cts/tools\r"
expect "*# "
send "./startcts\r"
expect "*connected\r
*cts_host > "
sleep 8

# which plans would be run.
# Here you can use commandlineparameter to set the value of plans which would be run.
set plans $argv
if {$plans eq ""} {
set plans {Signature RefApp Performance AppSecurity Android VM Java CTS}
}

# if a plan is ok, which should be removed from the full plans!?
#The variable plans is a list. Here use FOR-Loop to read the value of the full plans that specified list index.
#It will run the next one until the previous one is over.
for {set index [expr [llength $plans] - 1]} {$index >= 0} {incr index -1}  {

set plan [lindex $plans $index]
executePlan $plan
puts "--------------------next-------------------"
sleep 13
}

exit
expect eof

   到此为止,该脚本结束。测试脚本,只要在终端运行"./runCTS.exp"即可,若不想运行所有测试计划,也可用命令行参数在启动前指定需要运行的计划,各个计划之间用空格隔开,如"./runCTS.exp Android Java Vm"
分享到:
评论

相关推荐

    #!/usr/bin/expect

    Expect 是一个强大的自动化工具,常用于交互式应用程序的自动化,尤其是与远程服务器进行SSH连接、管理密码或密钥认证等任务。 在IT领域,了解 Expect 脚本编写是相当有用的,特别是对于系统管理员和自动化工程师。...

    expect交互式执行网络命令

    expect实现 shell 交互式网络命令,插件安装: tar xzvf expect5.45.tar.gz cd expect5.45 ./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-...ln -s /usr/tcl/bin/expect /usr/expect/bin/expect

    针对linux服务器交互式自动化脚本实现与研究.pdf

    "Linux服务器交互式自动化脚本实现与研究" 本文主要介绍了在Linux服务器集群之间实现无密码的SSH登录,并将其集成到集群的安装过程中实现自动化。通过 Expect 实现无密码登录 SSH,并将其写入 RPM 包中,实现安装...

    Tcl/Expect

    Tcl/Expect学习心得:等待操作是很有用的及COM通讯脚本

    expect5.43.0和tcl8.4.11.zip

    `Expect`是建立在`TCL`基础上的一个扩展,专为自动交互式应用程序设计,如SSH、telnet等。` Expect5.43.0`和`TCL8.4.11`是这两个工具的特定版本,它们可能包含了对某些功能的优化和改进。 首先,`TCL(Tool Command...

    Tcl/tk 宝典之一 - Expect讲解

    Expect 是一种基于Tcl(Tool Command Language)的脚本语言扩展,主要应用于自动化脚本编写中,特别是那些需要与远程服务如SSH、FTP等进行交互的场景。通过使用Expect,用户可以模拟人类与系统的交互过程,实现对...

    Tcl.rar_scripting_tcl/tk_脚本 解释

    2. **测试脚本**:在软件开发中,Tcl被广泛用于编写测试脚本,例如在自动化测试框架如Expect中,Tcl用于模拟用户与程序的交互。 3. **教学和研究**:由于其简洁性和易于理解,Tcl常被用于计算机科学的教学和科学...

    tcl864安装包

    tcl脚本语言安装包,要安装expect脚本,必须先安装tcl。 一)Tcl 安装 主页: http://www.tcl.tk 下载地址: http://www.tcl.tk/software/tcltk/downloadnow84.tml 1.下载源码包 wget ...

    Tcl语言,expect脚本

    - **简介**: Expect是一个Tcl的扩展包,用于自动化交互式程序的控制。它特别适用于远程管理任务,如通过telnet或SSH连接到其他计算机。 - **功能**: Expect允许编写脚本来模拟用户的键盘输入和响应预期的屏幕输出,...

    Tcl.And.Tk.rar_tcl/tk

    Tcl/Tk社区提供了丰富的扩展和库,如Tkinter(Python的GUI库,基于Tk)、Expect(用于自动化交互式程序)、BLT(扩展图形和图表功能)等,这些扩展进一步增强了Tcl/Tk的功能和适用性。 **学习资源** 这个“Tcl.And...

    tcl.rar_.tcl_tcl_tcl tk_tcl/tk_tcl_tk

    8. **应用领域**:TCL/TK不仅用于快速开发小型GUI应用,还在网络管理、科学计算、自动化测试等领域有广泛应用,例如 Expect工具用于自动应答终端交互。 在压缩包内的文件“tcl”可能是包含这些示例代码的脚本文件,...

    TCL_Expect_deja.zip_Exploring.Expect.pdf_deja gnu_tcl_tcl语言_自动化测

    Expect库是TCL中的一个强大工具,专为自动化交互式程序设计而生。它允许脚本模拟终端会话,自动处理预期的输出,然后根据预期的结果作出反应。这对于自动化测试网络服务、Unix命令行工具或者任何需要用户输入响应的...

    expect5.43.0_tcl8.4.11.zip

    Expect是一个由Dennis Rylands开发的开源工具,它基于TCL语言,专门设计用来自动化与交互式程序的通信。在许多场景下,例如SSH登录、脚本自动化测试、系统管理等,我们可能需要模拟用户输入来与程序进行交互。Expect...

    Tcl/expect sms gateway-开源

    - Expect是Tcl的一个扩展,专门用于自动化交互式程序,如telnet、ssh、ftp等。它通过匹配模式来响应程序的输出,从而实现自动化控制。 - 在SMS网关中,Expect库用于模拟用户与短信服务提供商的交互,例如登录、...

    交互试软件的脚本

    总之,Expect 脚本为 IT 管理员提供了一种强大的工具,通过自动化处理交互式任务,减少了人工干预的需求,提升了运维效率。熟练掌握 Expect,可以在日常工作中节省大量时间,同时也可以为构建更复杂的自动化解决方案...

    tcl-expect

    Expect是由Don Libes开发的一个基于TCL的自动化测试工具,用于自动交互式程序。Expect可以用来模拟终端用户的操作,从而实现自动化测试、配置管理等任务。 **特点概述:** - **TCL扩展**:Expect是作为TCL的一个...

    通过tcl安装expect

    在IT领域,`Expect`是一个强大的自动化脚本工具,它允许程序员或系统管理员与命令行接口(CLI)进行交互,特别是在需要输入响应的自动化场景下非常有用,如SSH登录、FTP传输等。`Expect`是基于TCL语言的一个扩展,...

    tcl和expect配置.zip

    接下来,Expect是基于TCL的扩展,主要用于自动化交互式应用程序,如telnet、ftp、passwd等。Expect由Don Libes在1993年开发,它通过模拟用户输入并响应程序输出,使得脚本能够自动控制这些程序的流程。 Expect5.45.4...

    expect交互式ssh登陆交换机实现自动备份

    bash 调用expect ssh到cisco设备,通过tftp方式备份配置 已经测试通过,并上到生产服务器 前提要先架设好TFTP服务器并测试通过

Global site tag (gtag.js) - Google Analytics