2 * QEMU I/O channel file 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-file.h"
23 #include "io/channel-util.h"
24 #include "io-channel-helpers.h"
27 static void test_io_channel_file(void)
29 QIOChannel
*src
, *dst
;
32 #define TEST_FILE "tests/test-io-channel-file.txt"
34 src
= QIO_CHANNEL(qio_channel_file_new_path(
36 O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, 0600,
38 dst
= QIO_CHANNEL(qio_channel_file_new_path(
40 O_RDONLY
| O_BINARY
, 0,
43 test
= qio_channel_test_new();
44 qio_channel_test_run_writer(test
, src
);
45 qio_channel_test_run_reader(test
, dst
);
46 qio_channel_test_validate(test
);
49 object_unref(OBJECT(src
));
50 object_unref(OBJECT(dst
));
54 static void test_io_channel_fd(void)
59 #define TEST_FILE "tests/test-io-channel-file.txt"
60 fd
= open(TEST_FILE
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
61 g_assert_cmpint(fd
, >, -1);
63 ioc
= qio_channel_new_fd(fd
, &error_abort
);
65 g_assert_cmpstr(object_get_typename(OBJECT(ioc
)),
67 TYPE_QIO_CHANNEL_FILE
);
70 object_unref(OBJECT(ioc
));
75 static void test_io_channel_pipe(bool async
)
77 QIOChannel
*src
, *dst
;
86 src
= QIO_CHANNEL(qio_channel_file_new_fd(fd
[1]));
87 dst
= QIO_CHANNEL(qio_channel_file_new_fd(fd
[0]));
89 test
= qio_channel_test_new();
90 qio_channel_test_run_threads(test
, async
, src
, dst
);
91 qio_channel_test_validate(test
);
93 object_unref(OBJECT(src
));
94 object_unref(OBJECT(dst
));
98 static void test_io_channel_pipe_async(void)
100 test_io_channel_pipe(true);
103 static void test_io_channel_pipe_sync(void)
105 test_io_channel_pipe(false);
107 #endif /* ! _WIN32 */
110 int main(int argc
, char **argv
)
112 module_call_init(MODULE_INIT_QOM
);
114 g_test_init(&argc
, &argv
, NULL
);
116 g_test_add_func("/io/channel/file", test_io_channel_file
);
117 g_test_add_func("/io/channel/file/fd", test_io_channel_fd
);
119 g_test_add_func("/io/channel/pipe/sync", test_io_channel_pipe_sync
);
120 g_test_add_func("/io/channel/pipe/async", test_io_channel_pipe_async
);