1 #!/usr/perl5/bin/perl
2 #
3 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4 # Use is subject to license terms.
5 #
6 #
7 # CDDL HEADER START
8 #
9 # The contents of this file are subject to the terms of the
10 # Common Development and Distribution License (the "License").
11 # You may not use this file except in compliance with the License.
12 #
13 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14 # or http://www.opensolaris.org/os/licensing.
15 # See the License for the specific language governing permissions
16 # and limitations under the License.
17 #
18 # When distributing Covered Code, include this CDDL HEADER in each
19 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
20 # If applicable, add the following below this CDDL HEADER, with the
21 # fields enclosed by brackets "[]" replaced with your own identifying
22 # information: Portions Copyright [yyyy] [name of copyright owner]
23 #
24 # CDDL HEADER END
25 #
26
27 #
28 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
29 # Use is subject to license terms.
30 #
31
32 #
33 # Generate tests to validate each of the validation possibilities
34 # singularly.
35 #
36
37 package validate;
38
39 use strict;
40 use warnings;
41
42 use lib "$ENV{STF_SUITE}/tests/include";
43 use gen_xml_manifest;
44
45 use Getopt::Std;
46 use Class::Struct;
47 use File::Basename;
48
49 sub usage() {
50 printf("Usage :\n");
51 printf("\tgen_validate_tests.pl -i <infile> [-p outfile prefix]\n");
52 printf("\n\t outfile prefix defaults to test\n");
53 }
54
55 sub gen_test_set() {
56 my $ctp = "";
57
58 foreach my $p (@validate::pieces) {
59 $ctp = $ctp."$p\n";
60 }
61
62 my $subtest = 0;
63 my $pnline = "";
64 foreach my $t (@validate::tests) {
65 printf(TFILE "$ctp");
66
67 $subtest++;
68 my ($t, $p) = split(/:/, $t, 2);
69 if ($t eq "invalid") {
70 (my $e, $p) = split(/:/, $p, 2);
71 $pnline = "negative:test${validate::cur_test}." .
72 "${subtest}:${e}";
73 } else {
74 $pnline = "positive:test${validate::cur_test}." .
75 "${subtest}:";
76 }
77
78 printf(TFILE "$p\n");
79 printf(TFILE "$pnline\n");
80 }
81 }
82
83 #
84 # Get the command line arguments :
85 # -i : input file
86 # -p : output file prefix
87 #
88 my %options = ();
89 getopts("i:o:", \%options);
90
91 my $dir = dirname($0);
92
93 $options{i} = "${dir}/validation_sets" unless defined $options{i};
94 $options{o} = "validate_test" unless defined $options{o};
95
96 my $outfile = $options{o};
97 my $infile = $options{i};
98
99 $validate::cur_test = -1;
100 unlink($outfile);
101 open(TFILE, "> ${outfile}") || die "Unable to open $outfile\n";
102 open(INFILE, "< $infile") || die "Unable to open $infile\n";
103 while (<INFILE>) {
104 chop($_);
105 my ($test_number, $rest) = split(/:/, $_, 2);
106
107 #
108 # Skip blank lines and comments
109 #
110 if (!$test_number || $test_number =~ /^#/) {
111 next;
112 }
113
114 if ($validate::cur_test != $test_number) {
115 if (! defined(@validate::tests)) {
116 @validate::tests = ();
117 @validate::pieces = ();
118 $validate::cur_test = $test_number;
119 } else {
120 &gen_test_set;
121
122 @validate::tests = ();
123 @validate::pieces = ();
124 $validate::cur_test = $test_number;
125 }
126 }
127
128 (my $type, $rest) = split(/:/, $rest, 2);
129 if ($type eq "valid" || $type eq "invalid") {
130 push(@validate::tests, "$type:$rest");
131 } else {
132 push(@validate::pieces, "$type:$rest");
133 }
134 }
135
136 #
137 # Generate the last test set...
138 #
139 &gen_test_set;
140
141 close(TFILE);
142 close(INFILE);
143
144 &gen_xml_manifest($outfile);