]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - continuous/gw-setup/run.pl
Add first automated test and supporting infrastructure
[can-benchmark.git] / continuous / gw-setup / run.pl
diff --git a/continuous/gw-setup/run.pl b/continuous/gw-setup/run.pl
new file mode 100755 (executable)
index 0000000..d026b12
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl -w
+
+use FindBin;
+
+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
+set -e
+source tmp-stat.txt
+for i in sent lost enobufs $(seq -f percentile%g 0 10 100); do keyval="$keyval $i=$((i))"; done
+echo "! PERF: gw_latency $avg µs $keyval ok"
+exit $r
+EOF
+
+my $status = system((qw(ssh -T glab), $latester));
+kill('TERM', -$pid);
+exit($status >> 8);
+
+
+sub run_boot()
+{
+    # die("No boot command") if ($#ARGV eq -1);
+    # my $bootcmd = "'".join("' '", @ARGV)."'";
+
+    my $bootcmd = "$FindBin::Bin/boot";
+
+    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('TERM', -$pid) if defined $pid; }