test/threads: add unit test for attributes

Test basic functionality and demonstrate use of following thread
attributes api. Additionally, test attributes are processed when
supplied to rte_thread_create().

    * rte_thread_attr_init
    * rte_thread_attr_set_affinity
    * rte_thread_attr_get_affinity
    * rte_thread_attr_set_priority

Signed-off-by: Narcisa Vasile <navasile@linux.microsoft.com>
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
This commit is contained in:
Tyler Retzlaff 2022-10-05 10:07:30 -07:00 committed by David Marchand
parent e1d35c1599
commit 4cba3e114b

View File

@ -165,6 +165,73 @@ test_thread_affinity(void)
return 0;
}
static int
test_thread_attributes_affinity(void)
{
rte_thread_t thread_id;
rte_thread_attr_t attr;
rte_cpuset_t cpuset0;
rte_cpuset_t cpuset1;
RTE_TEST_ASSERT(rte_thread_attr_init(&attr) == 0,
"Failed to initialize thread attributes");
CPU_ZERO(&cpuset0);
RTE_TEST_ASSERT(rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset0) == 0,
"Failed to get thread affinity");
RTE_TEST_ASSERT(rte_thread_attr_set_affinity(&attr, &cpuset0) == 0,
"Failed to set thread attributes affinity");
RTE_TEST_ASSERT(rte_thread_attr_get_affinity(&attr, &cpuset1) == 0,
"Failed to get thread attributes affinity");
RTE_TEST_ASSERT(memcmp(&cpuset0, &cpuset1, sizeof(rte_cpuset_t)) == 0,
"Affinity should be stable");
thread_id_ready = 0;
RTE_TEST_ASSERT(rte_thread_create(&thread_id, &attr, thread_main, NULL) == 0,
"Failed to create attributes affinity thread.");
while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
;
RTE_TEST_ASSERT(rte_thread_get_affinity_by_id(thread_id, &cpuset1) == 0,
"Failed to get attributes thread affinity");
RTE_TEST_ASSERT(memcmp(&cpuset0, &cpuset1, sizeof(rte_cpuset_t)) == 0,
"Failed to apply affinity attributes");
__atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
return 0;
}
static int
test_thread_attributes_priority(void)
{
rte_thread_t thread_id;
rte_thread_attr_t attr;
enum rte_thread_priority priority;
RTE_TEST_ASSERT(rte_thread_attr_init(&attr) == 0,
"Failed to initialize thread attributes");
RTE_TEST_ASSERT(rte_thread_attr_set_priority(&attr, RTE_THREAD_PRIORITY_NORMAL) == 0,
"Failed to set thread attributes priority");
thread_id_ready = 0;
RTE_TEST_ASSERT(rte_thread_create(&thread_id, &attr, thread_main, NULL) == 0,
"Failed to create attributes priority thread.");
while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
;
RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0,
"Failed to get thread priority");
RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_NORMAL,
"Failed to apply priority attributes");
__atomic_store_n(&thread_id_ready, 2, __ATOMIC_RELEASE);
return 0;
}
static struct unit_test_suite threads_test_suite = {
.suite_name = "threads autotest",
.setup = NULL,
@ -174,6 +241,8 @@ static struct unit_test_suite threads_test_suite = {
TEST_CASE(test_thread_create_detach),
TEST_CASE(test_thread_affinity),
TEST_CASE(test_thread_priority),
TEST_CASE(test_thread_attributes_affinity),
TEST_CASE(test_thread_attributes_priority),
TEST_CASES_END()
}
};