dejagnu
[Top][All Lists]
Advanced

[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: Thu, 22 Aug 2013 13:23:01 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8

Am 21.08.2013 20:34, schrieb Robert Hartmann:
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.


Well that was not true - after sleeping some hours, having some cup of coffee. I could correct my tcl code:

#==========8<=========

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} {incr pos} {

set mychar [string index $mystring $pos]

switch -exact $mychar {
< {incr x -1}
{incr x}
^ {incr y}
v {incr y -1}
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
}

#==========8<=========

Now I can think of how to use this procedure in my DejaGnu testscript.



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


#==========8<=========

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;

#==========8<=========


Best regards,
    Robert





reply via email to

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