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 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"
26 static void test_io_channel_command_fifo(bool async
)
28 #define TEST_FIFO "tests/test-io-channel-command.fifo"
29 QIOChannel
*src
, *dst
;
31 char *srcfifo
= g_strdup_printf("PIPE:%s,wronly", TEST_FIFO
);
32 char *dstfifo
= g_strdup_printf("PIPE:%s,rdonly", TEST_FIFO
);
33 const char *srcargv
[] = {
34 "/bin/socat", "-", srcfifo
, NULL
,
36 const char *dstargv
[] = {
37 "/bin/socat", dstfifo
, "-", NULL
,
41 if (access("/bin/socat", X_OK
) < 0) {
42 return; /* Pretend success if socat is not present */
44 if (mkfifo(TEST_FIFO
, 0600) < 0) {
47 src
= QIO_CHANNEL(qio_channel_command_new_spawn(srcargv
,
50 dst
= QIO_CHANNEL(qio_channel_command_new_spawn(dstargv
,
54 test
= qio_channel_test_new();
55 qio_channel_test_run_threads(test
, async
, src
, dst
);
56 qio_channel_test_validate(test
);
58 object_unref(OBJECT(src
));
59 object_unref(OBJECT(dst
));
67 static void test_io_channel_command_fifo_async(void)
69 test_io_channel_command_fifo(true);
72 static void test_io_channel_command_fifo_sync(void)
74 test_io_channel_command_fifo(false);
78 static void test_io_channel_command_echo(bool async
)
82 const char *socatargv
[] = {
83 "/bin/socat", "-", "-", NULL
,
86 if (access("/bin/socat", X_OK
) < 0) {
87 return; /* Pretend success if socat is not present */
90 ioc
= QIO_CHANNEL(qio_channel_command_new_spawn(socatargv
,
93 test
= qio_channel_test_new();
94 qio_channel_test_run_threads(test
, async
, ioc
, ioc
);
95 qio_channel_test_validate(test
);
97 object_unref(OBJECT(ioc
));
101 static void test_io_channel_command_echo_async(void)
103 test_io_channel_command_echo(true);
106 static void test_io_channel_command_echo_sync(void)
108 test_io_channel_command_echo(false);
112 int main(int argc
, char **argv
)
114 module_call_init(MODULE_INIT_QOM
);
116 g_test_init(&argc
, &argv
, NULL
);
119 g_test_add_func("/io/channel/command/fifo/sync",
120 test_io_channel_command_fifo_sync
);
121 g_test_add_func("/io/channel/command/fifo/async",
122 test_io_channel_command_fifo_async
);
123 g_test_add_func("/io/channel/command/echo/sync",
124 test_io_channel_command_echo_sync
);
125 g_test_add_func("/io/channel/command/echo/async",
126 test_io_channel_command_echo_async
);