Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
test-coroutine: test qemu_coroutine_entered()
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Fam Zheng <[email protected]>
Message-id: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
stefanhaRH committed Sep 28, 2016
1 parent f643e46 commit afe16f3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/test-coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,47 @@ static void test_self(void)
qemu_coroutine_enter(coroutine);
}

/*
* Check that qemu_coroutine_entered() works
*/

static void coroutine_fn verify_entered_step_2(void *opaque)
{
Coroutine *caller = (Coroutine *)opaque;

g_assert(qemu_coroutine_entered(caller));
g_assert(qemu_coroutine_entered(qemu_coroutine_self()));
qemu_coroutine_yield();

/* Once more to check it still works after yielding */
g_assert(qemu_coroutine_entered(caller));
g_assert(qemu_coroutine_entered(qemu_coroutine_self()));
qemu_coroutine_yield();
}

static void coroutine_fn verify_entered_step_1(void *opaque)
{
Coroutine *self = qemu_coroutine_self();
Coroutine *coroutine;

g_assert(qemu_coroutine_entered(self));

coroutine = qemu_coroutine_create(verify_entered_step_2, self);
g_assert(!qemu_coroutine_entered(coroutine));
qemu_coroutine_enter(coroutine);
g_assert(!qemu_coroutine_entered(coroutine));
qemu_coroutine_enter(coroutine);
}

static void test_entered(void)
{
Coroutine *coroutine;

coroutine = qemu_coroutine_create(verify_entered_step_1, NULL);
g_assert(!qemu_coroutine_entered(coroutine));
qemu_coroutine_enter(coroutine);
}

/*
* Check that coroutines may nest multiple levels
*/
Expand Down Expand Up @@ -389,6 +430,7 @@ int main(int argc, char **argv)
g_test_add_func("/basic/yield", test_yield);
g_test_add_func("/basic/nesting", test_nesting);
g_test_add_func("/basic/self", test_self);
g_test_add_func("/basic/entered", test_entered);
g_test_add_func("/basic/in_coroutine", test_in_coroutine);
g_test_add_func("/basic/order", test_order);
if (g_test_perf()) {
Expand Down

0 comments on commit afe16f3

Please sign in to comment.