tests/unit: make test-io-channel-command work on win32
This has been tested under msys2 & windows 11. I haven't tried to make it work with other environments yet, but that should be enough to validate the channel-command implementation anyway. Here are the changes: - drop tests/ from fifo/pipe path, to avoid directory issues - use g_find_program() to lookup the socat executable (otherwise we would need to change ChanneCommand to use G_SPAWN_SEARCH_PATH, and deal with missing socat differently) - skip the "echo" test when socat is missing as well Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20221006113657.2656108-7-marcandre.lureau@redhat.com>
This commit is contained in:
parent
ec5b6c9c5d
commit
76f5148c21
@ -24,29 +24,30 @@
|
|||||||
#include "qapi/error.h"
|
#include "qapi/error.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
|
|
||||||
#ifndef WIN32
|
#define TEST_FIFO "test-io-channel-command.fifo"
|
||||||
|
|
||||||
|
#define SOCAT_SRC "PIPE:" TEST_FIFO ",wronly"
|
||||||
|
#define SOCAT_DST "PIPE:" TEST_FIFO ",rdonly"
|
||||||
|
|
||||||
|
static char *socat = NULL;
|
||||||
|
|
||||||
static void test_io_channel_command_fifo(bool async)
|
static void test_io_channel_command_fifo(bool async)
|
||||||
{
|
{
|
||||||
#define TEST_FIFO "tests/test-io-channel-command.fifo"
|
|
||||||
QIOChannel *src, *dst;
|
QIOChannel *src, *dst;
|
||||||
QIOChannelTest *test;
|
QIOChannelTest *test;
|
||||||
const char *srcfifo = "PIPE:" TEST_FIFO ",wronly";
|
|
||||||
const char *dstfifo = "PIPE:" TEST_FIFO ",rdonly";
|
|
||||||
const char *srcargv[] = {
|
const char *srcargv[] = {
|
||||||
"/bin/socat", "-", srcfifo, NULL,
|
socat, "-", SOCAT_SRC, NULL,
|
||||||
};
|
};
|
||||||
const char *dstargv[] = {
|
const char *dstargv[] = {
|
||||||
"/bin/socat", dstfifo, "-", NULL,
|
socat, SOCAT_DST, "-", NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
unlink(TEST_FIFO);
|
if (!socat) {
|
||||||
if (access("/bin/socat", X_OK) < 0) {
|
g_test_skip("socat is not found in PATH");
|
||||||
g_test_skip("socat is missing");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mkfifo(TEST_FIFO, 0600) < 0) {
|
|
||||||
abort();
|
unlink(TEST_FIFO);
|
||||||
}
|
|
||||||
src = QIO_CHANNEL(qio_channel_command_new_spawn(srcargv,
|
src = QIO_CHANNEL(qio_channel_command_new_spawn(srcargv,
|
||||||
O_WRONLY,
|
O_WRONLY,
|
||||||
&error_abort));
|
&error_abort));
|
||||||
@ -81,11 +82,12 @@ static void test_io_channel_command_echo(bool async)
|
|||||||
QIOChannel *ioc;
|
QIOChannel *ioc;
|
||||||
QIOChannelTest *test;
|
QIOChannelTest *test;
|
||||||
const char *socatargv[] = {
|
const char *socatargv[] = {
|
||||||
"/bin/socat", "-", "-", NULL,
|
socat, "-", "-", NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (access("/bin/socat", X_OK) < 0) {
|
if (!socat) {
|
||||||
return; /* Pretend success if socat is not present */
|
g_test_skip("socat is not found in PATH");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ioc = QIO_CHANNEL(qio_channel_command_new_spawn(socatargv,
|
ioc = QIO_CHANNEL(qio_channel_command_new_spawn(socatargv,
|
||||||
@ -108,7 +110,6 @@ static void test_io_channel_command_echo_sync(void)
|
|||||||
{
|
{
|
||||||
test_io_channel_command_echo(false);
|
test_io_channel_command_echo(false);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -116,7 +117,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
|
||||||
#ifndef WIN32
|
socat = g_find_program_in_path("socat");
|
||||||
|
|
||||||
g_test_add_func("/io/channel/command/fifo/sync",
|
g_test_add_func("/io/channel/command/fifo/sync",
|
||||||
test_io_channel_command_fifo_sync);
|
test_io_channel_command_fifo_sync);
|
||||||
g_test_add_func("/io/channel/command/fifo/async",
|
g_test_add_func("/io/channel/command/fifo/async",
|
||||||
@ -125,7 +127,6 @@ int main(int argc, char **argv)
|
|||||||
test_io_channel_command_echo_sync);
|
test_io_channel_command_echo_sync);
|
||||||
g_test_add_func("/io/channel/command/echo/async",
|
g_test_add_func("/io/channel/command/echo/async",
|
||||||
test_io_channel_command_echo_async);
|
test_io_channel_command_echo_async);
|
||||||
#endif
|
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user