diff options
author | William Henderson <william.henderson@nutanix.com> | 2023-07-27 15:06:49 +0000 |
---|---|---|
committer | John Levon <john.levon@nutanix.com> | 2023-09-15 13:06:15 +0100 |
commit | fb1930ad81b0f357edc45677e97ed74ea4ca606d (patch) | |
tree | 61f3e8c44f3a4a556e18937abd178d32da605110 | |
parent | cd39e772fd1991c16b7b7ba201172c66fb28701f (diff) | |
download | libvfio-user-fb1930ad81b0f357edc45677e97ed74ea4ca606d.zip libvfio-user-fb1930ad81b0f357edc45677e97ed74ea4ca606d.tar.gz libvfio-user-fb1930ad81b0f357edc45677e97ed74ea4ca606d.tar.bz2 |
test: add migration state sequence test
Signed-off-by: William Henderson <william.henderson@nutanix.com>
-rw-r--r-- | test/py/meson.build | 1 | ||||
-rw-r--r-- | test/py/test_migration.py | 33 | ||||
-rw-r--r-- | test/unit-tests.c | 38 |
3 files changed, 37 insertions, 35 deletions
diff --git a/test/py/meson.build b/test/py/meson.build index 4b3e533..c98f4a7 100644 --- a/test/py/meson.build +++ b/test/py/meson.build @@ -36,7 +36,6 @@ python_tests = [ 'test_dma_map.py', 'test_dma_unmap.py', 'test_irq_trigger.py', - 'test_migration.py', 'test_negotiate.py', 'test_pci_caps.py', 'test_pci_ext_caps.py', diff --git a/test/py/test_migration.py b/test/py/test_migration.py deleted file mode 100644 index d8eaf86..0000000 --- a/test/py/test_migration.py +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (c) 2021 Nutanix Inc. All rights reserved. -# -# Authors: Thanos Makatos <thanos@nutanix.com> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of Nutanix nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -# DAMAGE. -# - -# TODO: this - -def test_migration(): - pass diff --git a/test/unit-tests.c b/test/unit-tests.c index 852016e..aafb15a 100644 --- a/test/unit-tests.c +++ b/test/unit-tests.c @@ -462,13 +462,19 @@ test_migration_state_transitions(void **state UNUSED) } } +static vfu_migr_state_t LAST_STATE = -1; +static int transition_callback(vfu_ctx_t *ctx UNUSED, vfu_migr_state_t state) { + LAST_STATE = state; + return 0; +} + static struct test_setup_migr_reg_dat { vfu_ctx_t *v; const vfu_migration_callbacks_t c; } migr_reg_data = { .c = { .version = VFU_MIGR_CALLBACKS_VERS, - .transition = (void *)0x1, + .transition = transition_callback, .read_data = (void *)0x2, .write_data = (void *)0x3 } @@ -505,6 +511,33 @@ test_setup_migration_callbacks(void **state) } static void +test_migration_state_sequence(void **state) +{ + test_setup_migration_callbacks(state); + + struct test_setup_migr_reg_dat *p = *state; + struct migration *migr = p->v->migration; + + int r; + + r = handle_device_state(p->v, migr, VFIO_DEVICE_STATE_PRE_COPY, true); + assert_int_equal(0, r); + assert_int_equal(LAST_STATE, VFU_MIGR_STATE_PRE_COPY); + + r = handle_device_state(p->v, migr, VFIO_DEVICE_STATE_STOP_COPY, true); + assert_int_equal(0, r); + assert_int_equal(LAST_STATE, VFU_MIGR_STATE_STOP_AND_COPY); + + r = handle_device_state(p->v, migr, VFIO_DEVICE_STATE_STOP, true); + assert_int_equal(0, r); + assert_int_equal(LAST_STATE, VFU_MIGR_STATE_STOP); + + r = handle_device_state(p->v, migr, VFIO_DEVICE_STATE_RUNNING, true); + assert_int_equal(0, r); + assert_int_equal(LAST_STATE, VFU_MIGR_STATE_RUNNING); +} + +static void test_device_is_stopped_and_copying(UNUSED void **state) { assert_false(device_is_stopped_and_copying(vfu_ctx.migration)); @@ -609,6 +642,9 @@ main(void) cmocka_unit_test_setup_teardown(test_setup_migration_callbacks, setup_test_setup_migration, teardown_test_setup_migration), + cmocka_unit_test_setup_teardown(test_migration_state_sequence, + setup_test_setup_migration, + teardown_test_setup_migration), cmocka_unit_test_setup(test_device_is_stopped_and_copying, setup), cmocka_unit_test_setup(test_cmd_allowed_when_stopped_and_copying, setup), cmocka_unit_test_setup(test_should_exec_command, setup), |