Merge remote-tracking branch 'remotes/stsquad/tags/pull-testing-and-python-021020...
[qemu/ar7.git] / tests / test-block-backend.c
blob2fb1a444bd4879f9f8c10917a728ae819107e184
1 /*
2 * BlockBackend tests
4 * Copyright (c) 2017 Kevin Wolf <kwolf@redhat.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include "qemu/osdep.h"
26 #include "block/block.h"
27 #include "sysemu/block-backend.h"
28 #include "qapi/error.h"
29 #include "qemu/main-loop.h"
31 static void test_drain_aio_error_flush_cb(void *opaque, int ret)
33 bool *completed = opaque;
35 g_assert(ret == -ENOMEDIUM);
36 *completed = true;
39 static void test_drain_aio_error(void)
41 BlockBackend *blk = blk_new(qemu_get_aio_context(),
42 BLK_PERM_ALL, BLK_PERM_ALL);
43 BlockAIOCB *acb;
44 bool completed = false;
46 acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
47 g_assert(acb != NULL);
48 g_assert(completed == false);
50 blk_drain(blk);
51 g_assert(completed == true);
53 blk_unref(blk);
56 static void test_drain_all_aio_error(void)
58 BlockBackend *blk = blk_new(qemu_get_aio_context(),
59 BLK_PERM_ALL, BLK_PERM_ALL);
60 BlockAIOCB *acb;
61 bool completed = false;
63 acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
64 g_assert(acb != NULL);
65 g_assert(completed == false);
67 blk_drain_all();
68 g_assert(completed == true);
70 blk_unref(blk);
73 int main(int argc, char **argv)
75 bdrv_init();
76 qemu_init_main_loop(&error_abort);
78 g_test_init(&argc, &argv, NULL);
80 g_test_add_func("/block-backend/drain_aio_error", test_drain_aio_error);
81 g_test_add_func("/block-backend/drain_all_aio_error",
82 test_drain_all_aio_error);
84 return g_test_run();