]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Add support for parallel "make check" (in tests/misc, for now)
authorJim Meyering <jim@meyering.net>
Tue, 14 Aug 2007 08:21:48 +0000 (10:21 +0200)
committerJim Meyering <jim@meyering.net>
Sat, 15 Sep 2007 06:40:38 +0000 (08:40 +0200)
13 files changed:
build-aux/check.mk [new file with mode: 0644]
tests/misc/Makefile.am
tests/misc/base64
tests/misc/basename
tests/misc/cut
tests/misc/dirname
tests/misc/expand
tests/misc/fold
tests/misc/sha224sum
tests/misc/sha256sum
tests/misc/sha384sum
tests/misc/sha512sum
tests/misc/wc-files0-from

diff --git a/build-aux/check.mk b/build-aux/check.mk
new file mode 100644 (file)
index 0000000..0674f23
--- /dev/null
@@ -0,0 +1,207 @@
+## Vaucanson, a generic library for finite state machines.
+## Copyright (C) 2006, 2007 The Vaucanson Group.
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License
+## as published by the Free Software Foundation; either version 2
+## of the License, or (at your option) any later version.
+##
+## The complete GNU General Public Licence Notice can be found as the
+## `COPYING' file in the root directory.
+##
+## The Vaucanson Group consists of people listed in the `AUTHORS' file.
+
+## Override the definition from Automake to generate a log file with
+## failed tests.  It also supports parallel make checks.
+##
+## This file provides special support for "unit tests", that is to
+## say, tests that (once run) no longer need to be re-compiled and
+## re-run at each "make check", unless their sources changed.  To
+## enable unit-test supports, define LAZY_TEST_SUITE.  In such a
+## setting, that heavily relies on correct dependencies, its users may
+## prefer to define EXTRA_PROGRAMS instead of check_PROGRAMS, because
+## it allows intertwined compilation and execution of the tests.
+## Sometimes this helps catching errors earlier (you don't have to
+## wait for all the tests to be compiled).
+##
+## Define TEST_SUITE_LOG to be the name of the global log to create.
+## Define TEST_LOGS to the set of logs to include in it.  It defaults
+## to $(TESTS:.test=.log).
+
+## We use GNU Make extensions (%-rules), and override check-TESTS.
+AUTOMAKE_OPTIONS = -Wno-portability -Wno-override
+
+# Restructured Text title and section.
+am__rst_title   = sed 's/.*/   &   /;h;s/./=/g;p;x;p;g;p;s/.*//'
+am__rst_section = sed 'p;s/./=/g;p;g'
+
+# Put stdin (possibly several lines separated by ".  ") in a box.
+am__text_box = $(AWK) '{gsub ("\\.  ", "\n"); print $$0; }' |  \
+$(AWK) '                                                       \
+max < length($$0) {                                            \
+  final= final (final ? "\n" : "") " " $$0;                    \
+  max = length($$0);                                           \
+}                                                              \
+END {                                                          \
+  for (i = 0; i < max + 2 ; ++i)                               \
+    line = line "=";                                           \
+  print line;                                                  \
+  print final;                                                 \
+  print line;                                                  \
+}'
+
+# If stdout is a tty, use colors.  If test -t is not supported, then
+# this fails; a conservative approach.  Of course do not redirect
+# stdout here, just stderr...
+am__tty_colors =                               \
+if test -t 1 2>/dev/null; then                 \
+  red='\e[0;31m';                               \
+  grn='\e[0;32m';                               \
+  blu='\e[1;34m';                               \
+  std='\e[m';                                   \
+fi
+
+# To be inserted before the command running the test.  Stores in $dir
+# the directory containing $<, and passes the TEST_ENVIRONMENT.
+am__check_pre =                                        \
+if test -f ./$<; then dir=./;                  \
+elif test -f $<; then dir=;                    \
+else dir="$(srcdir)/"; fi;                     \
+$(TESTS_ENVIRONMENT)
+
+# To be appended to the command running the test.  Handles the stdout
+# and stderr redirection, and catch the exit status.
+am__check_post =                                       \
+>$@-t 2>&1;                                            \
+estatus=$$?;                                           \
+$(am__tty_colors);                                     \
+case $$estatus:" $(XFAIL_TESTS) " in                   \
+    0:*" $$(basename $<) "*) col=$$red; res=XPASS;;    \
+    0:*)                     col=$$grn; res=PASS ;;    \
+    77:*)                    col=$$blu; res=SKIP ;;    \
+    *:*" $$(basename $<) "*) col=$$grn; res=XFAIL;;    \
+    *:*)                     col=$$red; res=FAIL ;;    \
+esac;                                                  \
+echo "$${col}$$res$${std}: $$(basename $<)";           \
+echo "$$res: $$(basename $<) (exit: $$estatus)" |      \
+  $(am__rst_section) >$@;                              \
+cat $@-t >>$@;                                         \
+rm $@-t
+
+# From a test file to a log file.
+# Do not use a regular `.test.log:' rule here, since in that case the
+# following rule (without incoming extension) will mask this one.
+%.log: %.test
+       @$(am__check_pre) $${dir}$< $(am__check_post)
+
+# The exact same commands, but for programs.
+%.log: %$(EXEEXT)
+       @$(am__check_pre) $${dir}$< $(am__check_post)
+
+TEST_LOGS ?= $(TESTS:.test=.log)
+TEST_SUITE_LOG = test-suite.log
+
+$(TEST_SUITE_LOG): $(TEST_LOGS)
+       @results=$$(for f in $(TEST_LOGS); do sed 1q $$f; done);        \
+       all=$$(echo "$$results" | wc -l | sed -e 's/^[ \t]*//');        \
+       fail=$$(echo "$$results" | grep -c '^FAIL');                    \
+       pass=$$(echo "$$results" | grep -c '^PASS');                    \
+       skip=$$(echo "$$results" | grep -c '^SKIP');                    \
+       xfail=$$(echo "$$results" | grep -c '^XFAIL');                  \
+       xpass=$$(echo "$$results" | grep -c '^XPASS');                  \
+       case fail=$$fail:xfail=$$xfail:xpass=$$xpass in                 \
+         fail=0:xfail=0:xpass=*)                                       \
+           msg="All $$all tests passed.  ";;                           \
+         fail=0:xfail=*:xpass=*)                                       \
+           msg="All $$all tests behaved as expected";                  \
+           msg="$$msg ($$xfail expected failures).  ";;                \
+         fail=*:xfail=*:xpass=0)                                       \
+           msg="$$fail of $$all tests failed.  ";;                     \
+         fail=*:xfail=*:xpass=*)                                       \
+           msg="$$fail of $$all tests did not behave as expected";     \
+           msg="$$msg ($$xpass unexpected passes).  ";;                \
+         *)                                                            \
+            echo >&2 "incorrect case"; exit 4;;                                \
+       esac;                                                           \
+       if test "$$skip" -ne 0; then                                    \
+         msg="$$msg($$skip tests were not run).  ";                    \
+       fi;                                                             \
+       if test "$$fail" -ne 0; then                                    \
+         {                                                             \
+           echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |     \
+             $(am__rst_title);                                         \
+           echo "$$msg";                                               \
+           echo;                                                       \
+           echo ".. contents:: :depth: 2";                             \
+           echo;                                                       \
+           for f in $(TEST_LOGS);                                      \
+           do                                                          \
+             case $$(sed 1q $$f) in                                    \
+               SKIP:*|PASS:*|XFAIL:*);;                                \
+               *) echo; cat $$f;;                                      \
+             esac;                                                     \
+           done;                                                       \
+         } >$(TEST_SUITE_LOG).tmp;                                     \
+         mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);                   \
+         msg="$${msg}See $(subdir)/$(TEST_SUITE_LOG).  ";              \
+         if test -n "$(PACKAGE_BUGREPORT)"; then                       \
+           msg="$${msg}Please report it to $(PACKAGE_BUGREPORT).  ";   \
+         fi;                                                           \
+       fi;                                                             \
+       $(am__tty_colors);                                              \
+       if test "$$fail" -eq 0; then echo $$grn; else echo $$red; fi;   \
+         echo "$$msg" | $(am__text_box);                               \
+       echo $$std;                                                     \
+       if test x"$$VERBOSE" != x && test "$$fail" -ne 0; then          \
+         cat $(TEST_SUITE_LOG);                                        \
+       fi;                                                             \
+       test "$$fail" -eq 0
+
+# Run all the tests.
+check-TESTS:
+       @if test -z '$(LAZY_TEST_SUITE)'; then  \
+         rm -f $(TEST_SUITE_LOG) $(TEST_LOGS); \
+       fi
+       @$(MAKE) $(TEST_SUITE_LOG)
+
+
+## -------------- ##
+## Produce HTML.  ##
+## -------------- ##
+
+TEST_SUITE_HTML = $(TEST_SUITE_LOG:.log=.html)
+
+%.html: %.log
+       @for r2h in $(RST2HTML) $$RST2HTML rst2html rst2html.py;        \
+       do                                                              \
+         if ($$r2h --version) >/dev/null 2>&1; then                    \
+           R2H=$$r2h;                                                  \
+         fi;                                                           \
+       done;                                                           \
+       if test -z "$$R2H"; then                                        \
+         echo >&2 "cannot find rst2html, cannot create $@";            \
+         exit 2;                                                       \
+       fi;                                                             \
+       $$R2H $< >$@.tmp
+       mv $@.tmp $@
+
+# Be sure to run check-TESTS first, and then to convert the result.
+# Beware of concurrent executions.  And expect check-TESTS to fail.
+check-html:
+       @if $(MAKE) $(AM_MAKEFLAGS) check-TESTS; then :; else   \
+         rv=$?;                                                \
+         $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_HTML);           \
+         exit $$rv;                                            \
+       fi
+
+.PHONY: check-html
+
+
+## ------- ##
+## Clean.  ##
+## ------- ##
+
+check-clean: check-clean-local
+       rm -f $(CHECK_CLEANFILES) $(TEST_SUITE_LOG) $(TEST_SUITE_HTML) $(TEST_LOGS)
+.PHONY: check-clean check-clean-local
+clean-local: check-clean
index f4e41df8fd3f4a3520cb7652462d1745efe758b2..236fb7f04073b5e61da954e01fd85abcfbcbabb0 100644 (file)
@@ -24,6 +24,7 @@ TESTS_ENVIRONMENT = \
   built_programs="`$(built_programs)`" \
   top_srcdir=$(top_srcdir) \
   abs_top_builddir=$(abs_top_builddir) \
