From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpKZO-0007CU-A8 for qemu-devel@nongnu.org; Wed, 28 Sep 2016 15:31:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpKZK-0005GY-3w for qemu-devel@nongnu.org; Wed, 28 Sep 2016 15:31:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpKZJ-0005GR-UO for qemu-devel@nongnu.org; Wed, 28 Sep 2016 15:31:02 -0400 From: Stefan Hajnoczi Date: Wed, 28 Sep 2016 19:15:36 +0100 Message-Id: <1475086537-31704-7-git-send-email-stefanha@redhat.com> In-Reply-To: <1475086537-31704-1-git-send-email-stefanha@redhat.com> References: <1475086537-31704-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 6/7] test-coroutine: test qemu_coroutine_entered() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Reviewed-by: Fam Zheng Message-id: 1474989516-18255-3-git-send-email-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- tests/test-coroutine.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test-coroutine.c b/tests/test-coroutine.c index 6431dd6..abd97c2 100644 --- a/tests/test-coroutine.c +++ b/tests/test-coroutine.c @@ -53,6 +53,47 @@ static void test_self(void) } /* + * 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 */ @@ -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()) { -- 2.7.4