aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2021-04-28 00:04:33 -0700
committerDamjan Marion <dmarion@me.com>2021-04-28 13:11:51 +0000
commit05c45b77d1f644cad82c4a65c7ca677d1dab74f8 (patch)
treebcc9afcd4aadfcbd98a208a803360819f66e7d62
parenta80ff1384cdcc1b3bd766f7fc504e7f3af4134e7 (diff)
hsa: support sigint in vcl test client
Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: Ie0d5fe97a727465f8851fc2110219483a5bf3f27
-rw-r--r--src/plugins/hs_apps/vcl/vcl_test_client.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/plugins/hs_apps/vcl/vcl_test_client.c b/src/plugins/hs_apps/vcl/vcl_test_client.c
index d87b4d3d3f6..83d6dd057f6 100644
--- a/src/plugins/hs_apps/vcl/vcl_test_client.c
+++ b/src/plugins/hs_apps/vcl/vcl_test_client.c
@@ -24,6 +24,7 @@
#include <arpa/inet.h>
#include <hs_apps/vcl/vcl_test.h>
#include <pthread.h>
+#include <signal.h>
typedef struct
{
@@ -51,6 +52,7 @@ typedef struct
uint8_t proto;
uint32_t n_workers;
volatile int active_workers;
+ volatile int test_running;
struct sockaddr_storage server_addr;
} vcl_test_client_main_t;
@@ -324,7 +326,7 @@ vtc_worker_loop (void *arg)
check_rx = wrk->cfg.test != VCL_TEST_TYPE_UNI;
n_active_sessions = wrk->cfg.num_test_sessions;
- while (n_active_sessions)
+ while (n_active_sessions && vcm->test_running)
{
_wfdset = wrk->wr_fdset;
_rfdset = wrk->rd_fdset;
@@ -349,7 +351,9 @@ vtc_worker_loop (void *arg)
if (FD_ISSET (vppcom_session_index (ts->fd), rfdset)
&& ts->stats.rx_bytes < ts->cfg.total_bytes)
{
- (void) ts->read (ts, ts->rxbuf, ts->rxbuf_size);
+ rv = ts->read (ts, ts->rxbuf, ts->rxbuf_size);
+ if (rv < 0)
+ goto exit;
}
if (FD_ISSET (vppcom_session_index (ts->fd), wfdset)
@@ -464,6 +468,7 @@ vtc_stream_client (vcl_test_client_main_t * vcm)
n_conn -= wrk->cfg.num_test_sessions;
}
+ vcm->test_running = 1;
ctrl->cfg.cmd = VCL_TEST_CMD_START;
if (vtc_cfg_sync (ctrl))
{
@@ -968,6 +973,31 @@ vtc_ctrl_session_init (vcl_test_client_main_t *vcm, vcl_test_session_t *ctrl)
return 0;
}
+static void
+vt_sigs_handler (int signum, siginfo_t *si, void *uc)
+{
+ vcl_test_client_main_t *vcm = &vcl_client_main;
+ vcl_test_session_t *ctrl = &vcm->ctrl_session;
+
+ vcm->test_running = 0;
+ clock_gettime (CLOCK_REALTIME, &ctrl->stats.stop);
+}
+
+static void
+vt_incercept_sigs (void)
+{
+ struct sigaction sa;
+
+ memset (&sa, 0, sizeof (sa));
+ sa.sa_sigaction = vt_sigs_handler;
+ sa.sa_flags = SA_SIGINFO;
+ if (sigaction (SIGINT, &sa, 0))
+ {
+ vtwrn ("couldn't intercept sigint");
+ exit (-1);
+ }
+}
+
int
main (int argc, char **argv)
{
@@ -980,6 +1010,7 @@ main (int argc, char **argv)
vcl_test_cfg_init (&ctrl->cfg);
vcl_test_session_buf_alloc (ctrl);
vtc_process_opts (vcm, argc, argv);
+ vt_incercept_sigs ();
vcm->workers = calloc (vcm->n_workers, sizeof (vcl_test_client_worker_t));
vt->wrk = calloc (vcm->n_workers, sizeof (vcl_test_wrk_t));