X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Funittest%2Fsession_test.c;h=c4e41c34dd033f8a0f6a8aec98bf2da56dbe06d9;hb=0028e6f31624246e831b5b1a13dc46ab1d864fa7;hp=37b4dac244d4265e22c0a768f50cd9eed42d1d46;hpb=11fb09e38ffcbadc2629361377413f3ce12ec4da;p=vpp.git diff --git a/src/plugins/unittest/session_test.c b/src/plugins/unittest/session_test.c index 37b4dac244d..c4e41c34dd0 100644 --- a/src/plugins/unittest/session_test.c +++ b/src/plugins/unittest/session_test.c @@ -136,7 +136,7 @@ session_create_lookpback (u32 table_id, u32 * sw_if_index, if (table_id != 0) { ip_table_create (FIB_PROTOCOL_IP4, table_id, 0, 0); - ip_table_bind (FIB_PROTOCOL_IP4, *sw_if_index, table_id, 0); + ip_table_bind (FIB_PROTOCOL_IP4, *sw_if_index, table_id); } vnet_sw_interface_set_flags (vnet_get_main (), *sw_if_index, @@ -290,11 +290,11 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) /* * Create the loopbacks */ - intf_addr[0].as_u32 = clib_host_to_net_u32 (0x01010101), - session_create_lookpback (0, &sw_if_index[0], &intf_addr[0]); + intf_addr[0].as_u32 = clib_host_to_net_u32 (0x01010101); + session_create_lookpback (0, &sw_if_index[0], &intf_addr[0]); - intf_addr[1].as_u32 = clib_host_to_net_u32 (0x02020202), - session_create_lookpback (1, &sw_if_index[1], &intf_addr[1]); + intf_addr[1].as_u32 = clib_host_to_net_u32 (0x02020202); + session_create_lookpback (1, &sw_if_index[1], &intf_addr[1]); session_add_del_route_via_lookup_in_table (0, 1, &intf_addr[1], 32, 1 /* is_add */ ); @@ -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, @@ -376,7 +379,18 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) /* wait for stuff to happen */ while (connected_session_index == ~0 && ++tries < 100) - vlib_process_suspend (vm, 100e-3); + { + vlib_worker_thread_barrier_release (vm); + vlib_process_suspend (vm, 100e-3); + vlib_worker_thread_barrier_sync (vm); + } + while (accepted_session_index == ~0 && ++tries < 100) + { + vlib_worker_thread_barrier_release (vm); + vlib_process_suspend (vm, 100e-3); + vlib_worker_thread_barrier_sync (vm); + } + clib_warning ("waited %.1f seconds for connections", tries / 10.0); SESSION_TEST ((connected_session_index != ~0), "session should exist"); SESSION_TEST ((connected_session_thread != ~0), "thread should exist"); @@ -390,14 +404,6 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) SESSION_TEST ((tc->lcl_port == placeholder_client_port), "ports should be equal"); - /* These sessions, because of the way they're established are pinned to - * main thread, even when we have workers and we avoid polling main thread, - * i.e., we can't cleanup pending disconnects, so force cleanup for both - */ - session_transport_cleanup (s); - s = session_get (accepted_session_index, accepted_session_thread); - session_transport_cleanup (s); - vnet_app_detach_args_t detach_args = { .app_index = server_index, .api_client_index = ~0, @@ -406,6 +412,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); @@ -422,7 +432,7 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) static int session_test_namespace (vlib_main_t * vm, unformat_input_t * input) { - u64 options[APP_OPTIONS_N_OPTIONS], placeholder_secret = 1234; + u64 options[APP_OPTIONS_N_OPTIONS], placeholder_secret = 1234, tries; u32 server_index, server_st_index, server_local_st_index; u32 placeholder_port = 1234, client_index, server_wrk_index; u32 placeholder_api_context = 4321, placeholder_client_api_index = ~0; @@ -517,7 +527,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) error = vnet_application_attach (&attach_args); SESSION_TEST ((error != 0), "app attachment should fail"); - SESSION_TEST ((error == VNET_API_ERROR_APP_WRONG_NS_SECRET), + SESSION_TEST ((error == SESSION_E_WRONG_NS_SECRET), "code should be wrong ns secret: %d", error); /* @@ -609,6 +619,16 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) connect_args.sep.ip.ip4.as_u8[0] = 127; error = vnet_connect (&connect_args); SESSION_TEST ((error == 0), "client connect should not return error code"); + + /* wait for accept */ + 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); + } + SESSION_TEST ((placeholder_segment_count == 1), "should've received request to map new segment"); SESSION_TEST ((placeholder_accept == 1), @@ -742,6 +762,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 */ @@ -1577,6 +1601,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; @@ -1714,9 +1742,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 { @@ -1740,10 +1766,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; } } } @@ -1797,8 +1820,6 @@ session_test_mq_speed (vlib_main_t * vm, unformat_input_t * input) /* Shut up coverity */ if (reg == 0) abort (); - if (!session_main.evt_qs_use_memfd_seg) - reg->clib_file_index = VL_API_INVALID_FI; vnet_app_attach_args_t attach_args = { .api_client_index = api_index, @@ -1817,18 +1838,17 @@ session_test_mq_speed (vlib_main_t * vm, unformat_input_t * input) mq = app_wrk->event_queue; if (use_eventfd) { - svm_msg_q_alloc_producer_eventfd (mq); - svm_msg_q_alloc_consumer_eventfd (mq); - prod_fd = svm_msg_q_get_producer_eventfd (mq); + svm_msg_q_alloc_eventfd (mq); + prod_fd = svm_msg_q_get_eventfd (mq); 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; s.session_state = SESSION_STATE_READY; - counter = (u64 *) rx_fifo->head_chunk->data; + counter = (u64 *) f_head_cptr (rx_fifo)->data; start = vlib_time_now (vm); pid = fork (); @@ -1850,7 +1870,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; @@ -1887,8 +1907,9 @@ session_test_mq_basic (vlib_main_t * vm, unformat_input_t * input) svm_msg_q_cfg_t _cfg, *cfg = &_cfg; svm_msg_q_msg_t msg1, msg2, msg[12]; int __clib_unused verbose, i, rv; - svm_msg_q_t *mq; + svm_msg_q_shared_t *smq; svm_msg_q_ring_t *ring; + svm_msg_q_t _mq = { 0 }, *mq = &_mq; u8 *rings_ptr; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) @@ -1911,28 +1932,30 @@ session_test_mq_basic (vlib_main_t * vm, unformat_input_t * input) cfg->q_nitems = 16; cfg->ring_cfgs = rc; - mq = svm_msg_q_alloc (cfg); - SESSION_TEST (mq != 0, "svm_msg_q_alloc"); + smq = svm_msg_q_alloc (cfg); + svm_msg_q_attach (mq, smq); + SESSION_TEST (smq != 0, "svm_msg_q_alloc"); SESSION_TEST (vec_len (mq->rings) == 2, "ring allocation"); - rings_ptr = (u8 *) mq->rings + vec_bytes (mq->rings); + rings_ptr = (u8 *) mq->rings[0].shr->data; vec_foreach (ring, mq->rings) { - SESSION_TEST (ring->data == rings_ptr, "ring data"); + SESSION_TEST (ring->shr->data == rings_ptr, "ring data"); rings_ptr += (uword) ring->nitems * ring->elsize; + rings_ptr += sizeof (svm_msg_q_ring_shared_t); } msg1 = svm_msg_q_alloc_msg (mq, 8); - rv = (mq->rings[0].cursize != 1 - || msg1.ring_index != 0 || msg1.elt_index != 0); + rv = (mq->rings[0].shr->cursize != 1 || msg1.ring_index != 0 || + msg1.elt_index != 0); SESSION_TEST (rv == 0, "msg alloc1"); msg2 = svm_msg_q_alloc_msg (mq, 15); - rv = (mq->rings[1].cursize != 1 - || msg2.ring_index != 1 || msg2.elt_index != 0); + rv = (mq->rings[1].shr->cursize != 1 || msg2.ring_index != 1 || + msg2.elt_index != 0); SESSION_TEST (rv == 0, "msg alloc2"); svm_msg_q_free_msg (mq, &msg1); - SESSION_TEST (mq->rings[0].cursize == 0, "free msg"); + SESSION_TEST (mq->rings[0].shr->cursize == 0, "free msg"); for (i = 0; i < 12; i++) { @@ -1940,7 +1963,7 @@ session_test_mq_basic (vlib_main_t * vm, unformat_input_t * input) *(u32 *) svm_msg_q_msg_data (mq, &msg[i]) = i; } - rv = (mq->rings[0].cursize != 8 || mq->rings[1].cursize != 5); + rv = (mq->rings[0].shr->cursize != 8 || mq->rings[1].shr->cursize != 5); SESSION_TEST (rv == 0, "msg alloc3"); *(u32 *) svm_msg_q_msg_data (mq, &msg2) = 123; @@ -1976,7 +1999,7 @@ session_test_mq_basic (vlib_main_t * vm, unformat_input_t * input) SESSION_TEST (0, "dequeue2 wrong data"); svm_msg_q_free_msg (mq, &msg[i]); } - rv = (mq->rings[0].cursize == 0 && mq->rings[1].cursize == 0); + rv = (mq->rings[0].shr->cursize == 0 && mq->rings[1].shr->cursize == 0); SESSION_TEST (rv, "post dequeue"); return 0;