1#!/usr/bin/perl 2 3# 4# make-test-arrays 5# 6# Given a test-arrays file, which specifies the test suite names, the 7# names of the functions which perform those test suites, and 8# descriptive comments, this script generates C structures for the 9# mpi-test program. The input consists of lines of the form: 10# 11# suite-name:function-name:comment 12# 13# The output is written to the standard output. Blank lines are 14# ignored, and comments beginning with '#' are stripped. 15 16# This Source Code Form is subject to the terms of the Mozilla Public 17# License, v. 2.0. If a copy of the MPL was not distributed with this 18# file, You can obtain one at http://mozilla.org/MPL/2.0/. 19 20# Read parameters from the environment, if available 21$NAMEVAR = $ENV{'NAMEVAR'} || "g_names"; 22$COUNTVAR = $ENV{'COUNTVAR'} || "g_count"; 23$FUNCVAR = $ENV{'FUNCVAR'} || "g_tests"; 24$DESCVAR = $ENV{'DESCVAR'} || "g_descs"; 25$FUNCLEN = 13; 26$NAMELEN = 18; 27$DESCLEN = 45; 28 29#------------------------------------------------------------------------ 30# Suck in input from the files on the command line, or standard input 31while(<>) { 32 chomp; 33 s/\#.*$//; 34 next if /^\s*$/; 35 36 ($suite, $func, $desc) = split(/:/, $_); 37 38 $tmp = { "suite" => $suite, 39 "func" => $func, 40 "desc" => $desc }; 41 42 push(@item, $tmp); 43} 44$count = scalar(@item); 45$last = pop(@item); 46 47#------------------------------------------------------------------------ 48# Output the table of names 49print "/* Table mapping test suite names to index numbers */\n"; 50printf("const int %s = %d;\n", $COUNTVAR, $count); 51printf("const char *%s[] = {\n", $NAMEVAR); 52 53foreach $elt (@item) { 54 printf(" \"%s\",%s/* %s%s */\n", $elt->{"suite"}, 55 " " x ($NAMELEN - length($elt->{"suite"})), 56 $elt->{"desc"}, 57 " " x ($DESCLEN - length($elt->{"desc"}))); 58} 59printf(" \"%s\" %s/* %s%s */\n", $last->{"suite"}, 60 " " x ($NAMELEN - length($last->{"suite"})), 61 $last->{"desc"}, 62 " " x ($DESCLEN - length($last->{"desc"}))); 63print "};\n\n"; 64 65#------------------------------------------------------------------------ 66# Output the driver function prototypes 67print "/* Test function prototypes */\n"; 68foreach $elt (@item, $last) { 69 printf("int %s(void);\n", $elt->{"func"}); 70} 71print "\n"; 72 73#------------------------------------------------------------------------ 74# Output the table of functions 75print "/* Table mapping index numbers to functions */\n"; 76printf("int (*%s[])(void) = {\n ", $FUNCVAR); 77$brk = 0; 78 79foreach $elt (@item) { 80 print($elt->{"func"}, ", ", 81 " " x ($FUNCLEN - length($elt->{"func"}))); 82 $brk = ($brk + 1) & 3; 83 print "\n " unless($brk); 84} 85print $last->{"func"}, "\n};\n\n"; 86 87#------------------------------------------------------------------------ 88# Output the table of descriptions 89print "/* Table mapping index numbers to descriptions */\n"; 90printf("const char *%s[] = {\n", $DESCVAR); 91 92foreach $elt (@item) { 93 printf(" \"%s\",\n", $elt->{"desc"}); 94} 95printf(" \"%s\"\n};\n\n", $last->{"desc"}); 96 97exit 0; 98 99