]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/01-test_symbol_presence.t
NonStop port updates for 3.0.0.
[thirdparty/openssl.git] / test / recipes / 01-test_symbol_presence.t
1 #! /usr/bin/env perl
2 # -*- mode: Perl -*-
3 # Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
4 #
5 # Licensed under the Apache License 2.0 (the "License"). You may not use
6 # this file except in compliance with the License. You can obtain a copy
7 # in the file LICENSE in the source distribution or at
8 # https://www.openssl.org/source/license.html
9
10 use strict;
11 use File::Spec::Functions qw(devnull);
12 use OpenSSL::Test qw(:DEFAULT srctop_file bldtop_dir bldtop_file);
13 use OpenSSL::Test::Utils;
14
15 setup("test_symbol_presence");
16
17 plan skip_all => "Only useful when building shared libraries"
18 if disabled("shared");
19
20 plan skip_all => "Test is disabled on NonStop" if config('target') =~ m|^nonstop|;
21
22 my @libnames = ("crypto", "ssl");
23 my $testcount = scalar @libnames;
24
25 plan tests => $testcount * 2;
26
27 note
28 "NOTE: developer test! It's possible that it won't run on your\n",
29 "platform, and that's perfectly fine. This is mainly for developers\n",
30 "on Unix to check that our shared libraries are consistent with the\n",
31 "ordinals (util/*.num in the source tree), something that should be\n",
32 "good enough a check for the other platforms as well.\n";
33
34 foreach my $libname (@libnames) {
35 SKIP:
36 {
37 my $shlibpath = bldtop_file("lib" . $libname . ".so");
38 *OSTDERR = *STDERR;
39 *OSTDOUT = *STDOUT;
40 open STDERR, ">", devnull();
41 open STDOUT, ">", devnull();
42 my @nm_lines = map { s|\R$||; $_ } `nm -Pg $shlibpath 2> /dev/null`;
43 close STDERR;
44 close STDOUT;
45 *STDERR = *OSTDERR;
46 *STDOUT = *OSTDOUT;
47 skip "Can't run 'nm -Pg $shlibpath' => $?... ignoring", 2
48 unless $? == 0;
49
50 my $bldtop = bldtop_dir();
51 my @def_lines;
52 indir $bldtop => sub {
53 my $mkdefpath = srctop_file("util", "mkdef.pl");
54 my $libnumpath = srctop_file("util", "lib$libname.num");
55 @def_lines = map { s|\R$||; $_ } `$^X $mkdefpath --ordinals $libnumpath --name $libname --OS linux 2> /dev/null`;
56 ok($? == 0, "running 'cd $bldtop; $^X $mkdefpath --ordinals $libnumpath --name $libname --OS linux' => $?");
57 }, create => 0, cleanup => 0;
58
59 note "Number of lines in \@nm_lines before massaging: ", scalar @nm_lines;
60 note "Number of lines in \@def_lines before massaging: ", scalar @def_lines;
61
62 # Massage the nm output to only contain defined symbols
63 @nm_lines = sort map { s| .*||; $_ } grep(m|.* [BCDST] .*|, @nm_lines);
64
65 # Massage the mkdef.pl output to only contain global symbols
66 # The output we got is in Unix .map format, which has a global
67 # and a local section. We're only interested in the global
68 # section.
69 my $in_global = 0;
70 @def_lines =
71 sort
72 map { s|;||; s|\s+||g; $_ }
73 grep { $in_global = 1 if m|global:|;
74 $in_global = 0 if m|local:|;
75 $in_global = 0 if m|\}|;
76 $in_global && m|;|; } @def_lines;
77
78 note "Number of lines in \@nm_lines after massaging: ", scalar @nm_lines;
79 note "Number of lines in \@def_lines after massaging: ", scalar @def_lines;
80
81 # Maintain lists of symbols that are missing in the shared library,
82 # or that are extra.
83 my @missing = ();
84 my @extra = ();
85
86 while (scalar @nm_lines || scalar @def_lines) {
87 my $nm_first = $nm_lines[0];
88 my $def_first = $def_lines[0];
89
90 if (!defined($nm_first)) {
91 push @missing, shift @def_lines;
92 } elsif (!defined($def_first)) {
93 push @extra, shift @nm_lines;
94 } elsif ($nm_first gt $def_first) {
95 push @missing, shift @def_lines;
96 } elsif ($nm_first lt $def_first) {
97 push @extra, shift @nm_lines;
98 } else {
99 shift @def_lines;
100 shift @nm_lines;
101 }
102 }
103
104 if (scalar @missing) {
105 note "The following symbols are missing in lib$libname.so:";
106 foreach (@missing) {
107 note " $_";
108 }
109 }
110 if (scalar @extra) {
111 note "The following symbols are extra in lib$libname.so:";
112 foreach (@extra) {
113 note " $_";
114 }
115 }
116 ok(scalar @missing == 0,
117 "check that there are no missing symbols in lib$libname.so");
118 }
119 }