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