aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/lib/ld.exp
blob: 659dfe299c617e0c117084a4334d1685390ba640 (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
165
166
167
168
169
170
171
#
# default_ld_version 
#	extract and print the version number of ld
#
proc default_ld_version { ld } {
    if { [file exists $ld] == 0 } then {
	error "$ld does not exist"
	exit 1
    }
    
    set tmp [exec $ld --version]
    regexp "version.*$" $tmp version
    
    if [info exists version] then {
	clone_output "$ld $version\n"
    }
}

#
# default_ld_relocate 
#	link an object using relocation
#
proc default_ld_relocate { ld target objects } {
    
    global HOSTING_EMU
    
    if { [file exists $ld] == 0 } then {
	error "$ld does not exist"
	exit 1
    }
    
    send_log "### EXEC \"$ld $HOSTING_EMU -o $target -r $objects\"\n"
    verbose "### EXEC \"$ld $HOSTING_EMU -o $target -r $objects\""
    
    catch "exec $ld $HOSTING_EMU -o $target -r $objects" exec_output
    if ![string match "" $exec_output] then {
	send_log "$exec_output\n"
	verbose "$exec_output"
    }
}


#
# default_ld_link 
#	link a program using ld
#
proc default_ld_link { ld target objects } {
    
    global BFDLIB
    global LIBIBERTY
    global HOSTING_EMU
    global HOSTING_CRT0
    global HOSTING_LIBS
    
    set objs "$HOSTING_CRT0 $objects"
    set libs "$BFDLIB $LIBIBERTY $HOSTING_LIBS"
    
    if { [file exists $ld] == 0 } then {
	error "$ld does not exist"
	exit 1
    }
    
    send_log "### EXEC \"$ld $HOSTING_EMU -o $target $objs $libs\"\n"
    verbose "### EXEC \"$ld $HOSTING_EMU -o $target $objs $libs\""
    
    catch "exec $ld $HOSTING_EMU -o $target $objs $libs" exec_output
    if ![string match "" $exec_output] then {
	send_log "$exec_output\n"
	verbose "$exec_output"
    }
}

#
# default_ld_compile 
#	compile an object using cc
#
proc default_ld_compile { cc source object } {
    global CFLAGS
    global srcdir
    global subdir
    
    if {[which $cc] == 0} then {
	error "$cc does not exist"
	exit 1
    }
    
    send_log "$cc $CFLAGS -I$srcdir/$subdir -c $source -o $object\n"
    verbose "### EXEC \"$cc $CFLAGS -I$srcdir/$subdir -c $source -o $object\""
    
    catch "exec $cc $CFLAGS -I$srcdir/$subdir -c $source -o $object" exec_output
    if ![string match "" $exec_output] then {
	send_log "$exec_output\n"
	verbose "$exec_output"
    }
}

#
# simple_diff
#	compares two files line-by-line
#	returns differences if exist
#	returns null if file(s) cannot be opened
#
proc simple_diff { file_1 file_2 } {
    global target
	
    set eof -1
    set differences 0
    
    if [file exists $file_1] then {
	set file_a [open $file_1 r]
    } else {
	warning "$file_1 doesn't exist"
	return
    }
    
    if [file exists $file_2] then {
	set file_b [open $file_2 r]
    } else {
	fail "$file_2 doesn't exist"
	return
    }
    
    verbose "### Diff'ing: $file_1 $file_2\n" 2
    
    while { [gets $file_a line] != $eof } {
	if [regexp "^#.*$" $line] then {
	    continue
	} else {
	    lappend list_a $line
	}
    }
    close $file_a
    
    while { [gets $file_b line] != $eof } {
	if [regexp "^#.*$" $line] then {
	    continue
	} else {
	    lappend list_b $line
	}
    }
    close $file_b

    for { set i 0 } { $i < [llength $list_a] } { incr i } {
	set line_a [lindex $list_a $i]
	set line_b [lindex $list_b $i]

	verbose "\t$file_1: $i: $line_a\n" 3
	verbose "\t$file_2: $i: $line_b\n" 3
	if [string compare $line_a $line_b] then {
	    verbose "\t$file_1: $i: $line_a\n" 1
	    verbose "\t$file_2: $i: $line_b\n" 1

	    send_log "\t$file_1: $i: $line_a\n"
	    send_log "\t$file_2: $i: $line_b\n"

	    fail "Test: $target"
	    return
	}
    }
    
    if { [llength $list_a] != [llength $list_b] } {
	fail "Test: $target"
	return
    }

    if $differences<1 then {
	pass "Test: $target"
    }
}