2 * QEMU I/O channel command test
4 * Copyright (c) 2015 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "io/channel-command.h"
23 #include "io-channel-helpers.h"
24 #include "qapi/error.h"
25 #include "qemu/module.h"
27 #define TEST_FIFO "test-io-channel-command.fifo"
29 #define SOCAT_SRC "PIPE:" TEST_FIFO ",wronly"
30 #define SOCAT_DST "PIPE:" TEST_FIFO ",rdonly"
32 static char *socat
= NULL
;
34 static void test_io_channel_command_fifo(bool async
)
36 QIOChannel
*src
, *dst
;
38 const char *srcargv
[] = {
39 socat
, "-", SOCAT_SRC
, NULL
,
41 const char *dstargv
[] = {
42 socat
, SOCAT_DST
, "-", NULL
,
46 g_test_skip("socat is not found in PATH");
51 src
= QIO_CHANNEL(qio_channel_command_new_spawn(srcargv
,
54 dst
= QIO_CHANNEL(qio_channel_command_new_spawn(dstargv
,
58 test
= qio_channel_test_new();
59 qio_channel_test_run_threads(test
, async
, src
, dst
);
60 qio_channel_test_validate(test
);
62 object_unref(OBJECT(src
));
63 object_unref(OBJECT(dst
));
69 static void test_io_channel_command_fifo_async(void)
71 test_io_channel_command_fifo(true);
74 static void test_io_channel_command_fifo_sync(void)
76 test_io_channel_command_fifo(false);
80 static void test_io_channel_command_echo(bool async
)
84 const char *socatargv
[] = {
85 socat
, "-", "-", NULL
,
89 g_test_skip("socat is not found in PATH");
93 ioc
= QIO_CHANNEL(qio_channel_command_new_spawn(socatargv
,
96 test
= qio_channel_test_new();
97 qio_channel_test_run_threads(test
, async
, ioc
, ioc
);
98 qio_channel_test_validate(test
);
100 object_unref(OBJECT(ioc
));
104 static void test_io_channel_command_echo_async(void)
106 test_io_channel_command_echo(true);
109 static void test_io_channel_command_echo_sync(void)
111 test_io_channel_command_echo(false);
114 int main(int argc
, char **argv
)
116 module_call_init(MODULE_INIT_QOM
);
118 g_test_init(&argc
, &argv
, NULL
);
120 socat
= g_find_program_in_path("socat");
122 g_test_add_func("/io/channel/command/fifo/sync",
123 test_io_channel_command_fifo_sync
);
124 g_test_add_func("/io/channel/command/fifo/async",
125 test_io_channel_command_fifo_async
);
126 g_test_add_func("/io/channel/command/echo/sync",
127 test_io_channel_command_echo_sync
);
128 g_test_add_func("/io/channel/command/echo/async",
129 test_io_channel_command_echo_async
);