security/nss/lib/freebl/mpi/make-test-arrays

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/freebl/mpi/make-test-arrays	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +#!/usr/bin/perl
     1.5 +
     1.6 +#
     1.7 +# make-test-arrays
     1.8 +#
     1.9 +# Given a test-arrays file, which specifies the test suite names, the
    1.10 +# names of the functions which perform those test suites, and
    1.11 +# descriptive comments, this script generates C structures for the
    1.12 +# mpi-test program.  The input consists of lines of the form:
    1.13 +#
    1.14 +# suite-name:function-name:comment
    1.15 +#
    1.16 +# The output is written to the standard output.  Blank lines are
    1.17 +# ignored, and comments beginning with '#' are stripped.
    1.18 +
    1.19 +# This Source Code Form is subject to the terms of the Mozilla Public
    1.20 +# License, v. 2.0. If a copy of the MPL was not distributed with this
    1.21 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
    1.22 +
    1.23 +# Read parameters from the environment, if available
    1.24 +$NAMEVAR = $ENV{'NAMEVAR'} || "g_names";
    1.25 +$COUNTVAR = $ENV{'COUNTVAR'} || "g_count";
    1.26 +$FUNCVAR = $ENV{'FUNCVAR'} || "g_tests";
    1.27 +$DESCVAR = $ENV{'DESCVAR'} || "g_descs";
    1.28 +$FUNCLEN = 13;
    1.29 +$NAMELEN = 18;
    1.30 +$DESCLEN = 45;
    1.31 +
    1.32 +#------------------------------------------------------------------------
    1.33 +# Suck in input from the files on the command line, or standard input
    1.34 +while(<>) {
    1.35 +    chomp;
    1.36 +    s/\#.*$//;
    1.37 +    next if /^\s*$/;
    1.38 +
    1.39 +    ($suite, $func, $desc) = split(/:/, $_);
    1.40 +
    1.41 +    $tmp = { "suite" => $suite,
    1.42 +	     "func"  => $func,
    1.43 +	     "desc"  => $desc };
    1.44 +
    1.45 +    push(@item, $tmp);
    1.46 +}
    1.47 +$count = scalar(@item);
    1.48 +$last = pop(@item);
    1.49 +
    1.50 +#------------------------------------------------------------------------
    1.51 +# Output the table of names
    1.52 +print "/* Table mapping test suite names to index numbers */\n";
    1.53 +printf("const int   %s = %d;\n", $COUNTVAR, $count);
    1.54 +printf("const char *%s[] = {\n", $NAMEVAR);
    1.55 +
    1.56 +foreach $elt (@item) {
    1.57 +    printf("   \"%s\",%s/* %s%s */\n", $elt->{"suite"},
    1.58 +	   " " x ($NAMELEN - length($elt->{"suite"})),
    1.59 +	   $elt->{"desc"},
    1.60 +	   " " x ($DESCLEN - length($elt->{"desc"})));
    1.61 +}
    1.62 +printf("   \"%s\" %s/* %s%s */\n", $last->{"suite"},
    1.63 +       " " x ($NAMELEN - length($last->{"suite"})),
    1.64 +       $last->{"desc"},
    1.65 +       " " x ($DESCLEN - length($last->{"desc"})));
    1.66 +print "};\n\n";
    1.67 +
    1.68 +#------------------------------------------------------------------------
    1.69 +# Output the driver function prototypes
    1.70 +print "/* Test function prototypes */\n";
    1.71 +foreach $elt (@item, $last) {
    1.72 +    printf("int  %s(void);\n", $elt->{"func"});
    1.73 +}
    1.74 +print "\n";
    1.75 +
    1.76 +#------------------------------------------------------------------------
    1.77 +# Output the table of functions
    1.78 +print "/* Table mapping index numbers to functions */\n";
    1.79 +printf("int (*%s[])(void)  = {\n   ", $FUNCVAR);
    1.80 +$brk = 0;
    1.81 +
    1.82 +foreach $elt (@item) {
    1.83 +    print($elt->{"func"}, ", ", 
    1.84 +	  " " x ($FUNCLEN - length($elt->{"func"})));
    1.85 +    $brk = ($brk + 1) & 3;
    1.86 +    print "\n   " unless($brk);
    1.87 +}
    1.88 +print $last->{"func"}, "\n};\n\n";
    1.89 +
    1.90 +#------------------------------------------------------------------------
    1.91 +# Output the table of descriptions
    1.92 +print "/* Table mapping index numbers to descriptions */\n";
    1.93 +printf("const char *%s[] = {\n", $DESCVAR);
    1.94 +
    1.95 +foreach $elt (@item) {
    1.96 +    printf("   \"%s\",\n", $elt->{"desc"});
    1.97 +}
    1.98 +printf("   \"%s\"\n};\n\n", $last->{"desc"});
    1.99 +
   1.100 +exit 0;
   1.101 +

mercurial