Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libio / testsuite / lib / libio.exp
1 # Copyright (C) 1997 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-lib-g++@prep.ai.mit.edu
19
20 # This file was written by Bob Manson. (manson@cygnus.com)
21
22 load_lib "libgloss.exp"
23
24 global base_dir
25
26 proc libio_init { args } {
27     global wrapper_file;
28     global wrap_compile_flags;
29     set wrapper_file "";
30     set wrap_compile_flags "";
31     if [target_info exists needs_status_wrapper] {
32         set result [build_wrapper "testglue.o"];
33         if { $result != "" } {
34             set wrapper_file [lindex $result 0];
35             set wrap_compile_flags [lindex $result 1];
36         } else {
37             warning "Status wrapper failed to build."
38         }
39     }
40 }
41 #
42 # Run the test specified by srcfile and resultfile. compile_args and
43 # exec_args are additional arguments to be passed in when compiling and
44 # running the testcase, respectively.
45 #
46
47 proc test_libio { srcfile compile_args inpfile resultfile exec_args } {
48     global LIBIO
49     global srcdir subdir objdir
50     global TOOL_OPTIONS
51     global wrapper_file wrap_compile_flags
52     global ld_library_path
53
54     if { $inpfile != "" } {
55         set inpfile "$srcdir/../tests/$inpfile"
56     }
57
58     set args ""
59     set ld_library_path ""
60     lappend args "additional_flags=-O3";
61     lappend args "additional_flags=-I.. -I$srcdir/.."
62     lappend args "additional_flags=$wrap_compile_flags";
63     lappend args "libs=$wrapper_file";
64     if { $compile_args != "" } {
65         lappend args "additional_flags=$compile_args"
66     }
67
68     if [regexp "\.cc$" $srcfile] {
69         lappend args "additional_flags=-nostdinc++"
70         lappend args "additional_flags=[libstdc++_include_flags]";
71         lappend args "additional_flags=[libstdc++_link_flags]";
72         lappend args "libs=-lstdc++"
73     } else {
74         if [info exists LIBIO] {
75             lappend args "libdir=$LIBIO"
76         } else {
77             lappend args "additional_flags=[libio_link_flags]";
78         }
79         lappend args "additional_flags=[libio_link_flags]";
80         lappend args "libs=-lio"
81     }
82
83     if [target_info exists slow_simulator] then {
84       lappend args "additional_flags=-DSLOW_SIMULATOR"
85     }
86
87     if [info exists TOOL_OPTIONS] {
88         lappend args "additional_options=$TOOL_OPTIONS"
89     }
90
91     set gp [get_multilibs];
92     if { $gp != "" } {
93         if [file exists $gp/libiberty/libiberty.a] {
94             lappend args "libdir=$gp/libiberty";
95             set found_libiberty 1;
96         }
97     }
98     if ![info exists found_libiberty] {
99         set lib [lookfor_file "$objdir" "libiberty/libiberty.a"];
100         if { $lib != "" } {
101             lappend args "libdir=[file dirname $lib]";
102         }
103     }
104     lappend args "libs=-liberty"
105     lappend args "debug";
106
107     set errname "$srcfile"
108     set srcfile "$srcdir/../tests/$srcfile"
109     regsub "\\..*$" "[file tail $srcfile]" "" executable
110     set executable "$objdir/$executable"
111
112     if { [target_compile $srcfile $executable executable $args] != "" } {
113         fail "$errname compilation $exec_args";
114         setup_xfail "*-*-*"
115         fail "$errname execution $exec_args"
116         if { $resultfile != "" } {
117             setup_xfail "*-*-*"
118             fail "$errname output $exec_args"
119         }
120         return;
121     }
122     pass "$errname compilation $exec_args"
123
124     set result [libio_load $executable $exec_args $inpfile];
125     set status [lindex $result 0];
126     set output [lindex $result 1];
127     if { $status == "unsupported" } {
128         unsupported "target does not support loading $srcfile"
129         return;
130     }
131     if { $status != "pass" } {
132         $status "$errname execution $exec_args"
133         setup_xfail "*-*-*"
134         fail "$errname output $exec_args"
135         return;
136     }
137     pass "$errname execution $exec_args"
138
139     if { $resultfile != "" } {
140         set id [open $srcdir/../tests/$resultfile r];
141         set expected ""
142         append expected [read $id];
143         verbose "expected is $expected"
144         verbose "actual is $output"
145         regsub -all "\r" $output "" output
146         regsub "\n+$" $expected "" expected
147         regsub "\n+$" $output "" output
148         regsub "^\n+" $expected "" expected
149         regsub "^\n+" $output "" output
150         if { $expected == $output } {
151             pass "$errname output $exec_args"
152         } else {
153             fail "$errname output $exec_args"
154         }
155         close $id;
156     }
157 }
158
159 #
160 # libio_version -- extract and print the version number of libio
161 #
162 proc default_libio_version {} {
163     global LIBIO
164 }
165
166 proc default_libio_start { } {
167 }