[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Testing program with random output [newbie]

From: Robert Hartmann
Subject: Re: Testing program with random output [newbie]
Date: Wed, 21 Aug 2013 20:34:00 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8

Hi Ben,

Am 19.08.2013 03:17, schrieb Ben Elliston via gmane.comp.sysutils.dejagnu.general:
On Sun, Aug 18, 2013 at 10:49:19PM +0200, Robert Hartmann wrote:

I did not see, how I can do my string parsing in the
"expect"-language, and I don't see, how I can check for an
indeterministic number of lines.

I think I understand what you're getting at.

What if your program-under-test had a test option that causes a marker
to be output after the last of the lines?  Then you could have a loop
that keeps matching lines, checking them, and if you're still passing
when the marker arrives, you pass.  If you never recieve the marker,
you will time out and fail the test.

Your idea with the end-programm-output-marker is very nice :-)

In my first step I try to parse only one string: (my code follows)

I tied my best, but tcl syntax is somehow "strange" for me, and my code doesn't work. I can't fix it. Could you please help me?

proc validString {mystring} {

set ok 0

set myKeyA "gefangen"
set myKeyB "Wasser"
set myKeyC "Wasser"
set myKeyD "Schiff"

set x 0
set y 0

set length [string length $mystring]

for {set pos 0} {$pos<$length} {inc pos} {
        set mychar [eval [string index $mystring $pos]]
        switch -exact $mychar {
                < {dec x}
                > {inc x}
                ^ {inc y}
                v {dec y}
                default { }

if {       $y < 0   && -1 != string last $myKeyA $mystring end } {
        set ok 1        
} elseif { $x < -2  && -1 != string last $myKeyB $mystring end } {
        set ok 1
} elseif { $x > 2   && -1 != string last $myKeyC $mystring end } {
        set ok 1
} elseif { $x >= -2 && $x <= 2 && $y >= 20 && -1 != string last $myKeyD $mystring end } {
        set ok 1

return $ok

validString "Matrose(1) -^-^-^-^->->-v-^-v-^-<-<-^-v-^-<->-^-v-^-v->-^-<-^-v-<-^-^-v-^-^-^-v-<->-^-^-^->-<-^->->-v-^-<-^-^-^-v-<-^-^->-v->-^-<-v->->-^-^-v-<-^-^-^(Schiff)"
validString "Matrose(15) -^-^-^-^-v-<-^->-v-^->-^-v-v->-^-^->(Wasser)"
validString "Matrose(16) -^->-v->->(Wasser)"
validString "Matrose(17) ->-^-v-v(gefangen)"
validString "Matrose(62)-<->-^-v->-^-v->-<->-<->-<-^-^-<-^-^-v-^-^->-v-^->-<-<-<-v-v->-^->-v-^-^-<->-<-v-^-^-v->-^->-^-^->(Wasser)"


If the validString procedure work correctly,
then I hope I could use this in the DejaGnu-Part

proc PROGRAM_test {expr result} {
    global feedback
    send "$expr\n"
    expect {
      -gl "$result\r\n" {pass {validString {$expr} }}
      "*\r\n" { fail "$expr"}
      timeout { fail "timeout $expr"}

PROGRAM_test "" 1;


Best regards,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]