From 3fca567ff438145e28dd1318ad5b1734c1091257 Mon Sep 17 00:00:00 2001 From: Mohsin Kazmi Date: Thu, 4 Jan 2018 18:57:26 +0100 Subject: svm: queue sub: Add conditional timed wait On reviece side svm queue only permits blocking and non-blocking calls. This patch adds timed wait blocking functionality which returns either on signal/event or on given time out. It also preserves the original behavior, so it will not hurt client applications which are using svm queue. Change-Id: Ic10632170330a80afb8bc781d4ccddfe4da2c69a Signed-off-by: Mohsin Kazmi --- test/ext/vapi_c_test.c | 8 ++++---- test/ext/vapi_cpp_test.cpp | 32 ++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) (limited to 'test/ext') diff --git a/test/ext/vapi_c_test.c b/test/ext/vapi_c_test.c index ad75ad6e8b8..52a939f72a5 100644 --- a/test/ext/vapi_c_test.c +++ b/test/ext/vapi_c_test.c @@ -66,12 +66,12 @@ START_TEST (test_invalid_values) ck_assert_int_eq (VAPI_EINVAL, rv); rv = vapi_send (NULL, NULL); ck_assert_int_eq (VAPI_EINVAL, rv); - rv = vapi_recv (NULL, NULL, NULL); + rv = vapi_recv (NULL, NULL, NULL, 0, 0); ck_assert_int_eq (VAPI_EINVAL, rv); - rv = vapi_recv (ctx, NULL, NULL); + rv = vapi_recv (ctx, NULL, NULL, 0, 0); ck_assert_int_eq (VAPI_EINVAL, rv); vapi_msg_show_version_reply *reply; - rv = vapi_recv (ctx, (void **) &reply, NULL); + rv = vapi_recv (ctx, (void **) &reply, NULL, 0, 0); ck_assert_int_eq (VAPI_EINVAL, rv); rv = vapi_disconnect (ctx); ck_assert_int_eq (VAPI_OK, rv); @@ -531,7 +531,7 @@ START_TEST (test_show_version_1) ck_assert_int_eq (VAPI_OK, rv); vapi_msg_show_version_reply *resp; size_t size; - rv = vapi_recv (ctx, (void *) &resp, &size); + rv = vapi_recv (ctx, (void *) &resp, &size, 0, 0); ck_assert_int_eq (VAPI_OK, rv); int dummy; show_version_cb (NULL, &dummy, VAPI_OK, true, &resp->payload); diff --git a/test/ext/vapi_cpp_test.cpp b/test/ext/vapi_cpp_test.cpp index 14c35d5bedd..25ea9cc7f7b 100644 --- a/test/ext/vapi_cpp_test.cpp +++ b/test/ext/vapi_cpp_test.cpp @@ -37,6 +37,13 @@ static char *api_prefix = nullptr; static const int max_outstanding_requests = 32; static const int response_queue_size = 32; +#define WAIT_FOR_RESPONSE(param, ret) \ + do \ + { \ + ret = con.wait_for_response (param); \ + } \ + while (ret == VAPI_EAGAIN) + using namespace vapi; void verify_show_version_reply (const Show_version_reply &r) @@ -68,7 +75,7 @@ START_TEST (test_show_version_1) Show_version sv (con); vapi_error_e rv = sv.execute (); ck_assert_int_eq (VAPI_OK, rv); - rv = con.wait_for_response (sv); + WAIT_FOR_RESPONSE (sv, rv); ck_assert_int_eq (VAPI_OK, rv); auto &r = sv.get_response (); verify_show_version_reply (r); @@ -122,7 +129,8 @@ START_TEST (test_loopbacks_1) memcpy (p.mac_address, mac_addresses[i], sizeof (p.mac_address)); auto e = cl.execute (); ck_assert_int_eq (VAPI_OK, e); - vapi_error_e rv = con.wait_for_response (cl); + vapi_error_e rv; + WAIT_FOR_RESPONSE (cl, rv); ck_assert_int_eq (VAPI_OK, rv); auto &rp = cl.get_response ().get_payload (); ck_assert_int_eq (0, rp.retval); @@ -145,7 +153,7 @@ START_TEST (test_loopbacks_1) memset (p.name_filter, 0, sizeof (p.name_filter)); auto rv = d.execute (); ck_assert_int_eq (VAPI_OK, rv); - rv = con.wait_for_response (d); + WAIT_FOR_RESPONSE (d, rv); ck_assert_int_eq (VAPI_OK, rv); auto &rs = d.get_result_set (); for (auto &r : rs) @@ -172,7 +180,7 @@ START_TEST (test_loopbacks_1) dl.get_request ().get_payload ().sw_if_index = sw_if_indexes[i]; auto rv = dl.execute (); ck_assert_int_eq (VAPI_OK, rv); - rv = con.wait_for_response (dl); + WAIT_FOR_RESPONSE (dl, rv); ck_assert_int_eq (VAPI_OK, rv); auto &response = dl.get_response (); auto rp = response.get_payload (); @@ -187,7 +195,7 @@ START_TEST (test_loopbacks_1) memset (p.name_filter, 0, sizeof (p.name_filter)); auto rv = d.execute (); ck_assert_int_eq (VAPI_OK, rv); - rv = con.wait_for_response (d); + WAIT_FOR_RESPONSE (d, rv); ck_assert_int_eq (VAPI_OK, rv); auto &rs = d.get_result_set (); for (auto &r : rs) @@ -305,7 +313,7 @@ START_TEST (test_loopbacks_2) memset (p.name_filter, 0, sizeof (p.name_filter)); auto rv = d.execute (); ck_assert_int_eq (VAPI_OK, rv); - rv = con.wait_for_response (d); + WAIT_FOR_RESPONSE (d, rv); ck_assert_int_eq (VAPI_OK, rv); ck_assert_int_ne (0, swdcb.called); std::array dcbs; @@ -334,7 +342,7 @@ START_TEST (test_loopbacks_2) memset (p.name_filter, 0, sizeof (p.name_filter)); auto rv = d.execute (); ck_assert_int_eq (VAPI_OK, rv); - rv = con.wait_for_response (d); + WAIT_FOR_RESPONSE (d, rv); ck_assert_int_eq (VAPI_OK, rv); auto &rs = d.get_result_set (); for (auto &r : rs) @@ -360,7 +368,7 @@ START_TEST (test_stats_1) auto rv = ws.execute (); ck_assert_int_eq (VAPI_OK, rv); Event_registration sc (con); - rv = con.wait_for_response (sc); + WAIT_FOR_RESPONSE (sc, rv); ck_assert_int_eq (VAPI_OK, rv); auto &rs = sc.get_result_set (); int count = 0; @@ -407,7 +415,7 @@ START_TEST (test_stats_2) ck_assert_int_eq (VAPI_OK, rv); Vnet_interface_simple_counters_cb cb; Event_registration sc (con, std::ref (cb)); - rv = con.wait_for_response (sc); + WAIT_FOR_RESPONSE (sc, rv); ck_assert_int_eq (VAPI_OK, rv); ck_assert_int_ne (0, cb.called); } @@ -452,7 +460,7 @@ START_TEST (test_stats_3) Event_registration sc (con, std::ref (cb)); for (int i = 0; i < 5; ++i) { - rv = con.wait_for_response (sc); + WAIT_FOR_RESPONSE (sc, rv); } ck_assert_int_eq (VAPI_OK, rv); ck_assert_int_eq (5, cb.called); @@ -472,9 +480,9 @@ START_TEST (test_stats_4) ck_assert_int_eq (VAPI_OK, rv); Event_registration sc (con); Event_registration cc (con); - rv = con.wait_for_response (sc); + WAIT_FOR_RESPONSE (sc, rv); ck_assert_int_eq (VAPI_OK, rv); - rv = con.wait_for_response (cc); + WAIT_FOR_RESPONSE (cc, rv); ck_assert_int_eq (VAPI_OK, rv); int count = 0; for (auto &r : sc.get_result_set ()) -- cgit 1.2.3-korg