]> Git Repo - qemu.git/blob - tests/test-io-channel-file.c
Merge remote-tracking branch 'remotes/sstabellini/tags/xen-2015-12-22' into staging
[qemu.git] / tests / test-io-channel-file.c
1 /*
2  * QEMU I/O channel file test
3  *
4  * Copyright (c) 2015 Red Hat, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  */
20
21 #include "io/channel-file.h"
22 #include "io-channel-helpers.h"
23
24
25 static void test_io_channel_file(void)
26 {
27     QIOChannel *src, *dst;
28     QIOChannelTest *test;
29
30 #define TEST_FILE "tests/test-io-channel-file.txt"
31     unlink(TEST_FILE);
32     src = QIO_CHANNEL(qio_channel_file_new_path(
33                           TEST_FILE,
34                           O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600,
35                           &error_abort));
36     dst = QIO_CHANNEL(qio_channel_file_new_path(
37                           TEST_FILE,
38                           O_RDONLY | O_BINARY, 0,
39                           &error_abort));
40
41     test = qio_channel_test_new();
42     qio_channel_test_run_writer(test, src);
43     qio_channel_test_run_reader(test, dst);
44     qio_channel_test_validate(test);
45
46     unlink(TEST_FILE);
47     object_unref(OBJECT(src));
48     object_unref(OBJECT(dst));
49 }
50
51
52 #ifndef _WIN32
53 static void test_io_channel_pipe(bool async)
54 {
55     QIOChannel *src, *dst;
56     QIOChannelTest *test;
57     int fd[2];
58
59     if (pipe(fd) < 0) {
60         perror("pipe");
61         abort();
62     }
63
64     src = QIO_CHANNEL(qio_channel_file_new_fd(fd[1]));
65     dst = QIO_CHANNEL(qio_channel_file_new_fd(fd[0]));
66
67     test = qio_channel_test_new();
68     qio_channel_test_run_threads(test, async, src, dst);
69     qio_channel_test_validate(test);
70
71     object_unref(OBJECT(src));
72     object_unref(OBJECT(dst));
73 }
74
75
76 static void test_io_channel_pipe_async(void)
77 {
78     test_io_channel_pipe(true);
79 }
80
81 static void test_io_channel_pipe_sync(void)
82 {
83     test_io_channel_pipe(false);
84 }
85 #endif /* ! _WIN32 */
86
87
88 int main(int argc, char **argv)
89 {
90     module_call_init(MODULE_INIT_QOM);
91
92     g_test_init(&argc, &argv, NULL);
93
94     g_test_add_func("/io/channel/file", test_io_channel_file);
95 #ifndef _WIN32
96     g_test_add_func("/io/channel/pipe/sync", test_io_channel_pipe_sync);
97     g_test_add_func("/io/channel/pipe/async", test_io_channel_pipe_async);
98 #endif
99     return g_test_run();
100 }
This page took 0.026218 seconds and 4 git commands to generate.