1 # Copyright (C) 2018, 2021 Free Software Foundation, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # DejaGnu is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19 # This file was written by Jacob Bachmeyer.
21 if { ![info exists LAUNCHER] } {
24 [file join [file dirname [testsuite file -source -top]] dejagnu]]
26 verbose "Using LAUNCHER $LAUNCHER" 2
28 if { [which $LAUNCHER] == 0 } {
29 perror "Can't find LAUNCHER = $LAUNCHER"
33 # run dejagnu(1) LAUNCHER with ARGLIST, returning { output exit_code }
34 proc dejagnu_run { launcher arglist envlist } {
37 set exec_cmd [list exec]
38 if { [llength $envlist] > 0 } {
40 foreach var $envlist { lappend exec_cmd $var }
42 lappend exec_cmd $launcher
47 verbose -log "Running \"[lrange $exec_cmd 1 end] $arglist\" ..."
48 catch { eval $exec_cmd $arglist } output
51 if { [lindex $errorCode 0] eq "CHILDSTATUS" } {
52 return [list $output [lindex $errorCode 2]]
54 return [list $output 0]
58 # evaluate a test against LAUNCHER, returning true if it passes
59 # TEST is a list: { name arglist envlist exit_code output_re... }
60 proc try_dejagnu_launcher { launcher test } {
61 foreach part [lrange $test 4 end] { append re $part }
63 if { [llength [lindex $test 2]] > 0 } {
64 verbose "Spawning \"env [lindex $test 2] $launcher [lindex $test 1]\" ..."
66 verbose "Spawning \"$launcher [lindex $test 1]\" ..."
68 verbose "Expecting to match {$re} ..." 2
69 set result [dejagnu_run $launcher [lindex $test 1] [lindex $test 2]]
70 verbose "Exit code [lindex $result 1]; output {[lindex $result 0]}" 2
72 if { [regexp $re [lindex $result 0]]
73 && [lindex $test 3] == [lindex $result 1] } {
80 proc link_dejagnu_launcher_test_item {link target} {
81 if {[file exists $link]} {
82 verbose -log " item $link already exists"
85 verbose -log "linking $link"
86 verbose -log " to $target"
87 if {[catch {file link -symbolic $link [file normalize $target]} err]} {
92 proc run_dejagnu_launcher_tests { launcher tests } {
94 if { [lindex $test 0] == "#" } {
95 # ignore comments in test list
96 } elseif { [llength $test] == 1 } {
98 untested [lindex $test 0]
99 } elseif { [try_dejagnu_launcher $launcher $test] } {
100 pass [lindex $test 0]
102 fail [lindex $test 0]
107 proc skip_dejagnu_launcher_tests { why result tests } {
109 foreach test $tests {
110 if { [lindex $test 0] == "#" } {
111 # ignore comments in test list
113 $result [lindex $test 0]
118 # stub: dejagnu(1) itself is non-interactive
119 proc dejagnu_exit {} {}
121 # stub: dejagnu(1) does not have a separate version number
122 proc dejagnu_version {} {