From 5481f29161477520c691d525653323b82fa47ad7 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Mon, 17 Jun 2013 19:22:10 +1000 Subject: * runtest.exp (libdirs): New global variable. (load_lib): Append libdirs to search_and_load_files directories. * doc/ref.xml (load_lib): Document global variable libdirs. * doc/dejagnu.texi: Regenerate. * testsuite/runtest.all/load_lib.exp: New testcase. * Makefile.am (TESTSUITE_FILES): Add new testcase. * Makefile.in: Regenerate. Signed-off-by: Ben Elliston --- ChangeLog | 10 +++++++++ Makefile.am | 1 + Makefile.in | 1 + doc/dejagnu.texi | 17 ++++++++++++++- doc/ref.xml | 15 ++++++++++++- runtest.exp | 11 +++++++--- testsuite/runtest.all/load_lib.exp | 44 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 testsuite/runtest.all/load_lib.exp diff --git a/ChangeLog b/ChangeLog index 0728842..2d23388 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2013-06-17 Bernhard Reutner-Fischer + + * runtest.exp (libdirs): New global variable. + (load_lib): Append libdirs to search_and_load_files directories. + * doc/ref.xml (load_lib): Document global variable libdirs. + * doc/dejagnu.texi: Regenerate. + * testsuite/runtest.all/load_lib.exp: New testcase. + * Makefile.am (TESTSUITE_FILES): Add new testcase. + * Makefile.in: Regenerate. + 2013-06-15 Ben Elliston * configure.ac: If DEJAGNU is unset, set it to /dev/null. diff --git a/Makefile.am b/Makefile.am index ac60114..7789e4d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -233,6 +233,7 @@ TESTSUITE_FILES = \ testsuite/runtest.all/clone_output.test \ testsuite/runtest.all/config.test \ testsuite/runtest.all/default_procs.tcl \ + testsuite/runtest.all/load_lib.exp \ testsuite/config/default.exp \ testsuite/lib/libsup.exp \ testsuite/lib/util-defs.exp \ diff --git a/Makefile.in b/Makefile.in index 1171a38..86c92cc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -478,6 +478,7 @@ TESTSUITE_FILES = \ testsuite/runtest.all/clone_output.test \ testsuite/runtest.all/config.test \ testsuite/runtest.all/default_procs.tcl \ + testsuite/runtest.all/load_lib.exp \ testsuite/config/default.exp \ testsuite/lib/libsup.exp \ testsuite/lib/util-defs.exp \ diff --git a/doc/dejagnu.texi b/doc/dejagnu.texi index f53291d..9e6c606 100644 --- a/doc/dejagnu.texi +++ b/doc/dejagnu.texi @@ -4257,7 +4257,8 @@ to print string without a trailing newline. Use the optional @node load_lib procedure, , verbose procedure, Core Internal Procedures @subsubsection Load_lib Procedure -Loads a DejaGnu library file by searching a fixed path built +Loads a DejaGnu library file by searching the default fixed paths +built into DejaGnu. If DejaGnu has been installed, it looks in a path starting with the installed library directory. If you are running DejaGnu directly from a source directory, without first running @@ -4279,6 +4280,20 @@ The name of the DejaGnu library file to load. @end table +The global variable @code{libdirs}, handled +as a list, is appended to the default fixed paths built +into DejaGnu. + +@strong{Additional search directories for load_lib} + +@example +# append a non-standard search path + global libdirs + lappend libdirs $srcdir/../../gcc/testsuite/lib + # now loading $srcdir/../../gcc/testsuite/lib/foo.exp works + load_lib foo.exp +@end example + @node Procedures For Remote Communication, connprocs, Core Internal Procedures, Builtin Procedures @subsection Procedures For Remote Communication diff --git a/doc/ref.xml b/doc/ref.xml index b366207..18ae3bc 100644 --- a/doc/ref.xml +++ b/doc/ref.xml @@ -1015,7 +1015,8 @@ Load_lib Procedure - Loads a &dj; library file by searching a fixed path built + Loads a &dj; library file by searching the default fixed paths + built into &dj;. If &dj; has been installed, it looks in a path starting with the installed library directory. If you are running &dj; directly from a source directory, without first running @@ -1038,6 +1039,18 @@ load. + The global variable libdirs, handled + as a list, is appended to the default fixed paths built + into &dj;. + + Additional search directories for <function>load_lib</function> + # append a non-standard search path + global libdirs + lappend libdirs $srcdir/../../gcc/testsuite/lib + # now loading $srcdir/../../gcc/testsuite/lib/foo.exp works + load_lib foo.exp + + diff --git a/runtest.exp b/runtest.exp index 78da782..bd39dd8 100644 --- a/runtest.exp +++ b/runtest.exp @@ -589,7 +589,7 @@ proc lookfor_file { dir name } { # source tree, (up one or two levels), then in the current dir. # proc load_lib { file } { - global verbose libdir srcdir base_dir execpath tool + global verbose libdir libdirs srcdir base_dir execpath tool global loaded_libs if {[info exists loaded_libs($file)]} { @@ -597,8 +597,11 @@ proc load_lib { file } { } set loaded_libs($file) "" - - if { [search_and_load_file "library file" $file [list ../lib $libdir $libdir/lib [file dirname [file dirname $srcdir]]/dejagnu/lib $srcdir/lib $execpath/lib . [file dirname [file dirname [file dirname $srcdir]]]/dejagnu/lib]] == 0 } { + set search_dirs [list ../lib $libdir $libdir/lib [file dirname [file dirname $srcdir]]/dejagnu/lib $srcdir/lib $execpath/lib . [file dirname [file dirname [file dirname $srcdir]]]/dejagnu/lib] + if {[info exists libdirs]} { + lappend search_dirs $libdirs + } + if { [search_and_load_file "library file" $file $search_dirs ] == 0 } { send_error "ERROR: Couldn't find library file $file.\n" exit 1 } @@ -652,6 +655,8 @@ set libdir [file dirname $execpath]/dejagnu if {[info exists env(DEJAGNULIBS)]} { set libdir $env(DEJAGNULIBS) } +# list of extra search directories used by load_lib to look for libs +set libdirs {} verbose "Using $libdir to find libraries" diff --git a/testsuite/runtest.all/load_lib.exp b/testsuite/runtest.all/load_lib.exp new file mode 100644 index 0000000..55a3a07 --- /dev/null +++ b/testsuite/runtest.all/load_lib.exp @@ -0,0 +1,44 @@ +# test load_lib + +# Verify that load_lib searches for a lib not only in it's default +# search_dirs but also in the libdirs list of directories. + +# load_lib f exits with a failure if it does not find f. +# Arrange for the testcase to handle this: +rename exit saved_exit +proc exit { args } { return [lindex $args 0] } + +# The test right below is supposed to fail. +# Prettify default output by only printing the message in verbose mode. +rename send_error saved_send_error +proc send_error { args } { + verbose [lindex $args 0] 2 +} + +if { [ load_lib "subfile1" ] != 1} { + fail "load_lib subfile1 found per default" +} else { + pass "load_lib subfile1 not found per default" +} + +rename send_error "" +rename saved_send_error send_error + +set extradir [file join $srcdir $subdir "topdir" "subdir1" ] +global libdirs +lappend libdirs $extradir +verbose "now added libdirs: $libdirs" 2 + +# In this testcase, we did not exit 1 from load_lib as per above rename. +# subfile1 thus is in the loaded_libs LUT and we won't walk the +# search_dirs again. Use another file for testing the lappend worked. + +if { [load_lib "subfile2"] == ""} { + pass "load_lib subfile2 loaded" +} else { + fail "load_lib subfile2 not found" +} + +# cleanup after us +rename exit "" +rename saved_exit exit -- cgit v1.1