Skip to content

Commit

Permalink
fix: conflict with kernel definitions in tests
Browse files Browse the repository at this point in the history
Signed-off-by: William Henderson <[email protected]>
  • Loading branch information
w-henderson committed Aug 2, 2023
1 parent 23761bf commit cc0b0e1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 58 deletions.
3 changes: 2 additions & 1 deletion test/mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ handle_device_state(vfu_ctx_t *vfu_ctx, struct migration *migr,
}

void
migr_state_transition(struct migration *migr, enum vfio_device_mig_state state)
migr_state_transition(struct migration *migr,
enum vfio_user_device_mig_state state)
{
if (!is_patched("migr_state_transition")) {
__real_migr_state_transition(migr, state);
Expand Down
6 changes: 0 additions & 6 deletions test/py/libvfio_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@

VFIO_DMA_UNMAP_FLAG_ALL = (1 << 1)

VFIO_DEVICE_STATE_V1_STOP = (0)
VFIO_DEVICE_STATE_V1_RUNNING = (1 << 0)
VFIO_DEVICE_STATE_V1_SAVING = (1 << 1)
VFIO_DEVICE_STATE_V1_RESUMING = (1 << 2)
VFIO_DEVICE_STATE_MASK = ((1 << 3) - 1)


# libvfio-user defines

Expand Down
102 changes: 51 additions & 51 deletions test/unit-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,59 +406,59 @@ test_migration_state_transitions(void **state UNUSED)

/* from ERROR: all transitions are invalid */
for (i = 0; i < 8; i++) {
assert_false(f(VFIO_DEVICE_STATE_ERROR, i));
assert_false(f(VFIO_USER_DEVICE_STATE_ERROR, i));
}

/* from STOP */
assert_false(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_ERROR));
assert_false(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_STOP));
assert_true(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_RUNNING));
assert_true(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_STOP_COPY));
assert_true(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_RESUMING));
assert_false(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_RUNNING_P2P));
assert_false(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_PRE_COPY));
assert_false(f(VFIO_DEVICE_STATE_STOP, VFIO_DEVICE_STATE_PRE_COPY_P2P));
assert_false(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_ERROR));
assert_false(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_STOP));
assert_true(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_RUNNING));
assert_true(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_STOP_COPY));
assert_true(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_RESUMING));
assert_false(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_RUNNING_P2P));
assert_false(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_PRE_COPY));
assert_false(f(VFIO_USER_DEVICE_STATE_STOP, VFIO_USER_DEVICE_STATE_PRE_COPY_P2P));

/* from RUNNING */
assert_false(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_ERROR));
assert_true(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_STOP));
assert_false(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_RUNNING));
assert_false(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_STOP_COPY));
assert_false(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_RESUMING));
assert_false(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_RUNNING_P2P));
assert_true(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_PRE_COPY));
assert_false(f(VFIO_DEVICE_STATE_RUNNING, VFIO_DEVICE_STATE_PRE_COPY_P2P));
assert_false(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_ERROR));
assert_true(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_STOP));
assert_false(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_RUNNING));
assert_false(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_STOP_COPY));
assert_false(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_RESUMING));
assert_false(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_RUNNING_P2P));
assert_true(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_PRE_COPY));
assert_false(f(VFIO_USER_DEVICE_STATE_RUNNING, VFIO_USER_DEVICE_STATE_PRE_COPY_P2P));

/* from STOP_COPY and RESUMING */
for (i = 3; i < 5; i++) {
assert_false(f(i, VFIO_DEVICE_STATE_ERROR));
assert_true(f(i, VFIO_DEVICE_STATE_STOP));
assert_false(f(i, VFIO_DEVICE_STATE_RUNNING));
assert_false(f(i, VFIO_DEVICE_STATE_STOP_COPY));
assert_false(f(i, VFIO_DEVICE_STATE_RESUMING));
assert_false(f(i, VFIO_DEVICE_STATE_RUNNING_P2P));
assert_false(f(i, VFIO_DEVICE_STATE_PRE_COPY));
assert_false(f(i, VFIO_DEVICE_STATE_PRE_COPY_P2P));
assert_false(f(i, VFIO_USER_DEVICE_STATE_ERROR));
assert_true(f(i, VFIO_USER_DEVICE_STATE_STOP));
assert_false(f(i, VFIO_USER_DEVICE_STATE_RUNNING));
assert_false(f(i, VFIO_USER_DEVICE_STATE_STOP_COPY));
assert_false(f(i, VFIO_USER_DEVICE_STATE_RESUMING));
assert_false(f(i, VFIO_USER_DEVICE_STATE_RUNNING_P2P));
assert_false(f(i, VFIO_USER_DEVICE_STATE_PRE_COPY));
assert_false(f(i, VFIO_USER_DEVICE_STATE_PRE_COPY_P2P));
}

/* from RUNNING_P2P: all transitions are invalid */
for (i = 0; i < 8; i++) {
assert_false(f(VFIO_DEVICE_STATE_RUNNING_P2P, i));
assert_false(f(VFIO_USER_DEVICE_STATE_RUNNING_P2P, i));
}

/* from PRE_COPY */
assert_false(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_ERROR));
assert_false(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_STOP));
assert_true(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_RUNNING));
assert_true(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_STOP_COPY));
assert_false(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_RESUMING));
assert_false(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_RUNNING_P2P));
assert_false(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_PRE_COPY));
assert_false(f(VFIO_DEVICE_STATE_PRE_COPY, VFIO_DEVICE_STATE_PRE_COPY_P2P));
assert_false(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_ERROR));
assert_false(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_STOP));
assert_true(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_RUNNING));
assert_true(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_STOP_COPY));
assert_false(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_RESUMING));
assert_false(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_RUNNING_P2P));
assert_false(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_PRE_COPY));
assert_false(f(VFIO_USER_DEVICE_STATE_PRE_COPY, VFIO_USER_DEVICE_STATE_PRE_COPY_P2P));

