72 lines
2.6 KiB
C
72 lines
2.6 KiB
C
// Simple test to verify input_queue_try_resume logic
|
|
#include "src/etcp.h"
|
|
#include "lib/ll_queue.h"
|
|
#include "lib/u_async.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main() {
|
|
printf("Testing input_queue_try_resume logic...\n");
|
|
|
|
// Create a mock ETCP_CONN structure
|
|
struct ETCP_CONN etcp = {0};
|
|
|
|
// Create uasync instance for queues
|
|
struct UASYNC* ua = uasync_new();
|
|
if (!ua) {
|
|
printf("Failed to create uasync instance\n");
|
|
return 1;
|
|
}
|
|
|
|
// Create queues
|
|
etcp.input_send_q = queue_new(ua, 0);
|
|
etcp.input_wait_ack = queue_new(ua, 0);
|
|
|
|
if (!etcp.input_send_q || !etcp.input_wait_ack) {
|
|
printf("Failed to create queues\n");
|
|
return 1;
|
|
}
|
|
|
|
// Test case 1: Both queues empty, optimal_inflight = 100
|
|
etcp.optimal_inflight = 100;
|
|
printf("Test 1: Empty queues, optimal_inflight=100\n");
|
|
printf(" input_send_q bytes: %zu\n", queue_total_bytes(etcp.input_send_q));
|
|
printf(" input_wait_ack bytes: %zu\n", queue_total_bytes(etcp.input_wait_ack));
|
|
printf(" Total: %zu (should be \u003c 100)\n",
|
|
queue_total_bytes(etcp.input_send_q) + queue_total_bytes(etcp.input_wait_ack));
|
|
|
|
// Test case 2: Add some data to make total > optimal_inflight
|
|
printf("\nTest 2: Adding data to exceed optimal_inflight\n");
|
|
|
|
// Add 60 bytes to send queue
|
|
void* data1 = queue_data_new(60);
|
|
queue_data_put(etcp.input_send_q, data1, 1);
|
|
|
|
printf(" input_send_q bytes: %zu\n", queue_total_bytes(etcp.input_send_q));
|
|
printf(" input_wait_ack bytes: %zu\n", queue_total_bytes(etcp.input_wait_ack));
|
|
printf(" Total: %zu (should be \u003e= 100)\n",
|
|
queue_total_bytes(etcp.input_send_q) + queue_total_bytes(etcp.input_wait_ack));
|
|
|
|
// Test case 3: Add more data to wait_ack queue
|
|
printf("\nTest 3: Adding data to wait_ack queue\n");
|
|
|
|
void* data2 = queue_data_new(50);
|
|
queue_data_put(etcp.input_wait_ack, data2, 2);
|
|
|
|
printf(" input_send_q bytes: %zu\n", queue_total_bytes(etcp.input_send_q));
|
|
printf(" input_wait_ack bytes: %zu\n", queue_total_bytes(etcp.input_wait_ack));
|
|
printf(" Total: %zu (should be \u003e 100)\n",
|
|
queue_total_bytes(etcp.input_send_q) + queue_total_bytes(etcp.input_wait_ack));
|
|
|
|
// Cleanup
|
|
queue_free(etcp.input_send_q);
|
|
queue_free(etcp.input_wait_ack);
|
|
uasync_free(ua);
|
|
|
|
printf("\n✅ Logic test completed successfully!\n");
|
|
printf("The input_queue_try_resume function should:\n");
|
|
printf("- Resume when total_bytes \u003c optimal_inflight\n");
|
|
printf("- Not resume when total_bytes \u003e= optimal_inflight\n");
|
|
|
|
return 0;
|
|
} |