robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | #LTP results gathering script: ltp_check |
| 4 | # 3/12/02 William Jay Huie (creation) |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 5 | # 3/28/02 William Jay Huie minor fixes, increased results parsing |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 6 | # 5/01/02 William Jay Huie parsing changes |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 7 | #This will log into the LTP_HOST machine, which may be different then the |
| 8 | #machine used to run the ltp_master script |
| 9 | #This script will check for *ltpoutput.tgz files created by the ltprun script |
| 10 | #and download them each to their own directory and do a bit of processing |
| 11 | #the results gathering probably needs to be extended but hopefully this is a good |
| 12 | #first go at it |
| 13 | |
| 14 | use Net::FTP (); |
| 15 | |
| 16 | #CHANGEME: |
| 17 | #For some reason doesn't work if you do ~/ltp/results, so you need to code the |
| 18 | #explicit path for LTP_RES_DIR unless someone can tell me why |
| 19 | $LTP_RES_DIR="/home/wjhuie/ltp/results"; |
| 20 | #CHANGEME: |
| 21 | $LTP_HOST="ltp_host.somewhere.org"; |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 22 | #This is who has the *ltpoutput.tgz files, where the results are uploaded |
| 23 | # not necessarially the user id that ran the test |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 24 | $LTP_USER="ltp"; |
| 25 | $LTP_PASS="ltp"; |
| 26 | $LTP_LOGFILE="ltp-logfile"; |
| 27 | $LTP_RUN_OUTPUT="ltprun.out"; |
| 28 | $LTP_RUNALL_OUT="runall.output"; |
| 29 | $RESULTS_OUT="results.out"; |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 30 | $FAILS_OUT="failures.list"; |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 31 | |
| 32 | @res_dirs; |
| 33 | $count = 0; |
| 34 | $RES = 0; |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 35 | $FAILS = 0; |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 36 | |
| 37 | sub download_results() |
| 38 | { |
| 39 | print "Attempting to download the LTP results\n"; |
| 40 | |
| 41 | $dir = system("ls $LTP_RES_DIR &> /dev/null") / 256; |
| 42 | if ($dir) |
| 43 | { |
| 44 | print "Making a results directory in $LTP_RES_DIR\n"; |
| 45 | `mkdir -p $LTP_RES_DIR`; |
| 46 | chdir "$LTP_RES_DIR" or die "Can't change to $LTP_RES_DIR\n"; |
| 47 | } |
| 48 | else |
| 49 | { chdir "$LTP_RES_DIR" or die "Can't change to $LTP_RES_DIR\n"; } |
| 50 | |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 51 | $ftp = Net::FTP->new($LTP_HOST, Debug => 0) or die "Can't connect to ftp: $LTP_HOST"; |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 52 | $ftp->login($LTP_USER, $LTP_PASS) or die "Unable to login"; |
| 53 | $ftp->type('I') or die "Unable to set type to Binary"; |
| 54 | @files = $ftp->ls("*ltpoutput.tgz"); |
| 55 | $num_files = $#files + 1; |
| 56 | print "New results files found $num_files:\n"; |
| 57 | for ($i = 0; $i < $num_files; $i++) { print "\t$files[$i]\n"; } |
| 58 | |
| 59 | for ($i = 0; $i < $num_files; $i++) |
| 60 | { |
| 61 | print "Downloading: $files[$i]\t"; |
| 62 | if ($ftp->get($files[$i])) |
| 63 | { |
| 64 | print "Successful\n"; |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 65 | $ftp->delete($files[$i]); |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 66 | } |
| 67 | else |
| 68 | { print "FAILED\n"; } |
| 69 | |
| 70 | } |
| 71 | $ftp->quit; |
| 72 | |
| 73 | @res = `ls $LTP_RES_DIR/*.tgz 2> /dev/null`; |
| 74 | |
| 75 | if (@res) |
| 76 | { |
| 77 | $num = $#res + 1; |
| 78 | print " download of LTP results finished\n"; |
| 79 | print "$num unprocessed results files found\n"; |
| 80 | chomp(@res); |
| 81 | return 1; |
| 82 | } |
| 83 | else |
| 84 | { print " no apparent results to process\n"; return 0; } |
| 85 | |
| 86 | } |
| 87 | |
| 88 | sub untar_results() |
| 89 | { |
| 90 | for ($i = 0; $i < $num; $i++) |
| 91 | { |
| 92 | if ( $res[$i] =~ m/\s*(\w+)-((\w+)-)*ltpoutput.tgz/ ) |
| 93 | { |
| 94 | $hostname = $1; |
| 95 | $epoch_time = $3; |
| 96 | $english_time = localtime($epoch_time); |
| 97 | $dir = "$LTP_RES_DIR/$hostname/$english_time"; |
| 98 | |
| 99 | if ($english_time) |
| 100 | { |
| 101 | $new_dir = $dir; |
| 102 | $new_dir =~ s/ /_/g; |
| 103 | print "New results: $hostname @ $english_time\n"; |
| 104 | `mkdir -p '$new_dir'`; |
| 105 | chdir "$new_dir" or die "Can't change to $new_dir\n"; |
| 106 | `tar -zxf $res[$i]`; |
| 107 | `mv $res[$i] $new_dir`; |
| 108 | $res_dirs[$count] = $new_dir; $count++; |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | print "No timestamp on results file, skipping for now\n"; |
| 113 | #Should come up with a soultion for this, check/create $hostname |
| 114 | # then some unique identifier but for now we'll complain and ignore |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | return 1; |
| 119 | } |
| 120 | |
| 121 | sub gather_results() |
| 122 | { |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 123 | print "Gathering $count result(s):\n"; |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 124 | |
| 125 | for ($i = 0; $i < $count; $i++) |
| 126 | { |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 127 | print "\nResults for: $res_dirs[$i]\n"; |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 128 | chdir "$res_dirs[$i]" or die "Can't change to $res_dirs[$i]\n"; |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 129 | |
| 130 | chomp($stat = `tail -n1 $LTP_RUNALL_OUT`); |
| 131 | print "\t\t$stat\n"; |
| 132 | |
| 133 | $num_success = `grep "stat=0" $LTP_LOGFILE | wc -l`; |
| 134 | if ( $num_success =~ /\s*(\d+)\s*/ ) { $num_success = $1; } |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 135 | |
| 136 | @fails = `grep "stat=" $LTP_LOGFILE | grep -v "stat=0"`; |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 137 | $num_fail = $#fails + 1; |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 138 | |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 139 | $pass_percent = sprintf("%.2f", |
| 140 | ($num_success / ($num_success + $num_fail)) * 100); |
| 141 | |
| 142 | $ltp_ver = `grep "version" $LTP_RUN_OUTPUT`; |
| 143 | if ( $ltp_ver =~ m/.*version: (.*)/ ) { $ltp_ver = $1; } |
| 144 | |
| 145 | $line = "Pass $pass_percent % : $num_success succeeded : $num_fail failed"; |
| 146 | print "$line"; |
| 147 | |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 148 | if (open RES, ">$RESULTS_OUT") |
| 149 | { |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 150 | print ". -> Results stored in $RESULTS_OUT\n"; |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 151 | if (!open FAILS, ">$FAILS_OUT") { print "Error opening $FAILS_OUT\n"; } |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 152 | $num = |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 153 | #The <<<test_start>>> doesn't always get into the runalltest.sh output capture |
| 154 | #because some output will appear before its corresponding block |
| 155 | #So for now relying on last thing from ver_linux to know when to stop copying |
| 156 | # system("awk '/<<<test_start>>>/ { exit NR-1; }' $LTP_RUNALL_OUT") / 256; |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 157 | system("awk '/bogomips/ { exit NR; }' $LTP_RUNALL_OUT") / 256; |
| 158 | |
| 159 | @system_info = `head -n $num $LTP_RUNALL_OUT`; |
| 160 | |
| 161 | if ($ltp_ver) { print RES "$ltp_ver : "; } |
| 162 | print RES "$line\n\n"; |
| 163 | print RES "@system_info\n"; |
| 164 | print RES "$stat:\n "; |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 165 | print RES "@fails\n"; |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 166 | |
| 167 | $runall = `cat $LTP_RUNALL_OUT`; |
| 168 | for ($j = 0; $j < $num_fail; $j++) |
| 169 | { |
| 170 | if ( $fails[$j] =~ m/^tag=(\w+?) / ) |
| 171 | { |
| 172 | $test_case = $1; |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 173 | if (FAILS) { print FAILS "$test_case\n"; } |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 174 | print RES "\nTrying to find $test_case output"; |
| 175 | if ( $runall =~ |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 176 | #modified because some output is appearing before tagline |
| 177 | m/((^$test_case.*?)*<<<test_start>>>.tag=$test_case.*?<<<test_end>>>)/ms |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 178 | ) |
| 179 | { |
| 180 | print RES "\n-------------------------\n"; |
| 181 | print RES "$1"; |
| 182 | print RES "\n-------------------------\n"; |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | print RES "\n-------------------------\n"; |
| 187 | print RES "Unable to locate output for $test_case!"; |
| 188 | print RES "\n-------------------------\n"; |
| 189 | } |
| 190 | } |
| 191 | } |
robbiew | a8dc211 | 2002-05-03 15:57:43 +0000 | [diff] [blame^] | 192 | close(RES); close(FAILS); |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 193 | } |
| 194 | else |
robbiew | dc61c58 | 2002-03-27 21:58:42 +0000 | [diff] [blame] | 195 | { print "Can't open $RESULTS_OUT, test failures are:\n @fails\n"; } |
robbiew | a1c6657 | 2002-03-13 16:38:50 +0000 | [diff] [blame] | 196 | } |
| 197 | return 1; |
| 198 | } |
| 199 | |
| 200 | if (!download_results) |
| 201 | { exit 0; } |
| 202 | |
| 203 | if (!untar_results) |
| 204 | { exit 0; } |
| 205 | |
| 206 | if (!gather_results) |
| 207 | { exit 0; } |