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