xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/testsuite/libphobos.shared/shared.exp (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1# Copyright (C) 2017-2022 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 3 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 GCC; see the file COPYING3.  If not see
15# <http://www.gnu.org/licenses/>.
16
17load_lib libphobos-dg.exp
18
19# Immediately exit if target doesn't support shared.
20if { ![is-effective-target shared] } {
21    return
22}
23
24# If a testcase doesn't have special options, use these.
25if ![info exists DEFAULT_CFLAGS] then {
26    set DEFAULT_CFLAGS "-g"
27}
28
29#
30# Build all shared libraries, used as dependencies for other tests.
31#
32
33proc shared_library { source destfile options } {
34    global DEFAULT_DFLAGS
35    global all_libraries
36
37    # Compiling with -fno-gnu-unique as tests call dlopen/dlclose multiple times on the same library.
38    lappend options "additional_flags=$DEFAULT_DFLAGS -fno-gnu-unique -fpic -shared -shared-libphobos"
39
40    set comp_output [libphobos_target_compile "$source" "$destfile" "executable" $options]
41    if ![ string match "" $comp_output ] {
42	fail "libphobos.shared/[file tail $source]"
43	verbose -log $comp_output
44	return 1
45    }
46
47    lappend all_libraries $destfile
48}
49
50# lib.so
51shared_library "$srcdir/$subdir/lib.d" "lib.so" ""
52
53# liblinkdep.so
54shared_library "$srcdir/$subdir/liblinkdep.d" "liblinkdep.so" \
55	[list "additional_flags=-I$srcdir/$subdir lib.so"]
56
57# libloaddep.so
58shared_library "$srcdir/$subdir/libloaddep.d" "libloaddep.so" ""
59
60# lib_13414.so
61shared_library "$srcdir/$subdir/lib_13414.d" "lib_13414.so" ""
62
63# plugin.so
64shared_library "$srcdir/$subdir/plugin.d" "plugin1.so" ""
65shared_library "$srcdir/$subdir/plugin.d" "plugin2.so" ""
66
67# Initialize dg.
68dg-init
69
70# Main loop.
71dg-runtest "$srcdir/$subdir/link.d" "-I$srcdir/$subdir lib.so -shared-libphobos" \
72	"$DEFAULT_DFLAGS"
73
74dg-runtest "$srcdir/$subdir/link_linkdep.d" \
75	"-I$srcdir/$subdir liblinkdep.so lib.so -shared-libphobos" \
76	"$DEFAULT_DFLAGS"
77
78dg-runtest "$srcdir/$subdir/link_loaddep.d" \
79	"-I$srcdir/$subdir libloaddep.so -shared-libphobos" "$DEFAULT_DFLAGS"
80
81# dlopen() tests.
82if [is-effective-target dlopen] {
83    dg-runtest "$srcdir/$subdir/load.d" "-shared-libphobos -ldl" "$DEFAULT_DFLAGS"
84    dg-runtest "$srcdir/$subdir/load_linkdep.d" "-shared-libphobos -ldl" "$DEFAULT_DFLAGS"
85    dg-runtest "$srcdir/$subdir/load_loaddep.d" "-shared-libphobos -ldl" "$DEFAULT_DFLAGS"
86    dg-runtest "$srcdir/$subdir/load_13414.d" "-shared-libphobos -ldl" "$DEFAULT_DFLAGS"
87    dg-runtest "$srcdir/$subdir/finalize.d" "-shared-libphobos -ldl" "$DEFAULT_DFLAGS"
88}
89
90# C program link tests.
91if { [is-effective-target dlopen] && [is-effective-target pthread] } {
92    dg-runtest "$srcdir/$subdir/linkD.c" "lib.so -ldl -pthread" "$DEFAULT_CFLAGS"
93    dg-runtest "$srcdir/$subdir/linkDR.c" "-shared-libphobos -ldl -pthread" "$DEFAULT_CFLAGS"
94    dg-runtest "$srcdir/$subdir/host.c" "-ldl -pthread" "$DEFAULT_CFLAGS"
95
96    # Test requires a command line argument to be passed to the program.
97    set libphobos_run_args "${blddir}/src/.libs/libgphobos.${shlib_ext}"
98    dg-runtest "$srcdir/$subdir/loadDR.c" "-ldl -pthread -g" "$DEFAULT_CFLAGS"
99    set libphobos_run_args ""
100}
101
102# All done.
103dg-finish
104
105# Remove all libraries built before running tests.
106foreach lib $all_libraries {
107    catch "file delete -force -- $lib"
108}
109