From: Richard W.M. Jones Date: Tue, 2 Aug 2011 09:56:41 +0000 (+0100) Subject: Add regression test to catch missing libraries in the appliance. X-Git-Tag: 1.13.2~1 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=d7356a2801130907997acd5c7502e8417566e782 Add regression test to catch missing libraries in the appliance. Related to RHBZ#727178. --- diff --git a/daemon/debug.c b/daemon/debug.c index 0ade2a4..2ba48a7 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -51,9 +51,11 @@ struct cmd { }; static char *debug_help (const char *subcmd, int argc, char *const *const argv); +static char *debug_binaries (const char *subcmd, int argc, char *const *const argv); static char *debug_core_pattern (const char *subcmd, int argc, char *const *const argv); static char *debug_env (const char *subcmd, int argc, char *const *const argv); static char *debug_fds (const char *subcmd, int argc, char *const *const argv); +static char *debug_ldd (const char *subcmd, int argc, char *const *const argv); static char *debug_ls (const char *subcmd, int argc, char *const *const argv); static char *debug_ll (const char *subcmd, int argc, char *const *const argv); static char *debug_progress (const char *subcmd, int argc, char *const *const argv); @@ -63,9 +65,11 @@ static char *debug_sh (const char *subcmd, int argc, char *const *const argv); static struct cmd cmds[] = { { "help", debug_help }, + { "binaries", debug_binaries }, { "core_pattern", debug_core_pattern }, { "env", debug_env }, { "fds", debug_fds }, + { "ldd", debug_ldd }, { "ls", debug_ls }, { "ll", debug_ll }, { "progress", debug_progress }, @@ -276,6 +280,73 @@ debug_env (const char *subcmd, int argc, char *const *const argv) return out; } +/* Return binaries in the appliance. See regressions/rhbz727178.sh */ +static char * +debug_binaries (const char *subcmd, int argc, char *const *const argv) +{ + int r; + char *out, *err; + + const char cmd[] = + "find / -xdev -type f -executable " + "| xargs file -i " + "| grep application/x-executable " + "| gawk -F: '{print $1}'"; + + r = command (&out, &err, "sh", "-c", cmd, NULL); + if (r == -1) { + reply_with_error ("find: %s", err); + free (out); + free (err); + return NULL; + } + + free (err); + + return out; +} + +/* Run 'ldd' on a file from the appliance. See regressions/rhbz727178.sh */ +static char * +debug_ldd (const char *subcmd, int argc, char *const *const argv) +{ + int r; + char *out, *err, *ret; + + if (argc != 1) { + reply_with_error ("ldd: no file argument"); + return NULL; + } + + /* Note that 'ldd' doesn't fail if it finds errors. We have to grep + * for errors in the regression test instead. 'ldd' only fails here + * if the binary is not a binary at all (eg. for shell scripts). + * Also 'ldd' randomly sends messages to stderr and errors to stdout + * depending on the phase of the moon. + */ + r = command (&out, &err, "ldd", "-r", argv[0], NULL); + if (r == -1) { + reply_with_error ("ldd: %s: %s", argv[0], err); + free (out); + free (err); + return NULL; + } + + /* Concatenate stdout and stderr in the result. */ + ret = realloc (out, strlen (out) + strlen (err) + 1); + if (ret == NULL) { + reply_with_perror ("realloc"); + free (out); + free (err); + return NULL; + } + + strcat (ret, err); + free (err); + + return ret; +} + /* List files in the appliance. */ static char * debug_ls (const char *subcmd, int argc, char *const *const argv) diff --git a/regressions/rhbz727178.sh b/regressions/rhbz727178.sh new file mode 100755 index 0000000..859a60b --- /dev/null +++ b/regressions/rhbz727178.sh @@ -0,0 +1,49 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2011 Red Hat 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 2 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, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# https://bugzilla.redhat.com/show_bug.cgi?id=727178 +# Check that all binaries that we ship in the appliance contain +# corresponding libraries. + +set -e +export LANG=C + +guestfish=../fish/guestfish +output=rhbz727178.output + +rm -f binaries.tmp $output + +eval `$guestfish -a /dev/null --listen` + +$guestfish --remote -- run +$guestfish --remote -- debug binaries "" | + grep -E '^/(bin|sbin|usr/bin|usr/sbin|usr/libexec)/' > binaries.tmp + +while read ex; do + echo ldd $ex + $guestfish --remote -- -debug ldd $ex +done < binaries.tmp > $output + +if grep -E '\bnot found\b|undefined symbol' $output; then + echo "Error: some libraries are missing from the appliance." + echo "See" $(pwd)/$output + echo "for the complete output." + exit 1 +fi + +rm binaries.tmp $output