From f15efcdf27f5f596e3e82a7cbc134c95092b0831 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 24 Mar 2008 10:19:36 +0000 Subject: [PATCH] Add new testing framework and the first test to use it. * tests/Makefile.am (test_scripts): Add vcpupin. (EXTRA_DIST): Add test-lib.sh. * tests/test-lib.sh: Testing framework, from coreutils. * tests/vcpupin: New file. * build-aux/mktempd: New file, from gnulib. * bootstrap: Add posix-shell and mktempd to the list of imported modules. * gnulib/m4/posix-shell.m4: New file, from gnulib. --- ChangeLog | 9 ++ bootstrap | 2 + build-aux/.cvsignore | 1 + build-aux/mktempd | 132 ++++++++++++++++++++++++++ build-aux/useless-if-before-free | 6 +- gnulib/lib/Makefile.am | 37 +++++--- gnulib/lib/alloca.in.h | 4 +- gnulib/lib/getaddrinfo.c | 2 +- gnulib/lib/getdelim.c | 6 +- gnulib/lib/unistd.in.h | 22 ++++- gnulib/lib/xsize.h | 2 +- gnulib/m4/absolute-header.m4 | 49 ---------- gnulib/m4/fseeko.m4 | 8 +- gnulib/m4/gnulib-cache.m4 | 6 +- gnulib/m4/gnulib-comp.m4 | 6 +- gnulib/m4/include_next.m4 | 7 +- gnulib/m4/lib-link.m4 | 66 +++++++++---- gnulib/m4/posix-shell.m4 | 58 ++++++++++++ gnulib/m4/unistd_h.m4 | 6 +- gnulib/tests/Makefile.am | 2 +- tests/Makefile.am | 7 +- tests/test-lib.sh | 155 +++++++++++++++++++++++++++++++ tests/vcpupin | 37 ++++++++ 23 files changed, 530 insertions(+), 100 deletions(-) create mode 100755 build-aux/mktempd delete mode 100644 gnulib/m4/absolute-header.m4 create mode 100644 gnulib/m4/posix-shell.m4 create mode 100644 tests/test-lib.sh create mode 100755 tests/vcpupin diff --git a/ChangeLog b/ChangeLog index 40128198f7..a1ed1bb17c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ Mon Mar 24 11:16:58 CET 2008 Jim Meyering + Add new testing framework and the first test to use it. + * tests/Makefile.am (test_scripts): Add vcpupin. + (EXTRA_DIST): Add test-lib.sh. + * tests/test-lib.sh: Testing framework, from coreutils. + * tests/vcpupin: New file. + * build-aux/mktempd: New file, from gnulib. + * bootstrap: Add posix-shell and mktempd to the list of imported modules. + * gnulib/m4/posix-shell.m4: New file, from gnulib. + Fix bugs in tests/Makefile.am. * tests/Makefile.am (TESTS_ENVIRONMENT): Correct invalid settings of abs_top_builddir and abs_top_srcdir. diff --git a/bootstrap b/bootstrap index d8b79d9390..f7b6aec968 100755 --- a/bootstrap +++ b/bootstrap @@ -79,6 +79,8 @@ $gnulib_tool \ sys_stat vasprintf strndup \ strsep poll gettext getpass \ useless-if-before-free \ + posix-shell \ + mktempd \ vc-list-files rm -f \ diff --git a/build-aux/.cvsignore b/build-aux/.cvsignore index 1798f40d35..096cccbf59 100644 --- a/build-aux/.cvsignore +++ b/build-aux/.cvsignore @@ -7,3 +7,4 @@ install-sh ltmain.sh missing mkinstalldirs +mktempd diff --git a/build-aux/mktempd b/build-aux/mktempd new file mode 100755 index 0000000000..7ac914b31c --- /dev/null +++ b/build-aux/mktempd @@ -0,0 +1,132 @@ +#!/bin/sh +# Create a temporary directory, much like mktemp -d does. + +# Copyright (C) 2007-2008 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Written by Jim Meyering. + +# Usage: mktempd /tmp phoey.XXXXXXXXXX + +# First, try to use the mktemp program. +# Failing that, we'll roll our own mktemp-like function: +# - try to get random bytes from /dev/urandom +# - failing that, generate output from a combination of quickly-varying +# sources and gzip. Ignore non-varying gzip header, and extract +# "random" bits from there. +# - given those bits, map to file-name bytes using tr, and try to create +# the desired directory. +# - make only $MAX_TRIES attempts + +ME=`basename "$0"` +die() { echo >&2 "$ME: $@"; exit 1; } + +MAX_TRIES=4 + +rand_bytes() +{ + n=$1 + + chars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 + + dev_rand=/dev/urandom + if test -r "$dev_rand"; then + # Note: 256-length($chars) == 194; 3 copies of $chars is 186 + 8 = 194. + head -c$n "$dev_rand" | tr -c $chars 01234567$chars$chars$chars + return + fi + + cmds='date; date +%N; free; who -a; w; ps auxww; ps ef; netstat -n' + data=` (eval "$cmds") 2>&1 | gzip ` + + n_plus_50=`expr $n + 50` + + # Ensure that $data has length at least 50+$n + while :; do + len=`echo "$data"|wc -c` + test $n_plus_50 -le $len && break; + data=` (echo "$data"; eval "$cmds") 2>&1 | gzip ` + done + + echo "$data" \ + | dd bs=1 skip=50 count=$n 2>/dev/null \ + | tr -c $chars 01234567$chars$chars$chars +} + +mktempd() +{ + case $# in + 2);; + *) die "Usage: $ME DIR TEMPLATE";; + esac + + destdir=$1 + template=$2 + + # Disallow any trailing slash on specified destdir: + # it would subvert the post-mktemp "case"-based destdir test. + case $destdir in + /) ;; + */) die "invalid destination dir: remove trailing slash(es)";; + esac + + case $template in + *XXXX) ;; + *) die "invalid template: $template (must have a suffix of at least 4 X's)";; + esac + + fail=0 + + # First, try to use mktemp. + d=`env -u TMPDIR mktemp -d -t -p "$destdir" "$template" 2>/dev/null` \ + || fail=1 + + # The resulting name must be in the specified directory. + case $d in "$destdir"*);; *) fail=1;; esac + + # It must have created the directory. + test -d "$d" || fail=1 + + # It must have 0700 permissions. Handle sticky "S" bits. + perms=`ls -dgo "$d" 2>/dev/null|tr S -` || fail=1 + case $perms in drwx------*) ;; *) fail=1;; esac + + test $fail = 0 && { + echo "$d" + return + } + + # If we reach this point, we'll have to create a directory manually. + + # Get a copy of the template without its suffix of X's. + base_template=`echo "$template"|sed 's/XX*$//'` + + # Calculate how many X's we've just removed. + nx=`expr length "$template" - length "$base_template"` + + err= + i=1 + while :; do + X=`rand_bytes $nx` + candidate_dir="$destdir/$base_template$X" + err=`mkdir -m 0700 "$candidate_dir" 2>&1` \ + && { echo "$candidate_dir"; return; } + test $MAX_TRIES -le $i && break; + i=`expr $i + 1` + done + die "$err" +} + +mktempd "$@" diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free index eb18483789..626d19ab2b 100755 --- a/build-aux/useless-if-before-free +++ b/build-aux/useless-if-before-free @@ -2,7 +2,7 @@ # Detect instances of "if (p) free (p);". # Likewise for "if (p != NULL) free (p);". And with braces. -my $VERSION = '2008-02-11 08:08'; # UTC +my $VERSION = '2008-03-12 13:06'; # UTC # The definition above must lie within the first 8 lines in order # for the Emacs time-stamp write hook (at end) to update it. # If you change this file with Emacs, please let the write hook @@ -123,8 +123,8 @@ EOF { if ($line =~ /\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\) - (?: \s*$regexp\s*\(\s*\2\s*\)| - \s*\{\s*$regexp\s*\(\s*\2\s*\)\s*;\s*\}))/sx) + (?: \s*$regexp\s*\((?:\s*\([^)]+\))\s*\2\s*\)| + \s*\{\s*$regexp\s*\((?:\s*\([^)]+\))\s*\2\s*\)\s*;\s*\}))/sx) { $found_match = 1; $list diff --git a/gnulib/lib/Makefile.am b/gnulib/lib/Makefile.am index 9495cafd3d..0321687d9d 100644 --- a/gnulib/lib/Makefile.am +++ b/gnulib/lib/Makefile.am @@ -1,6 +1,6 @@ ## DO NOT EDIT! GENERATED AUTOMATICALLY! ## Process this file with automake to produce Makefile.in. -# Copyright (C) 2004-2007 Free Software Foundation, Inc. +# Copyright (C) 2002-2008 Free Software Foundation, Inc. # # This file is free software, distributed under the terms of the GNU # General Public License. As a special exception to the GNU General @@ -9,7 +9,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gnulib/lib --m4-base=gnulib/m4 --doc-base=doc --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=gl getaddrinfo getpass gettext physmem poll strndup strsep sys_stat useless-if-before-free vasprintf vc-list-files +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gnulib/lib --m4-base=gnulib/m4 --doc-base=doc --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=gl getaddrinfo getpass gettext mktempd physmem poll posix-shell strndup strsep sys_stat useless-if-before-free vasprintf vc-list-files AUTOMAKE_OPTIONS = 1.5 gnits @@ -35,15 +35,6 @@ libgnu_la_DEPENDENCIES = $(gl_LTLIBOBJS) EXTRA_libgnu_la_SOURCES = libgnu_la_LDFLAGS = $(AM_LDFLAGS) -## begin gnulib module absolute-header - -# Use this preprocessor expression to decide whether #include_next works. -# Do not rely on a 'configure'-time test for this, since the expression -# might appear in an installed header, which is used by some other compiler. -HAVE_INCLUDE_NEXT = (__GNUC__ || 60000000 <= __DECC_VER) - -## end gnulib module absolute-header - ## begin gnulib module alloca-opt BUILT_SOURCES += $(ALLOCA_H) @@ -208,6 +199,13 @@ EXTRA_libgnu_la_SOURCES += malloc.c ## end gnulib module malloc-posix +## begin gnulib module mktempd + + +EXTRA_DIST += $(top_srcdir)/build-aux/mktempd + +## end gnulib module mktempd + ## begin gnulib module netinet_in BUILT_SOURCES += $(NETINET_IN_H) @@ -259,6 +257,21 @@ EXTRA_libgnu_la_SOURCES += poll.c ## end gnulib module poll +## begin gnulib module posix-shell + +##Sample usage of posix-shell module: +#script: script.in +# rm -f $@-t $@ +# sed -e 's#@''PREFERABLY_POSIX_SHELL''@#$(PREFERABLY_POSIX_SHELL)#g' \ +# -e 's#@''POSIX_SHELL''@#$(POSIX_SHELL)#g' \ +# -e $(srcdir)/$@.in >$@-t +# chmod a+x $@-t +# mv $@-t $@ +#EXTRA_DIST += script.in +#MOSTLYCLEANFILES += script script-t + +## end gnulib module posix-shell + ## begin gnulib module realloc-posix @@ -669,6 +682,7 @@ unistd.h: unistd.in.h -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \ -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \ + -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \ -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \ -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ @@ -683,6 +697,7 @@ unistd.h: unistd.in.h -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ + -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ diff --git a/gnulib/lib/alloca.in.h b/gnulib/lib/alloca.in.h index 1c1d9e68ed..38b20c3973 100644 --- a/gnulib/lib/alloca.in.h +++ b/gnulib/lib/alloca.in.h @@ -1,6 +1,6 @@ /* Memory allocation on the stack. - Copyright (C) 1995, 1999, 2001-2004, 2006-2007 Free Software + Copyright (C) 1995, 1999, 2001-2004, 2006-2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -42,6 +42,8 @@ # elif defined _MSC_VER # include # define alloca _alloca +# elif defined __DECC && defined __VMS +# define alloca __ALLOCA # else # include # ifdef __cplusplus diff --git a/gnulib/lib/getaddrinfo.c b/gnulib/lib/getaddrinfo.c index ecf98cadf0..56fd700649 100644 --- a/gnulib/lib/getaddrinfo.c +++ b/gnulib/lib/getaddrinfo.c @@ -326,7 +326,7 @@ freeaddrinfo (struct addrinfo *ai) cur = ai; ai = ai->ai_next; - if (cur->ai_canonname) free (cur->ai_canonname); + free (cur->ai_canonname); free (cur); } } diff --git a/gnulib/lib/getdelim.c b/gnulib/lib/getdelim.c index f903dfc3b3..37cfdc101c 100644 --- a/gnulib/lib/getdelim.c +++ b/gnulib/lib/getdelim.c @@ -69,13 +69,15 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (*lineptr == NULL || *n == 0) { + char *new_lineptr; *n = 120; - *lineptr = (char *) realloc (*lineptr, *n); - if (*lineptr == NULL) + new_lineptr = (char *) realloc (*lineptr, *n); + if (new_lineptr == NULL) { result = -1; goto unlock_return; } + *lineptr = new_lineptr; } for (;;) diff --git a/gnulib/lib/unistd.in.h b/gnulib/lib/unistd.in.h index 10678f4c99..1021d4173c 100644 --- a/gnulib/lib/unistd.in.h +++ b/gnulib/lib/unistd.in.h @@ -1,5 +1,5 @@ /* Substitute for and wrapper around . - Copyright (C) 2004-2007 Free Software Foundation, Inc. + Copyright (C) 2004-2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -86,6 +86,26 @@ extern int dup2 (int oldfd, int newfd); #endif +#if @GNULIB_ENVIRON@ +# if !@HAVE_DECL_ENVIRON@ +/* Set of environment variables and values. An array of strings of the form + "VARIABLE=VALUE", terminated with a NULL. */ +# if defined __APPLE__ && defined __MACH__ +# include +# define environ (*_NSGetEnviron ()) +# else +extern char **environ; +# endif +# endif +#elif defined GNULIB_POSIXCHECK +# undef environ +# define environ \ + (GL_LINK_WARNING ("environ is unportable - " \ + "use gnulib module environ for portability"), \ + environ) +#endif + + #if @GNULIB_FCHDIR@ # if @REPLACE_FCHDIR@ diff --git a/gnulib/lib/xsize.h b/gnulib/lib/xsize.h index 5083859ad9..42db052f8f 100644 --- a/gnulib/lib/xsize.h +++ b/gnulib/lib/xsize.h @@ -1,6 +1,6 @@ /* xsize.h -- Checked size_t computations. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/gnulib/m4/absolute-header.m4 b/gnulib/m4/absolute-header.m4 deleted file mode 100644 index 5b7a2fc35f..0000000000 --- a/gnulib/m4/absolute-header.m4 +++ /dev/null @@ -1,49 +0,0 @@ -# absolute-header.m4 serial 7 -dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Derek Price. - -# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...) -# --------------------------------------- -# Find the absolute name of a header file, assuming the header exists. -# If the header were sys/inttypes.h, this macro would define -# ABSOLUTE_SYS_INTTYPES_H to the `""' quoted absolute name of sys/inttypes.h -# in config.h -# (e.g. `#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"'). -# The three "///" are to pacify Sun C 5.8, which otherwise would say -# "warning: #include of /usr/include/... may be non-portable". -# Use `""', not `<>', so that the /// cannot be confused with a C99 comment. -AC_DEFUN([gl_ABSOLUTE_HEADER], -[AC_LANG_PREPROC_REQUIRE()dnl -AC_FOREACH([gl_HEADER_NAME], [$1], - [AS_VAR_PUSHDEF([gl_absolute_header], - [gl_cv_absolute_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl - AC_CACHE_CHECK([absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>], - m4_quote(m4_defn([gl_absolute_header])), - [AS_VAR_PUSHDEF([ac_header_exists], - [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl - AC_CHECK_HEADERS_ONCE(m4_quote(m4_defn([gl_HEADER_NAME])))dnl - if test AS_VAR_GET(ac_header_exists) = yes; then - AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]])]) -dnl eval is necessary to expand ac_cpp. -dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell. - AS_VAR_SET(gl_absolute_header, -[`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | -sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{ - s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1# - s#^/[^/]#//&# - p - q -}'`]) - fi - AS_VAR_POPDEF([ac_header_exists])dnl - ])dnl - AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_quote(m4_defn([gl_HEADER_NAME]))), - ["AS_VAR_GET(gl_absolute_header)"], - [Define this to an absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>.]) - AS_VAR_POPDEF([gl_absolute_header])dnl -])dnl -])# gl_ABSOLUTE_HEADER diff --git a/gnulib/m4/fseeko.m4 b/gnulib/m4/fseeko.m4 index 40be63b4c2..3d77365688 100644 --- a/gnulib/m4/fseeko.m4 +++ b/gnulib/m4/fseeko.m4 @@ -1,5 +1,5 @@ -# fseeko.m4 serial 3 -dnl Copyright (C) 2007 Free Software Foundation, Inc. +# fseeko.m4 serial 4 +dnl Copyright (C) 2007-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -9,6 +9,10 @@ AC_DEFUN([gl_FUNC_FSEEKO], AC_REQUIRE([gl_STDIO_H_DEFAULTS]) AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([gl_STDIN_LARGE_OFFSET]) + + dnl Persuade glibc to declare fseeko(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + AC_CACHE_CHECK([for fseeko], [gl_cv_func_fseeko], [ AC_TRY_LINK([#include ], [fseeko (stdin, 0, 0);], diff --git a/gnulib/m4/gnulib-cache.m4 b/gnulib/m4/gnulib-cache.m4 index 50f743b519..d7498a8d69 100644 --- a/gnulib/m4/gnulib-cache.m4 +++ b/gnulib/m4/gnulib-cache.m4 @@ -1,4 +1,4 @@ -# Copyright (C) 2004-2007 Free Software Foundation, Inc. +# Copyright (C) 2002-2008 Free Software Foundation, Inc. # # This file is free software, distributed under the terms of the GNU # General Public License. As a special exception to the GNU General @@ -15,11 +15,11 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=gnulib/lib --m4-base=gnulib/m4 --doc-base=doc --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=gl getaddrinfo getpass gettext physmem poll strndup strsep sys_stat useless-if-before-free vasprintf vc-list-files +# gnulib-tool --import --dir=. --lib=libgnu --source-base=gnulib/lib --m4-base=gnulib/m4 --doc-base=doc --aux-dir=build-aux --with-tests --lgpl=2 --libtool --macro-prefix=gl getaddrinfo getpass gettext mktempd physmem poll posix-shell strndup strsep sys_stat useless-if-before-free vasprintf vc-list-files # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([]) -gl_MODULES([getaddrinfo getpass gettext physmem poll strndup strsep sys_stat useless-if-before-free vasprintf vc-list-files]) +gl_MODULES([getaddrinfo getpass gettext mktempd physmem poll posix-shell strndup strsep sys_stat useless-if-before-free vasprintf vc-list-files]) gl_AVOID([]) gl_SOURCE_BASE([gnulib/lib]) gl_M4_BASE([gnulib/m4]) diff --git a/gnulib/m4/gnulib-comp.m4 b/gnulib/m4/gnulib-comp.m4 index 0eeee9c218..465df3c40f 100644 --- a/gnulib/m4/gnulib-comp.m4 +++ b/gnulib/m4/gnulib-comp.m4 @@ -1,5 +1,5 @@ # DO NOT EDIT! GENERATED AUTOMATICALLY! -# Copyright (C) 2004-2007 Free Software Foundation, Inc. +# Copyright (C) 2002-2008 Free Software Foundation, Inc. # # This file is free software, distributed under the terms of the GNU # General Public License. As a special exception to the GNU General @@ -65,6 +65,7 @@ AC_DEFUN([gl_INIT], AC_PROG_MKDIR_P gl_PHYSMEM gl_FUNC_POLL + gl_POSIX_SHELL gl_FUNC_REALLOC_POSIX gl_STDLIB_MODULE_INDICATOR([realloc-posix]) gl_SIZE_MAX @@ -225,6 +226,7 @@ AC_DEFUN([gltests_LIBSOURCES], [ AC_DEFUN([gl_FILE_LIST], [ build-aux/config.rpath build-aux/link-warning.h + build-aux/mktempd build-aux/useless-if-before-free build-aux/vc-list-files lib/alloca.in.h @@ -278,7 +280,6 @@ AC_DEFUN([gl_FILE_LIST], [ lib/vasprintf.c lib/wchar.in.h lib/xsize.h - m4/absolute-header.m4 m4/alloca.m4 m4/arpa_inet_h.m4 m4/codeset.m4 @@ -319,6 +320,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/physmem.m4 m4/po.m4 m4/poll.m4 + m4/posix-shell.m4 m4/printf-posix.m4 m4/progtest.m4 m4/realloc.m4 diff --git a/gnulib/m4/include_next.m4 b/gnulib/m4/include_next.m4 index 7ce472bc0a..7c08e9319b 100644 --- a/gnulib/m4/include_next.m4 +++ b/gnulib/m4/include_next.m4 @@ -1,5 +1,5 @@ -# include_next.m4 serial 4 -dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. +# include_next.m4 serial 5 +dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -63,6 +63,9 @@ EOF # The three "///" are to pacify Sun C 5.8, which otherwise would say # "warning: #include of /usr/include/... may be non-portable". # Use `""', not `<>', so that the /// cannot be confused with a C99 comment. +# Note: This macro assumes that the header file is not empty after +# preprocessing, i.e. it does not only define preprocessor macros but also +# provides some type/enum definitions or function/variable declarations. AC_DEFUN([gl_CHECK_NEXT_HEADERS], [ AC_REQUIRE([gl_INCLUDE_NEXT]) diff --git a/gnulib/m4/lib-link.m4 b/gnulib/m4/lib-link.m4 index e3d26fc42d..1602895105 100644 --- a/gnulib/m4/lib-link.m4 +++ b/gnulib/m4/lib-link.m4 @@ -1,5 +1,5 @@ -# lib-link.m4 serial 13 (gettext-0.17) -dnl Copyright (C) 2001-2007 Free Software Foundation, Inc. +# lib-link.m4 serial 15 (gettext-0.18) +dnl Copyright (C) 2001-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -18,9 +18,9 @@ AC_DEFUN([AC_LIB_LINKFLAGS], [ AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) - define([Name],[translit([$1],[./-], [___])]) - define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + pushdef([Name],[translit([$1],[./-], [___])]) + pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ AC_LIB_LINKFLAGS_BODY([$1], [$2]) ac_cv_lib[]Name[]_libs="$LIB[]NAME" @@ -39,8 +39,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS], dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the dnl results of this search when this library appears as a dependency. HAVE_LIB[]NAME=yes - undefine([Name]) - undefine([NAME]) + popdef([NAME]) + popdef([Name]) ]) dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode) @@ -57,9 +57,9 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], [ AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) - define([Name],[translit([$1],[./-], [___])]) - define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + pushdef([Name],[translit([$1],[./-], [___])]) + pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME dnl accordingly. @@ -95,8 +95,8 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], AC_SUBST([LIB]NAME) AC_SUBST([LTLIB]NAME) AC_SUBST([LIB]NAME[_PREFIX]) - undefine([Name]) - undefine([NAME]) + popdef([NAME]) + popdef([Name]) ]) dnl Determine the platform dependent parameters needed to use rpath: @@ -136,6 +136,27 @@ AC_DEFUN([AC_LIB_RPATH], :, enable_rpath=yes) ]) +dnl AC_LIB_FROMPACKAGE(name, package) +dnl declares that libname comes from the given package. The configure file +dnl will then not have a --with-libname-prefix option but a +dnl --with-package-prefix option. Several libraries can come from the same +dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar +dnl macro call that searches for libname. +AC_DEFUN([AC_LIB_FROMPACKAGE], +[ + pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + define([acl_frompackage_]NAME, [$2]) + popdef([NAME]) + pushdef([PACK],[$2]) + pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + define([acl_libsinpackage_]PACKUP, + m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1]) + popdef([PACKUP]) + popdef([PACK]) +]) + dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and dnl the libraries corresponding to explicit and implicit dependencies. dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. @@ -144,19 +165,23 @@ dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. AC_DEFUN([AC_LIB_LINKFLAGS_BODY], [ AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) - define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], - [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])]) + pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) dnl Autoconf >= 2.61 supports dots in --with options. - define([N_A_M_E],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit([$1],[.],[_])],[$1])]) + pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit(PACK,[.],[_])],PACK)]) dnl By default, look in $includedir and $libdir. use_additional=yes AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" ]) - AC_LIB_ARG_WITH([lib]N_A_M_E[-prefix], -[ --with-lib]N_A_M_E[-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib - --without-lib]N_A_M_E[-prefix don't search for lib$1 in includedir and libdir], + AC_ARG_WITH(P_A_C_K[-prefix], +[[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib + --without-]]P_A_C_K[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]], [ if test "X$withval" = "Xno"; then use_additional=no @@ -609,6 +634,11 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" done fi + popdef([P_A_C_K]) + popdef([PACKLIBS]) + popdef([PACKUP]) + popdef([PACK]) + popdef([NAME]) ]) dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, diff --git a/gnulib/m4/posix-shell.m4 b/gnulib/m4/posix-shell.m4 new file mode 100644 index 0000000000..ac526d5c37 --- /dev/null +++ b/gnulib/m4/posix-shell.m4 @@ -0,0 +1,58 @@ +# Find a POSIX-conforming shell. + +# Copyright (C) 2007 Free Software Foundation, Inc. + +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Written by Paul Eggert. + +# If a POSIX-conforming shell can be found, set POSIX_SHELL and +# PREFERABLY_POSIX_SHELL to it. If not, set POSIX_SHELL to the +# empty string and PREFERABLY_POSIX_SHELL to '/bin/sh'. + +AC_DEFUN([gl_POSIX_SHELL], +[ + AC_CACHE_CHECK([for a shell that conforms to POSIX], [gl_cv_posix_shell], + [gl_test_POSIX_SHELL=' + func_return () { + (exit [$]1) + } + func_success () { + func_return 0 + } + func_failure () { + func_return 1 + } + func_ret_success () { + return 0 + } + func_ret_failure () { + return 1 + } + test "[$](echo foo)" = foo && + func_success && + ! func_failure && + func_ret_success && + ! func_ret_failure && + (set x && func_ret_success y && test x = "[$]1") + ' + for gl_cv_posix_shell in \ + "$CONFIG_SHELL" "$SHELL" /bin/sh /bin/bash /bin/ksh /bin/sh5 no; do + case $gl_cv_posix_shell in + /*) + "$gl_cv_posix_shell" -c "$gl_test_POSIX_shell" 2>/dev/null && break;; + esac + done]) + + if test "$gl_cv_posix_shell" != no; then + POSIX_SHELL=$gl_cv_posix_shell + PREFERABLY_POSIX_SHELL=$POSIX_SHELL + else + POSIX_SHELL= + PREFERABLY_POSIX_SHELL=/bin/sh + fi + AC_SUBST([POSIX_SHELL]) + AC_SUBST([PREFERABLY_POSIX_SHELL]) +]) diff --git a/gnulib/m4/unistd_h.m4 b/gnulib/m4/unistd_h.m4 index 4b8857ca5b..e8ccab16e8 100644 --- a/gnulib/m4/unistd_h.m4 +++ b/gnulib/m4/unistd_h.m4 @@ -1,5 +1,5 @@ -# unistd_h.m4 serial 10 -dnl Copyright (C) 2006-2007 Free Software Foundation, Inc. +# unistd_h.m4 serial 11 +dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -34,6 +34,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], [ GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN]) GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2]) + GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON]) GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR]) GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE]) GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) @@ -49,6 +50,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) + HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) diff --git a/gnulib/tests/Makefile.am b/gnulib/tests/Makefile.am index 4dae90d322..7dec1df362 100644 --- a/gnulib/tests/Makefile.am +++ b/gnulib/tests/Makefile.am @@ -1,6 +1,6 @@ ## DO NOT EDIT! GENERATED AUTOMATICALLY! ## Process this file with automake to produce Makefile.in. -# Copyright (C) 2004-2007 Free Software Foundation, Inc. +# Copyright (C) 2002-2008 Free Software Foundation, Inc. # # This file is free software, distributed under the terms of the GNU # General Public License. As a special exception to the GNU General diff --git a/tests/Makefile.am b/tests/Makefile.am index 4810179a77..901e88aaac 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,7 @@ ## Process this file with automake to produce Makefile.in +SHELL = $(PREFERABLY_POSIX_SHELL) + SUBDIRS = virshdata confdata sexpr2xmldata \ xml2sexprdata xmconfigdata xencapsdata @@ -31,6 +33,7 @@ LDADDS = \ $(COVERAGE_LDFLAGS) EXTRA_DIST = \ + test-lib.sh \ xmlrpcserver.py \ test_conf.sh \ qemuxml2argvdata \ @@ -42,7 +45,8 @@ noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \ test_scripts = \ daemon-conf \ - int-overflow + int-overflow \ + vcpupin EXTRA_DIST += $(test_scripts) @@ -62,6 +66,7 @@ TESTS_ENVIRONMENT = \ abs_top_builddir=`cd '$(top_builddir)'; pwd` \ abs_top_srcdir=`cd '$(top_srcdir)'; pwd` \ PATH="$(path_add)$(PATH_SEPARATOR)$$PATH" \ + SHELL="$(SHELL)" \ $(VG) valgrind: diff --git a/tests/test-lib.sh b/tests/test-lib.sh new file mode 100644 index 0000000000..cdbea5d963 --- /dev/null +++ b/tests/test-lib.sh @@ -0,0 +1,155 @@ +# source this file; set up for tests + +# Skip this test if the shell lacks support for functions. +unset function_test +eval 'function_test() { return 11; }; function_test' +if test $? != 11; then + echo "$0: /bin/sh lacks support for functions; skipping this test." 1>&2 + (exit 77); exit 77 +fi + +skip_test_() +{ + echo "$0: skipping test: $@" 1>&2 + (exit 77); exit 77 +} + +require_acl_() +{ + getfacl --version < /dev/null > /dev/null 2>&1 \ + && setfacl --version < /dev/null > /dev/null 2>&1 \ + || skip_test_ "This test requires getfacl and setfacl." + + id -u bin > /dev/null 2>&1 \ + || skip_test_ "This test requires a local user named bin." +} + +require_ulimit_() +{ + ulimit_works=yes + # Expect to be able to exec a program in 10MB of virtual memory, + # but not in 20KB. I chose "date". It must not be a shell built-in + # function, so you can't use echo, printf, true, etc. + # Of course, in coreutils, I could use $top_builddir/src/true, + # but this should be able to work for other projects, too. + ( ulimit -v 10000; date ) > /dev/null 2>&1 || ulimit_works=no + ( ulimit -v 20; date ) > /dev/null 2>&1 && ulimit_works=no + + test $ulimit_works = no \ + && skip_test_ "this shell lacks ulimit support" +} + +require_readable_root_() +{ + test -r / || skip_test_ "/ is not readable" +} + +# Skip the current test if strace is not available or doesn't work. +require_strace_() +{ + strace -V < /dev/null > /dev/null 2>&1 || + skip_test_ 'no strace program' + + strace -qe unlink echo > /dev/null 2>&1 || + skip_test_ 'strace does not work' +} + +require_built_() +{ + skip_=no + for i in "$@"; do + case " $built_programs " in + *" $i "*) ;; + *) echo "$i: not built" 1>&2; skip_=yes ;; + esac + done + + test $skip_ = yes && skip_test_ "required program(s) not built" +} + +uid_is_privileged_() +{ + # Make sure id -u succeeds. + my_uid=$(id -u) \ + || { echo "$0: cannot run \`id -u'" 1>&2; return 1; } + + # Make sure it gives valid output. + case $my_uid in + 0) ;; + *[!0-9]*) + echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2 + return 1 ;; + *) return 1 ;; + esac +} + +skip_if_() +{ + case $1 in + root) skip_test_ must be run as root ;; + non-root) skip_test_ must be run as non-root ;; + *) ;; # FIXME? + esac +} + +require_selinux_() +{ + case `ls -Zd .` in + '? .'|'unlabeled .') + skip_test_ "this system (or maybe just" \ + "the current file system) lacks SELinux support" + ;; + esac +} + +very_expensive_() +{ + if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then + skip_test_ ' +This test is very expensive, so it is disabled by default. +To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS +environment variable set to yes. E.g., + + env RUN_VERY_EXPENSIVE_TESTS=yes make check +' + fi +} + +require_root_() { uid_is_privileged_ || skip_test_ "must be run as root"; } +skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; } +error_() { echo "$0: $@" 1>&2; (exit 1); exit 1; } +framework_failure() { error_ 'failure in testing framework'; } + +test_dir_=$(pwd) + +this_test_() { echo "./$0" | sed 's,.*/,,'; } +this_test=$(this_test_) + +# This is a stub function that is run upon trap (upon regular exit and +# interrupt). Override it with a per-test function, e.g., to unmount +# a partition, or to undo any other global state changes. +cleanup_() { :; } + +mktempd="$abs_top_srcdir/build-aux/mktempd" +t_=$("$SHELL" "$mktempd" "$test_dir_" lv-$this_test.XXXXXXXXXX) \ + || error_ "failed to create temporary directory in $test_dir_" + +# Run each test from within a temporary sub-directory named after the +# test itself, and arrange to remove it upon exception or normal exit. +trap 'st=$?; cleanup_; d='"$t_"'; + cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +cd "$t_" || error_ "failed to cd to $t_" + +if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then + compare() { diff -u "$@"; } +elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then + compare() { cmp -s "$@"; } +else + compare() { cmp "$@"; } +fi + +# Local Variables: +# indent-tabs-mode: nil +# End: diff --git a/tests/vcpupin b/tests/vcpupin new file mode 100755 index 0000000000..b56c7f266a --- /dev/null +++ b/tests/vcpupin @@ -0,0 +1,37 @@ +#!/bin/sh +# ensure that an invalid CPU spec elicits a diagnostic + +# Copyright (C) 2008 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if test "$VERBOSE" = yes; then + set -x + virsh --version +fi + +. $srcdir/test-lib.sh + +fail=0 +virsh --connect test:///default vcpupin test a 0,1 > out 2>&1 +test $? = 1 || fail=1 + +cat <<\EOF > exp || fail=1 +error: vcpupin: Invalid or missing vCPU number. + +EOF + +compare out exp || fail=1 + +(exit $fail); exit $fail -- GitLab