Debian Codegraph @

crt/s2n/tests/sidetrail/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 if (@ARGV != 3) {
26 die "usage: count_success.pl expected_success expected_failures filename";
27 }
28
29 my $expected_success = shift;
30 my $expected_failure = shift;
31 my $filename = shift;
32 my @undefined_functions = ();
33 my %allowed_undefined = ("__CONTRACT_invariant" => 1,
34 "malloc" => 1,
35 "nondet" => 1,
36 "free" => 1,
37 );
38
39 my $verified = 0;
40 my $errors = 0;
41 open (FILE, $filename) or die "Can't open $filename $!";
42 while (my $line = <FILE>){
43 #Check if the code under test used unexpected functions
44 if ($line =~ /warning: module contains undefined functions:([a-zA-Z0-9_, ]+)/) {
45 print "found undefined\n\n";
46 for my $fns (split(",",$1)){
47 my $trimmed = trim ($fns);
48 unless ($allowed_undefined{$trimmed}) {
49 push @undefined_functions, $trimmed;
50 }
51 }
52 }
53
54 #Count the number of errors / successes
55 if ($line =~ /Boogie program verifier finished with (\d+) verified, (\d+) error/) {
56 $verified = $verified + $1;
57 $errors = $errors + $2;
58 }
59 }
60
61 if($verified == $expected_success and $errors == $expected_failure){
62 print "verified: $verified errors: $errors as expected\n";
63 } else {
64 die "ERROR:\tExpected \tverified: $expected_success\terrors: $expected_failure.\n\tGot\t\tverified: $verified\terrors: $errors.\n";
65 }
66
67 if (@undefined_functions) {
68 die "Unable to prove that code was constant time due to the presence of external functions: @undefined_functions\n";
69 }