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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c61e39668e6a
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
31 while(<>) {
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
49 print "/* Table mapping test suite names to index numbers */\n";
50 printf("const int %s = %d;\n", $COUNTVAR, $count);
51 printf("const char *%s[] = {\n", $NAMEVAR);
52
53 foreach $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 }
59 printf(" \"%s\" %s/* %s%s */\n", $last->{"suite"},
60 " " x ($NAMELEN - length($last->{"suite"})),
61 $last->{"desc"},
62 " " x ($DESCLEN - length($last->{"desc"})));
63 print "};\n\n";
64
65 #------------------------------------------------------------------------
66 # Output the driver function prototypes
67 print "/* Test function prototypes */\n";
68 foreach $elt (@item, $last) {
69 printf("int %s(void);\n", $elt->{"func"});
70 }
71 print "\n";
72
73 #------------------------------------------------------------------------
74 # Output the table of functions
75 print "/* Table mapping index numbers to functions */\n";
76 printf("int (*%s[])(void) = {\n ", $FUNCVAR);
77 $brk = 0;
78
79 foreach $elt (@item) {
80 print($elt->{"func"}, ", ",
81 " " x ($FUNCLEN - length($elt->{"func"})));
82 $brk = ($brk + 1) & 3;
83 print "\n " unless($brk);
84 }
85 print $last->{"func"}, "\n};\n\n";
86
87 #------------------------------------------------------------------------
88 # Output the table of descriptions
89 print "/* Table mapping index numbers to descriptions */\n";
90 printf("const char *%s[] = {\n", $DESCVAR);
91
92 foreach $elt (@item) {
93 printf(" \"%s\",\n", $elt->{"desc"});
94 }
95 printf(" \"%s\"\n};\n\n", $last->{"desc"});
96
97 exit 0;
98

mercurial