#!/usr/bin/perl

open (RES, ">result" ) ;
close RES ;

$speed = "9" ;
$speed_max = "20" ;

while ($speed < $speed_max) {
   close RES ;
   open (RES, ">>result" ) ;

   $speed ++ ;
   $ret = `./test_tbf.sh $speed` ;
   print "Speed : $speed kbps\n" ;
  `monitor.pl > /dev/null &` ;
  `sleep 5` ;
 
   my @res ;
   while (1) {
      $i = 0 ;
      $i ++ ;
     `sleep 1`;
      @result = split (" ", `cat /tmp/monitor.log`) ;
      $res[9] = $res[8] ;
      $res[8] = $res[7] ;
      $res[7] = $res[6] ;
      $res[6] = $res[5] ;
      $res[5] = $res[4] ;
      $res[4] = $res[3] ;
      $res[3] = $res[2] ;
      $res[2] = $res[1] ;
      $res[1] = $res[0] ;
      $res[0] = $result[0] ;

$res = join (" ", @res) ;
print "$res\n" ;

      if ( $res[0] == "0" ) { next ; }
print "." ;
      if   ( ( $res[9] eq $res[0] ) 
         and ( $res[8] eq $res[0] ) 
         and ( $res[7] eq $res[0] ) 
         and ( $res[6] eq $res[0] ) 
         and ( $res[5] eq $res[0] ) 
         and ( $res[4] eq $res[0] ) 
         and ( $res[3] eq $res[0] ) 
         and ( $res[2] eq $res[0] ) 
         and ( $res[1] eq $res[0] ) ) { last ; }
   }
   print RES "$speed $res[0]\n" ;
   print "Result : $res[0]\n" ;
   `killall -9 monitor.pl` ;
   `sleep 1` ;
}

