Skip to content

Commit d25f9f1

Browse files
add intrusive tx test
1 parent 262cd10 commit d25f9f1

File tree

7 files changed

+1054
-3
lines changed

7 files changed

+1054
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*build/
2323
cmake-build-*/
2424
build-avr/
25+
.cache/
2526
.metadata
2627
.settings
2728
.project

.zed/tasks.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
{
3+
"label": "Configure (CMake)",
4+
"command": "cmake -B build",
5+
"tags": ["build"]
6+
},
7+
{
8+
"label": "Build",
9+
"command": "cmake --build build",
10+
"tags": ["build"]
11+
},
12+
{
13+
"label": "Configure and Build",
14+
"command": "cmake -B build && cmake --build build",
15+
"tags": ["build"]
16+
},
17+
{
18+
"label": "Run Tests",
19+
"command": "ctest --test-dir build --output-on-failure",
20+
"tags": ["test"]
21+
},
22+
{
23+
"label": "Clean",
24+
"command": "rm -rf build",
25+
"tags": ["build"]
26+
},
27+
{
28+
"label": "Format Code",
29+
"command": "cmake --build build --target format",
30+
"tags": ["format"]
31+
},
32+
{
33+
"label": "Full Build and Test",
34+
"command": "cmake -B build && cmake --build build && ctest --test-dir build --output-on-failure",
35+
"tags": ["build", "test"]
36+
}
37+
]

AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# LibUDPard instructions for agents
2+
3+
Please read README.md for general information about LibUDPard.
4+
Read `.clang-format` and `**/.clang-tidy` to understand the coding style used in this project.
5+
Avoid blank lines inside function bodies. Avoid redundant comments that do not add new information.

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ cmake_minimum_required(VERSION 3.20)
1212
project(udpard)
1313
enable_testing()
1414

15+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
16+
1517
# Shared Clang-Format target for all subprojects.
1618
find_program(clang_format NAMES clang-format)
1719
if (NOT clang_format)

libudpard/udpard.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,23 +436,25 @@ static uint32_t tx_push(udpard_tx_t* const tx,
436436
static uint64_t tx_purge_expired(udpard_tx_t* const self, const udpard_microsecond_t now)
437437
{
438438
uint64_t count = 0;
439-
for (udpard_tree_t* p = cavl2_min(self->index_deadline); p != NULL; p = cavl2_next_greater(p)) {
439+
for (udpard_tree_t* p = cavl2_min(self->index_deadline); p != NULL;) {
440440
udpard_tx_item_t* const item = CAVL2_TO_OWNER(p, udpard_tx_item_t, index_deadline);
441441
if (item->deadline >= now) {
442442
break;
443443
}
444+
udpard_tree_t* const next = cavl2_next_greater(p); // Get next before removing current node from tree.
444445
// Remove from both indices.
445446
cavl2_remove(&self->index_deadline, &item->index_deadline);
446447
cavl2_remove(&self->index_prio, &item->index_prio);
447448
// Free the entire transfer chain.
448449
udpard_tx_item_t* current = item;
449450
while (current != NULL) {
450-
udpard_tx_item_t* const next = current->next_in_transfer;
451+
udpard_tx_item_t* const next_in_transfer = current->next_in_transfer;
451452
udpard_tx_free(self->memory, current);
452-
current = next;
453+
current = next_in_transfer;
453454
count++;
454455
self->queue_size--;
455456
}
457+
p = next;
456458
}
457459
return count;
458460
}

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ endfunction()
8080
gen_test_matrix(test_helpers "src/test_helpers.c")
8181
gen_test_matrix(test_intrusive_header "src/test_intrusive_header.c")
8282
gen_test_matrix(test_intrusive_crc "src/test_intrusive_crc.c")
83+
gen_test_matrix(test_intrusive_tx "src/test_intrusive_tx.c")

0 commit comments

Comments
 (0)