]>
Commit | Line | Data |
---|---|---|
596d6b7e RS |
1 | #! /usr/bin/env perl |
2 | # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. | |
3 | # | |
4 | # Licensed under the OpenSSL license (the "License"). You may not use | |
5 | # this file except in compliance with the License. You can obtain a copy | |
6 | # in the file LICENSE in the source distribution or at | |
7 | # https://www.openssl.org/source/license.html | |
8 | ||
f3356b7f RL |
9 | |
10 | use strict; | |
11 | use warnings; | |
12 | ||
13 | use Math::BigInt; | |
14 | ||
42e0ccdf | 15 | use OpenSSL::Test qw/:DEFAULT srctop_file/; |
f3356b7f RL |
16 | |
17 | setup("test_bn"); | |
18 | ||
19 | plan tests => 3; | |
20 | ||
42e0ccdf | 21 | require_ok(srctop_file("test","recipes","bc.pl")); |
f3356b7f RL |
22 | |
23 | my $testresults = "tmp.bntest"; | |
24 | my $init = ok(run(test(["bntest"], stdout => $testresults)), 'initialize'); | |
25 | ||
26 | SKIP: { | |
27 | skip "Initializing failed, skipping", 1 if !$init; | |
28 | ||
29 | subtest 'Checking the bn results' => sub { | |
30 | my @lines = (); | |
31 | if (open DATA, $testresults) { | |
32 | @lines = <DATA>; | |
33 | close DATA; | |
34 | } | |
85833408 | 35 | map { s/\R//; } @lines; # chomp(@lines); |
f3356b7f RL |
36 | |
37 | plan tests => scalar grep(/^print /, @lines); | |
38 | ||
39 | my $l = ""; | |
40 | ||
41 | while (scalar @lines) { | |
42 | $l = shift @lines; | |
43 | ||
44 | last if $l =~ /^print /; | |
45 | } | |
46 | ||
47 | while (1) { | |
48 | $l =~ s/^print "//; | |
49 | $l =~ s/\\n"//; | |
50 | my $t = $l; | |
51 | my @operations = (); | |
52 | ||
53 | $l = undef; | |
54 | while (scalar @lines) { | |
55 | $l = shift @lines; | |
56 | ||
57 | last if $l =~ /^print /; | |
58 | push @operations, $l; | |
59 | $l = undef; | |
60 | } | |
61 | ||
62 | ok(check_operations(@operations), "verify $t"); | |
63 | ||
64 | last unless $l; | |
65 | } | |
66 | }; | |
67 | } | |
68 | ||
69 | sub check_operations { | |
70 | my $failcount = 0; | |
71 | ||
72 | foreach my $line (@_) { | |
73 | my $result = calc(split /\s+/, $line); | |
74 | ||
75 | if ($result ne "0" && $result ne "0x0") { | |
76 | $failcount++; | |
77 | print STDERR "Failed! $line => $result\n"; | |
78 | } | |
79 | } | |
80 | ||
81 | return $failcount == 0; | |
82 | } |