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#include "qemu/main-loop.h"
30
31static void test_drain_aio_error_flush_cb(void *opaque, int ret)
32{
33 bool *completed = opaque;
34
35 g_assert(ret == -ENOMEDIUM);
36 *completed = true;
37}
38
39static void test_drain_aio_error(void)
40{
41 BlockBackend *blk = blk_new(qemu_get_aio_context(),
42 BLK_PERM_ALL, BLK_PERM_ALL);
43 BlockAIOCB *acb;
44 bool completed = false;
45
46 acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
47 g_assert(acb != NULL);
48 g_assert(completed == false);
49
50 blk_drain(blk);
51 g_assert(completed == true);
52
53 blk_unref(blk);
54}
55
56static void test_drain_all_aio_error(void)
57{
58 BlockBackend *blk = blk_new(qemu_get_aio_context(),
59 BLK_PERM_ALL, BLK_PERM_ALL);
60 BlockAIOCB *acb;
61 bool completed = false;
62
63 acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
64 g_assert(acb != NULL);
65 g_assert(completed == false);
66
67 blk_drain_all();
68 g_assert(completed == true);
69
70 blk_unref(blk);
71}
72
73int main(int argc, char **argv)
74{
75 bdrv_init();
76 qemu_init_main_loop(&error_abort);
77
78 g_test_init(&argc, &argv, NULL);
79
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);
83
84 return g_test_run();
85}
86