service: fix core mapping reset
[dpdk.git] / app / test / test_service_cores.c
index ec31882..ef1d8fc 100644 (file)
@@ -114,6 +114,7 @@ unregister_all(void)
        }
 
        rte_service_lcore_reset_all();
+       rte_eal_mp_wait_lcore();
 
        return TEST_SUCCESS;
 }
@@ -259,7 +260,7 @@ service_attr_get(void)
        rte_service_set_stats_enable(id, 1);
 
        uint32_t attr_id = UINT32_MAX;
-       uint32_t attr_value = 0xdead;
+       uint64_t attr_value = 0xdead;
        /* check error return values */
        TEST_ASSERT_EQUAL(-EINVAL, rte_service_attr_get(id, attr_id,
                                                        &attr_value),
@@ -483,7 +484,7 @@ service_lcore_en_dis_able(void)
        int ret = rte_eal_remote_launch(service_remote_launch_func, NULL,
                                        slcore_id);
        TEST_ASSERT_EQUAL(0, ret, "Ex-service core remote launch failed.");
-       rte_eal_mp_wait_lcore();
+       rte_eal_wait_lcore(slcore_id);
        TEST_ASSERT_EQUAL(1, service_remote_launch_flag,
                        "Ex-service core function call had no effect.");
 
@@ -502,6 +503,10 @@ service_lcore_running_check(void)
 static int
 service_lcore_add_del(void)
 {
+       if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1) ||
+           !rte_lcore_is_enabled(2) || !rte_lcore_is_enabled(3))
+               return TEST_SKIPPED;
+
        /* check initial count */
        TEST_ASSERT_EQUAL(0, rte_service_lcore_count(),
                        "Service lcore count has value before adding a lcore");
@@ -669,6 +674,11 @@ static int
 service_mt_safe_poll(void)
 {
        int mt_safe = 1;
+
+       if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1) ||
+           !rte_lcore_is_enabled(2))
+               return TEST_SKIPPED;
+
        TEST_ASSERT_EQUAL(1, service_threaded_test(mt_safe),
                        "Error: MT Safe service not run by two cores concurrently");
        return TEST_SUCCESS;
@@ -681,6 +691,11 @@ static int
 service_mt_unsafe_poll(void)
 {
        int mt_safe = 0;
+
+       if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1) ||
+           !rte_lcore_is_enabled(2))
+               return TEST_SKIPPED;
+
        TEST_ASSERT_EQUAL(1, service_threaded_test(mt_safe),
                        "Error: NON MT Safe service run by two cores concurrently");
        return TEST_SUCCESS;
@@ -775,8 +790,19 @@ service_app_lcore_poll_impl(const int mt_safe)
                                "MT Unsafe: App core1 didn't return -EBUSY");
        }
 
-       unregister_all();
+       /* Performance test: call in a loop, and measure tsc() */
+       const uint32_t perf_iters = (1 << 12);
+       uint64_t start = rte_rdtsc();
+       uint32_t i;
+       for (i = 0; i < perf_iters; i++) {
+               int err = service_run_on_app_core_func(&id);
+               TEST_ASSERT_EQUAL(0, err, "perf test: returned run failure");
+       }
+       uint64_t end = rte_rdtsc();
+       printf("perf test for %s: %0.1f cycles per call\n", mt_safe ?
+               "MT Safe" : "MT Unsafe", (end - start)/(float)perf_iters);
 
+       unregister_all();
        return TEST_SUCCESS;
 }
 
@@ -885,6 +911,59 @@ service_may_be_active(void)
        return unregister_all();
 }
 
+/* check service may be active when service is running on a second lcore */
+static int
+service_active_two_cores(void)
+{
+       if (!rte_lcore_is_enabled(0) || !rte_lcore_is_enabled(1) ||
+           !rte_lcore_is_enabled(2))
+               return TEST_SKIPPED;
+
+       const uint32_t sid = 0;
+       int i;
+
+       uint32_t lcore = rte_get_next_lcore(/* start core */ -1,
+                                           /* skip master */ 1,
+                                           /* wrap */ 0);
+       uint32_t slcore = rte_get_next_lcore(/* start core */ lcore,
+                                            /* skip master */ 1,
+                                            /* wrap */ 0);
+
+       /* start the service on the second available lcore */
+       TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 1),
+                       "Starting valid service failed");
+       TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore),
+                       "Add service core failed when not in use before");
+       TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore, 1),
+                       "Enabling valid service on valid core failed");
+       TEST_ASSERT_EQUAL(0, rte_service_lcore_start(slcore),
+                       "Service core start after add failed");
+
+       /* ensures core really is running the service function */
+       TEST_ASSERT_EQUAL(1, service_lcore_running_check(),
+                       "Service core expected to poll service but it didn't");
+
+       /* ensures that service may be active reports running state */
+       TEST_ASSERT_EQUAL(1, rte_service_may_be_active(sid),
+                       "Service may be active did not report running state");
+
+       /* stop the service */
+       TEST_ASSERT_EQUAL(0, rte_service_runstate_set(sid, 0),
+                       "Error: Service stop returned non-zero");
+
+       /* give the service 100ms to stop running */
+       for (i = 0; i < 100; i++) {
+               if (!rte_service_may_be_active(sid))
+                       break;
+               rte_delay_ms(SERVICE_DELAY);
+       }
+
+       TEST_ASSERT_EQUAL(0, rte_service_may_be_active(sid),
+                         "Error: Service not stopped after 100ms");
+
+       return unregister_all();
+}
+
 static struct unit_test_suite service_tests  = {
        .suite_name = "service core test suite",
        .setup = testsuite_setup,
@@ -906,6 +985,7 @@ static struct unit_test_suite service_tests  = {
                TEST_CASE_ST(dummy_register, NULL, service_app_lcore_mt_safe),
                TEST_CASE_ST(dummy_register, NULL, service_app_lcore_mt_unsafe),
                TEST_CASE_ST(dummy_register, NULL, service_may_be_active),
+               TEST_CASE_ST(dummy_register, NULL, service_active_two_cores),
                TEST_CASES_END() /**< NULL terminate unit test array */
        }
 };