diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2021-02-18 11:16:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-18 11:16:37 +0000 |
commit | 22a80ef616beaf7ac495698a4219f37efe5635c8 (patch) | |
tree | 5ea58cbaa0123adf48add07aee5b09b26ede0d56 /test/mocks.c | |
parent | 0243c6dd892f5ac0ed9c195034a67d2f1f08cec6 (diff) | |
download | libvfio-user-22a80ef616beaf7ac495698a4219f37efe5635c8.zip libvfio-user-22a80ef616beaf7ac495698a4219f37efe5635c8.tar.gz libvfio-user-22a80ef616beaf7ac495698a4219f37efe5635c8.tar.bz2 |
unit test exec_command and friends w.r.t. migration device state (#346)
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'test/mocks.c')
-rw-r--r-- | test/mocks.c | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/test/mocks.c b/test/mocks.c index 80545e6..363e9ca 100644 --- a/test/mocks.c +++ b/test/mocks.c @@ -86,12 +86,12 @@ __wrap__dma_controller_do_remove_region(dma_controller_t *dma, } bool -__wrap_device_is_stopped(struct migration *migr) +__wrap_device_is_stopped(struct migration *migration) { if (!is_patched(device_is_stopped)) { - return __real_device_is_stopped(migr); + return __real_device_is_stopped(migration); } - check_expected(migr); + check_expected(migration); return mock(); } @@ -195,6 +195,47 @@ int __wrap_listen(int sockfd __attribute__((unused)), return 0; } +bool +__wrap_device_is_stopped_and_copying(struct migration *migration) +{ + if (!is_patched(device_is_stopped_and_copying)) { + return __real_device_is_stopped_and_copying(migration); + } + check_expected(migration); + return mock(); +} + +bool +__wrap_cmd_allowed_when_stopped_and_copying(uint16_t cmd) +{ + if (!is_patched(cmd_allowed_when_stopped_and_copying)) { + return __real_cmd_allowed_when_stopped_and_copying(cmd); + } + check_expected(cmd); + return mock(); +} + +bool +__wrap_cmd_allowed_when_stopped(struct migration *migration) +{ + if (!is_patched(device_is_stopped)) { + return __real_device_is_stopped(migration); + } + check_expected(migration); + return mock(); +} + +bool +__wrap_should_exec_command(vfu_ctx_t *vfu_ctx, uint16_t cmd) +{ + if (!is_patched(should_exec_command)) { + return __real_should_exec_command(vfu_ctx, cmd); + } + check_expected(vfu_ctx); + check_expected(cmd); + return mock(); +} + int __wrap_handle_dirty_pages(vfu_ctx_t *vfu_ctx, uint32_t size, struct iovec **iovecs, size_t *nr_iovecs, @@ -226,6 +267,10 @@ static struct function funcs[] = { {.addr = &__wrap_process_request}, {.addr = &__wrap_bind}, {.addr = &__wrap_listen}, + {.addr = &__wrap_device_is_stopped_and_copying}, + {.addr = &__wrap_cmd_allowed_when_stopped_and_copying}, + {.addr = &__wrap_device_is_stopped}, + {.addr = &__wrap_should_exec_command}, {.addr = &__wrap_handle_dirty_pages}, }; |