1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26#include "block/block.h"
27#include "sysemu/block-backend.h"
28#include "qapi/error.h"
29
30static void test_drain_aio_error_flush_cb(void *opaque, int ret)
31{
32 bool *completed = opaque;
33
34 g_assert(ret == -ENOMEDIUM);
35 *completed = true;
36}
37
38static void test_drain_aio_error(void)
39{
40 BlockBackend *blk = blk_new(qemu_get_aio_context(),
41 BLK_PERM_ALL, BLK_PERM_ALL);
42 BlockAIOCB *acb;
43 bool completed = false;
44
45 acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
46 g_assert(acb != NULL);
47 g_assert(completed == false);
48
49 blk_drain(blk);
50 g_assert(completed == true);
51
52 blk_unref(blk);
53}
54
55static void test_drain_all_aio_error(void)
56{
57 BlockBackend *blk = blk_new(qemu_get_aio_context(),
58 BLK_PERM_ALL, BLK_PERM_ALL);
59 BlockAIOCB *acb;
60 bool completed = false;
61
62 acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
63 g_assert(acb != NULL);
64 g_assert(completed == false);
65
66 blk_drain_all();
67 g_assert(completed == true);
68
69 blk_unref(blk);
70}
71
72int main(int argc, char **argv)
73{
74 bdrv_init();
75 qemu_init_main_loop(&error_abort);
76
77 g_test_init(&argc, &argv, NULL);
78
79 g_test_add_func("/block-backend/drain_aio_error", test_drain_aio_error);
80 g_test_add_func("/block-backend/drain_all_aio_error",
81 test_drain_all_aio_error);
82
83 return g_test_run();
84}
85