| 1 |
# -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*- |
| 2 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 |
|
| 6 |
package Patterns; |
| 7 |
|
| 8 |
sub getuniversekey |
| 9 |
{ |
| 10 |
my ($machinerecord, $excludeduniversefield) = @_; |
| 11 |
my $i; |
| 12 |
my $key = ''; |
| 13 |
|
| 14 |
if ($DEBUG) { |
| 15 |
dbg("getuniversekey: \$machinerecord=" . recordtostring($machinerecord) . ", \$excludeduniversefield=$excludeduniversefield"); |
| 16 |
} |
| 17 |
|
| 18 |
for ($i = 0; $i < @universefields; $i++) |
| 19 |
{ |
| 20 |
if ($DEBUG) { |
| 21 |
dbg("getuniversekey: \$universefields[$i]=$universefields[$i]"); |
| 22 |
} |
| 23 |
|
| 24 |
if ($universefields[$i] ne $excludeduniversefield) |
| 25 |
{ |
| 26 |
$key .= $machinerecord->{$universefields[$i]} |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
if ($DEBUG) { |
| 31 |
dbg("getuniversekey=$key"); |
| 32 |
} |
| 33 |
|
| 34 |
return $key; |
| 35 |
} |
| 36 |
|
| 37 |
sub getuniverse |
| 38 |
{ |
| 39 |
my ($universekey, $excludeduniversefield) = @_; |
| 40 |
my $i; |
| 41 |
my $value; |
| 42 |
my $testrun; |
| 43 |
my @universe = (); |
| 44 |
my %universehash = (); |
| 45 |
|
| 46 |
if ($DEBUG) { |
| 47 |
dbg("getuniverse: \$universekey=$universekey, \$excludeduniversefield=$excludeduniversefield"); |
| 48 |
} |
| 49 |
|
| 50 |
for ($i = 0; $i < @testruns; $i++) |
| 51 |
{ |
| 52 |
$testrun = $testruns[$i]; |
| 53 |
if ($DEBUG) { |
| 54 |
dbg("getuniverse: \$testruns[$i]=" . recordtostring($testrun)); |
| 55 |
} |
| 56 |
$testrununiversekey = getuniversekey($testrun, $excludeduniversefield); |
| 57 |
if ($DEBUG) { |
| 58 |
dbg("getuniverse: \$testrununiversekey=$testrununiversekey"); |
| 59 |
} |
| 60 |
if ($testrununiversekey =~ /$universekey/) |
| 61 |
{ |
| 62 |
if ($DEBUG) { |
| 63 |
dbg("getuniverse: matched \$testrununiversekey=$testrununiversekey to \$universekey=$universekey"); |
| 64 |
} |
| 65 |
$value = $testrun->{$excludeduniversefield}; |
| 66 |
|
| 67 |
if ($DEBUG) { |
| 68 |
dbg("getuniverse: \$testrun->{$excludeduniversefield}=$value"); |
| 69 |
} |
| 70 |
|
| 71 |
if (! $universehash{$value} ) |
| 72 |
{ |
| 73 |
if ($DEBUG) { |
| 74 |
dbg("getuniverse: pushing $value"); |
| 75 |
} |
| 76 |
push @universe, ($value); |
| 77 |
$universehash{$value} = 1; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
@universe = sort @universe; |
| 82 |
if ($DEBUG) { |
| 83 |
dbg("getuniverse=" . join(',', @universe)); |
| 84 |
} |
| 85 |
return @universe; |
| 86 |
} |
| 87 |
|
| 88 |
sub recordtostring |
| 89 |
{ |
| 90 |
my ($record) = @_; |
| 91 |
my $j; |
| 92 |
my $line = ''; |
| 93 |
my $field; |
| 94 |
|
| 95 |
for ($j = 0; $j < @recordfields - 1; $j++) |
| 96 |
{ |
| 97 |
$field = $recordfields[$j]; |
| 98 |
if ($DEBUG) { |
| 99 |
dbg("recordtostring: \$field=$field, \$record->{$field}=$record->{$field}"); |
| 100 |
} |
| 101 |
$line .= "$field=$record->{$field}, "; |
| 102 |
} |
| 103 |
$field = $recordfields[$#recordfields]; |
| 104 |
if ($DEBUG) { |
| 105 |
dbg("recordtodtring: \$field=$field, \$record->{$field}= $record->{$field}"); |
| 106 |
} |
| 107 |
$line .= "$field=$record->{$field}"; |
| 108 |
|
| 109 |
return $line; |
| 110 |
} |
| 111 |
|
| 112 |
sub dumprecords |
| 113 |
{ |
| 114 |
my $record; |
| 115 |
my $line; |
| 116 |
my $prevline = ''; |
| 117 |
my $i; |
| 118 |
|
| 119 |
if ($DEBUG) { |
| 120 |
dbg("dumping records"); |
| 121 |
} |
| 122 |
|
| 123 |
# @records = sort sortrecords @records; |
| 124 |
|
| 125 |
for ($i = 0; $i < @records; $i++) |
| 126 |
{ |
| 127 |
$record = $records[$i]; |
| 128 |
$line = recordtostring($record); |
| 129 |
if ($line eq $prevline) |
| 130 |
{ |
| 131 |
dbg("DUPLICATE $line") if ($DEBUG); |
| 132 |
} |
| 133 |
else |
| 134 |
{ |
| 135 |
print "$line\n"; |
| 136 |
$prevline = $line; |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
sub sortrecords |
| 142 |
{ |
| 143 |
return recordtostring($a) cmp recordtostring($b); |
| 144 |
} |
| 145 |
|
| 146 |
sub dbg |
| 147 |
{ |
| 148 |
if ($DEBUG) |
| 149 |
{ |
| 150 |
print STDERR "DEBUG: " . join(" ", @_) . "\n"; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
sub copyreference |
| 155 |
{ |
| 156 |
my ($fromreference) = @_; |
| 157 |
my $toreference = {}; |
| 158 |
my $key; |
| 159 |
|
| 160 |
foreach $key (keys %{$fromreference}) |
| 161 |
{ |
| 162 |
$toreference->{$key} = $fromreference->{$key}; |
| 163 |
} |
| 164 |
return $toreference; |
| 165 |
} |
| 166 |
|
| 167 |
BEGIN |
| 168 |
{ |
| 169 |
dbg("begin"); |
| 170 |
|
| 171 |
my $test_dir = $ENV{TEST_DIR} || "/work/mozilla/mozilla.com/test.mozilla.com/www"; |
| 172 |
|
| 173 |
$DEBUG = $ENV{DEBUG}; |
| 174 |
|
| 175 |
@recordfields = ('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'); |
| 176 |
@sortkeyfields = ('TEST_ID', 'TEST_RESULT', 'TEST_EXITSTATUS', 'TEST_DESCRIPTION', 'TEST_BRANCH', 'TEST_REPO', 'TEST_BUILDTYPE', 'TEST_TYPE', 'TEST_OS', 'TEST_KERNEL', 'TEST_PROCESSORTYPE', 'TEST_MEMORY', 'TEST_TIMEZONE', 'TEST_OPTIONS'); |
| 177 |
@universefields = ('TEST_BRANCH', 'TEST_REPO', 'TEST_BUILDTYPE', 'TEST_TYPE', 'TEST_OS', 'TEST_KERNEL', 'TEST_PROCESSORTYPE', 'TEST_MEMORY', 'TEST_TIMEZONE', 'TEST_OPTIONS'); |
| 178 |
|
| 179 |
@records = (); |
| 180 |
|
| 181 |
@testruns = (); |
| 182 |
|
| 183 |
my $UNIVERSE = $ENV{TEST_UNIVERSE} || "$test_dir/tests/mozilla.org/js/universe.data"; |
| 184 |
|
| 185 |
dbg "UNIVERSE=$UNIVERSE"; |
| 186 |
|
| 187 |
open TESTRUNS, "<$UNIVERSE" or die "$?"; |
| 188 |
|
| 189 |
while (<TESTRUNS>) { |
| 190 |
|
| 191 |
chomp; |
| 192 |
|
| 193 |
dbg("BEGIN: \$_=$_\n"); |
| 194 |
|
| 195 |
my $record = {}; |
| 196 |
|
| 197 |
my ($test_os, $test_kernel, $test_processortype, $test_memory, $test_timezone, $test_jsoptions, $test_branch, $test_repo, $test_buildtype, $test_type) = $_ =~ |
| 198 |
/^TEST_OS=([^,]*), TEST_KERNEL=([^,]*), TEST_PROCESSORTYPE=([^,]*), TEST_MEMORY=([^,]*), TEST_TIMEZONE=([^,]*), TEST_OPTIONS=([^,]*), TEST_BRANCH=([^,]*), TEST_REPO=([^,]*), TEST_BUILDTYPE=([^,]*), TEST_TYPE=([^,]*)/; |
| 199 |
|
| 200 |
$record->{TEST_ID} = 'dummy'; |
| 201 |
$record->{TEST_RESULT} = 'dummy'; |
| 202 |
$record->{TEST_EXITSTATUS} = 'dummy'; |
| 203 |
$record->{TEST_DESCRIPTION} = 'dummy'; |
| 204 |
|
| 205 |
$record->{TEST_BRANCH} = $test_branch; |
| 206 |
$record->{TEST_REPO} = $test_repo; |
| 207 |
$record->{TEST_BUILDTYPE} = $test_buildtype; |
| 208 |
$record->{TEST_TYPE} = $test_type; |
| 209 |
$record->{TEST_OS} = $test_os; |
| 210 |
$record->{TEST_KERNEL} = $test_kernel; |
| 211 |
$record->{TEST_PROCESSORTYPE} = $test_processortype; |
| 212 |
$record->{TEST_MEMORY} = $test_memory; |
| 213 |
$record->{TEST_TIMEZONE} = $test_timezone; |
| 214 |
$record->{TEST_OPTIONS} = $test_jsoptions; |
| 215 |
|
| 216 |
dbg("BEGIN: testrun: " . recordtostring($record)); |
| 217 |
|
| 218 |
push @testruns, ($record); |
| 219 |
} |
| 220 |
|
| 221 |
close TESTRUNS; |
| 222 |
|
| 223 |
} |
| 224 |
|
| 225 |
1; |