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 package validate;
  33 
  34 use strict;
  35 use warnings;
  36 
  37 use lib "$ENV{STF_SUITE}/tests/include";
  38 use gen_xml_manifest;
  39 
  40 use Getopt::Std;
  41 use Class::Struct;
  42 use File::Basename;
  43 
  44 struct sw_t => { reverse qw{
  45         $ on
  46         $ off
  47         $ message
  48         @ pieces
  49 }};
  50 
  51 struct tests_t => { reverse qw{
  52         @ testlist
  53 }};
  54 
  55 
  56 sub conv_type() {
  57         my $x = shift;
  58 
  59         $x =~ s/_//g;
  60 
  61         $x =~ tr/a-z/A-Z/;
  62 
  63         return ($x);
  64 }
  65 
  66 
  67 my %options = ();
  68 getopts("i:o:", \%options);
  69 
  70 my $dir = dirname($0);
  71 
  72 $options{i} = "${dir}/validation_combo_sets" unless defined $options{i};
  73 $options{o} = "./v_sets" unless defined $options{o};
  74 
  75 my $cursw = -1;
  76 my $swcnt = 0;
  77 my $outfile = $options{o};
  78 my $infile = $options{i};
  79 my @switches = ();
  80 
  81 open(INFILE, "< $infile") || die "Unalbe to open $infile\n";
  82 while (<INFILE>) {
  83         chop($_);
  84         my ($swnumber, $rest) = split(/:/, $_, 2);
  85 
  86         #
  87         # Skip blank lines and comments
  88         #
  89         if (!$swnumber || $swnumber =~ /^#/) {
  90                 next;
  91         }
  92 
  93         if ($cursw != $swnumber) {
  94                 $cursw = $swnumber;
  95                 if (defined $validate::newsw) {
  96                         push(@switches, $validate::newsw);
  97                 }
  98                 $validate::newsw = sw_t->new();
  99                 $swcnt++;
 100         }
 101 
 102         (my $type, $rest) = split(/:/, $rest, 2);
 103         if ($type eq "valid") {
 104                 $validate::newsw->on($rest);
 105                 next;
 106         }
 107 
 108         if ($type eq "invalid") {
 109                 (my $mess, $rest) = split(/:/, $rest, 2);
 110                 $validate::newsw->off($rest);
 111                 $validate::newsw->message($mess);
 112                 next;
 113         }
 114 
 115         push(@{$validate::newsw->pieces}, "$type:$rest");
 116 }
 117 
 118 push(@switches, $validate::newsw);
 119 
 120 #
 121 # Now create the arrays of different possible switch combinations
 122 # Storing a number and an o or f.  The number will be an offset into
 123 # the @switches array and the o or f will indicate whether to use
 124 # the on or off setting.
 125 #
 126 my @s;
 127 my %t = ();
 128 for (my $x = 0; $x < $swcnt; $x++) {
 129         $s[$x] = $x;
 130         $t{$s[$x]}[0] = "$s[$x]o";
 131         $t{$s[$x]}[1] = "$s[$x]f";
 132 }
 133 
 134 my @sw_sets = ();
 135 for (my $x = 1; $x < (2**$swcnt); $x++) {
 136         my $st = tests_t->new();
 137         for (my $y = $swcnt; $y >= 0; $y--) {
 138                 if (($x >> $y) & 1) {
 139                         push(@{$st->testlist}, $s[$y]);
 140                 }
 141         }
 142 
 143         push(@sw_sets, $st);
 144 }
 145 
 146 my @t_sets = ();
 147 foreach my $set (@sw_sets) {
 148         my $sc = $#{$set->testlist} + 1;
 149 
 150         for (my $x = 0; $x < (2**$sc); $x++) {
 151                 my $ts = tests_t->new();
 152                 for (my $y = $sc; $y >= 0; $y--) {
 153                         if (defined ${$set->testlist}[$y]) {
 154                                 push(@{$ts->testlist},
 155                                     $t{${$set->testlist}[$y]}[($x >> $y) & 1]);
 156                         }
 157                 }
 158 
 159                 push(@t_sets, $ts);
 160         }
 161 }
 162 
 163 my $cntr = 0;
 164 open(TMPFILE, "> $outfile");
 165 foreach $a (@t_sets) {
 166         my $offsw = 0;
 167         my $ems = "";
 168         my @lines = ();
 169         $cntr++;
 170 
 171         foreach $b (@{$a->testlist}) {
 172                 if (!$b) {
 173                         next;
 174                 }
 175 
 176                 my $myb = $b;
 177                 my $onoff = chop($myb);
 178                 my $myswtch = $switches[$myb];
 179                 foreach my $c (@{$myswtch->pieces}) {
 180                         my $lfnd = 0;
 181                         foreach my $l (@lines) {
 182                                 if ("$c" eq "$l") {
 183                                         $lfnd = 1;
 184                                         last;
 185                                 }
 186                         }
 187 
 188                         if ($lfnd == 0) {
 189                                 printf(TMPFILE "$c\n");
 190                                 push(@lines, $c);
 191                         }
 192                 }
 193 
 194                 my $d;
 195                 if ($onoff eq "f") {
 196                         my $newms;
 197                         $offsw = 1;
 198                         $d = $myswtch->off;
 199                         if ($ems ne "") {
 200                                 $newms = $myswtch->message;
 201                                 $ems = "$ems:$newms";
 202                         } else {
 203                                 $newms = $myswtch->message;
 204                                 $ems = "$newms";
 205                         }
 206                 } else {
 207                         $d = $myswtch->on;
 208                 }
 209                 printf(TMPFILE "$d\n");
 210         }
 211 
 212         if ($offsw == 1) {
 213                 printf(TMPFILE "negative:vitests_$cntr:$ems\n");
 214         } else {
 215                 printf(TMPFILE "positive:vitests_$cntr\n");
 216         }
 217 
 218 }
 219 
 220 close(TMPFILE);
 221 
 222 &gen_xml_manifest($outfile);