+  abs_top_srcdir=$(abs_top_srcdir) \
   srcdir=$(srcdir) \
   PACKAGE_VERSION=$(PACKAGE_VERSION) \
   PERL="$(PERL)" \
@@ -32,8 +33,7 @@ TESTS_ENVIRONMENT = \
   PATH="$(VG_PATH_PREFIX)`pwd`/../../src$(PATH_SEPARATOR)$$PATH" \
   CONFIG_HEADER=$(CONFIG_HEADER) \
   REPLACE_GETCWD=$(REPLACE_GETCWD) \
-  host_os=$(host_os) \
-  PROG=`../../src/basename -- "$$tst"`
+  host_os=$(host_os)
 
 # Do not choose a name that is a shell keyword like 'if', or a
 # commonly-used utility like 'cat' or 'test', as the name of a test.
@@ -42,8 +42,10 @@ TESTS_ENVIRONMENT = \
 # will execute the test script rather than the standard utility.
 
 TESTS = \
-  od \
+  head-elide-tail \
+  date \
   xstrtol \
+  od \
   arch \
   pr \
   df-P \
@@ -59,7 +61,6 @@ TESTS = \
   basename \
   close-stdout \
   csplit \
-  date \
   date-sec \
   df \
   dirname \
@@ -68,7 +69,6 @@ TESTS = \
   fold \
   groups-version \
   head-c \
