Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #! /bin/perl |
michael@0 | 2 | |
michael@0 | 3 | ####################################################################### |
michael@0 | 4 | # |
michael@0 | 5 | # /u/sonmi/bin/clean_tbx.pl |
michael@0 | 6 | # |
michael@0 | 7 | # this script is supposed to remove tinderbox QA if: |
michael@0 | 8 | # QA has passed, there are 2+ newer QA dirs of the same machine and |
michael@0 | 9 | # platform (32/64) and it is older than 2 hours |
michael@0 | 10 | # QA has failed, there are 2+ newer QA dirsof the same machine and |
michael@0 | 11 | # platform (32/64) with _identical failures and it is older than |
michael@0 | 12 | # 2 hours |
michael@0 | 13 | # directory is older than 48 hours |
michael@0 | 14 | # |
michael@0 | 15 | ####################################################################### |
michael@0 | 16 | |
michael@0 | 17 | use Time::Local; |
michael@0 | 18 | |
michael@0 | 19 | $ANY_TBX_KEEP_HOURS=48; |
michael@0 | 20 | $NOT_FAILED_TBX_KEEP_HOURS=24; |
michael@0 | 21 | $PASSED_TBX_KEEP_HOURS=2; |
michael@0 | 22 | $IF_TBX_KEEP_HOURS=2; |
michael@0 | 23 | $PASSED_NEWER_DIRS=2; |
michael@0 | 24 | $IF_NEWER_DIRS=2; |
michael@0 | 25 | $verbose = 1; |
michael@0 | 26 | |
michael@0 | 27 | $TBX_TESTDIR="/share/builds/mccrel3/nss/nsstip/tinderbox/tests_results/security"; |
michael@0 | 28 | $FTP_STAGE="/u/sonmi/tmp/ftp_stage/tinderbox"; |
michael@0 | 29 | |
michael@0 | 30 | @tbx_dirs = (); |
michael@0 | 31 | |
michael@0 | 32 | $eANY_TBX_KEEP=$ANY_TBX_KEEP_HOURS*60*60; |
michael@0 | 33 | $ePASSED_TBX_KEEP=$PASSED_TBX_KEEP_HOURS*60*60; |
michael@0 | 34 | $eIF_TBX_KEEP=$IF_TBX_KEEP_HOURS*60*60; |
michael@0 | 35 | $eNOT_FAILED_TBX_KEEP=$NOT_FAILED_TBX_KEEP_HOURS*60*60; |
michael@0 | 36 | |
michael@0 | 37 | $year, $month, $days, $hours, $minutes, $seconds; |
michael@0 | 38 | $efulldate=0; |
michael@0 | 39 | |
michael@0 | 40 | $fulldate=0; |
michael@0 | 41 | |
michael@0 | 42 | $no_bits=""; |
michael@0 | 43 | $last_no_bits=""; |
michael@0 | 44 | |
michael@0 | 45 | $host=""; |
michael@0 | 46 | $last_host=""; |
michael@0 | 47 | |
michael@0 | 48 | @tbx_dirs = `ls -r $TBX_TESTDIR`; #sort first by host, |
michael@0 | 49 | #then 64, |
michael@0 | 50 | #then newest - oldest |
michael@0 | 51 | debug ("found $#tbx_dirs directories "); |
michael@0 | 52 | |
michael@0 | 53 | ($seconds, $minutes, $hours, $days, $month, $year) = localtime; |
michael@0 | 54 | |
michael@0 | 55 | debug ("$seconds, $minutes, $hours, $days, $month, $year"); |
michael@0 | 56 | |
michael@0 | 57 | $enow = timelocal(localtime); |
michael@0 | 58 | |
michael@0 | 59 | sub debug; |
michael@0 | 60 | sub warning; |
michael@0 | 61 | sub error; |
michael@0 | 62 | sub msg; |
michael@0 | 63 | sub init; |
michael@0 | 64 | sub check_tbx_dirs; |
michael@0 | 65 | |
michael@0 | 66 | sub check_tbx_dirs |
michael@0 | 67 | { |
michael@0 | 68 | my $platform_idx=0; # counts directories per platform, newest |
michael@0 | 69 | # to oldest (ignores incomplete) |
michael@0 | 70 | my $passed_idx=0; # counts passed directories newest to oldest |
michael@0 | 71 | my $QAstatus="unknown"; |
michael@0 | 72 | foreach $tbx_dir (@tbx_dirs) { |
michael@0 | 73 | $tbx_dir =~ s/\n//g; |
michael@0 | 74 | $fulldate = $tbx_dir; |
michael@0 | 75 | $fulldate =~ s/^.*-(20.*-..\...$)/$1/; |
michael@0 | 76 | $day = $month = $year = $hour = $min = $fulldate; |
michael@0 | 77 | $host = $tbx_dir; |
michael@0 | 78 | $host =~ s/-20.*//; |
michael@0 | 79 | $no_bits = $host; |
michael@0 | 80 | $host =~ s/64$//; |
michael@0 | 81 | $no_bits =~ s/.*64$/64/; |
michael@0 | 82 | $no_bits =~ s/^[^6].*/other/; |
michael@0 | 83 | $year =~ s/(....).*/$1/; |
michael@0 | 84 | $month =~ s/....(..).*/$1/; |
michael@0 | 85 | $day =~ s/......(..).*/$1/; |
michael@0 | 86 | $hour =~ s/........-(..).*/$1/; |
michael@0 | 87 | $min =~ s/.*\.(..)$/$1/; |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | if ( -f "$TBX_TESTDIR/$tbx_dir/QAstatus" ) { |
michael@0 | 91 | $QAstatus=`cat $TBX_TESTDIR/$tbx_dir/QAstatus 2>/dev/null`; |
michael@0 | 92 | $QAstatus =~ s/\n$//g; |
michael@0 | 93 | } else { |
michael@0 | 94 | $QAstatus="unknown"; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | $efulldate = timelocal( 0, $min, $hour, $day, $month-1, $year-1900); |
michael@0 | 98 | if ( "$host" !~ "$last_host" || "$no_bits" !~ "$last_no_bits" ) { |
michael@0 | 99 | if ( $QAstatus !~ "QA running" ) { |
michael@0 | 100 | $platform_idx = 0; |
michael@0 | 101 | } else { |
michael@0 | 102 | $platform_idx = -1; |
michael@0 | 103 | } |
michael@0 | 104 | $passed_idx = 0; |
michael@0 | 105 | |
michael@0 | 106 | $last_host = $host; |
michael@0 | 107 | $last_no_bits = $no_bits; |
michael@0 | 108 | } else { |
michael@0 | 109 | $platform_idx ++; |
michael@0 | 110 | $passed_idx++ if ( $QAstatus =~ "QA passed" ) ; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | debug ("$tbx_dir host $host date $fulldate bits $no_bits $year/$month/$day $hour:$min QAstatus $QAstatus pli $platform_idx pai $passed_idx"); |
michael@0 | 114 | |
michael@0 | 115 | if ( $passed_idx > $PASSED_NEWER_DIRS && $QAstatus =~ "QA passed" ) { |
michael@0 | 116 | $ekeeptime=$efulldate + $ePASSED_TBX_KEEP; |
michael@0 | 117 | #($s, $m, $h, $d, $mo, $y) = localtime($ekeeptime); |
michael@0 | 118 | #debug ("$passed_idx > $PASSED_NEWER_DIRS ekeeptime ($s, $m, $h, $d, $mo, $y) == $ekeeptime"); |
michael@0 | 119 | rm_tbx ("Passed $PASSED_TBX_KEEP_HOURS + hours old") if ( $ekeeptime <= $enow ); |
michael@0 | 120 | } elsif ( $QAstatus !~ "QA failed" ) { |
michael@0 | 121 | $ekeeptime=$efulldate + $eNOT_FAILED_TBX_KEEP; |
michael@0 | 122 | rm_tbx ("Not failed $NOT_FAILED_TBX_KEEP_HOURS + hours old") if ( $ekeeptime <= $enow ); |
michael@0 | 123 | } else { |
michael@0 | 124 | $ekeeptime=$efulldate + $eANY_TBX_KEEP; |
michael@0 | 125 | rm_tbx ("Passed 2+ hours old") if ( $ekeeptime <= $enow ); |
michael@0 | 126 | } |
michael@0 | 127 | if ( $QAstatus =~ "QA failed" ) { |
michael@0 | 128 | $ekeeptime=$efulldate + $eIF_TBX_KEEP; |
michael@0 | 129 | #FIXME - compare to the previous failure by filtering and |
michael@0 | 130 | #FIXME diffing the results.html files (first grep failed) |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | sub rm_tbx() |
michael@0 | 137 | { |
michael@0 | 138 | |
michael@0 | 139 | debug ("DELETING $tbx_dir... (@_[0]) "); |
michael@0 | 140 | system("rm -rf $TBX_TESTDIR/$tbx_dir"); |
michael@0 | 141 | #debug ("rm -rf $TBX_TESTDIR/$tbx_dir"); |
michael@0 | 142 | |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | sub msg |
michael@0 | 146 | { |
michael@0 | 147 | my $i; |
michael@0 | 148 | for ($i = 0; $i <= $#_ ; $i++ ) { |
michael@0 | 149 | print "@_[$i] "; |
michael@0 | 150 | } |
michael@0 | 151 | print "\n"; |
michael@0 | 152 | |
michael@0 | 153 | } |
michael@0 | 154 | sub error |
michael@0 | 155 | { |
michael@0 | 156 | msg ("ERROR: " ,@_ ); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | sub warning |
michael@0 | 160 | { |
michael@0 | 161 | msg ("WARNING:" ,@_ ); |
michael@0 | 162 | } |
michael@0 | 163 | sub debug |
michael@0 | 164 | { |
michael@0 | 165 | if ( $verbose == 1 ) { |
michael@0 | 166 | msg ("DEBUG: " ,@_ ); |
michael@0 | 167 | } elsif ( $verbose == 2 ) { |
michael@0 | 168 | msg (@_ ); |
michael@0 | 169 | } |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | check_tbx_dirs; |