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