summaryrefslogtreecommitdiff
path: root/tests/t_event.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-26 20:03:22 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-26 20:03:22 +0100
commit2d6b6d4da1d9732b2b02989a4374d356ff840d1b (patch)
tree50ff9d2fba93934d1572706f10593aec0ea57e07 /tests/t_event.c
parentf2f5b0450d4b7269bafdfb1bd1788303f6d8ce7b (diff)
Replace libowfat's event waiter with our own abstraction
It's with a heavy heart that I remove libowfat as my event library from opentracker. libowfat is what taught opentracker to walk and then fly. The tracker was literally standing on the shoulder of giants when I started writing it in 2006. For its time, the event abstraction was unparalleled and it has held up for many years, and it served the bittorrent community greatly. https://erdgeist.org/gitweb/opentracker/commit/?id=ad472597c569568bad0526d116b601dfcb36638c Unfortunately, it is very likely that libowfat will not be maintained anymore for the foreseeable future, it is already not easy to get its source from upstream and opentracker started receiving bug reports that I can not reasonably answer or patch. Before the project gets more dependent on the limitations of libowfat's current state, I need to teach opentracker to stand on its own feet and fly by itself. I've learned a great deal in the process and have even more respect now for what libowfat pioneered. The path for opentracker is cleared now. Ground work has already been laid in the migration process to support multi threaded http processing while keeping the aggressive reduction of syscalls alive that made the libowfat+opentracker combo so scalable. Here be some dragons, though: Even though there is a unit test suite now, the event loop's rewrite has not been battle tested yet. So you might want to hold up for a bit before jumping on the solo band wagon. What awaits at the end will be a long overdue v1.0, which will be named in honour of Felix.
Diffstat (limited to 'tests/t_event.c')
-rw-r--r--tests/t_event.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/tests/t_event.c b/tests/t_event.c
index 306f8cd..5509f19 100644
--- a/tests/t_event.c
+++ b/tests/t_event.c
@@ -59,18 +59,18 @@ static void case_readable(void) {
59 test_case("a descriptor with something to read is reported, with its generation"); 59 test_case("a descriptor with something to read is reported, with its generation");
60 pair_open(); 60 pair_open();
61 CHECK(sv[0] != -1); 61 CHECK(sv[0] != -1);
62 CHECK_INT(event_add(sv[0], EVENT_READ, 4711), 0); 62 CHECK_INT(event_add(sv[0], EVENT_IN, 4711), 0);
63 CHECK_INT(write(sv[1], "x", 1), 1); 63 CHECK_INT(write(sv[1], "x", 1), 1);
64 CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, &generation), 1); 64 CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, &generation), 1);
65 CHECK_INT(generation, 4711); 65 CHECK_INT(generation, 4711);
66 66
67 test_case("and keeps being reported until it is read"); 67 test_case("and keeps being reported until it is read");
68 CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, NULL), 1); 68 CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, NULL), 1);
69 { 69 {
70 char scratch[4]; 70 char scratch[4];
71 CHECK_INT(read(sv[0], scratch, sizeof(scratch)), 1); 71 CHECK_INT(read(sv[0], scratch, sizeof(scratch)), 1);
72 } 72 }
73 CHECK_INT(wait_for(sv[0], EVENT_READ, 50, NULL), 0); 73 CHECK_INT(wait_for(sv[0], EVENT_IN, 50, NULL), 0);
74 74
75 CHECK_INT(event_del(sv[0]), 0); 75 CHECK_INT(event_del(sv[0]), 0);
76 pair_close(); 76 pair_close();
@@ -80,12 +80,12 @@ static void case_writable(void) {
80 test_case("a descriptor with room to write is reported"); 80 test_case("a descriptor with room to write is reported");
81 pair_open(); 81 pair_open();
82 CHECK(sv[0] != -1); 82 CHECK(sv[0] != -1);
83 CHECK_INT(event_add(sv[0], EVENT_WRITE, 1), 0); 83 CHECK_INT(event_add(sv[0], EVENT_OUT, 1), 0);
84 CHECK_INT(wait_for(sv[0], EVENT_WRITE, 1000, NULL), 1); 84 CHECK_INT(wait_for(sv[0], EVENT_OUT, 1000, NULL), 1);
85 85
86 test_case("and is not, once we say we no longer care"); 86 test_case("and is not, once we say we no longer care");
87 CHECK_INT(event_modify(sv[0], EVENT_READ, 1), 0); 87 CHECK_INT(event_modify(sv[0], EVENT_IN, 1), 0);
88 CHECK_INT(wait_for(sv[0], EVENT_WRITE, 50, NULL), 0); 88 CHECK_INT(wait_for(sv[0], EVENT_OUT, 50, NULL), 0);
89 89
90 CHECK_INT(event_del(sv[0]), 0); 90 CHECK_INT(event_del(sv[0]), 0);
91 pair_close(); 91 pair_close();
@@ -95,13 +95,13 @@ static void case_interest_is_separate(void) {
95 test_case("asking only about writing does not report reading"); 95 test_case("asking only about writing does not report reading");
96 pair_open(); 96 pair_open();
97 CHECK(sv[0] != -1); 97 CHECK(sv[0] != -1);
98 CHECK_INT(event_add(sv[0], EVENT_WRITE, 1), 0); 98 CHECK_INT(event_add(sv[0], EVENT_OUT, 1), 0);
99 CHECK_INT(write(sv[1], "x", 1), 1); 99 CHECK_INT(write(sv[1], "x", 1), 1);
100 CHECK_INT(wait_for(sv[0], EVENT_READ, 50, NULL), 0); 100 CHECK_INT(wait_for(sv[0], EVENT_IN, 50, NULL), 0);
101 101
102 test_case("until we ask about it"); 102 test_case("until we ask about it");
103 CHECK_INT(event_modify(sv[0], EVENT_READ | EVENT_WRITE, 1), 0); 103 CHECK_INT(event_modify(sv[0], EVENT_IN | EVENT_OUT, 1), 0);
104 CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, NULL), 1); 104 CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, NULL), 1);
105 105
106 CHECK_INT(event_del(sv[0]), 0); 106 CHECK_INT(event_del(sv[0]), 0);
107 pair_close(); 107 pair_close();
@@ -111,11 +111,11 @@ static void case_removed_is_silent(void) {
111 test_case("a removed descriptor is not reported again"); 111 test_case("a removed descriptor is not reported again");
112 pair_open(); 112 pair_open();
113 CHECK(sv[0] != -1); 113 CHECK(sv[0] != -1);
114 CHECK_INT(event_add(sv[0], EVENT_READ, 1), 0); 114 CHECK_INT(event_add(sv[0], EVENT_IN, 1), 0);
115 CHECK_INT(write(sv[1], "x", 1), 1); 115 CHECK_INT(write(sv[1], "x", 1), 1);
116 CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, NULL), 1); 116 CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, NULL), 1);
117 CHECK_INT(event_del(sv[0]), 0); 117 CHECK_INT(event_del(sv[0]), 0);
118 CHECK_INT(wait_for(sv[0], EVENT_READ, 50, NULL), 0); 118 CHECK_INT(wait_for(sv[0], EVENT_IN, 50, NULL), 0);
119 pair_close(); 119 pair_close();
120} 120}
121 121
@@ -127,21 +127,21 @@ static void case_generations_do_not_mix(void) {
127 pair_open(); 127 pair_open();
128 CHECK(sv[0] != -1); 128 CHECK(sv[0] != -1);
129 CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, other), 0); 129 CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, other), 0);
130 CHECK_INT(event_add(sv[0], EVENT_READ, 100), 0); 130 CHECK_INT(event_add(sv[0], EVENT_IN, 100), 0);
131 CHECK_INT(event_add(other[0], EVENT_READ, 200), 0); 131 CHECK_INT(event_add(other[0], EVENT_IN, 200), 0);
132 CHECK_INT(write(sv[1], "x", 1), 1); 132 CHECK_INT(write(sv[1], "x", 1), 1);
133 CHECK_INT(write(other[1], "y", 1), 1); 133 CHECK_INT(write(other[1], "y", 1), 1);
134 134
135 CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, &generation), 1); 135 CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, &generation), 1);
136 CHECK_INT(generation, 100); 136 CHECK_INT(generation, 100);
137 CHECK_INT(wait_for(other[0], EVENT_READ, 1000, &generation), 1); 137 CHECK_INT(wait_for(other[0], EVENT_IN, 1000, &generation), 1);
138 CHECK_INT(generation, 200); 138 CHECK_INT(generation, 200);
139 139
140 test_case("and re-registering one changes only its own"); 140 test_case("and re-registering one changes only its own");
141 CHECK_INT(event_modify(sv[0], EVENT_READ, 101), 0); 141 CHECK_INT(event_modify(sv[0], EVENT_IN, 101), 0);
142 CHECK_INT(wait_for(sv[0], EVENT_READ, 1000, &generation), 1); 142 CHECK_INT(wait_for(sv[0], EVENT_IN, 1000, &generation), 1);
143 CHECK_INT(generation, 101); 143 CHECK_INT(generation, 101);
144 CHECK_INT(wait_for(other[0], EVENT_READ, 1000, &generation), 1); 144 CHECK_INT(wait_for(other[0], EVENT_IN, 1000, &generation), 1);
145 CHECK_INT(generation, 200); 145 CHECK_INT(generation, 200);
146 146
147 event_del(sv[0]); 147 event_del(sv[0]);
@@ -162,23 +162,23 @@ static void case_delete_from_the_middle(void) {
162 test_case("deleting one of three leaves the others reported correctly"); 162 test_case("deleting one of three leaves the others reported correctly");
163 for (i = 0; i < 3; ++i) { 163 for (i = 0; i < 3; ++i) {
164 CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, pair[i]), 0); 164 CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, pair[i]), 0);
165 CHECK_INT(event_add(pair[i][0], EVENT_READ, (uint32_t)(10 + i)), 0); 165 CHECK_INT(event_add(pair[i][0], EVENT_IN, (uint32_t)(10 + i)), 0);
166 } 166 }
167 CHECK_INT(event_del(pair[1][0]), 0); 167 CHECK_INT(event_del(pair[1][0]), 0);
168 168
169 for (i = 0; i < 3; i += 2) { 169 for (i = 0; i < 3; i += 2) {
170 CHECK_INT(write(pair[i][1], "x", 1), 1); 170 CHECK_INT(write(pair[i][1], "x", 1), 1);
171 CHECK_INT(wait_for(pair[i][0], EVENT_READ, 1000, &generation), 1); 171 CHECK_INT(wait_for(pair[i][0], EVENT_IN, 1000, &generation), 1);
172 CHECK_INT(generation, 10 + i); 172 CHECK_INT(generation, 10 + i);
173 } 173 }
174 174
175 test_case("and the survivors can still be changed and removed"); 175 test_case("and the survivors can still be changed and removed");
176 CHECK_INT(event_modify(pair[2][0], EVENT_READ, 99), 0); 176 CHECK_INT(event_modify(pair[2][0], EVENT_IN, 99), 0);
177 CHECK_INT(wait_for(pair[2][0], EVENT_READ, 1000, &generation), 1); 177 CHECK_INT(wait_for(pair[2][0], EVENT_IN, 1000, &generation), 1);
178 CHECK_INT(generation, 99); 178 CHECK_INT(generation, 99);
179 CHECK_INT(event_del(pair[0][0]), 0); 179 CHECK_INT(event_del(pair[0][0]), 0);
180 CHECK_INT(event_del(pair[2][0]), 0); 180 CHECK_INT(event_del(pair[2][0]), 0);
181 CHECK_INT(wait_for(pair[2][0], EVENT_READ, 50, NULL), 0); 181 CHECK_INT(wait_for(pair[2][0], EVENT_IN, 50, NULL), 0);
182 182
183 for (i = 0; i < 3; ++i) 183 for (i = 0; i < 3; ++i)
184 close(pair[i][0]), close(pair[i][1]); 184 close(pair[i][0]), close(pair[i][1]);
@@ -201,7 +201,7 @@ static void case_timeout(void) {
201 201
202static void case_unknown_descriptor(void) { 202static void case_unknown_descriptor(void) {
203 test_case("changing or removing one that was never added is refused"); 203 test_case("changing or removing one that was never added is refused");
204 CHECK_INT(event_modify(4096, EVENT_READ, 1), -1); 204 CHECK_INT(event_modify(4096, EVENT_IN, 1), -1);
205 CHECK_INT(event_del(4096), -1); 205 CHECK_INT(event_del(4096), -1);
206} 206}
207 207