-  head-elide-tail \
   head-pos \
   mknod \
   nice \
@@ -96,3 +96,9 @@ TESTS = \
   tac-continue \
   test-diag \
   tty-eof
+
+TEST_LOGS = $(TESTS:=.log)
+
+# Parallel replacement of Automake's check-TESTS target.
+# Include it last: TEST_LOGS has a default value there.
+include $(top_srcdir)/build-aux/check.mk
index 592d11391001d32062336257a82748c532420361..56c5e2427bbe532677d21d5c85dac823854c8598 100755 (executable)
@@ -20,6 +20,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index e4c145d17d694e0190ab1c7ed9432b76e92718f4..07b118559f1ea5e53787dd503c3d1707eeda4c15 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # -*-perl-*-
 
-# Copyright (C) 20062007 Free Software Foundation, Inc.
+# Copyright (C) 2006-2007 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index 40ae2cb317e6add7393e99e2bcdb08c8d48a578b..be2378250c6d4ba057aaf348ebb67b50e21b3a3a 100755 (executable)
@@ -36,10 +36,10 @@ use strict;
 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
 
 my $prog = 'cut';
-my $diag = <<EOF;
+my $diag = <<DIAG_EOF;
 $prog: fields and positions are numbered from 1
 Try \`cut --help' for more information.
-EOF
+DIAG_EOF
 
 my @Tests =
   (
@@ -60,4 +60,4 @@ my $verbose = $ENV{VERBOSE};
 
 my $fail = run_tests ($ME, $prog, \@Tests, $save_temps, $verbose);
 exit $fail;
-FILE_EOF
+EOF
index d88c9a953be9f1f14f9ffb7d8743c8ab3ac2976b..7d0ffda8a1c0d88a413ff2fb34f60b105f4b385f 100755 (executable)
@@ -20,6 +20,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index dff13b8d80b71917a061cff5d332fe107bff1a47..7772fefe732d88071473078d64eb94c6fb96d754 100755 (executable)
@@ -2,7 +2,7 @@
 # -*- perl -*-
 # Exercise expand.
 
-# Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2004-2007 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,6 +20,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index 343279603232c4f305ae90e985bbcb802b2cd264..df017019ee074d7cf883a3e588c65dc3f738c8fe 100755 (executable)
@@ -20,6 +20,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index d7d55952ebbab590dab358961ea0ebedab291d37..220a498648e2d16215114290580f78b0ea5945e8 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Test "sha224sum".
 
-# Copyright (C) 2005 Free Software Foundation, Inc.
+# Copyright (C) 2005, 2007 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index 906b1e89934c131d270aa3b8f2c16d1b14e24901..2d6a0d963afcda0f1c56f9b47ee4908850f704d9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Test "sha256sum".
 
-# Copyright (C) 2005 Free Software Foundation, Inc.
+# Copyright (C) 2005, 2007 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index c37ba8a35f963971c3fa4497e38f9afdce230e1e..1d3aff0036b5bfb905c6a165ed7eafdebdb782a8 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Test "sha384sum".
 
-# Copyright (C) 2005 Free Software Foundation, Inc.
+# Copyright (C) 2005, 2007 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index 52a2ca5dcfcdcbe84d509fb4d8cc21c8afbf1dd8..74deec5f3bc355c491e24ec22f0cf45bff93765f 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Test "sha512sum".
 
-# Copyright (C) 2005 Free Software Foundation, Inc.
+# Copyright (C) 2005, 2007 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
 : ${PERL=perl}
 : ${srcdir=.}
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
index eab8c6ece774603875723ea1f64ab6ee5f24bb4e..53511c84acfa2b67e4506c7798117a1e8fa1e0a9 100755 (executable)
@@ -23,6 +23,8 @@
 
 . $srcdir/../envvar-check
 
+PROG=`echo $0|sed 's,.*/,,'`; export PROG
+
 $PERL -e 1 > /dev/null 2>&1 || {
   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
     "so can't run this test"
@@ -37,8 +39,7 @@ use strict;
 
 (my $program_name = $0) =~ s|.*/||;
 
-$ENV{PROG} = 'wc';
-my $ME = $ENV{PROG};
+my $prog = 'wc';
 
 # Turn off localization of executable's ouput.
 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
@@ -47,14 +48,14 @@ my @Tests =
   (
    # invalid extra command line argument
    ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1},
-    {ERR => "$ME: extra operand `no-such'\n"
+    {ERR => "$prog: extra operand `no-such'\n"
        . "File operands cannot be combined with --files0-from.\n"
-       . "Try `$ME --help' for more information.\n"}
+       . "Try `$prog --help' for more information.\n"}
     ],
 
    # missing input file
    ['missing', '--files0-from=missing', {EXIT=>1},
-    {ERR => "$ME: cannot open `missing' for reading: "
+    {ERR => "$prog: cannot open `missing' for reading: "
      . "No such file or directory\n"}],
 
    # empty input
@@ -65,13 +66,13 @@ my @Tests =
 
    # one NUL
    ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1},
-    {ERR => "$ME: : No such file or directory\n"}],
+    {ERR => "$prog: : No such file or directory\n"}],
 
    # two NULs
    ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1},
     {OUT=>"0 0 0 total\n"},
-    {ERR => "$ME: : No such file or directory\n"
-          . "$ME: : No such file or directory\n"}],
+    {ERR => "$prog: : No such file or directory\n"
+          . "$prog: : No such file or directory\n"}],
 
    # one file name, no NUL
    ['1', '--files0-from=-', '<',
@@ -95,13 +96,12 @@ my @Tests =
    ['zero-len', '--files0-from=-', '<',
     {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}},
     {OUT=>"0 0 0 g\n0 0 0 total\n"},
-    {ERR => "$ME: : No such file or directory\n"}, {EXIT=>1} ],
+    {ERR => "$prog: : No such file or directory\n"}, {EXIT=>1} ],
   );
 
 my $save_temps = $ENV{DEBUG};
 my $verbose = $ENV{VERBOSE};
 
-my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
 exit $fail;
 EOF