xref: /netbsd-src/external/gpl3/gdb.old/dist/libctf/testsuite/libctf-regression/libctf-repeat-cu.exp (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1*6881a400Schristos# Copyright (C) 2021-2022 Free Software Foundation, Inc.
2*6881a400Schristos#
3*6881a400Schristos# This file is part of the GNU Binutils.
4*6881a400Schristos#
5*6881a400Schristos# This program is free software; you can redistribute it and/or modify
6*6881a400Schristos# it under the terms of the GNU General Public License as published by
7*6881a400Schristos# the Free Software Foundation; either version 3 of the License, or
8*6881a400Schristos# (at your option) any later version.
9*6881a400Schristos#
10*6881a400Schristos# This program is distributed in the hope that it will be useful,
11*6881a400Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
12*6881a400Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*6881a400Schristos# GNU General Public License for more details.
14*6881a400Schristos#
15*6881a400Schristos# You should have received a copy of the GNU General Public License
16*6881a400Schristos# along with this program; if not, write to the Free Software
17*6881a400Schristos# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18*6881a400Schristos# MA 02110-1301, USA.
19*6881a400Schristos#
20*6881a400Schristos
21*6881a400Schristosload_file $srcdir/../../ld/testsuite/lib/ld-lib.exp
22*6881a400Schristos
23*6881a400Schristosglobal srcdir subdir OBJDUMP
24*6881a400Schristosglobal testname
25*6881a400Schristosglobal subsrcdir
26*6881a400Schristos
27*6881a400Schristosset subsrcdir "$srcdir/$subdir/"
28*6881a400Schristosset testname "$dir/libctf-repeat-cu.exp"
29*6881a400Schristos
30*6881a400Schristosif ![is_elf_format] {
31*6881a400Schristos    unsupported "CTF needs bfd changes to be emitted on non-ELF"
32*6881a400Schristos    return 0
33*6881a400Schristos}
34*6881a400Schristos
35*6881a400Schristosif {![check_ctf_available]} {
36*6881a400Schristos    unsupported "no CTF format support in the compiler"
37*6881a400Schristos    return 0
38*6881a400Schristos}
39*6881a400Schristos
40*6881a400Schristosif {[info exists env(LC_ALL)]} {
41*6881a400Schristos    set old_lc_all $env(LC_ALL)
42*6881a400Schristos}
43*6881a400Schristosset env(LC_ALL) "C"
44*6881a400Schristos
45*6881a400Schristos# Compile one SRC to OBJ and put it into ARCHIVE.
46*6881a400Schristosproc one_lib_compile { src flags obj archive } {
47*6881a400Schristos    global CC_FOR_TARGET CFLAGS_FOR_TARGET AR subsrcdir
48*6881a400Schristos
49*6881a400Schristos    if [is_remote host] {
50*6881a400Schristos	set src [remote_download host [file join $subsrcdir $src]]
51*6881a400Schristos    } else {
52*6881a400Schristos	set src [file join $subsrcdir $src]
53*6881a400Schristos    }
54*6881a400Schristos
55*6881a400Schristos    set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $flags -gctf -fPIC -c -o $obj $src"]]
56*6881a400Schristos    if { $comp_output != "" } {
57*6881a400Schristos	return $comp_output
58*6881a400Schristos    }
59*6881a400Schristos
60*6881a400Schristos    set ar_output [prune_warnings [run_host_cmd "$AR" "rc $archive $obj"]]
61*6881a400Schristos    return $comp_output
62*6881a400Schristos}
63*6881a400Schristos
64*6881a400Schristos# Compile one SRC to OBJ and put it into ARCHIVE: error-check the result.
65*6881a400Schristosproc one_lib_compile_check { src flags obj archive } {
66*6881a400Schristos    global testname
67*6881a400Schristos
68*6881a400Schristos    set comp_output [one_lib_compile $src $flags $obj $archive]
69*6881a400Schristos
70*6881a400Schristos    if { $comp_output != ""} {
71*6881a400Schristos	send_log "compilation of $src with $flags failed with <$comp_output>"
72*6881a400Schristos	perror "compilation of $src with $flags failed"
73*6881a400Schristos	fail $testname
74*6881a400Schristos	return 0
75*6881a400Schristos    }
76*6881a400Schristos    return 1
77*6881a400Schristos}
78*6881a400Schristos
79*6881a400Schristosif { ! [one_lib_compile_check libctf-repeat-cu-lib.c "-DINT -DFUN=a" tmpdir/libctf-repeat-cu-lib.o tmpdir/a.a] } {
80*6881a400Schristos    return 0
81*6881a400Schristos}
82*6881a400Schristos
83*6881a400Schristosif { ! [one_lib_compile_check libctf-repeat-cu-lib.c "-DCHAR -DFUN=b" tmpdir/libctf-repeat-cu-lib.o tmpdir/b.a] } {
84*6881a400Schristos    return 0
85*6881a400Schristos}
86*6881a400Schristos
87*6881a400Schristosif { ! [one_lib_compile_check libctf-repeat-cu-lib.c "-DFUN=c" tmpdir/libctf-repeat-cu-lib.o tmpdir/c.a] } {
88*6881a400Schristos    return 0
89*6881a400Schristos}
90*6881a400Schristos
91*6881a400Schristosif [is_remote host] {
92*6881a400Schristos    set src [remote_download host [file join $subsrcdir libctf-repeat-cu-main.c]]
93*6881a400Schristos} else {
94*6881a400Schristos    set src [file join $subsrcdir libctf-repeat-cu-main.c]
95*6881a400Schristos}
96*6881a400Schristos
97*6881a400Schristosset comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET -gctf -fPIC -shared -o tmpdir/libctf-repeat-cu-main.so $src tmpdir/a.a tmpdir/b.a tmpdir/c.a"]]
98*6881a400Schristosif { $comp_output != "" } {
99*6881a400Schristos    send_log "compilation of tmpdir/libctf-repeat-cu-main.so failed"
100*6881a400Schristos    perror "compilation of tmpdir/libctf-repeat-cu-main.so failed"
101*6881a400Schristos    fail $testname
102*6881a400Schristos    return $comp_output
103*6881a400Schristos}
104*6881a400Schristos
105*6881a400Schristosset comp_output [prune_warnings [run_host_cmd "$OBJDUMP" "--ctf tmpdir/libctf-repeat-cu-main.so > tmpdir/dump.out"]]
106*6881a400Schristos
107*6881a400Schristosif { [regexp_diff "tmpdir/dump.out"  [file join $subsrcdir libctf-repeat-cu.d] ] } {
108*6881a400Schristos    fail $testname
109*6881a400Schristos    if { $verbose == 2 } then { verbose "output is [file_contents tmpdir/dump.out]" 2 }
110*6881a400Schristos}
111*6881a400Schristos
112*6881a400Schristospass $testname
113*6881a400Schristos
114*6881a400Schristosif {[info exists old_lc_all]} {
115*6881a400Schristos    set env(LC_ALL) $old_lc_all
116*6881a400Schristos} else {
117*6881a400Schristos    unset env(LC_ALL)
118*6881a400Schristos}
119