]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - continuous/gw-setup/run.pl
f594fad3960021386c106a87b3bc2f46a05aefaa
[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 = m/Welcome to Buildroot/ ||
18                       m/UGW started/ ||
19                       m/t...a...s...k...s... ...s...t...a...r...t...e...d/); # RTEMS has bug - it sends 4 characters instead of just one
20 }
21 die "Boot failed" unless $ready;
22
23 # Measure latencies
24 my $latester=<<'EOF';
25 rm -f tmp-stat.txt
26 echo "Starting latester"
27 sudo ip l set eth0 down
28 sudo ~/bin/latester -d can0 -d can1 -d can2 -c 3200 -q --oneattime -n tmp
29 r=$?
30 sudo ip l set eth0 up
31 set -e
32 source tmp-stat.txt
33 for i in sent lost enobufs $(seq -f percentile%g 0 10 100); do keyval="$keyval $i=$((i))"; done
34 echo "! PERF: gw_latency $avg µs $keyval ok"
35 exit $r
36 EOF
37
38 my $status = system((qw(ssh -T glab), $latester));
39 kill('TERM', -$pid);
40 exit($status >> 8);
41
42 # Helper functions
43 sub kill_boot() { kill('TERM', -$pid) if defined $pid; }
44 sub run_boot()
45 {
46     # die("No boot command") if ($#ARGV eq -1);
47     my $bootcmd = scalar @ARGV ? "'".join("' '", @ARGV)."'" : "$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(); }