]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - continuous/gw-setup/run.pl
f1bfe33fcca9fddf8bde06d1f7fdd8682bec55c8
[can-benchmark.git] / continuous / gw-setup / run.pl
1 #!/usr/bin/perl -w
2
3 use FindBin;
4
5 # Create startup script in ramdisk
6 my $S99 = "$FindBin::Bin/initramfs/etc/init.d/S99benchmark";
7 system("rm -f $S99");
8 system("cat > $S99; chmod +x $S99") unless -t STDIN;
9
10 # Boot gateway
11 my $boot;
12 my $pid = &run_boot;
13 $|=1;
14
15 my $ready;
16 while (<$boot>){
17   last if ($ready = /Welcome to Buildroot/ || /UGW started/);
18 }
19 die "Boot failed" unless $ready;
20
21 # Measure latencies
22 my $latester=<<'EOF';
23 rm -f tmp-stat.txt
24 echo "Starting latester"
25 sudo ip l set eth0 down
26 sudo ~/bin/latester -d can0 -d can1 -d can2 -c 3200 -q --oneattime -n tmp
27 r=$?
28 sudo ip l set eth0 up
29 set -e
30 source tmp-stat.txt
31 for i in sent lost enobufs $(seq -f percentile%g 0 10 100); do keyval="$keyval $i=$((i))"; done
32 echo "! PERF: gw_latency $avg µs $keyval ok"
33 exit $r
34 EOF
35
36 my $status = system((qw(ssh -T glab), $latester));
37 kill('TERM', -$pid);
38 exit($status >> 8);
39
40 # Helper functions
41 sub kill_boot() { kill('TERM', -$pid) if defined $pid; }
42 sub run_boot()
43 {
44     # die("No boot command") if ($#ARGV eq -1);
45     my $bootcmd = "'".join("' '", @ARGV)."'";
46
47     $bootcmd ||= "$FindBin::Bin/boot";
48
49     $SIG{INT} = sub { kill_boot(); exit; };
50
51     pipe($boot, $wh) || die("pipe: $!");
52     my $pid = fork() // die("fork: $!");
53     if ($pid == 0) {
54         setpgrp(); # Start new process group so that we can kill all
55                    # background processes at once
56         close($boot);
57         open(STDERR, ">&", $wh) || die "Can't dup STDERR: $!";
58         my $cmd = "$bootcmd 2>&1 | tee /dev/stderr";
59         exec($cmd) || die "Can't exec $cmd: $!";
60     }
61     close($wh);
62     return $pid;
63 }
64
65 END { kill_boot(); }