02-test_ordinals.t 1.6 KB
Newer Older
R
Rich Salz 已提交
1 2
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3
#
R
Rich Salz 已提交
4 5 6 7
# Licensed under the OpenSSL license (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
8 9

use strict;
10
use OpenSSL::Test qw/:DEFAULT srctop_file/;
11 12 13 14 15

setup("test_ordinals");

plan tests => 2;

16 17
ok(testordinals(srctop_file("util", "libcrypto.num")), "Test libcrypto.num");
ok(testordinals(srctop_file("util", "libssl.num")), "Test libssl.num");
18 19 20 21 22 23 24 25 26 27 28 29

sub testordinals
{
    my $filename = shift;
    my $cnt = 0;
    my $ret = 1;
    my $qualifier = "";
    my $newqual;
    my $lastfunc = "";

    open(my $fh, '<', $filename);
    while (my $line = <$fh>) {
30
        my @tokens = split(/(?:\s+|\s*:\s*)/, $line);
31
        #Check the line looks sane
M
Matt Caswell 已提交
32
        if ($#tokens < 5 || $#tokens > 6) {
33 34 35 36
            print STDERR "Invalid line:\n$line\n";
            $ret = 0;
            last;
        }
M
Matt Caswell 已提交
37
        if ($tokens[3] eq "NOEXIST") {
38 39 40 41
            #Ignore this line
            next;
        }
        #Some ordinals can be repeated, e.g. if one is VMS and another is !VMS
M
Matt Caswell 已提交
42
        $newqual = $tokens[4];
43
        $newqual =~ s/!//g;
44 45
        if ($cnt > $tokens[1]
                || ($cnt == $tokens[1] && ($qualifier ne $newqual
M
Matt Caswell 已提交
46
                                           || $qualifier eq ""))) {
47
            print STDERR "Invalid ordinal detected: ".$tokens[1]."\n";
48 49 50
            $ret = 0;
            last;
        }
51
        $cnt = $tokens[1];
52 53 54 55 56 57 58
        $qualifier = $newqual;
        $lastfunc = $tokens[0];
    }
    close($fh);

    return $ret;
}