1
This commit is contained in:
1 parent
226a5744b5
commit
4556f327c2
10 files changed
+63
-94
No files matched your search
+14
-24
@@ -177,9 +177,8 @@ static void test_waiter(void) {
|
||||
queue_set_threshold(q, 2, 0);
|
||||
|
||||
int called = 0;
|
||||
struct queue_waiter_handle h;
|
||||
queue_waiter_handle_init(&h, waiter_cb, &called);
|
||||
int ret = queue_waiter_wait(q, &h);
|
||||
struct queue_waiter_handle h = {0};
|
||||
int ret = queue_waiter_wait(q, &h, waiter_cb, &called);
|
||||
ASSERT(ret == 1 && called == 1, "immediate when condition met"); // empty queue
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -188,7 +187,7 @@ static void test_waiter(void) {
|
||||
}
|
||||
|
||||
called = 0;
|
||||
ret = queue_waiter_wait(q, &h);
|
||||
ret = queue_waiter_wait(q, &h, waiter_cb, &called);
|
||||
ASSERT(ret == 0 && called == 0, "");
|
||||
|
||||
for (int i = 0; i < 3; i++) queue_entry_free((struct ll_entry*)queue_data_get(q));
|
||||
@@ -214,11 +213,8 @@ static void test_waiter_multiple(void) {
|
||||
|
||||
waiter_order_idx = 0;
|
||||
int ids[4] = {10, 20, 30, 40};
|
||||
struct queue_waiter_handle handles[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
queue_waiter_handle_init(&handles[i], waiter_cb_order, &ids[i]);
|
||||
ASSERT(queue_waiter_wait(q, &handles[i]) == 0, "should queue");
|
||||
}
|
||||
struct queue_waiter_handle handles[4] = {0};
|
||||
for (int i = 0; i < 4; i++) ASSERT(queue_waiter_wait(q, &handles[i], waiter_cb_order, &ids[i]) == 0, "should queue");
|
||||
|
||||
for (int i = 0; i < 5; i++) queue_entry_free((struct ll_entry*)queue_data_get(q));
|
||||
ASSERT_EQ(waiter_order_idx, 3, "3 waiters fired");
|
||||
@@ -242,11 +238,8 @@ static void test_waiter_cancel(void) {
|
||||
|
||||
waiter_order_idx = 0;
|
||||
int ids[3] = {1, 2, 3};
|
||||
struct queue_waiter_handle handles[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
queue_waiter_handle_init(&handles[i], waiter_cb_order, &ids[i]);
|
||||
queue_waiter_wait(q, &handles[i]); // count=10 > 3, all queued
|
||||
}
|
||||
struct queue_waiter_handle handles[3] = {0};
|
||||
for (int i = 0; i < 3; i++) queue_waiter_wait(q, &handles[i], waiter_cb_order, &ids[i]); // count=10 > 3, all queued
|
||||
|
||||
queue_waiter_cancel(q, &handles[1]); // cancel middle (ID 2)
|
||||
|
||||
@@ -270,9 +263,8 @@ static void test_waiter_queue_free(void) {
|
||||
}
|
||||
|
||||
int called = 0;
|
||||
struct queue_waiter_handle h;
|
||||
queue_waiter_handle_init(&h, waiter_cb, &called);
|
||||
queue_waiter_wait(q, &h);
|
||||
struct queue_waiter_handle h = {0};
|
||||
queue_waiter_wait(q, &h, waiter_cb, &called);
|
||||
ASSERT(h.internal != NULL, "waiter is queued");
|
||||
|
||||
queue_free(q);
|
||||
@@ -293,9 +285,8 @@ static void test_waiter_threshold(void) {
|
||||
}
|
||||
|
||||
int called = 0;
|
||||
struct queue_waiter_handle h;
|
||||
queue_waiter_handle_init(&h, waiter_cb, &called);
|
||||
int ret = queue_waiter_wait(q, &h);
|
||||
struct queue_waiter_handle h = {0};
|
||||
int ret = queue_waiter_wait(q, &h, waiter_cb, &called);
|
||||
ASSERT(ret == 0 && called == 0, "queued (10 > 0)");
|
||||
|
||||
queue_set_threshold(q, 10, 0); // raise threshold
|
||||
@@ -313,10 +304,9 @@ static void test_waiter_reuse(void) {
|
||||
struct ll_queue *q = queue_new(ua, 0, 0, 0, "wr");
|
||||
|
||||
int called = 0;
|
||||
struct queue_waiter_handle h;
|
||||
queue_waiter_handle_init(&h, waiter_cb, &called);
|
||||
struct queue_waiter_handle h = {0};
|
||||
|
||||
int ret = queue_waiter_wait(q, &h);
|
||||
int ret = queue_waiter_wait(q, &h, waiter_cb, &called);
|
||||
ASSERT(ret == 1 && called == 1, "immediate (empty queue)");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -325,7 +315,7 @@ static void test_waiter_reuse(void) {
|
||||
}
|
||||
|
||||
called = 0;
|
||||
ret = queue_waiter_wait(q, &h);
|
||||
ret = queue_waiter_wait(q, &h, waiter_cb, &called);
|
||||
ASSERT(ret == 0 && called == 0, "queued");
|
||||
|
||||
for (int i = 0; i < 3; i++) queue_entry_free((struct ll_entry*)queue_data_get(q));
|
||||
|
||||
Reference in new issue
Block a user