[dpdk-dev] [PATCH 5/6] service core: add unit tests
Jerin Jacob
jerin.jacob at caviumnetworks.com
Mon Jun 26 15:06:10 CEST 2017
-----Original Message-----
> Date: Fri, 23 Jun 2017 10:06:18 +0100
> From: Harry van Haaren <harry.van.haaren at intel.com>
> To: dev at dpdk.org
> CC: thomas at monjalon.net, jerin.jacob at caviumnetworks.com,
> keith.wiles at intel.com, bruce.richardson at intel.com, Harry van Haaren
> <harry.van.haaren at intel.com>
> Subject: [PATCH 5/6] service core: add unit tests
> X-Mailer: git-send-email 2.7.4
>
> Add a bunch of unit tests, to ensure that the service
> core functions are operating as expected.
>
> As part of these tests a dummy service is registered which
> allows identifying if a service callback has been invoked
> by using the CPU tick counter. This allows identifying if
> functions to start and stop service lcores are actually having
> effect.
>
> Signed-off-by: Harry van Haaren <harry.van.haaren at intel.com>
> ---
> +#define SERVICE_DELAY 1
> +
> +static int
> +testsuite_setup(void)
> +{
> + /* assuming lcore 1 is available for service-core testing */
We can check the number of available lcores is >= 2.
> + score_id = 1;
How about slcore_id?
> + return TEST_SUCCESS;
> +}
> +
> +static void
> +testsuite_teardown(void)
> +{
> + /* release service cores? */
> +}
> +
> +static int32_t dummy_cb(void *args)
> +{
> + RTE_SET_USED(args);
> + service_tick++;
> + rte_delay_ms(SERVICE_DELAY);
> + return 0;
> +}
> +
> +/* unregister all services */
> +static int
> +dummy_unregister(void)
How about unregister_all(void) as it is un registering all services.
> +{
> + uint32_t i;
> + struct rte_service_spec *dead = (struct rte_service_spec *)0xdead;
> +
> + TEST_ASSERT_EQUAL(-EINVAL, rte_service_unregister(0),
> + "Unregistered NULL pointer");
> + TEST_ASSERT_EQUAL(-EINVAL, rte_service_unregister(dead),
> + "Unregistered invalid pointer");
> +
> + uint32_t c = rte_service_get_count();
> + for (i = 0; i < c; i++) {
> + struct rte_service_spec *s = rte_service_get_by_id(i);
> + TEST_ASSERT_EQUAL(0, rte_service_unregister(s),
> + "Error unregistering a valid service");
> + }
> +
> + rte_service_core_reset_all();
> +
> + return TEST_SUCCESS;
> +}
> +
> +/* enable and disable a core for a service */
> +static int
> +service_core_enable_disable(void)
> +{
> + struct rte_service_spec *s = rte_service_get_by_id(0);
> +
> + /* expected failure cases */
> + TEST_ASSERT_EQUAL(-EINVAL, rte_service_enable_on_core(s, 100000),
> + "Enable on invalid core did not fail");
> + TEST_ASSERT_EQUAL(-EINVAL, rte_service_disable_on_core(s, 100000),
> + "Dispable on invalid core did not fail");
s/Dispable/Disable
> +
> + /* add service core to allow enabling */
> + TEST_ASSERT_EQUAL(0, rte_service_core_add(score_id),
> + "Add service core failed when not in use before");
> +
> + /* valid enable */
> + TEST_ASSERT_EQUAL(0, rte_service_enable_on_core(s, score_id),
> + "Enabling valid service and core failed");
> + TEST_ASSERT_EQUAL(1, rte_service_get_enabled_on_core(s, score_id),
> + "Enabled core returned not-enabled");
> +
> + /* valid disable */
> + TEST_ASSERT_EQUAL(0, rte_service_disable_on_core(s, score_id),
> + "Disabling valid service and core failed");
> + TEST_ASSERT_EQUAL(0, rte_service_get_enabled_on_core(s, score_id),
> + "Disabled core returned enabled");
> +
> + return dummy_unregister();
> +}
> +
> +static struct unit_test_suite service_tests = {
> + .suite_name = "service core test suite",
> + .setup = testsuite_setup,
> + .teardown = testsuite_teardown,
> + .unit_test_cases = {
> + TEST_CASE_ST(dummy_register, NULL, dummy_unregister),
> + TEST_CASE_ST(dummy_register, NULL, service_start_stop),
> + TEST_CASE_ST(dummy_register, NULL, service_core_add_del),
> + TEST_CASE_ST(dummy_register, NULL, service_core_start_stop),
> + TEST_CASE_ST(dummy_register, NULL, service_core_enable_disable),
IMO, Following functions/functionality coverage is missing. How about add that
in unit test case.
1) rte_service_get_name()
2) Verify RTE_SERVICE_CAP_MT_SAFE with available lcores
3) rte_service_probe_capability()
4) rte_service_dump()
5) Moving service lcore to/from rte lcore back and forth.
More information about the dev
mailing list