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