diff options
author | Jim Meyering <meyering@redhat.com> | 2008-03-24 10:19:36 +0000 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2008-03-24 10:19:36 +0000 |
commit | f15efcdf27f5f596e3e82a7cbc134c95092b0831 (patch) | |
tree | 24fe0b38bd9a535c83098a4c1431c47c4d8d6e03 /build-aux | |
parent | Fix bugs in tests/Makefile.am. (diff) | |
download | libvirt-f15efcdf27f5f596e3e82a7cbc134c95092b0831.tar.gz libvirt-f15efcdf27f5f596e3e82a7cbc134c95092b0831.tar.bz2 libvirt-f15efcdf27f5f596e3e82a7cbc134c95092b0831.zip |
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.
Diffstat (limited to 'build-aux')
-rw-r--r-- | build-aux/.cvsignore | 1 | ||||
-rwxr-xr-x | build-aux/mktempd | 132 | ||||
-rwxr-xr-x | build-aux/useless-if-before-free | 6 |
3 files changed, 136 insertions, 3 deletions
diff --git a/build-aux/.cvsignore b/build-aux/.cvsignore index 1798f40d3..096cccbf5 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 000000000..7ac914b31 --- /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 <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 "$@" diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free index eb1848378..626d19ab2 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 |