test-block-backend.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * BlockBackend tests
  3. *
  4. * Copyright (c) 2017 Kevin Wolf <kwolf@redhat.com>
  5. *
  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:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  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.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "block/block.h"
  26. #include "sysemu/block-backend.h"
  27. #include "qapi/error.h"
  28. #include "qemu/main-loop.h"
  29. static void test_drain_aio_error_flush_cb(void *opaque, int ret)
  30. {
  31. bool *completed = opaque;
  32. g_assert(ret == -ENOMEDIUM);
  33. *completed = true;
  34. }
  35. static void test_drain_aio_error(void)
  36. {
  37. BlockBackend *blk = blk_new(qemu_get_aio_context(),
  38. BLK_PERM_ALL, BLK_PERM_ALL);
  39. BlockAIOCB *acb;
  40. bool completed = false;
  41. acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
  42. g_assert(acb != NULL);
  43. g_assert(completed == false);
  44. blk_drain(blk);
  45. g_assert(completed == true);
  46. blk_unref(blk);
  47. }
  48. static void test_drain_all_aio_error(void)
  49. {
  50. BlockBackend *blk = blk_new(qemu_get_aio_context(),
  51. BLK_PERM_ALL, BLK_PERM_ALL);
  52. BlockAIOCB *acb;
  53. bool completed = false;
  54. acb = blk_aio_flush(blk, test_drain_aio_error_flush_cb, &completed);
  55. g_assert(acb != NULL);
  56. g_assert(completed == false);
  57. blk_drain_all();
  58. g_assert(completed == true);
  59. blk_unref(blk);
  60. }
  61. int main(int argc, char **argv)
  62. {
  63. bdrv_init();
  64. qemu_init_main_loop(&error_abort);
  65. g_test_init(&argc, &argv, NULL);
  66. g_test_add_func("/block-backend/drain_aio_error", test_drain_aio_error);
  67. g_test_add_func("/block-backend/drain_all_aio_error",
  68. test_drain_all_aio_error);
  69. return g_test_run();
  70. }