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