RE: [RFC] Improve testsuite for poor expect behavior

Pierre Muller
2009-06-17T20:17:45Z

[-- Attachment #1: Type: text/plain, Size: 2757 bytes --]

My way to use cygwin expect for DJGPP
is quite ugly, but it gives some results.

The basic idea is to consider that djgpp
is a remote target and to overload several
expect procedures to cope with DJGPP specific
features.

I added a .dejagnu directory in my cygwin home,
with an empty site.exp file
and a boards directory.
This directory stores several files,
but only one concerns DJGPP.
I simply called it djgpp.exp
and I run the testsuite
in
djbuild/gdb/testsuite
(with a DJGPP compiled gdb.exe at djgpp/gdb level).
I an sereral testsuite subsets using
make check RUNTESTFLAGS="--target=djgpp --host_board=djgpp gdb.*/wa*.exp"
Which means that the same file ($HOME/.dejagnu/boards/djgpp.exp)
is used both as host_board and target...
as I said it is really ugly, but I didn't have time to
sort things out, and I am not sure I will have the willingness
to do it...

I attached the djpp.exp file.

The key functions are
djgpp_spawn and djgpp_exec
djgpp_exec uses a response file
for long commandlines, to overcome the
80 chars limitations for Dos command lines.
In its present form, it prints out lots of
information, send_user can probably be changed to verbose
if someone just wants to use it.

Eli, tell me if you get a chance to try it out.

Pierre

> -----Message d'origine-----
> De : Eli Zaretskii [mailto:eliz@gnu.org]
> Envoyé : Wednesday, June 17, 2009 7:17 PM
> À : 'Daniel Jacobowitz'
> Cc : muller@ics.u-strasbg.fr; brobecker@adacore.com; gdb-
> patches@sourceware.org
> Objet : Re: [RFC] Improve testsuite for poor expect behavior
>
> > Date: Wed, 17 Jun 2009 09:36:26 -0400
> > From: 'Daniel Jacobowitz' <drow@false.org>
> > Cc: 'Joel Brobecker' <brobecker@adacore.com>, gdb-
> patches@sourceware.org
> >
> > I have not tried this on DJGPP at all.
>
> You cannot try this with DJGPP, because there are no such APIs in
> DJGPP (with the exception of `setmode', which does exist). Also,
> there are no pipes in DJGPP.
>
> I cannot judge what would be needed for DJGPP, since Pierre did not
> yet explain how does he run DJGPP with the test suite, nor show any
> code that achieves that. All I can say is that DJGPP has the
> `setmode' function that can be used to switch a standard handle into
> binary mode, and that `isatty' is available to detect whether a handle
> is connected to a terminal device. Note that the DJGPP build of GDB
> generally does not always use file I/O functions to write to the
> terminal; it uses direct screen I/O for some ops. Thus, binary mode
> file I/O not necessarily will solve the problem that bothers Pierre,
> although I do not yet understand fully whether it is relevant to DJGPP
> as it is to MinGW.

[-- Attachment #2: djgpp.exp --]
[-- Type: application/octet-stream, Size: 4386 bytes --]

# djgpp gdb running n cygwin expect.

# The canonical unix board description.
load_generic_config "unix";

global env
global EXEEXT
set EXEEXT ".exe"
set env(EXEEXT) ".exe"
set env(DJDIR) e:/djgpp
set env(DJGPP) ${env(DJDIR)}/djgpp.env
set DJGPP_BIN_DIR /cygdrive/e/djgpp/bin

global CC_FOR_TARGET
global GNATMAKE_FOR_TARGET

set CC_FOR_TARGET ${DJGPP_BIN_DIR}/gcc.exe
set GNATMAKE_FOR_TARGET ${DJGPP_BIN_DIR}/gnatmake.exe

process_multilib_options "";

set_board_info inputnotfromterminal 1;

# set_board_info compiler "[find_gcc]";

# set_board_info bmk,use_alarm 1;

# set_board_info gdb,noinferiorio 1;

send_user "configuring for djgpp, board=\"$board\" testing inside Cygwin\n";

global store_host_board;

proc disable_host_board {} {
global host_board
global store_host_board
if {[info exists host_board]} {
set store_host_board $host_board;
} else {
set store_host_board "";
}
unset host_board;
return 0;
}

proc reenable_host_board {} {
global host_board
global store_host_board
if {[info exists store_host_board]} {
set host_board $store_host_board;
} else {
unset host_board;
}
unset store_host_board;
return 0;
}

proc djgpp_spawn { board cmd } {
global board_info
global host

verbose "DJGPP: djgpp_spawn called board=\"$board\" cmd=\"$cmd\""
set baseboard [lindex [split $board "/"] 0]

disable_host_board
set board_info($baseboard,isremote) 0
set result [remote_spawn $board $cmd]
set board_info($baseboard,isremote) 1

reenable_host_board

return $result
}

proc djgpp_exec { hostname prog args } {
global board_info
global host

verbose "DJGPP: djgpp_exec called hostname=\"$hostname\" \
prog=\"$prog\" args=\"$args\""
disable_host_board

set args_needed 0;
set largs $args;
verbose "largs=\"$largs\""
if { [llength $args] == 1 } {
set largs [lindex $args 0]
}
verbose "largs=\"$largs\""
for {set i 0 } { $i < [llength $largs] } { incr i } {
verbose "lindex $i is \"[lindex $largs $i]\""
if { [lindex $largs $i] != {} } {
set args_needed 1;
}
}

set djgpp_res_file "./djgpp.res";
set real_prog "";
if { [ string length "$prog $args"] > 80 } {
send_user "DJGPP: long command line prog=\"$prog\" args=\"$args\"\n"
set djgpp_id [open "$djgpp_res_file" "w"]
send_user "DJGPP: Using response file $djgpp_res_file id=$djgpp_id\n"
set n [llength $prog];
if {$n > 1} {
set prog_args [lrange $prog 1 end];
set real_prog [lindex $prog 0];
} else {
set prog_args "";
set real_prog $prog;
}
if {$prog_args != ""} {
puts $djgpp_id "$prog_args"
}
if {$args_needed} {
puts $djgpp_id "$args"
}
close $djgpp_id
}
if {$real_prog != ""} {
set result [remote_exec $hostname "$real_prog" "@$djgpp_res_file"]
} else {
if {$args_needed} {
set result [remote_exec $hostname "$prog" "$args"]
} else {
set result [remote_exec $hostname $prog ""]
}
}
reenable_host_board
return $result
}

proc ${board}_download { board host dest } {
verbose "DJGPP: ${board}_download host=\"$host\" dest=\"$dest\""
disable_host_board
set res [remote_download "$board" "$host" "$dest"]
reenable_host_board
return $res
}

proc ${board}_file { dest op args } {
verbose "DJGPP: board_file dest=\"$dest\" op=\"$op\" args=\"$args\""
if { $op == "delete" } {
return 0;
}
return [eval [list standard_file $dest $op] $args]
}

proc ${board}_upload { target source dest } {
verbose "DJGPP: ${target}_upload source=\"$source\" dest=\"$dest\""
disable_host_board
set res [remote_upload $target "$source" "$dest"]
reenable_host_board
return $res
}

proc transform_gdb_expect { expcode } {
verbose "DJGPP: djgpp_gdb_expect entry expcode=\"$expcode\""
set subst1 [regsub -all {\\r+\\n} $expcode {\\r\\n} expcode1]
set subst2 [regsub -all {\\r\\n} $expcode1 {\\r+\\n} expcode2]
verbose "DJGPP: djgpp_gdb_expect returned expcode=\"$expcode2\""
if { $subst1 != 0 || $subst2 != 0 } {
send_user "DJGPP: djgpp_gdb_expect substs=$subst1 + $subst2\n"
verbose "DJGPP: djgpp_gdb_expect returned expcode=\"$expcode2\""
return $expcode2;
}
return $expcode;
}