Signed-off-by: Tyler Retzlaff <roret...@linux.microsoft.com> --- app/test/test_lcores.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c index a6bb412..153b6f4 100644 --- a/app/test/test_lcores.c +++ b/app/test/test_lcores.c @@ -379,6 +379,55 @@ static void *ctrl_thread_loop(void *arg) } static int +test_lcores_set_get_name(void) +{ + char out[RTE_LCORE_NAME_MAX_LEN]; + char outcmp[RTE_LCORE_NAME_MAX_LEN]; + const unsigned int lcore_id = rte_get_main_lcore(); + const size_t outlen = sizeof(out); + const char empty[] = ""; + const char valid[] = "0123456789abcde"; + const char invalid[] = "0123456789abcdef"; + + memset(outcmp, 0xff, outlen); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, empty) == 0, + "Failed to set empty lcore name."); + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0, + "Failed to get empty lcore name."); + RTE_TEST_ASSERT(strcmp(empty, out) == 0, + "Failed to set and get empty lcore name."); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, valid) == 0, + "Failed to set valid lcore name."); + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0, + "Failed to get valid lcore name."); + RTE_TEST_ASSERT(strcmp(valid, out) == 0, + "Failed to set and get valid lcore name."); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_set_name(lcore_id, invalid) == -ERANGE, + "Failed to fail set with invalid lcore name."); + RTE_TEST_ASSERT(memcmp(outcmp, out, outlen) == 0, + "Failed to preserve caller buffer after set failure."); + + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen) == 0, + "Failed to get valid lcore name after set failure."); + RTE_TEST_ASSERT(strcmp(valid, out) == 0, + "Failed to preserve valid lcore name after set failure."); + + memset(out, 0xff, outlen); + RTE_TEST_ASSERT(rte_lcore_get_name(lcore_id, out, outlen - 1) == -EINVAL, + "Failed to fail get with output buffer too small."); + RTE_TEST_ASSERT(memcmp(outcmp, out, outlen) == 0, + "Failed to preserve caller buffer after get failure."); + + return TEST_SUCCESS; +} + +static int test_lcores(void) { unsigned int eal_threads_count = 0; @@ -411,6 +460,9 @@ static void *ctrl_thread_loop(void *arg) if (test_ctrl_thread() < 0) return TEST_FAILED; + if (test_lcores_set_get_name() < 0) + return TEST_FAILED; + return TEST_SUCCESS; } -- 1.8.3.1