Add coverage for requests the peer has no action for. The secondary
asks the primary for an action nobody registered and checks that the
call fails with ENOTSUP rather than blocking until the timeout.

The async form of the same request is checked as well. Its callback
has to run even though no reply comes back, reporting the request as
sent and nothing received.

The MP_IGN direction is not covered here. That needs a primary
broadcasting to a secondary which did not register the action, and
the test primary is blocked waiting for the secondary to exit.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 app/test/test_mp_secondary.c | 85 +++++++++++++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 1 deletion(-)

diff --git a/app/test/test_mp_secondary.c b/app/test/test_mp_secondary.c
index d89419c253..8101c2cafc 100644
--- a/app/test/test_mp_secondary.c
+++ b/app/test/test_mp_secondary.c
@@ -53,6 +53,7 @@ test_mp_secondary(void)
 #endif /* RTE_LIB_LPM */
 
 #include <rte_string_fns.h>
+#include <rte_cycles.h>
 
 #include "process.h"
 
@@ -197,6 +198,85 @@ run_object_creation_tests(void)
        return 0;
 }
 
+#define NO_SUCH_ACTION "test_mp_no_action"
+#define MP_WAIT_S 5
+
+static int async_replied;
+static int async_nb_sent;
+static int async_nb_received;
+
+static int
+unsupported_async_reply(const struct rte_mp_msg *request __rte_unused,
+                       const struct rte_mp_reply *reply)
+{
+       async_nb_sent = reply->nb_sent;
+       async_nb_received = reply->nb_received;
+       async_replied = 1;
+       return 0;
+}
+
+/*
+ * Run in the secondary to check requests the primary has no handler for.
+ * The primary answers MP_ERR, so the request fails right away instead of
+ * waiting for the timeout.
+ */
+static int
+run_unsupported_request_tests(void)
+{
+       struct timespec ts = { .tv_sec = MP_WAIT_S, .tv_nsec = 0 };
+       struct rte_mp_msg msg = { .len_param = 0, .num_fds = 0 };
+       struct rte_mp_reply reply = { };
+       time_t start;
+       int ret;
+
+       printf("### Testing request with no handler in primary:\n");
+
+       strlcpy(msg.name, NO_SUCH_ACTION, sizeof(msg.name));
+
+       start = time(NULL);
+       ret = rte_mp_request_sync(&msg, &reply, &ts);
+       if (ret == 0 || rte_errno != ENOTSUP) {
+               printf("Error: rte_mp_request_sync() returned %d errno %d, 
expected -1/ENOTSUP\n",
+                      ret, rte_errno);
+               free(reply.msgs);
+               return -1;
+       }
+       /* a dropped request would have cost the full timeout */
+       if (time(NULL) - start >= MP_WAIT_S) {
+               printf("Error: rte_mp_request_sync() waited for the timeout\n");
+               return -1;
+       }
+       printf("# Checked rte_mp_request_sync() returns ENOTSUP\n");
+
+       async_replied = 0;
+       if (rte_mp_request_async(&msg, &ts, unsupported_async_reply) != 0) {
+               printf("Error: rte_mp_request_async() failed: %s\n",
+                      rte_strerror(rte_errno));
+               return -1;
+       }
+
+       /* the callback runs on the interrupt thread */
+       for (int i = 0; i < MP_WAIT_S * 10 && !async_replied; i++)
+               rte_delay_ms(100);
+
+       if (!async_replied) {
+               printf("Error: rte_mp_request_async() callback never ran\n");
+               return -1;
+       }
+       /*
+        * The request was sent and answered with an error, so the callback
+        * must see it as sent but carrying no reply.
+        */
+       if (async_nb_sent != 1 || async_nb_received != 0) {
+               printf("Error: async reply sent %d received %d, expected 1/0\n",
+                      async_nb_sent, async_nb_received);
+               return -1;
+       }
+       printf("# Checked rte_mp_request_async() callback runs with no 
reply\n");
+
+       return 0;
+}
+
 /* if called in a primary process, just spawns off a secondary process to
  * run validation tests - which brings us right back here again...
  * if called in a secondary process, this runs a series of API tests to check
@@ -211,7 +291,10 @@ test_mp_secondary(void)
 
        printf("IN SECONDARY PROCESS\n");
 
-       return run_object_creation_tests();
+       if (run_object_creation_tests() < 0)
+               return -1;
+
+       return run_unsupported_request_tests();
 }
 
 #endif /* !RTE_EXEC_ENV_WINDOWS */
-- 
2.53.0

Reply via email to