test: Move test_data_file() to test.h
[dpkg.git] / scripts / t / Dpkg_BuildFlags_Ubuntu.t
blob53cd1e8f3fc19a036deaeddfbc34ec6874074f90
1 #!/usr/bin/perl
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 use strict;
17 use warnings;
19 use Test::More tests => 21;
21 BEGIN {
22 use_ok('Dpkg::BuildFlags');
25 sub test_optflag
27 my ($bf, $optflag) = @_;
29 foreach my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
30 FFLAGS FCFLAGS)) {
31 my $value = $bf->get($flag);
32 ok($value =~ m/$optflag/, "$flag contains $optflag: $value");
36 sub test_ltoflag
38 my $bf = shift;
40 # Test the LTO flags enabled by default on some arches.
41 ok($bf->get('LDFLAGS') =~ m/-flto=auto -ffat-lto-objects/,
42 "LDFLAGS contains LTO flags on $ENV{DEB_HOST_ARCH}");
45 sub test_no_ltoflag
47 my $bf = shift;
49 # Test the LTO flags not being enabled.
50 ok($bf->get('LDFLAGS') !~ m/-flto=auto -ffat-lto-objects/,
51 "LDFLAGS does not contain LTO flags on $ENV{DEB_HOST_ARCH}");
54 my $bf;
56 # Force loading the Dpkg::Vendor::Ubuntu module.
57 $ENV{DEB_VENDOR} = 'Ubuntu';
59 # Test the optimization flag inherited from the Dpkg::Vendor::Debian module.
60 $ENV{DEB_HOST_ARCH} = 'amd64';
61 $bf = Dpkg::BuildFlags->new();
63 test_optflag($bf, '-O2');
64 test_ltoflag($bf);
66 # Test the overlaid Ubuntu-specific linker flag.
67 ok($bf->get('LDFLAGS') =~ m/-Wl,-Bsymbolic-functions/,
68 'LDFLAGS contains -Bsymbolic-functions');
70 # Test the optimization flag override only for ppc64el.
71 $ENV{DEB_HOST_ARCH} = 'ppc64el';
72 $bf = Dpkg::BuildFlags->new();
74 test_optflag($bf, '-O3');
75 test_ltoflag($bf);
77 # Test the optimization flag not enabled for riscv64.
78 $ENV{DEB_HOST_ARCH} = 'riscv64';
79 $bf = Dpkg::BuildFlags->new();
81 test_no_ltoflag($bf);
83 # Test the optimization flag override by DEB_BUILD_MAINT_OPTIONS.
84 $ENV{DEB_BUILD_MAINT_OPTIONS} = 'optimize=+lto';
85 $bf = Dpkg::BuildFlags->new();
87 test_ltoflag($bf);
89 $ENV{DEB_HOST_ARCH} = 'amd64';
90 $ENV{DEB_BUILD_MAINT_OPTIONS} = 'optimize=-lto';
91 $bf = Dpkg::BuildFlags->new();
92 test_no_ltoflag($bf);