1 # Copyright (C) 2018, 2021, 2024 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, see <http://www.gnu.org/licenses/>.
18 # This file was written by Jacob Bachmeyer.
20 if { ![info exists LAUNCHER] } {
23 [file join [file dirname [testsuite file -source -top]] dejagnu]]
25 verbose "Using LAUNCHER $LAUNCHER" 2
27 if { [which $LAUNCHER] == 0 } {
28 perror "Can't find LAUNCHER = $LAUNCHER"
32 # run dejagnu(1) LAUNCHER with ARGLIST, returning { output exit_code }
33 proc dejagnu_run { launcher arglist envlist } {
34 global LAUNCHER_SHELL errorCode
36 set exec_cmd [list exec]
37 if { [llength $envlist] > 0 } {
39 foreach var $envlist { lappend exec_cmd $var }
41 if { [info exists LAUNCHER_SHELL] && $LAUNCHER_SHELL ne "" } {
42 lappend exec_cmd $LAUNCHER_SHELL
44 lappend exec_cmd $launcher
49 verbose -log "Running \"[lrange $exec_cmd 1 end] $arglist\" ..."
50 catch { eval $exec_cmd $arglist } output
53 if { [lindex $errorCode 0] eq "CHILDSTATUS" } {
54 return [list $output [lindex $errorCode 2]]
56 return [list $output 0]
60 # evaluate a test against LAUNCHER, returning true if it passes
61 # TEST is a list: { name arglist envlist exit_code output_re... }
62 proc try_dejagnu_launcher { launcher test } {
63 foreach part [lrange $test 4 end] { append re $part }
65 if { [llength [lindex $test 2]] > 0 } {
66 verbose "Spawning \"env [lindex $test 2] $launcher [lindex $test 1]\" ..."
68 verbose "Spawning \"$launcher [lindex $test 1]\" ..."
70 verbose "Expecting to match {$re} ..." 2
71 set result [dejagnu_run $launcher [lindex $test 1] [lindex $test 2]]
72 verbose "Exit code [lindex $result 1]; output {[lindex $result 0]}" 2
74 if { [regexp $re [lindex $result 0]]
75 && [lindex $test 3] == [lindex $result 1] } {
82 proc link_dejagnu_launcher_test_item {link target} {
83 if {[file exists $link]} {
84 verbose -log " item $link already exists"
87 verbose -log "linking $link"
88 verbose -log " to $target"
89 if {[catch {file link -symbolic $link [file normalize $target]} err]} {
94 proc run_dejagnu_launcher_tests { launcher tests } {
96 if { [lindex $test 0] == "#" } {
97 # ignore comments in test list
98 } elseif { [llength $test] == 1 } {
100 untested [lindex $test 0]
101 } elseif { [try_dejagnu_launcher $launcher $test] } {
102 pass [lindex $test 0]
104 fail [lindex $test 0]
109 proc skip_dejagnu_launcher_tests { why result tests } {
111 foreach test $tests {
112 if { [lindex $test 0] == "#" } {
113 # ignore comments in test list
115 $result [lindex $test 0]
120 # stub: dejagnu(1) itself is non-interactive
121 proc dejagnu_exit {} {}
123 # stub: dejagnu(1) does not have a separate version number
124 proc dejagnu_version {} {