mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
tests: commandtest: use g_autofree
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
ad8d52909c
commit
363dd1b5e5
@ -58,10 +58,10 @@ extern char **environ;
|
|||||||
static int checkoutput(const char *testname)
|
static int checkoutput(const char *testname)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *expectname = NULL;
|
g_autofree char *expectname = NULL;
|
||||||
char *expectlog = NULL;
|
g_autofree char *expectlog = NULL;
|
||||||
char *actualname = NULL;
|
g_autofree char *actualname = NULL;
|
||||||
char *actuallog = NULL;
|
g_autofree char *actuallog = NULL;
|
||||||
|
|
||||||
expectname = g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, testname);
|
expectname = g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, testname);
|
||||||
actualname = g_strdup_printf("%s/commandhelper.log", abs_builddir);
|
actualname = g_strdup_printf("%s/commandhelper.log", abs_builddir);
|
||||||
@ -86,10 +86,6 @@ static int checkoutput(const char *testname)
|
|||||||
cleanup:
|
cleanup:
|
||||||
if (actualname)
|
if (actualname)
|
||||||
unlink(actualname);
|
unlink(actualname);
|
||||||
VIR_FREE(actuallog);
|
|
||||||
VIR_FREE(actualname);
|
|
||||||
VIR_FREE(expectlog);
|
|
||||||
VIR_FREE(expectname);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +243,7 @@ static int test4(const void *unused G_GNUC_UNUSED)
|
|||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNewArgList(abs_builddir "/commandhelper",
|
virCommandPtr cmd = virCommandNewArgList(abs_builddir "/commandhelper",
|
||||||
"--check-daemonize", NULL);
|
"--check-daemonize", NULL);
|
||||||
char *pidfile = virPidFileBuildPath(abs_builddir, "commandhelper");
|
g_autofree char *pidfile = virPidFileBuildPath(abs_builddir, "commandhelper");
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -275,7 +271,6 @@ static int test4(const void *unused G_GNUC_UNUSED)
|
|||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
if (pidfile)
|
if (pidfile)
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
VIR_FREE(pidfile);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,7 +479,7 @@ static int test12(const void *unused G_GNUC_UNUSED)
|
|||||||
static int test13(const void *unused G_GNUC_UNUSED)
|
static int test13(const void *unused G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
||||||
char *outactual = NULL;
|
g_autofree char *outactual = NULL;
|
||||||
const char *outexpect = "BEGIN STDOUT\n"
|
const char *outexpect = "BEGIN STDOUT\n"
|
||||||
"Hello World\n"
|
"Hello World\n"
|
||||||
"END STDOUT\n";
|
"END STDOUT\n";
|
||||||
@ -512,7 +507,6 @@ static int test13(const void *unused G_GNUC_UNUSED)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(outactual);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,16 +517,16 @@ static int test13(const void *unused G_GNUC_UNUSED)
|
|||||||
static int test14(const void *unused G_GNUC_UNUSED)
|
static int test14(const void *unused G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
||||||
char *outactual = NULL;
|
g_autofree char *outactual = NULL;
|
||||||
const char *outexpect = "BEGIN STDOUT\n"
|
const char *outexpect = "BEGIN STDOUT\n"
|
||||||
"Hello World\n"
|
"Hello World\n"
|
||||||
"END STDOUT\n";
|
"END STDOUT\n";
|
||||||
char *erractual = NULL;
|
g_autofree char *erractual = NULL;
|
||||||
const char *errexpect = "BEGIN STDERR\n"
|
const char *errexpect = "BEGIN STDERR\n"
|
||||||
"Hello World\n"
|
"Hello World\n"
|
||||||
"END STDERR\n";
|
"END STDERR\n";
|
||||||
|
|
||||||
char *jointactual = NULL;
|
g_autofree char *jointactual = NULL;
|
||||||
const char *jointexpect = "BEGIN STDOUT\n"
|
const char *jointexpect = "BEGIN STDOUT\n"
|
||||||
"BEGIN STDERR\n"
|
"BEGIN STDERR\n"
|
||||||
"Hello World\n"
|
"Hello World\n"
|
||||||
@ -582,9 +576,6 @@ static int test14(const void *unused G_GNUC_UNUSED)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(outactual);
|
|
||||||
VIR_FREE(erractual);
|
|
||||||
VIR_FREE(jointactual);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,7 +587,7 @@ static int test14(const void *unused G_GNUC_UNUSED)
|
|||||||
static int test15(const void *unused G_GNUC_UNUSED)
|
static int test15(const void *unused G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
||||||
char *cwd = NULL;
|
g_autofree char *cwd = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
cwd = g_strdup_printf("%s/commanddata", abs_srcdir);
|
cwd = g_strdup_printf("%s/commanddata", abs_srcdir);
|
||||||
@ -611,7 +602,6 @@ static int test15(const void *unused G_GNUC_UNUSED)
|
|||||||
ret = checkoutput("test15");
|
ret = checkoutput("test15");
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(cwd);
|
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -623,7 +613,7 @@ static int test15(const void *unused G_GNUC_UNUSED)
|
|||||||
static int test16(const void *unused G_GNUC_UNUSED)
|
static int test16(const void *unused G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNew("true");
|
virCommandPtr cmd = virCommandNew("true");
|
||||||
char *outactual = NULL;
|
g_autofree char *outactual = NULL;
|
||||||
const char *outexpect = "A=B C='D E' true F 'G H'";
|
const char *outexpect = "A=B C='D E' true F 'G H'";
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
@ -658,7 +648,6 @@ static int test16(const void *unused G_GNUC_UNUSED)
|
|||||||
cleanup:
|
cleanup:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
VIR_FREE(outactual);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,8 +658,8 @@ static int test17(const void *unused G_GNUC_UNUSED)
|
|||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNew("true");
|
virCommandPtr cmd = virCommandNew("true");
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *outbuf;
|
char *outbuf = NULL;
|
||||||
char *errbuf = NULL;
|
g_autofree char *errbuf = NULL;
|
||||||
|
|
||||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||||
if (outbuf != NULL) {
|
if (outbuf != NULL) {
|
||||||
@ -711,7 +700,6 @@ static int test17(const void *unused G_GNUC_UNUSED)
|
|||||||
cleanup:
|
cleanup:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(outbuf);
|
VIR_FREE(outbuf);
|
||||||
VIR_FREE(errbuf);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -721,7 +709,7 @@ static int test17(const void *unused G_GNUC_UNUSED)
|
|||||||
static int test18(const void *unused G_GNUC_UNUSED)
|
static int test18(const void *unused G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNewArgList("sleep", "100", NULL);
|
virCommandPtr cmd = virCommandNewArgList("sleep", "100", NULL);
|
||||||
char *pidfile = virPidFileBuildPath(abs_builddir, "commandhelper");
|
g_autofree char *pidfile = virPidFileBuildPath(abs_builddir, "commandhelper");
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -759,7 +747,6 @@ static int test18(const void *unused G_GNUC_UNUSED)
|
|||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
if (pidfile)
|
if (pidfile)
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
VIR_FREE(pidfile);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,7 +794,7 @@ static int test20(const void *unused G_GNUC_UNUSED)
|
|||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNewArgList(abs_builddir "/commandhelper",
|
virCommandPtr cmd = virCommandNewArgList(abs_builddir "/commandhelper",
|
||||||
"--close-stdin", NULL);
|
"--close-stdin", NULL);
|
||||||
char *buf;
|
g_autofree char *buf = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
struct sigaction sig_action;
|
struct sigaction sig_action;
|
||||||
@ -829,7 +816,6 @@ static int test20(const void *unused G_GNUC_UNUSED)
|
|||||||
ret = checkoutput("test20");
|
ret = checkoutput("test20");
|
||||||
cleanup:
|
cleanup:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(buf);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,7 +836,8 @@ static int test21(const void *unused G_GNUC_UNUSED)
|
|||||||
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char *wrbuf = "Hello world\n";
|
const char *wrbuf = "Hello world\n";
|
||||||
char *outbuf = NULL, *errbuf = NULL;
|
g_autofree char *outbuf = NULL;
|
||||||
|
g_autofree char *errbuf = NULL;
|
||||||
const char *outbufExpected = "BEGIN STDOUT\n"
|
const char *outbufExpected = "BEGIN STDOUT\n"
|
||||||
"Hello world\n"
|
"Hello world\n"
|
||||||
"END STDOUT\n";
|
"END STDOUT\n";
|
||||||
@ -886,8 +873,6 @@ static int test21(const void *unused G_GNUC_UNUSED)
|
|||||||
|
|
||||||
ret = checkoutput("test21");
|
ret = checkoutput("test21");
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(outbuf);
|
|
||||||
VIR_FREE(errbuf);
|
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1006,7 +991,7 @@ static int test25(const void *unused G_GNUC_UNUSED)
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
ssize_t tries = 100;
|
ssize_t tries = 100;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
gid_t *groups = NULL;
|
g_autofree gid_t *groups = NULL;
|
||||||
int ngroups;
|
int ngroups;
|
||||||
virCommandPtr cmd = virCommandNew("some/nonexistent/binary");
|
virCommandPtr cmd = virCommandNew("some/nonexistent/binary");
|
||||||
|
|
||||||
@ -1068,7 +1053,6 @@ static int test25(const void *unused G_GNUC_UNUSED)
|
|||||||
cleanup:
|
cleanup:
|
||||||
VIR_FORCE_CLOSE(pipeFD[0]);
|
VIR_FORCE_CLOSE(pipeFD[0]);
|
||||||
VIR_FORCE_CLOSE(pipeFD[1]);
|
VIR_FORCE_CLOSE(pipeFD[1]);
|
||||||
VIR_FREE(groups);
|
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1080,7 +1064,7 @@ static int test25(const void *unused G_GNUC_UNUSED)
|
|||||||
static int test26(const void *unused G_GNUC_UNUSED)
|
static int test26(const void *unused G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = virCommandNew("true");
|
virCommandPtr cmd = virCommandNew("true");
|
||||||
char *outactual = NULL;
|
g_autofree char *outactual = NULL;
|
||||||
const char *outexpect =
|
const char *outexpect =
|
||||||
"A=B \\\n"
|
"A=B \\\n"
|
||||||
"C='D E' \\\n"
|
"C='D E' \\\n"
|
||||||
@ -1131,7 +1115,6 @@ static int test26(const void *unused G_GNUC_UNUSED)
|
|||||||
cleanup:
|
cleanup:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
VIR_FREE(outactual);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1142,16 +1125,16 @@ static int test27(const void *unused G_GNUC_UNUSED)
|
|||||||
int pipe2[2];
|
int pipe2[2];
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t buflen = 1024 * 128;
|
size_t buflen = 1024 * 128;
|
||||||
char *buffer0 = NULL;
|
g_autofree char *buffer0 = NULL;
|
||||||
char *buffer1 = NULL;
|
g_autofree char *buffer1 = NULL;
|
||||||
char *buffer2 = NULL;
|
g_autofree char *buffer2 = NULL;
|
||||||
char *outactual = NULL;
|
g_autofree char *outactual = NULL;
|
||||||
char *erractual = NULL;
|
g_autofree char *erractual = NULL;
|
||||||
char *outexpect = NULL;
|
g_autofree char *outexpect = NULL;
|
||||||
# define TEST27_OUTEXPECT_TEMP "BEGIN STDOUT\n" \
|
# define TEST27_OUTEXPECT_TEMP "BEGIN STDOUT\n" \
|
||||||
"%s%s%s" \
|
"%s%s%s" \
|
||||||
"END STDOUT\n"
|
"END STDOUT\n"
|
||||||
char *errexpect = NULL;
|
g_autofree char *errexpect = NULL;
|
||||||
# define TEST27_ERREXPECT_TEMP "BEGIN STDERR\n" \
|
# define TEST27_ERREXPECT_TEMP "BEGIN STDERR\n" \
|
||||||
"%s%s%s" \
|
"%s%s%s" \
|
||||||
"END STDERR\n"
|
"END STDERR\n"
|
||||||
@ -1235,13 +1218,6 @@ static int test27(const void *unused G_GNUC_UNUSED)
|
|||||||
VIR_FORCE_CLOSE(pipe2[0]);
|
VIR_FORCE_CLOSE(pipe2[0]);
|
||||||
VIR_FORCE_CLOSE(pipe1[1]);
|
VIR_FORCE_CLOSE(pipe1[1]);
|
||||||
VIR_FORCE_CLOSE(pipe2[1]);
|
VIR_FORCE_CLOSE(pipe2[1]);
|
||||||
VIR_FREE(buffer0);
|
|
||||||
VIR_FREE(buffer1);
|
|
||||||
VIR_FREE(buffer2);
|
|
||||||
VIR_FREE(outactual);
|
|
||||||
VIR_FREE(erractual);
|
|
||||||
VIR_FREE(outexpect);
|
|
||||||
VIR_FREE(errexpect);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user