/* from PRE_COPY_P2P: all transitions are invalid */
for (i = 0; i < 8; i++) {
assert_false(f(VFIO_DEVICE_STATE_PRE_COPY_P2P, i));
assert_false(f(VFIO_USER_DEVICE_STATE_PRE_COPY_P2P, i));
}
}

Expand Down Expand Up @@ -534,7 +534,7 @@ test_setup_migration_callbacks(void **state)
int r = vfu_setup_device_migration_callbacks(p->v, 0, &p->c);
assert_int_equal(0, r);
assert_non_null(p->v->migration);
assert_int_equal(p->v->migration->state, VFIO_DEVICE_STATE_RUNNING);
assert_int_equal(p->v->migration->state, VFIO_USER_DEVICE_STATE_RUNNING);
}

static void
Expand All @@ -545,7 +545,7 @@ test_setup_migration_callbacks_resuming(void **state)
LIBVFIO_USER_MIG_FLAG_START_RESUMING, &p->c);
assert_int_equal(0, r);
assert_non_null(p->v->migration);
assert_int_equal(p->v->migration->state, VFIO_DEVICE_STATE_RESUMING);
assert_int_equal(p->v->migration->state, VFIO_USER_DEVICE_STATE_RESUMING);
}

static void
Expand All @@ -556,23 +556,23 @@ test_handle_device_state(void **state)
struct test_setup_migr_reg_dat *p = *state;
struct migration *migr = p->v->migration;

assert(migr->state == VFIO_DEVICE_STATE_RUNNING);
assert(migr->state == VFIO_USER_DEVICE_STATE_RUNNING);

int r;

r = handle_device_state(p->v, migr, VFIO_DEVICE_STATE_PRE_COPY, true);
r = handle_device_state(p->v, migr, VFIO_USER_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);
r = handle_device_state(p->v, migr, VFIO_USER_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);
r = handle_device_state(p->v, migr, VFIO_USER_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);
r = handle_device_state(p->v, migr, VFIO_USER_DEVICE_STATE_RUNNING, true);
assert_int_equal(0, r);
assert_int_equal(LAST_STATE, VFU_MIGR_STATE_RUNNING);
}
Expand All @@ -598,13 +598,13 @@ test_handle_mig_data_read(void **state)

ssize_t r;

migr->state = VFIO_DEVICE_STATE_PRE_COPY;
migr->state = VFIO_USER_DEVICE_STATE_PRE_COPY;
r = handle_mig_data_read(p->v, m);
assert_int_equal(4, r);
assert_int_equal(0, memcmp(msg.out.iov.iov_base + sizeof(data), &expect, 4));
free(msg.out.iov.iov_base);

migr->state = VFIO_DEVICE_STATE_STOP_COPY;
migr->state = VFIO_USER_DEVICE_STATE_STOP_COPY;
r = handle_mig_data_read(p->v, m);
assert_int_equal(4, r);
assert_int_equal(0, memcmp(msg.out.iov.iov_base + sizeof(data), &expect, 4));
Expand All @@ -629,7 +629,7 @@ test_handle_mig_data_read_too_long(void **state) {

ssize_t r;

migr->state = VFIO_DEVICE_STATE_PRE_COPY;
migr->state = VFIO_USER_DEVICE_STATE_PRE_COPY;
r = handle_mig_data_read(p->v, m);
assert_int_equal(-EINVAL, r);
}
Expand All @@ -652,11 +652,11 @@ test_handle_mig_data_read_invalid_state(void **state) {

ssize_t r;

migr->state = VFIO_DEVICE_STATE_RUNNING;
migr->state = VFIO_USER_DEVICE_STATE_RUNNING;
r = handle_mig_data_read(p->v, m);
assert_int_equal(-EINVAL, r);

migr->state = VFIO_DEVICE_STATE_STOP;
migr->state = VFIO_USER_DEVICE_STATE_STOP;
r = handle_mig_data_read(p->v, m);
assert_int_equal(-EINVAL, r);
}
Expand Down Expand Up @@ -686,7 +686,7 @@ test_handle_mig_data_write(void **state)

ssize_t r;

migr->state = VFIO_DEVICE_STATE_RESUMING;
migr->state = VFIO_USER_DEVICE_STATE_RESUMING;
r = handle_mig_data_write(p->v, m);
assert_int_equal(4, r);
assert_int_equal(0, memcmp(LAST_WRITE, buf, 4));
Expand Down Expand Up @@ -717,7 +717,7 @@ test_handle_mig_data_write_invalid_state(void **state)

ssize_t r;

migr->state = VFIO_DEVICE_STATE_RUNNING;
migr->state = VFIO_USER_DEVICE_STATE_RUNNING;
r = handle_mig_data_write(p->v, m);
assert_int_equal(-EINVAL, r);
}
Expand All @@ -734,13 +734,13 @@ test_device_is_stopped_and_copying(UNUSED void **state)
for (i = 0; i < 8; i++) {
migration.state = i;
bool r = device_is_stopped_and_copying(vfu_ctx.migration);
if (i == VFIO_DEVICE_STATE_STOP_COPY) {
if (i == VFIO_USER_DEVICE_STATE_STOP_COPY) {
assert_true(r);
} else {
assert_false(r);
}
r = device_is_stopped(vfu_ctx.migration);
if (i == VFIO_DEVICE_STATE_STOP) {
if (i == VFIO_USER_DEVICE_STATE_STOP) {
assert_true(r);
} else {
assert_false(r);
Expand Down

0 comments on commit cc0b0e1

Please sign in to comment.