Debian Codegraph @

crt/s2n/tests/ctverif/count_success.pl

raw
1 #!/usr/bin/perl -w
2 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License").
5 # You may not use this file except in compliance with the License.
6 # A copy of the License is located at
7 #
8 # http://aws.amazon.com/apache2.0
9 #
10 # or in the "license" file accompanying this file. This file is distributed
11 # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 # express or implied. See the License for the specific language governing
13 # permissions and limitations under the License.
14 #
15
16 # This script takes ct-verif output, and counts the number of successful
17 # and failed tests. If these match expected, it returns 0. Else it dies
18 # with a non-zero exit code.
19
20 use strict;
21 use warnings;
22
23 sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
24
25
26 if (@ARGV != 2) {
27 die "usage: count_success.pl expected_success expected_failures";
28 }
29
30 my $expected_success = shift;
31 my $expected_failure = shift;
32 my @undefined_functions = ();
33
34 my $verified = 0;
35 my $errors = 0;
36 while (my $line = <STDIN>){
37 print $line;
38 #Check if the code under test used unexpected functions
39 if ($line =~ /warning: module contains undefined functions:([a-zA-Z0-9_, ]+)/) {
40 for my $fns (split(",",$1)){
41 my $trimmed = trim ($fns);
42 push @undefined_functions, $trimmed;
43 }
44 }
45
46 #Count the number of errors / successes
47 if ($line =~ /Boogie program verifier finished with (\d+) verified, (\d+) error/) {
48 $verified = $verified + $1;
49 $errors = $errors + $2;
50 }
51 }
52
53 if($verified == $expected_success and $errors == $expected_failure){
54 print "verified: $verified errors: $errors as expected\n";
55 } else {
56 die "ERROR:\tExpected \tverified: $expected_success\terrors: $expected_failure.\n\tGot\t\tverified: $verified\terrors: $errors.\n";
57 }
58
59 if (@undefined_functions) {
60 die "Unable to prove that code was constant time due to the presence of external functions: @undefined_functions\n";
61 }