mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-19 22:21:27 +00:00
virshtest: Adapt 'virsh-read-bufsiz' and 'virsh-read-non-seekable'
Test both situations (reading from non-regular file and reading a file larger than (arbitrary) buffer size) via 'virshtest'. To feed the pipe we need to create a thread that does it, but otherwise it's fairly straightforward. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
60cc7bd1c0
commit
3ace963662
@ -691,8 +691,6 @@ if conf.has('WITH_LIBVIRTD')
|
|||||||
'libvirtd-fail',
|
'libvirtd-fail',
|
||||||
'libvirtd-pool',
|
'libvirtd-pool',
|
||||||
'virsh-auth',
|
'virsh-auth',
|
||||||
'virsh-read-bufsiz',
|
|
||||||
'virsh-read-non-seekable',
|
|
||||||
'virsh-self-test',
|
'virsh-self-test',
|
||||||
'virsh-uriprecedence',
|
'virsh-uriprecedence',
|
||||||
'virt-admin-self-test',
|
'virt-admin-self-test',
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# ensure that reading a file larger than BUFSIZ works
|
|
||||||
|
|
||||||
# Copyright (C) 2008, 2010 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, see
|
|
||||||
# <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
. "$(dirname $0)/test-lib.sh"
|
|
||||||
|
|
||||||
if test "$VERBOSE" = yes; then
|
|
||||||
set -x
|
|
||||||
$abs_top_builddir/tools/virsh --version
|
|
||||||
fi
|
|
||||||
|
|
||||||
fail=0
|
|
||||||
|
|
||||||
# Output a valid definition, to be used as input.
|
|
||||||
$abs_top_builddir/tools/virsh -c test:///default dumpxml 1 > xml.t || fail=1
|
|
||||||
|
|
||||||
# Change the VM name and UUID
|
|
||||||
sed -e "s|<name>test</name>|<name>newtest</name>|g" \
|
|
||||||
-e "\|<uuid>.*</uuid>|d" \
|
|
||||||
xml.t > xml
|
|
||||||
|
|
||||||
for i in before after; do
|
|
||||||
# The largest BUFSIZ I've seen is 128K. This is slightly larger.
|
|
||||||
printf %132000s ' ' > sp || fail=1
|
|
||||||
in=in-$i
|
|
||||||
# Append or prepend enough spaces to push the size over the limit:
|
|
||||||
( test $i = before && cat sp xml || cat xml sp ) > $in || fail=1
|
|
||||||
|
|
||||||
$abs_top_builddir/tools/virsh --connect test:///default define $in > out || fail=1
|
|
||||||
printf "Domain 'newtest' defined from $in\n\n" > exp || fail=1
|
|
||||||
compare exp out || fail=1
|
|
||||||
done
|
|
||||||
|
|
||||||
(exit $fail); exit $fail
|
|
@ -1,51 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# ensure that certain file-reading commands can handle non-seekable files
|
|
||||||
|
|
||||||
# Copyright (C) 2008 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, see
|
|
||||||
# <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
. "$(dirname $0)/test-lib.sh"
|
|
||||||
|
|
||||||
if test "$VERBOSE" = yes; then
|
|
||||||
set -x
|
|
||||||
$abs_top_builddir/tools/virsh --version
|
|
||||||
fi
|
|
||||||
|
|
||||||
fail=0
|
|
||||||
|
|
||||||
cat <<\EOF > dom
|
|
||||||
<domain type='test' id='2'>
|
|
||||||
<name>t2</name>
|
|
||||||
<uuid>004b96e1-2d78-c30f-5aa5-000000000000</uuid>
|
|
||||||
<memory>8388608</memory>
|
|
||||||
<vcpu>2</vcpu>
|
|
||||||
<os>
|
|
||||||
<type>xen</type>
|
|
||||||
</os>
|
|
||||||
<on_reboot>restart</on_reboot>
|
|
||||||
<on_poweroff>destroy</on_poweroff>
|
|
||||||
<on_crash>restart</on_crash>
|
|
||||||
</domain>
|
|
||||||
EOF
|
|
||||||
|
|
||||||
$abs_top_builddir/tools/virsh -c test:///default define dom > /dev/null || fail=1
|
|
||||||
|
|
||||||
mkfifo_or_skip_ fifo
|
|
||||||
cat dom > fifo &
|
|
||||||
|
|
||||||
$abs_top_builddir/tools/virsh -c test:///default define fifo > /dev/null || fail=1
|
|
||||||
|
|
||||||
(exit $fail); exit $fail
|
|
@ -1,11 +1,14 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
#include "vircommand.h"
|
#include "vircommand.h"
|
||||||
|
|
||||||
|
#include "util/virthread.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -103,6 +106,90 @@ static int testCompare(const void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
testPipeFeeder(void *opaque)
|
||||||
|
{
|
||||||
|
/* feed more than observed buffer size which was historically 128k in the
|
||||||
|
* test this was adapted from */
|
||||||
|
size_t emptyspace = 140 * 1024;
|
||||||
|
const char *pipepath = opaque;
|
||||||
|
const char *xml =
|
||||||
|
"<domain type='test' id='2'>\n"
|
||||||
|
" <name>t2</name>\n"
|
||||||
|
" <uuid>004b96e1-2d78-c30f-5aa5-000000000000</uuid>\n"
|
||||||
|
" <memory>8388608</memory>\n"
|
||||||
|
" <vcpu>2</vcpu>\n"
|
||||||
|
" <os>\n"
|
||||||
|
" <type>xen</type>\n"
|
||||||
|
" </os>\n"
|
||||||
|
"</domain>\n";
|
||||||
|
size_t xmlsize = strlen(xml);
|
||||||
|
g_autofree char *doc = g_new0(char, emptyspace + xmlsize + 1);
|
||||||
|
VIR_AUTOCLOSE fd = -1;
|
||||||
|
|
||||||
|
if ((fd = open(pipepath, O_RDWR)) < 0) {
|
||||||
|
fprintf(stderr, "\nfailed to open pipe '%s': %s\n", pipepath, g_strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(doc, ' ', emptyspace);
|
||||||
|
virStrcpy(doc + emptyspace, xml, xmlsize);
|
||||||
|
|
||||||
|
if (safewrite(fd, doc, emptyspace + xmlsize + 1) < 0) {
|
||||||
|
fprintf(stderr, "\nfailed to write to pipe '%s': %s\n", pipepath, g_strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testVirshPipe(const void *data G_GNUC_UNUSED)
|
||||||
|
{
|
||||||
|
char tmpdir[] = "/tmp/libvirt_virshtest_XXXXXXX";
|
||||||
|
g_autofree char *pipepath = NULL;
|
||||||
|
virThread feeder;
|
||||||
|
bool join = false;
|
||||||
|
g_autofree char *cmdstr = NULL;
|
||||||
|
const char *argv[] = { VIRSH_DEFAULT, NULL, NULL };
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!g_mkdtemp(tmpdir)) {
|
||||||
|
fprintf(stderr, "\nfailed to create temporary directory\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pipepath = g_strdup_printf("%s/pipe", tmpdir);
|
||||||
|
|
||||||
|
|
||||||
|
cmdstr = g_strdup_printf("define %s ; list --all", pipepath);
|
||||||
|
argv[3] = cmdstr;
|
||||||
|
|
||||||
|
if (mkfifo(pipepath, 0600) < 0) {
|
||||||
|
fprintf(stderr, "\nfailed to create pipe '%s': %s\n", pipepath, g_strerror(errno));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virThreadCreate(&feeder, true, testPipeFeeder, pipepath) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
join = true;
|
||||||
|
|
||||||
|
if (testCompareOutputLit(abs_srcdir "/virshtestdata/read-big-pipe.out",
|
||||||
|
"/tmp/libvirt_virshtest", argv) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (join)
|
||||||
|
virThreadJoin(&feeder);
|
||||||
|
unlink(pipepath);
|
||||||
|
rmdir(tmpdir);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
@ -238,6 +325,9 @@ mymain(void)
|
|||||||
"checkpoint-create test --redefine checkpoint-c2.xml ;"
|
"checkpoint-create test --redefine checkpoint-c2.xml ;"
|
||||||
"checkpoint-info test c2");
|
"checkpoint-info test c2");
|
||||||
|
|
||||||
|
if (virTestRun("read-big-pipe", testVirshPipe, NULL) < 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
VIR_FREE(custom_uri);
|
VIR_FREE(custom_uri);
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
7
tests/virshtestdata/read-big-pipe.out
Normal file
7
tests/virshtestdata/read-big-pipe.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Domain 't2' defined from
|
||||||
|
|
||||||
|
Id Name State
|
||||||
|
-----------------------
|
||||||
|
1 test running
|
||||||
|
- t2 shut off
|
||||||
|
|
Loading…
Reference in New Issue
Block a user