From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, dmitry.kozliuk@gmail.com,
anatoly.burakov@intel.com,
Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v2 2/2] test/threads: add unit test for get set priority
Date: Mon, 23 May 2022 06:07:14 -0700 [thread overview]
Message-ID: <1653311234-329-3-git-send-email-roretzla@linux.microsoft.com> (raw)
In-Reply-To: <1653311234-329-1-git-send-email-roretzla@linux.microsoft.com>
Add unit tests to exercise and demonstrate rte_thread_{get,set}_priority().
Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
app/test/test_threads.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/app/test/test_threads.c b/app/test/test_threads.c
index e1a2ea5..dbc20e6 100644
--- a/app/test/test_threads.c
+++ b/app/test/test_threads.c
@@ -24,6 +24,56 @@
}
static int
+test_thread_priority(void)
+{
+ pthread_t id;
+ rte_thread_t thread_id;
+ enum rte_thread_priority priority;
+
+ thread_id_ready = 0;
+ RTE_TEST_ASSERT(pthread_create(&id, NULL, thread_main, &thread_id) == 0,
+ "Failed to create thread");
+
+ while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0)
+ ;
+
+ priority = RTE_THREAD_PRIORITY_NORMAL;
+ RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == 0,
+ "Failed to set thread priority");
+ RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0,
+ "Failed to get thread priority");
+ RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_NORMAL,
+ "Priority set mismatches priority get");
+
+ priority = RTE_THREAD_PRIORITY_REALTIME_CRITICAL;
+#ifndef RTE_EXEC_ENV_WINDOWS
+ RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == -ENOTSUP,
+ "Priority set to critical should fail");
+ 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 set to critical should have retained normal");
+#else
+ RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == 0,
+ "Priority set to critical should succeed");
+ RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0,
+ "Failed to get thread priority");
+ RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_REALTIME_CRITICAL,
+ "Priority set mismatches priority get");
+#endif
+
+ priority = RTE_THREAD_PRIORITY_NORMAL;
+ RTE_TEST_ASSERT(rte_thread_set_priority(thread_id, priority) == 0,
+ "Failed to set thread priority");
+ RTE_TEST_ASSERT(rte_thread_get_priority(thread_id, &priority) == 0,
+ "Failed to get thread priority");
+ RTE_TEST_ASSERT(priority == RTE_THREAD_PRIORITY_NORMAL,
+ "Priority set mismatches priority get");
+
+ return 0;
+}
+
+static int
test_thread_affinity(void)
{
pthread_t id;
@@ -31,6 +81,7 @@
rte_cpuset_t cpuset0;
rte_cpuset_t cpuset1;
+ thread_id_ready = 0;
RTE_TEST_ASSERT(pthread_create(&id, NULL, thread_main, &thread_id) == 0,
"Failed to create thread");
@@ -68,6 +119,7 @@
.teardown = NULL,
.unit_test_cases = {
TEST_CASE(test_thread_affinity),
+ TEST_CASE(test_thread_priority),
TEST_CASES_END()
}
};
--
1.8.3.1
next prev parent reply other threads:[~2022-05-23 13:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-23 10:46 [PATCH 0/2] add thread priority accessors Tyler Retzlaff
2022-05-23 10:46 ` [PATCH 1/2] eal: get/set thread priority per thread identifier Tyler Retzlaff
2022-05-23 10:46 ` [PATCH 2/2] test/threads: add unit test for get set priority Tyler Retzlaff
2022-05-23 10:52 ` Tyler Retzlaff
2022-05-23 13:07 ` [PATCH v2 0/2] add thread priority accessors Tyler Retzlaff
2022-05-23 13:07 ` [PATCH v2 1/2] eal: get/set thread priority per thread identifier Tyler Retzlaff
2022-05-23 13:07 ` Tyler Retzlaff [this message]
2022-05-24 11:08 ` [PATCH v3 0/2] add thread priority accessors Tyler Retzlaff
2022-05-24 11:08 ` [PATCH v3 1/2] eal: get/set thread priority per thread identifier Tyler Retzlaff
2022-05-24 14:51 ` Stephen Hemminger
2022-05-26 6:29 ` Tyler Retzlaff
2022-05-26 15:21 ` Stephen Hemminger
2022-05-27 11:15 ` Tyler Retzlaff
2022-05-24 11:08 ` [PATCH v3 2/2] test/threads: add unit test for get set priority Tyler Retzlaff
2022-06-07 10:39 ` [PATCH v3 0/2] add thread priority accessors David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1653311234-329-3-git-send-email-roretzla@linux.microsoft.com \
--to=roretzla@linux.microsoft.com \
--cc=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=dmitry.kozliuk@gmail.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).