为什么期望与预期不符?

问题描述 投票:0回答:1

在我的情况下,expect与调试模式的预期不匹配,我不明白为什么......

相关tcl的部分是这样的

...
set index 0
set p [lindex $propname $index]
send "prove -property {<embedded>::wrapper.$p}\r"
expect {
  "*proven\r\n\[<embedded>\] % " { 
        incr index
        if {$index == [llength $propname]} {
            send "exit\r"
            expect "*bash-4.2$ "
            send "exit\r"
            close
        }
        set p [lindex $propname $index]
        send "prove -property {<embedded>::wrapper.$p}\r"
        exp_continue
        }

  "*cex\r\n\[<embedded>\] % " { 
        send "visualize -violation -property <embedded>::wrapper.$p\r"
        expect "*\[<embedded>\] % "
        send "visualize -save -vcd cex.vcd -force\r"
        }
}
...

从调试模式的输出:

expect: does "prove -property {<embedded>::wrapper.x0_nouse}\r\nINFO (IPF031): Settings used for this proof:\r\n    time_limit                    = 86400s\r\n    per_property_time_limit       = 1s * 10 ^ scan\r\n    engine_mode                   = Hp Ht N B \r\n    proofgrid_per_engine_max_jobs = 1\r\n    proofgrid_mode                = local\r\n    proofgrid_restarts            = 10\r\nINFO (IPF036): Starting proof on task: "<embedded>", 1 properties to prove with 0 already proven/unreachable\r\nINFO (IRS029): Starting reset analysis: phase 1 of 4.\r\nINFO (IRS030): Running reset analysis phase 2 of 4.\r\nINFO (IRS031): Running reset analysis phase 3 of 4.\r\nINFO (IRS020): Starting the reset analysis simulation with a limit of 100 iterations (phase 4 of 4).\r\nINFO (IRS024): Reset iterations 0 to 4 analyzed.\r\nINFO (IRS018): Reset analysis simulation executed for 3 iterations. Assigned values for 280 of 4626 design flops, 0 of 32 design latches, 136 of 2696 internal elements.\r\nUsing multistage preprocessing\r\nStarting reduce\r\nFinished reduce in 0.192s\r\n0.PRE: A proof was found: No trace exists. [0.00 s]\r\nINFO (IPF057): 0.PRE: The property "wrapper.x0_nouse" was proven in 0.00 s.\r\nFound proofs for 1 properties in preprocessing\r\nINFO (IPF059): Completed proof on task: <embedded>\r\nproven\r\n[<embedded>] % " (spawn_id exp4) match glob pattern "*proven\r\n[<embedded>] % "? no
 "*cex\r\n[<embedded>] % "? no

对不起,该行有点长,但如果向右滚动,您会看到该行的结尾正是第一种情况下的预期结果。

tcl expect
1个回答
3
投票

你提供了一个glob模式,并且正确地需要逃避[],以便它不被tcl作为命令执行。你需要进一步逃离[],以便[abc]匹配文字字符串[abc]而不仅仅是设置abc中的一个字符。

但是,当引用""时,反斜杠也需要转义,所以你需要作为你的glob模式

"proven\r\n\\\[<embedded>\\\] % " 

作为替代方案,您可以在没有glob的情况下尝试完全匹配

 -exact "proven\r\n\[<embedded>\] % "

您也可以使用{}而不是"",但之后您的\r等将不会被转换。

© www.soinside.com 2019 - 2024. All rights reserved.