Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392604
  • 博文数量: 77
  • 博客积分: 2031
  • 博客等级: 大尉
  • 技术积分: 855
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 19:54
文章分类

全部博文(77)

文章存档

2011年(1)

2009年(52)

2008年(24)

我的朋友

分类: LINUX

2008-10-23 21:22:50

在测试过程中,在具体测试某一个功能点时,往往需要为此进行大量的配置。为了简化测试过程,我们可以把所有的配置命令放在一个文本文件中,然后使用测试脚本来执行这些命令。这样就不需要再手工进行配置了,费时费力。
基于如上考虑,编写了下面的脚本tCmd.exp。这个脚本被我们前面介绍过的test.exp脚本调用。

# $Id$

# This file is used to execute specific commands list in a file

proc execCmdFile {cmdFile} {
    global g_dbgFlag g_prompt

    # enable debug
    set g_dbgFlag 1

    # login
    set spawn_id [login $g_devip $g_user $g_passwd]
    if {$spawn_id == 0} {
        errLog "login $g_devip failed"
        return 0
    }

    # open cmdFile
    set cmdFd [open $cmdFile r]

    while true {
        # get a line
        if {![getLine $cmdFd line]} {
            dbgLog "reached eof"
            break
        }

        # split the line
        set ln [split $line ","]
        set cmd [string trim [lindex $ln 0]]
        set out [string trim [lindex $ln 1]]

        if {$cmd == ""} continue
        if {$out == ""} set out $g_prompt

        # send cmd line
        exp_send "$cmd\n"
        dbgLog "send $cmd"

        # expect output
        dbgLog "expect $out"
        expect {
            timeout {
                errLog "TIMEOUT: while exec \"$cmd\""
                continue
            }
            -ex "$out" {
                continue
            }
        } ;# end expect
    }

    # close cmdFile
    close $cmdFd
}

# if no cmdFile, use default
if {$cmdFile == ""} {
    set cmdFile "cmdFile.txt"
}

execCmdFile $cmdFile

有了这个脚本,我们可以使用"./test.exp -cinterface.txt cmd"来执行interface.txt中的命令。
阅读(1840) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~