Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testcases for cpu affinity and wait queue #2

Merged
merged 8 commits into from
Oct 17, 2024
Prev Previous commit
Next Next commit
[refactor] rename ax_wait_queue_wait_cond to ax_wait_queue_wait
hky1999 committed Oct 16, 2024
commit 7566d872f0b4b936c1e1a1c0d25250bd089e9d76
4 changes: 2 additions & 2 deletions rust/task/parallel/src/main.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ fn barrier() {
static BARRIER_COUNT: AtomicUsize = AtomicUsize::new(0);

BARRIER_COUNT.fetch_add(1, Ordering::Relaxed);
api::ax_wait_queue_wait_cond(
api::ax_wait_queue_wait_until(
&BARRIER_WQ,
|| BARRIER_COUNT.load(Ordering::Relaxed) == NUM_TASKS,
None,
@@ -60,7 +60,7 @@ fn main() {
#[cfg(feature = "axstd")]
{
// equals to sleep(500ms)
let timeout = api::ax_wait_queue_wait_cond(
let timeout = api::ax_wait_queue_wait_until(
&AxWaitQueueHandle::new(),
|| false,
Some(std::time::Duration::from_millis(500)),
18 changes: 9 additions & 9 deletions rust/task/wait_queue/src/main.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ fn test_wait() {
"task {:?} is waiting for tasks to start...",
axtask::current().id()
);
api::ax_wait_queue_wait_cond(&WQ1, || COUNTER.load(Ordering::Relaxed) == NUM_TASKS, None);
api::ax_wait_queue_wait_until(&WQ1, || COUNTER.load(Ordering::Relaxed) == NUM_TASKS, None);
assert_eq!(COUNTER.load(Ordering::Relaxed), NUM_TASKS);

api::ax_wait_queue_wake(&WQ2, u32::MAX); // WQ2.wait()
@@ -47,7 +47,7 @@ fn test_wait() {
"task {:?} is waiting for tasks to finish...",
axtask::current().id()
);
api::ax_wait_queue_wait_cond(&WQ1, || COUNTER.load(Ordering::Relaxed) == 0, None);
api::ax_wait_queue_wait_until(&WQ1, || COUNTER.load(Ordering::Relaxed) == 0, None);
assert_eq!(COUNTER.load(Ordering::Relaxed), 0);

println!("wait_queue: test_wait() OK!");
@@ -70,7 +70,7 @@ fn test_wait_timeout_until() {
// Sleep more than 60s, which exceeds the timeout limited by test script.
let time_to_wait_in_seconds = 100;
thread::spawn(move || {
let timeout = api::ax_wait_queue_wait_cond(
let timeout = api::ax_wait_queue_wait_until(
&WQ3,
// It is strange, but it is just for testing.
// We have to use `true` here to allow the task to be woken up by notification.
@@ -94,7 +94,7 @@ fn test_wait_timeout_until() {
// Wake up all tasks who are waiting for timeout.
api::ax_wait_queue_wake(&WQ3, u32::MAX);
// Wait for all tasks to finish (woken up by notification).
api::ax_wait_queue_wait_cond(&WQ4, || COUNTER2.load(Ordering::Relaxed) == NUM_TASKS, None);
api::ax_wait_queue_wait_until(&WQ4, || COUNTER2.load(Ordering::Relaxed) == NUM_TASKS, None);
assert_eq!(COUNTER2.load(Ordering::Relaxed), NUM_TASKS);

println!("wait_timeout_until: tasks woken up by notification test OK!");
@@ -110,7 +110,7 @@ fn test_wait_timeout_until() {

for _ in 0..NUM_TASKS {
thread::spawn(move || {
let timeout = api::ax_wait_queue_wait_cond(
let timeout = api::ax_wait_queue_wait_until(
&WQ3,
|| false,
// equals to sleep(0.1s)
@@ -126,7 +126,7 @@ fn test_wait_timeout_until() {

println!("wait_timeout_until: wait for all tasks to finish");
// Wait for all tasks to finish (woken up by timeout).
api::ax_wait_queue_wait_cond(&WQ4, || COUNTER2.load(Ordering::Relaxed) == 0, None);
api::ax_wait_queue_wait_until(&WQ4, || COUNTER2.load(Ordering::Relaxed) == 0, None);
assert_eq!(COUNTER2.load(Ordering::Relaxed), 0);

println!("wait_timeout_until: tasks woken up by timeout test OK!");
@@ -142,7 +142,7 @@ fn test_wait_timeout_until() {
for _ in 0..NUM_TASKS {
// Sleep just 100ms.
thread::spawn(move || {
let timeout = api::ax_wait_queue_wait_cond(
let timeout = api::ax_wait_queue_wait_until(
&WQ3,
|| CONDITION.load(Ordering::Relaxed),
// equals to sleep(0.1s)
@@ -162,13 +162,13 @@ fn test_wait_timeout_until() {

// Sleep for 100ms to let all tasks start and wait for timeout.
thread::sleep(Duration::from_millis(time_to_wait_in_millis - 10));
// Set condition to true to wake up all tasks who call `ax_wait_queue_wait_cond`.
// Set condition to true to wake up all tasks who call `ax_wait_queue_wait_until`.
CONDITION.store(true, Ordering::Relaxed);
// Wake up all tasks who are waiting for timeout.
api::ax_wait_queue_wake(&WQ3, u32::MAX);

// Wait for all tasks to finish (woken up by timeout).
api::ax_wait_queue_wait_cond(&WQ4, || COUNTER2.load(Ordering::Relaxed) == NUM_TASKS, None);
api::ax_wait_queue_wait_until(&WQ4, || COUNTER2.load(Ordering::Relaxed) == NUM_TASKS, None);
assert_eq!(COUNTER2.load(Ordering::Relaxed), NUM_TASKS);

println!("wait_timeout_until: test tasks woken up by notification or timeout, test OK!");