]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add new testing framework and the first test to use it.
authorJim Meyering <meyering@redhat.com>
Mon, 24 Mar 2008 10:19:36 +0000 (10:19 +0000)
committerJim Meyering <meyering@redhat.com>
Mon, 24 Mar 2008 10:19:36 +0000 (10:19 +0000)
* 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.

23 files changed:
ChangeLog
bootstrap
build-aux/.cvsignore
build-aux/mktempd [new file with mode: 0755]
build-aux/useless-if-before-free
gnulib/lib/Makefile.am
gnulib/lib/alloca.in.h
gnulib/lib/getaddrinfo.c
gnulib/lib/getdelim.c
gnulib/lib/unistd.in.h
gnulib/lib/xsize.h
gnulib/m4/absolute-header.m4 [deleted file]
gnulib/m4/fseeko.m4
gnulib/m4/gnulib-cache.m4
gnulib/m4/gnulib-comp.m4
gnulib/m4/include_next.m4
gnulib/m4/lib-link.m4
gnulib/m4/posix-shell.m4 [new file with mode: 0644]
gnulib/m4/unistd_h.m4
gnulib/tests/Makefile.am
tests/Makefile.am
tests/test-lib.sh [new file with mode: 0644]
tests/vcpupin [new file with mode: 0755]

index 40128198f7c77f40c19c5a5e0b2453b6ef33d08e..a1ed1bb17c3b87b2ff86b37229dd22891a2b7e90 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 Mon Mar 24 11:16:58 CET 2008 Jim Meyering <meyering@redhat.com>
 
+       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.
index d8b79d9390ac5e3bc102ea88ec3659c347d0a902..f7b6aec96894e084ce7e7db91a2e6ae0efd9d673 100755 (executable)
--- 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                          \
index 1798f40d35bf0c1b4727aaf4f8082f46be3a5cf5..096cccbf59876e7dcd5e314ee12fa39f172f389c 100644 (file)
@@ -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 (executable)
index 0000000..7ac914b
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+# 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 "$@"
index eb18483789b538ac4363627b2f3ab1350f69efa5..626d19ab2b57763c1ce6e56c015778cebae33ef3 100755 (executable)
@@ -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
index 9495cafd3da23bad447449764b9a131a55a28a57..0321687d9dc08f272e74bce13e71d1afcc52a48d 100644 (file)
@@ -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' \
index 1c1d9e68ed32ca752a435a986d321f48bef06d1f..38b20c3973dc6050198ed106048ff04e86e1292e 100644 (file)
@@ -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 <malloc.h>
 #  define alloca _alloca
+# elif defined __DECC && defined __VMS
+#  define alloca __ALLOCA
 # else
 #  include <stddef.h>
 #  ifdef  __cplusplus
index ecf98cadf0be0e271ad8e58504d1fe83a738de1f..56fd700649ffcb5f2a10a7de3c6a687ac791b69f 100644 (file)
@@ -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);
     }
 }
index f903dfc3b3f9d5c81bbaca820c85d821e53b1df6..37cfdc101c108efa39245d60beee85d6209f2c66 100644 (file)
@@ -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 (;;)
index 10678f4c997049e31577b69e63251e7c7ef73ffe..1021d4173c6b02e21768513d35592795cd2d886c 100644 (file)
@@ -1,5 +1,5 @@
 /* Substitute for and wrapper around <unistd.h>.
-   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 <crt_externs.h>
+#   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@
 
index 5083859ad997c1d0236938238e0cd8faee492796..42db052f8fe3fb6e382e62506b577af6efb0bd20 100644 (file)
@@ -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 (file)
index 5b7a2fc..0000000
+++ /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
index 40be63b4c2e490c7929c466d09067056166e5946..3d773656886d4f9811ee80be0fe07a37f347a9c9 100644 (file)
@@ -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 <stdio.h> to declare fseeko().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
   AC_CACHE_CHECK([for fseeko], [gl_cv_func_fseeko],
     [
       AC_TRY_LINK([#include <stdio.h>], [fseeko (stdin, 0, 0);],
index 50f743b51937f46dd49f91ffd421e8324ac8b2ef..d7498a8d69ac7961a5cb11ab657fe44c0d62ceb6 100644 (file)
@@ -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
 
 
 # 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])
index 0eeee9c2181f96ac52b459e9bca96073a8797b44..465df3c40f90ea19044389ca5e400afb461def62 100644 (file)
@@ -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
index 7ce472bc0a0b9b9d7a4c4c9ccca8b8a680e07eca..7c08e9319bf83cdb3ca6ee3b16ad679fc292fe3f 100644 (file)
@@ -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])
index e3d26fc42dc0687fb3000d67df040d7fa64df1a5..16028951051a3f018fb40ba76efb3dad998692a5 100644 (file)
@@ -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 (file)
index 0000000..ac526d5
--- /dev/null
@@ -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])
+])
index 4b8857ca5bba04f307e39ac3fec537b3855f336c..e8ccab16e837659cb30099432991a810bd7698cf 100644 (file)
@@ -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])
index 4dae90d32284b61a2690a9d492421e006a607d06..7dec1df362122b19f913e993feac2dd9f46bad35 100644 (file)
@@ -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
index 4810179a773504d2a2402f067a41c3f160ed530f..901e88aaacdd4861f01d336fbe18668c0f3bf370 100644 (file)
@@ -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 (file)
index 0000000..cdbea5d
--- /dev/null
@@ -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 (executable)
index 0000000..b56c7f2
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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