X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-benchmark.git/blobdiff_plain/c3437f2bdbb60a09c19b4d4f04312195d9d683e0..HEAD:/continuous/gw-setup/run.pl diff --git a/continuous/gw-setup/run.pl b/continuous/gw-setup/run.pl index 04433d6..713f044 100755 --- a/continuous/gw-setup/run.pl +++ b/continuous/gw-setup/run.pl @@ -1,61 +1,40 @@ #!/usr/bin/perl -w use FindBin; +use Expect; +# Create startup script in ramdisk my $S99 = "$FindBin::Bin/initramfs/etc/init.d/S99benchmark"; system("rm -f $S99"); system("cat > $S99; chmod +x $S99") unless -t STDIN; -my $boot; -my $pid = &run_boot; -$|=1; - -my $ready; -while (<$boot>){ - last if ($ready = /Welcome to Buildroot/ || /UGW started/); -} -die "Boot failed" unless $ready; - -my $latester=<<'EOF'; -rm -f tmp-stat.txt -echo "Starting latester" -sudo ip l set eth0 down -sudo ~/bin/latester -d can0 -d can1 -d can2 -c 3200 -q --oneattime -n tmp -r=$? -sudo ip l set eth0 up +# Boot the gateway +# die("No boot command") if ($#ARGV eq -1); +my $bootcmd = scalar @ARGV ? "'".join("' '", @ARGV)."'" : "$FindBin::Bin/boot"; +$exp = Expect->spawn($bootcmd) or die "Cannot spawn $bootcmd: $!"; +$exp->expect(120, + 'Welcome to Buildroot', + 'UGW started', + '-re', 't...a...s...k...s... ...s...t...a...r...t...e...d') # RTEMS has bug - it sends 4 characters instead of just one + or die("Boot failed"); + +# Measure latencies +my $latester = ' set -e +echo "Starting latester" +rm -f tmp-stat.txt +sudo /sbin/ifdown --no-scripts eth0 +r=0 +sudo ~/bin/latester -d can0 -d can1 -d can2 -c 3200 -q --oneattime -n tmp || r=$? +sudo /sbin/ifup --no-scripts eth0 source tmp-stat.txt -for i in sent lost enobufs $(seq -f percentile%g 0 10 100); do keyval="$keyval $i=$((i))"; done +unset keyval +for i in sent lost enobufs out_of_range_below out_of_range_above $(seq -f percentile%g 0 10 100); do keyval="$keyval $i=$((i))"; done echo "! PERF: gw_latency $avg µs $keyval ok" +if [ $(bc -l <<< "$avg == 0") -eq 1 ]; then exit 1; fi exit $r -EOF +'; my $status = system((qw(ssh -T glab), $latester)); -kill('TERM', -$pid); +$exp->close(); exit($status >> 8); - -sub kill_boot() { kill('TERM', -$pid) if defined $pid; } -sub run_boot() -{ - # die("No boot command") if ($#ARGV eq -1); - # my $bootcmd = "'".join("' '", @ARGV)."'"; - - my $bootcmd = "$FindBin::Bin/boot"; - - $SIG{INT} = sub { kill_boot(); exit; }; - - pipe($boot, $wh) || die("pipe: $!"); - my $pid = fork() // die("fork: $!"); - if ($pid == 0) { - setpgrp(); # Start new process group so that we can kill all - # background processes at once - close($boot); - open(STDERR, ">&", $wh) || die "Can't dup STDERR: $!"; - my $cmd = "$bootcmd | tee /dev/stderr"; - exec($cmd) || die "Can't exec $cmd: $!"; - } - close($wh); - return $pid; -} - -END { kill_boot(); }