@@ -52,6 +52,47 @@ static void test_self(void)
52
52
qemu_coroutine_enter (coroutine );
53
53
}
54
54
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
+
55
96
/*
56
97
* Check that coroutines may nest multiple levels
57
98
*/
@@ -389,6 +430,7 @@ int main(int argc, char **argv)
389
430
g_test_add_func ("/basic/yield" , test_yield );
390
431
g_test_add_func ("/basic/nesting" , test_nesting );
391
432
g_test_add_func ("/basic/self" , test_self );
433
+ g_test_add_func ("/basic/entered" , test_entered );
392
434
g_test_add_func ("/basic/in_coroutine" , test_in_coroutine );
393
435
g_test_add_func ("/basic/order" , test_order );
394
436
if (g_test_perf ()) {
0 commit comments