session: implement app_ns deletion
[vpp.git] / src / plugins / unittest / session_test.c
index 6496a99..292f725 100644 (file)
@@ -337,6 +337,9 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input)
 
   attach_args.name = format (0, "session_test_server");
   attach_args.namespace_id = appns_id;
+  /* Allow server to allocate another segment for listens. Needed
+   * because by default we do not allow segment additions */
+  attach_args.options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 32 << 20;
   attach_args.options[APP_OPTIONS_NAMESPACE_SECRET] = placeholder_secret;
   error = vnet_application_attach (&attach_args);
   SESSION_TEST ((error == 0), "server app attached: %U", format_clib_error,
@@ -417,6 +420,10 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input)
   detach_args.app_index = client_index;
   vnet_application_detach (&detach_args);
 
+  ns_args.is_add = 0;
+  error = vnet_app_namespace_add_del (&ns_args);
+  SESSION_TEST ((error == 0), "app ns delete should succeed: %d", error);
+
   /* Allow the disconnects to finish before removing the routes. */
   vlib_process_suspend (vm, 10e-3);
 
@@ -622,15 +629,12 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   SESSION_TEST ((error == 0), "client connect should not return error code");
 
   /* wait for accept */
-  if (vlib_num_workers ())
+  tries = 0;
+  while (!placeholder_accept && ++tries < 100)
     {
-      tries = 0;
-      while (!placeholder_accept && ++tries < 100)
-       {
-         vlib_worker_thread_barrier_release (vm);
-         vlib_process_suspend (vm, 100e-3);
-         vlib_worker_thread_barrier_sync (vm);
-       }
+      vlib_worker_thread_barrier_release (vm);
+      vlib_process_suspend (vm, 100e-3);
+      vlib_worker_thread_barrier_sync (vm);
     }
 
   SESSION_TEST ((placeholder_segment_count == 1),
@@ -766,6 +770,10 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   detach_args.app_index = server_index;
   vnet_application_detach (&detach_args);
 
+  ns_args.is_add = 0;
+  error = vnet_app_namespace_add_del (&ns_args);
+  SESSION_TEST ((error == 0), "app ns delete should succeed: %d", error);
+
   /*
    * Cleanup
    */
@@ -1601,6 +1609,10 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   detach_args.app_index = server_index2;
   vnet_application_detach (&detach_args);
 
+  ns_args.is_add = 0;
+  error = vnet_app_namespace_add_del (&ns_args);
+  SESSION_TEST ((error == 0), "app ns delete should succeed: %d", error);
+
   vec_free (ns_id);
   vec_free (attach_args.name);
   return 0;
@@ -1738,9 +1750,7 @@ wait_for_event (svm_msg_q_t * mq, int fd, int epfd, u8 use_eventfd)
 {
   if (!use_eventfd)
     {
-      svm_msg_q_lock (mq);
-      while (svm_msg_q_is_empty (mq))
-       svm_msg_q_wait (mq);
+      svm_msg_q_wait (mq, SVM_MQ_WAIT_EMPTY);
     }
   else
     {
@@ -1764,10 +1774,7 @@ wait_for_event (svm_msg_q_t * mq, int fd, int epfd, u8 use_eventfd)
            continue;
 
          if (!svm_msg_q_is_empty (mq))
-           {
-             svm_msg_q_lock (mq);
-             break;
-           }
+           break;
        }
     }
 }
@@ -1844,7 +1851,7 @@ session_test_mq_speed (vlib_main_t * vm, unformat_input_t * input)
       SESSION_TEST (prod_fd != -1, "mq producer eventd valid %u", prod_fd);
     }
 
-  sm = app_worker_get_or_alloc_connect_segment_manager (app_wrk);
+  sm = app_worker_get_connect_segment_manager (app_wrk);
   segment_manager_alloc_session_fifos (sm, 0, &rx_fifo, &tx_fifo);
   s.rx_fifo = rx_fifo;
   s.tx_fifo = tx_fifo;
@@ -1871,7 +1878,7 @@ session_test_mq_speed (vlib_main_t * vm, unformat_input_t * input)
       for (i = 0; i < n_test_msgs; i++)
        {
          wait_for_event (mq, prod_fd, epfd, use_eventfd);
-         svm_msg_q_sub_w_lock (mq, &msg);
+         svm_msg_q_sub_raw (mq, &msg);
          svm_msg_q_free_msg (mq, &msg);
          svm_msg_q_unlock (mq);
          *counter = *counter + 1;