]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/01-test_symbol_presence.t
e979c18f46f60e066f30bc861497d37bfb2504c6
3 # Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
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
11 use File
::Spec
::Functions
qw(devnull);
12 use OpenSSL
::Test
qw(:DEFAULT srctop_file srctop_dir bldtop_dir bldtop_file);
13 use OpenSSL
::Test
::Utils
;
16 setup
("test_symbol_presence");
19 use lib srctop_dir
('Configurations');
20 use lib bldtop_dir
('.');
23 plan skip_all
=> "Test is disabled on NonStop" if config
('target') =~ m
|^nonstop
|;
24 plan skip_all
=> "Only useful when building shared libraries"
25 if disabled
("shared");
27 my @libnames = ("crypto", "ssl");
28 my $testcount = scalar @libnames;
30 plan tests
=> $testcount * 2;
33 "NOTE: developer test! It's possible that it won't run on your\n",
34 "platform, and that's perfectly fine. This is mainly for developers\n",
35 "on Unix to check that our shared libraries are consistent with the\n",
36 "ordinals (util/*.num in the source tree), something that should be\n",
37 "good enough a check for the other platforms as well.\n";
39 foreach my $libname (@libnames) {
42 my $shlibpath = bldtop_file
(platform
->sharedlib("lib$libname"));
45 open STDERR
, ">", devnull
();
46 open STDOUT
, ">", devnull
();
47 my @nm_lines = map { s
|\R
$||; $_ } `nm -Pg $shlibpath 2> /dev/null`;
52 skip
"Can't run 'nm -Pg $shlibpath' => $?... ignoring", 2
55 my $bldtop = bldtop_dir
();
57 indir
$bldtop => sub {
58 my $mkdefpath = srctop_file
("util", "mkdef.pl");
59 my $libnumpath = srctop_file
("util", "lib$libname.num");
60 @def_lines = map { s
|\R
$||; $_ } `$^X $mkdefpath --ordinals $libnumpath --name $libname --OS linux 2> /dev/null`;
61 ok
($?
== 0, "running 'cd $bldtop; $^X $mkdefpath --ordinals $libnumpath --name $libname --OS linux' => $?");
62 }, create
=> 0, cleanup
=> 0;
64 note
"Number of lines in \@nm_lines before massaging: ", scalar @nm_lines;
65 note
"Number of lines in \@def_lines before massaging: ", scalar @def_lines;
67 # Massage the nm output to only contain defined symbols
68 @nm_lines = sort map { s
| .*||; $_ } grep(m
|.* [BCDST
] .*|, @nm_lines);
70 # Massage the mkdef.pl output to only contain global symbols
71 # The output we got is in Unix .map format, which has a global
72 # and a local section. We're only interested in the global
77 map { s
|;||; s
|\s
+||g
; $_ }
78 grep { $in_global = 1 if m
|global
:|;
79 $in_global = 0 if m
|local:|;
80 $in_global = 0 if m
|\
}|;
81 $in_global && m
|;|; } @def_lines;
83 note
"Number of lines in \@nm_lines after massaging: ", scalar @nm_lines;
84 note
"Number of lines in \@def_lines after massaging: ", scalar @def_lines;
86 # Maintain lists of symbols that are missing in the shared library,
91 while (scalar @nm_lines || scalar @def_lines) {
92 my $nm_first = $nm_lines[0];
93 my $def_first = $def_lines[0];
95 if (!defined($nm_first)) {
96 push @missing, shift @def_lines;
97 } elsif (!defined($def_first)) {
98 push @extra, shift @nm_lines;
99 } elsif ($nm_first gt $def_first) {
100 push @missing, shift @def_lines;
101 } elsif ($nm_first lt $def_first) {
102 push @extra, shift @nm_lines;
109 if (scalar @missing) {
110 note
"The following symbols are missing in lib$libname.so:";
116 note
"The following symbols are extra in lib$libname.so:";
121 ok
(scalar @missing == 0,
122 "check that there are no missing symbols in lib$libname.so");