Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / pattern-expander.pl
1 #!/usr/bin/perl -w
2 # -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 #
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
10 #
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
15 #
16 # The Original Code is Mozilla JavaScript Testing Utilities
17 #
18 # The Initial Developer of the Original Code is
19 # Mozilla Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 2008
21 # the Initial Developer. All Rights Reserved.
22 #
23 # Contributor(s): Bob Clary <bclary@bclary.com>
24 #
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
36 #
37 # ***** END LICENSE BLOCK *****
38
39 # usage: pattern-expander.pl knownfailures > knownfailures.expanded
40 #
41 # pattern-expander.pl reads the specified knownfailures file and
42 # writes to stdout an expanded set of failures where the wildcards
43 # ".*" are replaced with the set of possible values specified in the
44 # universe.data file.
45
46 use lib $ENV{TEST_DIR} . "/tests/mozilla.org/js";
47
48 use Patterns;
49
50 package Patterns;
51
52 processfile();
53
54 sub processfile
55 {
56     my ($i, $j);
57
58     while (<ARGV>) {
59
60         chomp;
61
62         $record = {};
63
64         my ($test_id, $test_branch, $test_repo, $test_buildtype, $test_type, $test_os, $test_kernel, $test_processortype, $test_memory, $test_timezone, $test_options, $test_result, $test_exitstatus, $test_description) = $_ =~ 
65             /TEST_ID=([^,]*), TEST_BRANCH=([^,]*), TEST_REPO=([^,]*), TEST_BUILDTYPE=([^,]*), TEST_TYPE=([^,]*), TEST_OS=([^,]*), TEST_KERNEL=([^,]*), TEST_PROCESSORTYPE=([^,]*), TEST_MEMORY=([^,]*), TEST_TIMEZONE=([^,]*), TEST_OPTIONS=([^,]*), TEST_RESULT=([^,]*), TEST_EXITSTATUS=([^,]*), TEST_DESCRIPTION=(.*)/;
66
67         $record->{TEST_ID}            = $test_id;
68         $record->{TEST_BRANCH}        = $test_branch;
69         $record->{TEST_REPO}          = $test_repo;
70         $record->{TEST_BUILDTYPE}     = $test_buildtype;
71         $record->{TEST_TYPE}          = $test_type;
72         $record->{TEST_OS}            = $test_os;
73         $record->{TEST_KERNEL}        = $test_kernel;
74         $record->{TEST_PROCESSORTYPE} = $test_processortype;
75         $record->{TEST_MEMORY}        = $test_memory;
76         $record->{TEST_TIMEZONE}      = $test_timezone;
77         $record->{TEST_OPTIONS}       = $test_options;
78         $record->{TEST_RESULT}        = $test_result;
79         $record->{TEST_EXITSTATUS}    = $test_exitstatus;
80         $record->{TEST_DESCRIPTION}   = $test_description;
81
82         if ($DEBUG) {
83             dbg("processfile: \$_=$_");
84         }
85
86         my @list1 = ();
87         my @list2 = ();
88
89         my $iuniversefield;
90         my $universefield;
91
92         $item1 = copyreference($record);
93         if ($DEBUG) {
94             dbg("processfile: check copyreference");
95             dbg("processfile: \$record=" . recordtostring($record));
96             dbg("processfile: \$item1=" . recordtostring($item1));
97         }
98         push @list1, ($item1);
99
100         for ($iuniversefield = 0; $iuniversefield < @universefields; $iuniversefield++)
101         {
102             $universefield = $universefields[$iuniversefield];
103
104             if ($DEBUG) {
105                 dbg("processfile: \$universefields[$iuniversefield]=$universefield, \$record->{$universefield}=$record->{$universefield}");
106             }
107
108             for ($j = 0; $j < @list1; $j++)
109             {
110                 $item1 = $list1[$j];
111                 if ($DEBUG) {
112                     dbg("processfile: item1 \$list1[$j]=" . recordtostring($item1));
113                 }
114                 # create a reference to a copy of the hash referenced by $item1
115                 if ($item1->{$universefield} ne '.*')
116                 {
117                     if ($DEBUG) {
118                         dbg("processfile: literal value");
119                     }
120                     $item2 = copyreference($item1);
121                     if ($DEBUG) {
122                         dbg("processfile: check copyreference");
123                         dbg("processfile: \$item1=" . recordtostring($item1));
124                         dbg("processfile: \$item2=" . recordtostring($item2));
125                         dbg("processfile: pushing existing record to list 2: " . recordtostring($item2));
126                     }
127                     push @list2, ($item2);
128                 }
129                 else
130                 {
131                     if ($DEBUG) {                    
132                         dbg("processfile: wildcard value");
133                     }
134                     $keyfielduniversekey = getuniversekey($item1, $universefield);
135                     @keyfielduniverse = getuniverse($keyfielduniversekey, $universefield);
136
137                     if ($DEBUG) {
138                         dbg("processfile: \$keyfielduniversekey=$keyfielduniversekey, \@keyfielduniverse=" . join(',', @keyfielduniverse));
139                     }
140
141                     for ($i = 0; $i < @keyfielduniverse; $i++)
142                     {
143                         $item2 = copyreference($item1);
144                         if ($DEBUG) {
145                             dbg("processfile: check copyreference");
146                             dbg("processfile: \$item1=" . recordtostring($item1));
147                             dbg("processfile: \$item2=" . recordtostring($item2));
148                         }
149                         $item2->{$universefield} = $keyfielduniverse[$i];
150                         if ($DEBUG) {
151                             dbg("processfile: pushing new record to list 2 " . recordtostring($item2));
152                         }
153                         push @list2, ($item2);
154                     }
155                 }
156                 if ($DEBUG) {
157                     for ($i = 0; $i < @list1; $i++)
158                     {
159                         dbg("processfile: \$list1[$i]=" . recordtostring($list1[$i]));
160                     }
161                     for ($i = 0; $i < @list2; $i++)
162                     {
163                         dbg("processfile: \$list2[$i]=" . recordtostring($list2[$i]));
164                     }
165                 }
166             }
167
168             @list1 = @list2;
169             @list2 = ();
170         }
171         for ($j = 0; $j < @list1; $j++)
172         {
173             $item1 = $list1[$j];
174             push @records, ($item1);
175         }
176     }
177     @records = sort sortrecords @records;
178
179     dumprecords();
180 }
181