Test queue discard without allocation or stale callbacks

This commit is contained in:
evgeny committed 2026-10-23 12:27:38 +02:00
1 parent caf37e9541
commit d2b195473d
1 file changed
+27
+27
View File
@@ -349,9 +349,36 @@ static int test_waiter_schedule_oom(int param) {
dispose(q); uasync_destroy(ua, 0); return 0;
}
static int test_discard(int indexed) {
struct UASYNC* ua = uasync_create(); CHECK(ua);
struct ll_queue* q = queue_new(ua, indexed ? 8 : 0, 0, indexed ? sizeof(int) : 0, "discard"); CHECK(q);
struct queue_waiter_handle deferred = {0}, busy = {0}; int calls = 0;
queue_set_waiter_defer(q, 1); queue_set_callback_defer(q, 1); queue_set_callback(q, count_cb, &calls);
CHECK_EQ(queue_waiter_wait(q, &deferred, count_cb, &calls), 1);
queue_set_empty_callback(q, count_cb, &calls); queue_set_on_get(q, count_cb, &calls);
for (int i = 0; i < 3; i++) {
struct ll_entry* e = new_entry(i, 12); CHECK(e); e->dgram = u_malloc(12); CHECK(e->dgram);
CHECK_EQ(indexed ? queue_data_put_with_index(q, e) : queue_data_put(q, e), 0);
}
struct ll_entry* first = queue_data_get(q); queue_dgram_free(first); queue_entry_free(first);
CHECK_EQ(queue_waiter_wait(q, &busy, count_cb, &calls), 0);
regression_fault_arm(FAULT_ALLOC, NULL, 0);
queue_clear(q);
CHECK(!regression_fault_hit()); regression_fault_reset();
CHECK_EQ(q->count, 0); CHECK_EQ(q->total_bytes, 0); CHECK(!q->head && !q->tail);
CHECK(!busy.internal && !deferred.call_soon_id && !q->resume_timeout_id && !q->on_get_call_soon_id);
CHECK_EQ(queue_check_consistency(q), 0);
for (int key = 0; indexed && key < 3; key++) CHECK(!queue_find_data_by_index(q, &key));
uasync_drain_immediate(ua); CHECK_EQ(calls, 0);
CHECK_EQ(indexed ? queue_data_put_with_index(q, new_entry(9, 5)) : queue_data_put(q, new_entry(9, 5)), 0);
queue_resume_callback(q); uasync_drain_immediate(ua); CHECK_EQ(calls, 1);
dispose(q); uasync_destroy(ua, 0); return 0;
}
#define CASE(name, fn, p) {name, fn, p}
int main(int argc, char** argv) {
const struct regression_case cases[] = {
CASE("discard/no-index-no-allocation", test_discard, 0), CASE("discard/index-no-allocation", test_discard, 1),
CASE("empty/refill-before-dispatch", test_empty_notification, 0),
CASE("empty/drain-before-dispatch", test_empty_notification, 1),
CASE("empty/drain-get", test_empty_notification, 2), CASE("empty/drain-remove", test_empty_notification, 3),