chiark / gitweb /
Introduce a 'make test' target.
authorSimon Tatham <anakin@pobox.com>
Mon, 10 Mar 2014 18:40:54 +0000 (18:40 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 10 Mar 2014 18:40:54 +0000 (18:40 +0000)
This checks the expected results for all the easy cases, both in
single-core mode and repeatedly in multicore mode (to try to smoke out
intermittent errors like the negative-max-frags bug fixed a couple of
commits ago).

Makefile
test.pl [new file with mode: 0755]

index 139319be8531e42c7d00b89191429f648a15bbf7..ea91fcd564379082d2c8d619ff580f23574f913e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,3 +5,6 @@ LC_CTYPE=C
 LDLIBS = -lpub -lglpk -lm
 
 all: main
+
+test: test.pl main
+       ./test.pl
diff --git a/test.pl b/test.pl
new file mode 100755 (executable)
index 0000000..ec92fa9
--- /dev/null
+++ b/test.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Getopt::Long;
+
+my $main = "./main";
+my $verbose = 0;
+
+die "usage: test.pl [-v] [-c COMMAND]\n" unless GetOptions(
+    "verbose|v" => \$verbose,
+    "command|c=s" => \$main);
+
+&runtest(3,2,"1");
+&runtest(4,2,"2");
+&runtest(4,3,"1");
+&runtest(5,2,"1");
+&runtest(5,3,"1.25");
+&runtest(5,4,"1.5");
+&runtest(6,2,"2");
+&runtest(6,3,"3");
+&runtest(6,4,"2");
+&runtest(6,5,"2");
+&runtest(7,2,"1");
+&runtest(7,3,"1.25");
+&runtest(7,4,"1.66667");
+&runtest(7,5,"1.66667");
+print "ok\n";
+
+sub runtest {
+    my ($n, $m, $expected) = @_;
+    &singletest("$main $n $m", $expected);
+    for (my $i = 0; $i < 10; $i++) {
+        &singletest("$main -j4 $n $m", $expected);
+    }
+}
+
+sub singletest {
+    my ($cmd, $expected) = @_;
+    print "test: $cmd\n" if $verbose;
+    open my $pipe, "-|", "$cmd 2>/dev/null"
+        or die "open: $!\n";
+    my $firstline = <$pipe>;
+    chomp($firstline);
+    die "$cmd: first line of output not as expected:\n$firstline\n"
+        unless $firstline =~ /^(\d+) into (\d+): min fragment ([\d\.e\+\-]+)/;
+    die "$cmd: min fragment $3, expected $expected\n"
+        unless $3 eq $expected;
+}