aboutsummaryrefslogtreecommitdiff
path: root/libio/testsuite/lib/libio.exp
blob: 22bd3b9c8ffa06308ed1f327bf9486d3a54c95d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Copyright (C) 1997 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Please email any bugs, comments, and/or additions to this file to:
# bug-lib-g++@prep.ai.mit.edu

# This file was written by Bob Manson. (manson@cygnus.com)

load_lib "libgloss.exp"

global base_dir

proc libio_init { args } {
    global wrapper_file;
    global wrap_compile_flags;
    set wrapper_file "";
    set wrap_compile_flags "";
    if [target_info exists needs_status_wrapper] {
	set result [build_wrapper "testglue.o"];
	if { $result != "" } {
	    set wrapper_file [lindex $result 0];
	    set wrap_compile_flags [lindex $result 1];
	} else {
	    warning "Status wrapper failed to build."
	}
    }
}
#
# Run the test specified by srcfile and resultfile. compile_args and
# exec_args are additional arguments to be passed in when compiling and
# running the testcase, respectively.
#

proc test_libio { srcfile compile_args inpfile resultfile exec_args } {
    global LIBIO
    global srcdir subdir objdir
    global TOOL_OPTIONS
    global wrapper_file wrap_compile_flags;

    if { $inpfile != "" } {
	set inpfile "$srcdir/../tests/$inpfile"
    }

    set args ""
    lappend args "additional_flags=-O3";
    lappend args "additional_flags=-I.. -I$srcdir/.."
    lappend args "additional_flags=$wrap_compile_flags";
    lappend args "libs=$wrapper_file";
    if { $compile_args != "" } {
	lappend args "additional_flags=$compile_args"
    }

    if [regexp "\.cc$" $srcfile] {
	lappend args "additional_flags=-nostdinc++"
	lappend args "additional_flags=[g++_include_flags]";
	lappend args "additional_flags=[g++_link_flags]";
	lappend args "libs=-lstdc++"
    } else {
	if [info exists LIBIO] {
	    lappend args "libdir=$LIBIO"
	} else {
	    lappend args "additional_flags=[libio_link_flags]";
	}
	lappend args "libs=-lio"
    }

    if [target_info exists slow_simulator] then {
      lappend args "additional_flags=-DSLOW_SIMULATOR"
    }

    if [info exists TOOL_OPTIONS] {
	lappend args "additional_options=$TOOL_OPTIONS"
    }

    set gp [get_multilibs];
    if { $gp != "" } {
	if [file exists $gp/libiberty/libiberty.a] {
	    lappend args "libdir=$gp/libiberty";
	    set found_libiberty 1;
	}
    }
    if ![info exists found_libiberty] {
	set lib [lookfor_file "$objdir" "libiberty/libiberty.a"];
	if { $lib != "" } {
	    lappend args "libdir=[file dirname $lib]";
	}
    }
    lappend args "libs=-liberty"
    lappend args "debug";

    set errname "$srcfile"
    set srcfile "$srcdir/../tests/$srcfile"
    regsub "\\..*$" "[file tail $srcfile]" "" executable
    set executable "$objdir/$executable"

    if { [target_compile $srcfile $executable executable $args] != "" } {
	fail "$errname compilation $exec_args";
	setup_xfail "*-*-*"
	fail "$errname execution $exec_args"
	if { $resultfile != "" } {
	    setup_xfail "*-*-*"
	    fail "$errname output $exec_args"
	}
	return;
    }
    pass "$errname compilation $exec_args"

    set result [libio_load $executable $exec_args $inpfile];
    set status [lindex $result 0];
    set output [lindex $result 1];
    if { $status == "unsupported" } {
	unsupported "target does not support loading $srcfile"
	return;
    }
    if { $status != "pass" } {
	$status "$errname execution $exec_args"
	setup_xfail "*-*-*"
	fail "$errname output $exec_args"
	return;
    }
    pass "$errname execution $exec_args"

    if { $resultfile != "" } {
	set id [open $srcdir/../tests/$resultfile r];
	set expected ""
	append expected [read $id];
	verbose "expected is $expected"
	verbose "actual is $output"
	regsub -all "\r" $output "" output
	regsub "\n+$" $expected "" expected
	regsub "\n+$" $output "" output
	regsub "^\n+" $expected "" expected
	regsub "^\n+" $output "" output
	if { $expected == $output } {
	    pass "$errname output $exec_args"
	} else {
	    fail "$errname output $exec_args"
	}
	close $id;
    }
}

#
# libio_version -- extract and print the version number of libio
#
proc default_libio_version {} {
    global LIBIO
}

proc default_libio_start { } {
}