Skip to content

Commit afe16f3

Browse files
committed
test-coroutine: test qemu_coroutine_entered()
Signed-off-by: Stefan Hajnoczi <[email protected]> Reviewed-by: Fam Zheng <[email protected]> Message-id: [email protected] Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent f643e46 commit afe16f3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test-coroutine.c

+42
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,47 @@ static void test_self(void)
5252
qemu_coroutine_enter(coroutine);
5353
}
5454

55+
/*
56+
* Check that qemu_coroutine_entered() works
57+
*/
58+
59+
static void coroutine_fn verify_entered_step_2(void *opaque)
60+
{
61+
Coroutine *caller = (Coroutine *)opaque;
62+
63+
g_assert(qemu_coroutine_entered(caller));
64+
g_assert(qemu_coroutine_entered(qemu_coroutine_self()));
65+
qemu_coroutine_yield();
66+
67+
/* Once more to check it still works after yielding */
68+
g_assert(qemu_coroutine_entered(caller));
69+
g_assert(qemu_coroutine_entered(qemu_coroutine_self()));
70+
qemu_coroutine_yield();
71+
}
72+
73+
static void coroutine_fn verify_entered_step_1(void *opaque)
74+
{
75+
Coroutine *self = qemu_coroutine_self();
76+
Coroutine *coroutine;
77+
78+
g_assert(qemu_coroutine_entered(self));
79+
80+
coroutine = qemu_coroutine_create(verify_entered_step_2, self);
81+
g_assert(!qemu_coroutine_entered(coroutine));
82+
qemu_coroutine_enter(coroutine);
83+
g_assert(!qemu_coroutine_entered(coroutine));
84+
qemu_coroutine_enter(coroutine);
85+
}
86+
87+
static void test_entered(void)
88+
{
89+
Coroutine *coroutine;
90+
91+
coroutine = qemu_coroutine_create(verify_entered_step_1, NULL);
92+
g_assert(!qemu_coroutine_entered(coroutine));
93+
qemu_coroutine_enter(coroutine);
94+
}
95+
5596
/*
5697
* Check that coroutines may nest multiple levels
5798
*/
@@ -389,6 +430,7 @@ int main(int argc, char **argv)
389430
g_test_add_func("/basic/yield", test_yield);
390431
g_test_add_func("/basic/nesting", test_nesting);
391432
g_test_add_func("/basic/self", test_self);
433+
g_test_add_func("/basic/entered", test_entered);
392434
g_test_add_func("/basic/in_coroutine", test_in_coroutine);
393435
g_test_add_func("/basic/order", test_order);
394436
if (g_test_perf()) {

0 commit comments

Comments
 (0)