1e1051a39Sopenharmony_ci#! /usr/bin/env perl
2e1051a39Sopenharmony_ci# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci#
4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci# this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci
9e1051a39Sopenharmony_ciuse strict;
10e1051a39Sopenharmony_ciuse OpenSSL::Test qw/:DEFAULT srctop_file/;
11e1051a39Sopenharmony_ci
12e1051a39Sopenharmony_cisetup("test_ordinals");
13e1051a39Sopenharmony_ci
14e1051a39Sopenharmony_ciplan tests => 2;
15e1051a39Sopenharmony_ci
16e1051a39Sopenharmony_ciok(testordinals(srctop_file("util", "libcrypto.num")), "Test libcrypto.num");
17e1051a39Sopenharmony_ciok(testordinals(srctop_file("util", "libssl.num")), "Test libssl.num");
18e1051a39Sopenharmony_ci
19e1051a39Sopenharmony_cisub testordinals
20e1051a39Sopenharmony_ci{
21e1051a39Sopenharmony_ci    my $filename = shift;
22e1051a39Sopenharmony_ci    my $cnt = 0;
23e1051a39Sopenharmony_ci    my $ret = 1;
24e1051a39Sopenharmony_ci    my $qualifier = "";
25e1051a39Sopenharmony_ci    my $newqual;
26e1051a39Sopenharmony_ci    my $lastfunc = "";
27e1051a39Sopenharmony_ci
28e1051a39Sopenharmony_ci    open(my $fh, '<', $filename);
29e1051a39Sopenharmony_ci    while (my $line = <$fh>) {
30e1051a39Sopenharmony_ci        my @tokens = split(/(?:\s+|\s*:\s*)/, $line);
31e1051a39Sopenharmony_ci        #Check the line looks sane
32e1051a39Sopenharmony_ci        if ($#tokens < 5 || $#tokens > 6) {
33e1051a39Sopenharmony_ci            print STDERR "Invalid line:\n$line\n";
34e1051a39Sopenharmony_ci            $ret = 0;
35e1051a39Sopenharmony_ci            last;
36e1051a39Sopenharmony_ci        }
37e1051a39Sopenharmony_ci        if ($tokens[3] eq "NOEXIST") {
38e1051a39Sopenharmony_ci            #Ignore this line
39e1051a39Sopenharmony_ci            next;
40e1051a39Sopenharmony_ci        }
41e1051a39Sopenharmony_ci        #Some ordinals can be repeated, e.g. if one is VMS and another is !VMS
42e1051a39Sopenharmony_ci        $newqual = $tokens[4];
43e1051a39Sopenharmony_ci        $newqual =~ s/!//g;
44e1051a39Sopenharmony_ci        my $number = $tokens[1];
45e1051a39Sopenharmony_ci        $number = $cnt + 1 if $number eq '?';
46e1051a39Sopenharmony_ci        $number = $cnt if $number eq '?+';
47e1051a39Sopenharmony_ci        if ($cnt > $number
48e1051a39Sopenharmony_ci                || ($cnt == $number && ($qualifier ne $newqual
49e1051a39Sopenharmony_ci                                           || $qualifier eq ""))) {
50e1051a39Sopenharmony_ci            print STDERR "Invalid ordinal detected: ".$tokens[1]."\n";
51e1051a39Sopenharmony_ci            $ret = 0;
52e1051a39Sopenharmony_ci            last;
53e1051a39Sopenharmony_ci        }
54e1051a39Sopenharmony_ci        $cnt = $tokens[1];
55e1051a39Sopenharmony_ci        $qualifier = $newqual;
56e1051a39Sopenharmony_ci        $lastfunc = $tokens[0];
57e1051a39Sopenharmony_ci    }
58e1051a39Sopenharmony_ci    close($fh);
59e1051a39Sopenharmony_ci
60e1051a39Sopenharmony_ci    return $ret;
61e1051a39Sopenharmony_ci}
62