From daf1de2cd72d7b635f692deeab908d5f5a1673dc Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 10 Mar 2014 18:40:54 +0000 Subject: [PATCH] Introduce a 'make test' target. 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 | 3 +++ test.pl | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 test.pl diff --git a/Makefile b/Makefile index 139319b..ea91fcd 100644 --- 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 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; +} -- 2.30.2