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

Packit 40b132
#!/usr/bin/perl
Packit 40b132
Packit 40b132
#
Packit 40b132
# make-test-arrays
Packit 40b132
#
Packit 40b132
# Given a test-arrays file, which specifies the test suite names, the
Packit 40b132
# names of the functions which perform those test suites, and
Packit 40b132
# descriptive comments, this script generates C structures for the
Packit 40b132
# mpi-test program.  The input consists of lines of the form:
Packit 40b132
#
Packit 40b132
# suite-name:function-name:comment
Packit 40b132
#
Packit 40b132
# The output is written to the standard output.  Blank lines are
Packit 40b132
# ignored, and comments beginning with '#' are stripped.
Packit 40b132
Packit 40b132
# This Source Code Form is subject to the terms of the Mozilla Public
Packit 40b132
# License, v. 2.0. If a copy of the MPL was not distributed with this
Packit 40b132
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit 40b132
Packit 40b132
# Read parameters from the environment, if available
Packit 40b132
$NAMEVAR = $ENV{'NAMEVAR'} || "g_names";
Packit 40b132
$COUNTVAR = $ENV{'COUNTVAR'} || "g_count";
Packit 40b132
$FUNCVAR = $ENV{'FUNCVAR'} || "g_tests";
Packit 40b132
$DESCVAR = $ENV{'DESCVAR'} || "g_descs";
Packit 40b132
$FUNCLEN = 13;
Packit 40b132
$NAMELEN = 18;
Packit 40b132
$DESCLEN = 45;
Packit 40b132
Packit 40b132
#------------------------------------------------------------------------
Packit 40b132
# Suck in input from the files on the command line, or standard input
Packit 40b132
while(<>) {
Packit 40b132
    chomp;
Packit 40b132
    s/\#.*$//;
Packit 40b132
    next if /^\s*$/;
Packit 40b132
Packit 40b132
    ($suite, $func, $desc) = split(/:/, $_);
Packit 40b132
Packit 40b132
    $tmp = { "suite" => $suite,
Packit 40b132
	     "func"  => $func,
Packit 40b132
	     "desc"  => $desc };
Packit 40b132
Packit 40b132
    push(@item, $tmp);
Packit 40b132
}
Packit 40b132
$count = scalar(@item);
Packit 40b132
$last = pop(@item);
Packit 40b132
Packit 40b132
#------------------------------------------------------------------------
Packit 40b132
# Output the table of names
Packit 40b132
print "/* Table mapping test suite names to index numbers */\n";
Packit 40b132
printf("const int   %s = %d;\n", $COUNTVAR, $count);
Packit 40b132
printf("const char *%s[] = {\n", $NAMEVAR);
Packit 40b132
Packit 40b132
foreach $elt (@item) {
Packit 40b132
    printf("   \"%s\",%s/* %s%s */\n", $elt->{"suite"},
Packit 40b132
	   " " x ($NAMELEN - length($elt->{"suite"})),
Packit 40b132
	   $elt->{"desc"},
Packit 40b132
	   " " x ($DESCLEN - length($elt->{"desc"})));
Packit 40b132
}
Packit 40b132
printf("   \"%s\" %s/* %s%s */\n", $last->{"suite"},
Packit 40b132
       " " x ($NAMELEN - length($last->{"suite"})),
Packit 40b132
       $last->{"desc"},
Packit 40b132
       " " x ($DESCLEN - length($last->{"desc"})));
Packit 40b132
print "};\n\n";
Packit 40b132
Packit 40b132
#------------------------------------------------------------------------
Packit 40b132
# Output the driver function prototypes
Packit 40b132
print "/* Test function prototypes */\n";
Packit 40b132
foreach $elt (@item, $last) {
Packit 40b132
    printf("int  %s(void);\n", $elt->{"func"});
Packit 40b132
}
Packit 40b132
print "\n";
Packit 40b132
Packit 40b132
#------------------------------------------------------------------------
Packit 40b132
# Output the table of functions
Packit 40b132
print "/* Table mapping index numbers to functions */\n";
Packit 40b132
printf("int (*%s[])(void)  = {\n   ", $FUNCVAR);
Packit 40b132
$brk = 0;
Packit 40b132
Packit 40b132
foreach $elt (@item) {
Packit 40b132
    print($elt->{"func"}, ", ", 
Packit 40b132
	  " " x ($FUNCLEN - length($elt->{"func"})));
Packit 40b132
    $brk = ($brk + 1) & 3;
Packit 40b132
    print "\n   " unless($brk);
Packit 40b132
}
Packit 40b132
print $last->{"func"}, "\n};\n\n";
Packit 40b132
Packit 40b132
#------------------------------------------------------------------------
Packit 40b132
# Output the table of descriptions
Packit 40b132
print "/* Table mapping index numbers to descriptions */\n";
Packit 40b132
printf("const char *%s[] = {\n", $DESCVAR);
Packit 40b132
Packit 40b132
foreach $elt (@item) {
Packit 40b132
    printf("   \"%s\",\n", $elt->{"desc"});
Packit 40b132
}
Packit 40b132
printf("   \"%s\"\n};\n\n", $last->{"desc"});
Packit 40b132
Packit 40b132
exit 0;
Packit 40b132