Debian Codegraph @

rhino/testsrc/tests/pattern-extracter.pl

raw
1 #!/usr/bin/perl -w
2 # -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 # usage: pattern-extracter.pl knownfailures.expanded > knownfailures
8 #
9 # pattern-extracter.pl reads the specified expanded knownfailures file
10 # (see pattern-expander.pl) and writes to stdout a set of knownfailures
11 # where repetitions of values found in the universe.data file are
12 # replaced with wildcards ".*".
13
14 use lib $ENV{TEST_DIR} . "/tests/mozilla.org/js";
15
16 use Patterns;
17
18 package Patterns;
19
20
21 my $universefield;
22
23 processfile();
24
25 sub processfile
26 {
27 my $recordcurr = {};
28 my $recordprev;
29
30 my @output;
31 my $keycurr = '';
32 my $keyprev = '';
33 my @values = ();
34 my $universefielduniversekey; # universekey for universefield
35 my @universefielduniverse;
36 my $i;
37 my $j;
38 my $v;
39
40 while (<ARGV>) {
41
42 chomp;
43
44 $recordcurr = {};
45
46 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) = $_ =~
47 /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=(.*)/;
48
49 $recordcurr->{TEST_ID} = $test_id;
50 $recordcurr->{TEST_BRANCH} = $test_branch;
51 $recordcurr->{TEST_REPO} = $test_repo;
52 $recordcurr->{TEST_BUILDTYPE} = $test_buildtype;
53 $recordcurr->{TEST_TYPE} = $test_type;
54 $recordcurr->{TEST_OS} = $test_os;
55 $recordcurr->{TEST_KERNEL} = $test_kernel;
56 $recordcurr->{TEST_PROCESSORTYPE} = $test_processortype;
57 $recordcurr->{TEST_MEMORY} = $test_memory;
58 $recordcurr->{TEST_TIMEZONE} = $test_timezone;
59 $recordcurr->{TEST_OPTIONS} = $test_options;
60 $recordcurr->{TEST_RESULT} = $test_result;
61 $recordcurr->{TEST_EXITSTATUS} = $test_exitstatus;
62 $recordcurr->{TEST_DESCRIPTION} = $test_description;
63
64 push @records, ($recordcurr);
65 }
66
67 for ($j = $#universefields; $j >= 0; $j--)
68 {
69 $universefield = $universefields[$j];
70
71 @records = sort {getkey($a, $universefield) cmp getkey($b, $universefield);} @records;
72
73 $recordprev = $records[0];
74 $keyprev = getkey($recordprev, $universefield);
75 @values = ();
76
77 my $recordtemp;
78 my $keytemp;
79
80 dbg("processfile: begin processing records for \$universefields[$j]=$universefield");
81
82 for ($i = 0; $i < @records; $i++)
83 {
84 $recordcurr = $records[$i];
85 $keycurr = getkey($recordcurr, $universefield);
86
87 dbg("processfile: processing record[$i]");
88 dbg("processfile: recordprev: " . recordtostring($recordprev));
89 dbg("processfile: recordcurr: " . recordtostring($recordcurr));
90 dbg("processfile: \$keyprev=$keyprev");
91 dbg("processfile: \$keycurr=$keycurr");
92
93 if ($keycurr ne $keyprev)
94 {
95 # key changed, must output previous record
96 dbg("processfile: new key");
97 $universefielduniversekey = getuniversekey($recordprev, $universefield);
98 @universefielduniverse = getuniverse($universefielduniversekey, $universefield);
99 dbg("processfile: \@values: ". join(',', @values));
100 dbg("processfile: \$universefielduniversekey=$universefielduniversekey, \@universefielduniverse=" . join(',', @universefielduniverse));
101 @values = ('.*') if (arraysequal($universefield, \@values, \@universefielduniverse));
102 dbg("processfile: \@values=" . join(',', @values));
103
104 for ($v = 0; $v < @values; $v++)
105 {
106 dbg("processfile: stuffing $values[$v]");
107 $recordtemp = copyreference($recordprev);
108 $recordtemp->{$universefield} = $values[$v];
109 dbg("processfile: stuffed $recordtemp->{$universefield}");
110 dbg("processfile: recordprev: " . recordtostring($recordprev));
111 dbg("processfile: output: " . recordtostring($recordtemp));
112 push @output, ($recordtemp);
113 }
114 @values = ();
115 }
116 dbg("processfile: collecting \$recordcurr->{$universefield}=$recordcurr->{$universefield}");
117 push @values, ($recordcurr->{$universefield});
118 $keyprev = $keycurr;
119 $recordprev = $recordcurr;
120 }
121 dbg("processfile: finish processing records for \$universefields[$j]=$universefield");
122 if (@values)
123 {
124 dbg("processfile: last record for \$universefields[$j]=$universefield has pending values");
125 $universefielduniversekey = getuniversekey($recordprev, $universefield);
126 @universefielduniverse = getuniverse($universefielduniversekey, $universefield);
127 dbg("processfile: \@values: ". join(',', @values));
128 dbg("processfile: \$universefielduniversekey=$universefielduniversekey, \@universefielduniverse=" . join(',', @universefielduniverse));
129 @values = ('.*') if (arraysequal($universefield, \@values, \@universefielduniverse));
130 dbg("processfile: \@values=" . join(',', @values));
131
132 for ($v = 0; $v < @values; $v++)
133 {
134 dbg("processfile: stuffing $values[$v]");
135 $recordtemp = copyreference($recordprev);
136 $recordtemp->{$universefield} = $values[$v];
137 dbg("processfile: stuffed $recordprev->{$universefield}");
138 dbg("processfile: recordprev: " . recordtostring($recordprev));
139 dbg("processfile: output: " . recordtostring($recordtemp));
140 push @output, ($recordtemp);
141 }
142 @values = ();
143 }
144 @records = @output;
145 @output = ();
146 }
147
148 @records = sort sortrecords @records;
149 dumprecords();
150 }
151
152
153 sub getkey
154 {
155 my ($record, $universefield) = @_;
156
157 my $i;
158
159 my $key = '';
160
161 for ($i = 0; $i < @sortkeyfields; $i++)
162 {
163 if ($sortkeyfields[$i] ne $universefield)
164 {
165 $key .= $record->{$sortkeyfields[$i]}
166 }
167 }
168 return $key;
169 }
170
171 sub arraysequal
172 {
173 my ($universefield, $larrayref, $rarrayref) = @_;
174 my $i;
175
176 dbg("arraysequal: checking $universefield if " . (join ',', @{$larrayref}) . " is equal to " . (join ',', @{$rarrayref}));
177
178 # fail if lengths not equal
179 return 0 if (@{$larrayref} != @{$rarrayref});
180
181 # if the universe field is 'important', fail if lengths are 1,
182 # so that important field singletons are not replaced by wildcards.
183 my @importantfields = ('TEST_BRANCH', 'TEST_REPO', 'TEST_BUILDTYPE', 'TEST_TYPE', 'TEST_OS');
184 my @matches = grep /$universefield/, @importantfields;
185
186 return 0 if ( @matches && @{$larrayref} == 1);
187
188 for ($i = 0; $i < @{$larrayref}; $i++)
189 {
190 return 0 if ($rarrayref->[$i] ne $larrayref->[$i]);
191 }
192 dbg("arraysequal: equal");
193 return 1;
194 }
195