include/hyperman/hm_abi_impl.h

filter: Statementstmt 95.8% 316 / 338 (37 uncoverable) Branchbran 83.3% 131 / 252 (92 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 90.5% 447 / 590 (129 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/hyperman/hm_compat.h ↑ Summary include/hyperman/hm_tls.h »
1 #ifndef HM_ABI_IMPL_H
2 #define HM_ABI_IMPL_H
3  
4 /* Provider side of the public C ABI (hm_abi.h): thin wrappers translating
5 * the stable table entries onto the hm_* / hmf_* internals, plus the filled
6 * table itself. Consumers reach it via Hyperman::_abi_ptr (xs/abi.xs).
7 * Requires hm_future.h and hm_core.h (included before this file). */
8  
9 /*
10 # uncoverable statement
11 # uncoverable subroutine */
12 0 static void *hm_abi_cur_loop(pTHX) {
13 PERL_UNUSED_CONTEXT;
14 0 return (void *)hm_cur_loop; /* # uncoverable statement */
15 }
16  
17 /*
18 # uncoverable statement
19 # uncoverable subroutine */
20 0 static void *hm_abi_loop_of_sv(pTHX_ SV *loop_sv) {
21 0 return (void *)hm_loop_from_sv(aTHX_ loop_sv); /* # uncoverable statement */
22 }
23  
24 /* Shared wrapper, same caching as psgix.loop: one blessed SV per loop, so a
25 * consumer never holds a second independently-destroyed wrapper. */
26 /*
27 # uncoverable statement
28 # uncoverable subroutine */
29 0 static SV *hm_abi_sv_of_loop(pTHX_ void *vl) {
30 0 hm_loop *loop = (hm_loop *)vl; /* # uncoverable statement */
31 0 return hm_loop_to_sv(aTHX_ loop); /* # uncoverable statement */
32 }
33  
34 1 static void hm_abi_io_watch(pTHX_ void *vl, int fd, int mask,
35 hm_abi_io_cb cb, void *ud) {
36 1 hm_add_io_watch_c(aTHX_ (hm_loop *)vl, fd, mask, cb, ud);
37 1 }
38  
39 1 static void hm_abi_io_unwatch(pTHX_ void *vl, int fd, int mask) {
40 1 hm_del_io_watch(aTHX_ (hm_loop *)vl, fd, mask);
41 1 }
42  
43 62 static hm_abi_timer *hm_abi_timer_add(pTHX_ void *vl, double secs,
44 hm_abi_timer_cb cb, void *ud) {
45 PERL_UNUSED_CONTEXT;
46 62 return (hm_abi_timer *)hm_add_timer_watch_c((hm_loop *)vl, secs, cb, ud);
47 }
48  
49 11 static void hm_abi_timer_cancel(pTHX_ void *vl, hm_abi_timer *t) {
50 11 hm_del_timer_watch(aTHX_ (hm_loop *)vl, (hm_tw *)t);
51 11 }
52  
53 44 static SV *hm_abi_future_new(pTHX) {
54 44 return hmf_new(aTHX_ "Hyperman::Future");
55 }
56  
57 1 static int hm_abi_is_future(pTHX_ SV *sv) {
58 1 return hmf_is_future(aTHX_ sv);
59 }
60  
61 /* The C doors never croak over something that is not a future: a croak is
62 * a longjmp through the consumer's frames. A non-future reads as -1 from
63 * state and is ignored by the rest; is_future is there to ask first. */
64 5 static IV hm_abi_future_state(pTHX_ SV *f) {
65 /*
66 # uncoverable branch true
67 # uncoverable condition left count:1 class:ignore_covered_err */
68 5 ▶ if (!hmf_is_future(aTHX_ f)) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!hmf_is_future(aTHX_ f)) return -1; 0 5 5
69 5 return hmf_state(aTHX_ f);
70 }
71  
72 44 static void hm_abi_future_done(pTHX_ SV *f, SV **vals, SSize_t n) {
73 44 ▶ if (!hmf_is_future(aTHX_ f) || hmf_state(aTHX_ f) != HMF_PENDING) return; /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (!hmf_is_future(aTHX_ f) || hmf_state(aTHX_ f) != HMF_PENDING) return; /* # uncoverable condition left count:1 class:ignore_covered_err */ 44 0 44
if (!hmf_is_future(aTHX_ f) || hmf_state(aTHX_ f) != HMF_PENDING) return; /* # uncoverable condition left count:1 class:ignore_covered_err */ 1 43 44
74 43 hmf_settle(aTHX_ f, HMF_DONE, vals, n);
75 }
76  
77 1 static void hm_abi_future_fail(pTHX_ SV *f, SV *err) {
78 /*
79 # uncoverable branch true class:ignore_covered_err
80 # uncoverable condition left count:1 class:ignore_covered_err
81 # uncoverable condition left count:2 class:ignore_covered_err */
82 1 ▶ if (!hmf_is_future(aTHX_ f) || hmf_state(aTHX_ f) != HMF_PENDING) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!hmf_is_future(aTHX_ f) || hmf_state(aTHX_ f) != HMF_PENDING) return; 1 0 1
if (!hmf_is_future(aTHX_ f) || hmf_state(aTHX_ f) != HMF_PENDING) return; 0 1 1
83 1 hmf_settle(aTHX_ f, HMF_FAILED, &err, 1);
84 }
85  
86 /* on_ready continuation body: unbox the C fn + ud from the closure and call
87 * it with the future (ST(0), pushed by the fire queue). */
88 XS_INTERNAL(hm_xs_abi_ready_cb);
89 1 XS_INTERNAL(hm_xs_abi_ready_cb) {
90 1 dXSARGS;
91 1 hm_clos *cl = hm_clos_of(aTHX_ cv);
92 hm_abi_ready_cb cb;
93 /*
94 # uncoverable branch true class:ignore_covered_err
95 # uncoverable condition left count:1 class:ignore_covered_err
96 # uncoverable condition left count:2 class:ignore_covered_err */
97 1 ▶ if (!cl || items < 1) XSRETURN_EMPTY;
Branch: 2 branches
BranchTrueFalseTotal
if (!cl || items < 1) XSRETURN_EMPTY; 1 0 1
if (!cl || items < 1) XSRETURN_EMPTY; 0 1 1
98 1 cb = (hm_abi_ready_cb)INT2PTR(void *, cl->i);
99 1 cb(aTHX_ ST(0), INT2PTR(void *, cl->u));
100 1 XSRETURN_EMPTY;
101 }
102  
103 1 static void hm_abi_future_on_ready(pTHX_ SV *f, hm_abi_ready_cb cb, void *ud) {
104 SV *cbsv;
105 /*
106 # uncoverable branch true
107 # uncoverable condition left count:1 class:ignore_covered_err */
108 1 ▶ if (!hmf_is_future(aTHX_ f)) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!hmf_is_future(aTHX_ f)) return; 0 1 1
109 1 cbsv = hm_closure(aTHX_ hm_xs_abi_ready_cb, NULL, NULL, NULL, NULL,
110 PTR2IV(cb), PTR2UV(ud));
111 1 hmf_on_ready(aTHX_ f, cbsv);
112 1 SvREFCNT_dec(cbsv);
113 }
114  
115 42 static void hm_abi_run_until(pTHX_ void *vl, SV *f) {
116 /*
117 # uncoverable branch true class:ignore_covered_err
118 # uncoverable condition left count:1 class:ignore_covered_err
119 # uncoverable condition right count:1 class:ignore_covered_err
120 # uncoverable condition left count:2 class:ignore_covered_err */
121 42 ▶ if (f && !hmf_is_future(aTHX_ f)) return; /* would never become ready */
Branch: 2 branches
BranchTrueFalseTotal
if (f && !hmf_is_future(aTHX_ f)) return; /* would never become ready */ 42 0 42
if (f && !hmf_is_future(aTHX_ f)) return; /* would never become ready */ 0 42 42
122 42 hm_loop_run(aTHX_ (hm_loop *)vl, f);
123 }
124  
125 1 static int hm_abi_conn_detach(pTHX_ void *vl, int fd, UV id) {
126 1 return hm_detach(aTHX_ (hm_loop *)vl, fd, id);
127 }
128  
129 /* v3: abuse controls. Plain forwards onto the two maps in the Shared::Arena
130 * (hm_sa_abuse.h); no pTHX, no SV - the maps are process-global. */
131 4 static int hm_abi_deny_check(const char *ip) { return hm_sa_deny_check(ip); }
132 1 static void hm_abi_deny_add(const char *ip, long ttl) { hm_sa_deny_add(ip, ttl); }
133 1 static void hm_abi_deny_remove(const char *ip) { hm_sa_deny_remove(ip); }
134 4 static int hm_abi_ratelimit_hit(const void *key, STRLEN klen,
135 IV limit, IV window, IV *remaining, IV *reset) {
136 4 long rem = 0, rst = 0;
137 4 int ok = hm_sa_ratelimit_hit(key, (size_t)klen, (long)limit, (long)window,
138 &rem, &rst);
139 /*
140 # uncoverable branch false class:ignore_covered_err
141 # uncoverable condition right count:1 class:ignore_covered_err */
142 4 ▶ if (remaining) *remaining = (IV)rem;
Branch: 1 branch
BranchTrueFalseTotal
if (remaining) *remaining = (IV)rem; 4 0 4
143 /*
144 # uncoverable branch false class:ignore_covered_err
145 # uncoverable condition right count:1 class:ignore_covered_err */
146 4 ▶ if (reset) *reset = (IV)rst;
Branch: 1 branch
BranchTrueFalseTotal
if (reset) *reset = (IV)rst; 4 0 4
147 4 return ok;
148 }
149  
150 /* ---- v5: the bus -------------------------------------------------------- */
151  
152 13 static int hm_abi_bus_publish(const char *topic, STRLEN tlen,
153 const char *payload, STRLEN plen) {
154 13 int r = hm_sa_bus_publish(topic, (uint32_t)tlen, payload, (uint32_t)plen);
155 13 ▶ return r == HM_BUS_OK ? 1 : r == HM_BUS_LOCAL ? 0 : -1; /* # uncoverable condition left count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
return r == HM_BUS_OK ? 1 : r == HM_BUS_LOCAL ? 0 : -1; /* # uncoverable condition left count:2 class:ignore_covered_err */ 1 12 13
return r == HM_BUS_OK ? 1 : r == HM_BUS_LOCAL ? 0 : -1; /* # uncoverable condition left count:2 class:ignore_covered_err */ 0 1 1
156 }
157  
158 /* The ABI's callback takes pTHX and no sequence; the ring's takes a sequence
159 * and no pTHX. This is the shim between them, so the ABI can stay a stable C
160 * surface while the ring's internals move. */
161 typedef struct { hm_abi_bus_cb cb; void *ud; } hm_abi_bus_sub;
162 static hm_abi_bus_sub hm_abi_bus_subs[HM_BUS_SUBS];
163  
164 12 static void hm_abi_bus_trampoline(void *ud, uint64_t seq, const char *topic,
165 uint32_t tlen, const char *payload,
166 uint32_t plen) {
167 dTHX;
168 12 hm_abi_bus_sub *s = (hm_abi_bus_sub *)ud;
169 (void)seq;
170 /*
171 # uncoverable branch false class:ignore_covered_err
172 # uncoverable condition right count:1 class:ignore_covered_err
173 # uncoverable condition right count:2 class:ignore_covered_err */
174 12 ▶ if (s && s->cb)
Branch: 2 branches
BranchTrueFalseTotal
if (s && s->cb) 12 0 12
if (s && s->cb) 12 0 12
175 12 s->cb(aTHX_ topic, (STRLEN)tlen, payload, (STRLEN)plen, s->ud);
176 12 }
177  
178 3 static int hm_abi_bus_subscribe(pTHX_ const char *topic, STRLEN tlen,
179 const char *group, STRLEN glen,
180 hm_abi_bus_cb cb, void *ud) {
181 int id;
182 PERL_UNUSED_CONTEXT;
183 /*
184 # uncoverable branch true
185 # uncoverable condition left count:1 class:ignore_covered_err */
186 3 ▶ if (!cb) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!cb) return -1; 0 3 3
187 3 id = hm_sa_bus_subscribe(topic, (uint32_t)tlen, group, (uint32_t)glen,
188 hm_abi_bus_trampoline, NULL);
189 /*
190 # uncoverable branch true
191 # uncoverable condition left count:1 class:ignore_covered_err */
192 3 ▶ if (id < 0) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) return -1; 0 3 3
193 3 hm_abi_bus_subs[id].cb = cb;
194 3 hm_abi_bus_subs[id].ud = ud;
195 3 hm_bus_subs[id].ud = &hm_abi_bus_subs[id];
196 3 return id;
197 }
198  
199 3 static int hm_abi_bus_unsubscribe(pTHX_ int id) {
200 PERL_UNUSED_CONTEXT;
201 /*
202 # uncoverable branch false class:ignore_covered_err
203 # uncoverable condition right count:1 class:ignore_covered_err
204 # uncoverable condition right count:2 class:ignore_covered_err */
205 3 ▶ if (id >= 0 && id < HM_BUS_SUBS) {
Branch: 2 branches
BranchTrueFalseTotal
if (id >= 0 && id < HM_BUS_SUBS) { 3 0 3
if (id >= 0 && id < HM_BUS_SUBS) { 3 0 3
206 3 hm_abi_bus_subs[id].cb = NULL;
207 3 hm_abi_bus_subs[id].ud = NULL;
208 }
209 3 return hm_sa_bus_unsubscribe(id);
210 }
211  
212 3 static int hm_abi_bus_dispatch(pTHX) {
213 PERL_UNUSED_CONTEXT;
214 3 return (int)hm_sa_bus_dispatch();
215 }
216  
217 /* ---- v9: the arena and the scoreboard ------------------------------------ */
218  
219 2 static void *hm_abi_arena_region(void) { return (void *)hm_sa_region; }
220 1 static const void *hm_abi_arena_table(void) { return (const void *)HM_SA; }
221  
222 2 static int hm_abi_pool_sum(hm_abi_pool_stats *out) {
223 hm_sa_pool_stats p;
224 /*
225 # uncoverable branch true
226 # uncoverable condition left count:1 class:ignore_covered_err */
227 2 ▶ if (!out) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!out) return 0; 0 2 2
228 /*
229 # uncoverable branch true
230 # uncoverable condition left count:1 class:ignore_covered_err */
231 2 ▶ if (!hm_sa_board_pool(&p)) { memset(out, 0, sizeof *out); return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_sa_board_pool(&p)) { memset(out, 0, sizeof *out); return 0; } 0 2 2
232 2 out->workers = (UV)p.workers; out->alive = (UV)p.alive;
233 2 out->requests = (UV)p.requests; out->accepts = (UV)p.accepts;
234 2 out->denied = (UV)p.denied; out->conns = (UV)p.conns;
235 2 out->bytes_out = (UV)p.bytes_out; out->datagrams = (UV)p.datagrams;
236 2 out->h3 = (UV)p.h3;
237 2 return 1;
238 }
239  
240 /* The selftest's bus subscriber: counts what reached it. */
241 static int hm_abi_selftest_bus_n = 0;
242 12 static void hm_abi_selftest_bus_cb(pTHX_ const char *topic, STRLEN tl,
243 const char *payload, STRLEN pl, void *ud) {
244 PERL_UNUSED_CONTEXT;
245 (void)topic; (void)tl; (void)payload; (void)pl; (void)ud;
246 12 hm_abi_selftest_bus_n++;
247 12 }
248  
249 static const hm_abi hm_abi_table = {
250 HM_ABI_VERSION,
251 hm_abi_cur_loop,
252 hm_abi_loop_of_sv,
253 hm_abi_sv_of_loop,
254 hm_abi_io_watch,
255 hm_abi_io_unwatch,
256 hm_abi_timer_add,
257 hm_abi_timer_cancel,
258 hm_abi_future_new,
259 hm_abi_is_future,
260 hm_abi_future_state,
261 hm_abi_future_done,
262 hm_abi_future_fail,
263 hm_abi_future_on_ready,
264 hm_abi_run_until,
265 hm_abi_conn_detach, /* v2 */
266 hm_abi_deny_check, /* v3 */
267 hm_abi_deny_add,
268 hm_abi_deny_remove,
269 hm_abi_ratelimit_hit,
270 hm_worker_hook_add, /* v4 */
271 hm_abi_bus_publish, /* v5 */
272 hm_abi_bus_subscribe,
273 hm_abi_bus_unsubscribe,
274 hm_abi_bus_dispatch,
275 hm_stream_open, /* v6 - the registry lives in hm_stream.h, */
276 hm_stream_write_h, /* which owns the transport branch so the */
277 hm_stream_close_h, /* table can stay four plain forwards */
278 hm_stream_on_drain,
279 hm_stream_on_abort,
280 hm_stream_abort_h, /* v7 - the ending a failed producer needs */
281 hm_stream_on_data, /* v8 - the read half */
282 hm_abi_arena_region, /* v9 - the arena, its table, the board */
283 hm_abi_arena_table,
284 hm_abi_pool_sum,
285 };
286  
287 /* ---- v4 on_worker_start, driven from C (t/33-worker-start.t) ------------ *
288 * A Perl test cannot register a C callback, so the observable half lives
289 * here: _abi_worker_hook_install registers this through the TABLE, and the
290 * worker it fires in reports the count back through an ordinary request. The
291 * count is a plain static, so it is inherited as 0 across the fork and each
292 * worker increments its own copy - which is exactly the property being
293 * tested. */
294 static IV HM_ABI_ST_WORKER_N = 0;
295 static int HM_ABI_ST_WORKER_LOOP_OK = 1;
296  
297 2 static void hm_abi_st_worker_cb(pTHX_ void *loop, void *ud) {
298 PERL_UNUSED_ARG(ud);
299 /*
300 # uncoverable branch true class:ignore_covered_err
301 # uncoverable condition left count:1 class:ignore_covered_err */
302 2 ▶ if (!loop) HM_ABI_ST_WORKER_LOOP_OK = 0; /* must be handed a real loop */
Branch: 1 branch
BranchTrueFalseTotal
if (!loop) HM_ABI_ST_WORKER_LOOP_OK = 0; /* must be handed a real loop */ 0 2 2
303 2 HM_ABI_ST_WORKER_N++;
304 2 }
305  
306 /* Register through the table, not by calling hm_worker_hook_add directly -
307 * the point of a selftest is to prove the function pointer works. */
308 3 static int hm_abi_worker_hook_install(pTHX) {
309 3 const hm_abi *A = INT2PTR(const hm_abi *, PTR2IV(&hm_abi_table));
310 /*
311 # uncoverable branch true class:ignore_covered_err
312 # uncoverable condition left count:1 class:ignore_covered_err
313 # uncoverable condition left count:2 class:ignore_covered_err */
314 3 ▶ if (!A || A->abi_version != HM_ABI_VERSION) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!A || A->abi_version != HM_ABI_VERSION) return 0; 3 0 3
if (!A || A->abi_version != HM_ABI_VERSION) return 0; 0 3 3
315 3 return A->on_worker_start(aTHX_ hm_abi_st_worker_cb, NULL);
316 }
317  
318 /* ---- v6 stream handles, driven from C (t/41-stream-abi.t) --------------- *
319 *
320 * The static half - that the entries exist and that a stale handle is an
321 * error return rather than a crash - is in hm_abi_selftest below. This is the
322 * live half, which needs a real connection and therefore a real server: an
323 * application calls these from inside a request, the C side does everything
324 * through the TABLE, and a later request reads the counters back out.
325 *
326 * One handle at a time, in a process-global, because the tests that use it
327 * run with workers => 1 and a single handle is what makes "did the abort
328 * fire" answerable from Perl at all. */
329 static void *HM_ABI_ST_SH = NULL;
330 static IV HM_ABI_ST_SH_ABORTS = 0;
331 static IV HM_ABI_ST_SH_DRAINS = 0;
332 static IV HM_ABI_ST_SH_WRITES = 0;
333 static IV HM_ABI_ST_SH_TODO = 0; /* chunks still owed on the stream */
334 static IV HM_ABI_ST_SH_FULLS = 0; /* times the connection said stop */
335  
336 1 static void hm_abi_st_stream_abort(pTHX_ void *h, void *ud) {
337 PERL_UNUSED_CONTEXT;
338 PERL_UNUSED_ARG(ud);
339 1 HM_ABI_ST_SH_ABORTS++;
340 1 HM_ABI_ST_SH_TODO = 0; /* nobody is listening any more */
341 /* The handle survives an abort - only stream_close frees it - so it is
342 * deliberately NOT released here. The test's next request closes it and
343 * proves the release path copes with a stream that died first. */
344 (void)h;
345 1 }
346  
347 /* Produce until the connection says stop, then stop until it says go. This is
348 * the whole backpressure contract, and it is the only honest way to test it:
349 * a producer that only ever writes small chunks never reaches it. */
350 993 static void hm_abi_st_stream_pump(pTHX_ void *h) {
351 993 const hm_abi *A = &hm_abi_table;
352 char buf[4096];
353 993 memset(buf, 'x', sizeof buf);
354 2049 ▶ while (HM_ABI_ST_SH_TODO > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (HM_ABI_ST_SH_TODO > 0) { 2048 1 2049
355 2048 int r = A->stream_write(aTHX_ h, buf, sizeof(buf));
356 /*
357 # uncoverable branch true class:ignore_covered_err
358 # uncoverable condition left count:1 class:ignore_covered_err */
359 3040 ▶ if (r < 0) { HM_ABI_ST_SH_TODO = 0; return; }
Branch: 1 branch
BranchTrueFalseTotal
if (r < 0) { HM_ABI_ST_SH_TODO = 0; return; } 0 2048 2048
360 2048 HM_ABI_ST_SH_TODO--;
361 2048 HM_ABI_ST_SH_WRITES++;
362 2048 ▶ if (r == HM_ABI_STREAM_FULL) { HM_ABI_ST_SH_FULLS++; return; }
Branch: 1 branch
BranchTrueFalseTotal
if (r == HM_ABI_STREAM_FULL) { HM_ABI_ST_SH_FULLS++; return; } 992 1056 2048
363 }
364 /*
365 # uncoverable branch false class:ignore_covered_err
366 # uncoverable condition right count:1 class:ignore_covered_err */
367 1 ▶ if (HM_ABI_ST_SH == h) {
Branch: 1 branch
BranchTrueFalseTotal
if (HM_ABI_ST_SH == h) { 1 0 1
368 1 A->stream_close(aTHX_ h);
369 1 HM_ABI_ST_SH = NULL;
370 }
371 }
372  
373 992 static void hm_abi_st_stream_drain(pTHX_ void *h, void *ud) {
374 PERL_UNUSED_ARG(ud);
375 992 HM_ABI_ST_SH_DRAINS++;
376 992 hm_abi_st_stream_pump(aTHX_ h);
377 992 }
378  
379 /* Open a stream on the request this env names, over whichever transport it
380 * arrived on. 1 = open, 0 = refused. */
381 14 static int hm_abi_st_stream_open(pTHX_ SV *env, int status, SV *headers) {
382 14 const hm_abi *A = &hm_abi_table;
383 int fd;
384 UV id;
385 int64_t sid;
386 /*
387 # uncoverable branch true
388 # uncoverable condition left count:1 class:ignore_covered_err */
389 14 ▶ if (HM_ABI_ST_SH) return 0; /* one at a time */
Branch: 1 branch
BranchTrueFalseTotal
if (HM_ABI_ST_SH) return 0; /* one at a time */ 0 14 14
390 /*
391 # uncoverable branch true
392 # uncoverable condition left count:1 class:ignore_covered_err */
393 14 ▶ if (!hm_stream_ticket(aTHX_ env, &fd, &id, &sid)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_ticket(aTHX_ env, &fd, &id, &sid)) return 0; 0 14 14
394 14 HM_ABI_ST_SH = A->stream_open(aTHX_ (void *)hm_cur_loop, fd, id, sid,
395 status, headers);
396 /*
397 # uncoverable branch true
398 # uncoverable condition left count:1 class:ignore_covered_err */
399 14 ▶ if (!HM_ABI_ST_SH) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return 0; 0 14 14
400 14 HM_ABI_ST_SH_WRITES = 0;
401 14 A->stream_on_abort(aTHX_ HM_ABI_ST_SH, hm_abi_st_stream_abort, NULL);
402 14 A->stream_on_drain(aTHX_ HM_ABI_ST_SH, hm_abi_st_stream_drain, NULL);
403 14 return 1;
404 }
405  
406 18 static int hm_abi_st_stream_write(pTHX_ SV *data) {
407 18 const hm_abi *A = &hm_abi_table;
408 STRLEN l;
409 const char *p;
410 int r;
411 /*
412 # uncoverable branch true
413 # uncoverable condition left count:1 class:ignore_covered_err */
414 18 ▶ if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE; 0 18 18
415 18 p = SvPV(data, l);
416 18 r = A->stream_write(aTHX_ HM_ABI_ST_SH, p, l);
417 18 ▶ if (r >= 0) HM_ABI_ST_SH_WRITES++;
Branch: 1 branch
BranchTrueFalseTotal
if (r >= 0) HM_ABI_ST_SH_WRITES++; 17 1 18
418 18 return r;
419 }
420  
421 /* Owe the stream n chunks of 4KiB and start producing them. */
422 1 static void hm_abi_st_stream_produce(pTHX_ IV n) {
423 /*
424 # uncoverable branch true
425 # uncoverable condition left count:1 class:ignore_covered_err */
426 1 ▶ if (!HM_ABI_ST_SH) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return; 0 1 1
427 1 HM_ABI_ST_SH_TODO = n;
428 1 hm_abi_st_stream_pump(aTHX_ HM_ABI_ST_SH);
429 }
430  
431 /* v8: what the read half delivered, echoed back so a Perl test can see it.
432 * Bounded - this is a test hook on an unbounded stream, and an unbounded
433 * buffer behind a test hook is still an unbounded buffer. */
434 static char HM_ABI_ST_SH_RX[4096];
435 static IV HM_ABI_ST_SH_RXLEN = 0;
436 static IV HM_ABI_ST_SH_RXN = 0;
437  
438 15 static void hm_abi_st_stream_data(pTHX_ void *h, const char *buf, STRLEN len,
439 int fin, void *ud) {
440 PERL_UNUSED_CONTEXT;
441 PERL_UNUSED_ARG(ud);
442 (void)h; (void)fin;
443 15 HM_ABI_ST_SH_RXN++;
444 /*
445 # uncoverable branch true class:ignore_covered_err
446 # uncoverable condition left count:1 class:ignore_covered_err */
447 15 ▶ if (len > sizeof(HM_ABI_ST_SH_RX) - (size_t)HM_ABI_ST_SH_RXLEN)
Branch: 1 branch
BranchTrueFalseTotal
if (len > sizeof(HM_ABI_ST_SH_RX) - (size_t)HM_ABI_ST_SH_RXLEN) 0 15 15
448 0 len = sizeof(HM_ABI_ST_SH_RX) - (size_t)HM_ABI_ST_SH_RXLEN; /* # uncoverable statement */
449 /*
450 # uncoverable branch false class:ignore_covered_err
451 # uncoverable condition right count:1 class:ignore_covered_err */
452 15 ▶ if (len) {
Branch: 1 branch
BranchTrueFalseTotal
if (len) { 15 0 15
453 15 memcpy(HM_ABI_ST_SH_RX + HM_ABI_ST_SH_RXLEN, buf, len);
454 15 HM_ABI_ST_SH_RXLEN += (IV)len;
455 }
456 15 }
457  
458 /* Register the read half on the open handle, through the TABLE. */
459 9 static int hm_abi_st_stream_read(pTHX) {
460 9 const hm_abi *A = &hm_abi_table;
461 /*
462 # uncoverable branch true
463 # uncoverable condition left count:1 class:ignore_covered_err */
464 9 ▶ if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE; 0 9 9
465 9 HM_ABI_ST_SH_RXLEN = 0;
466 9 HM_ABI_ST_SH_RXN = 0;
467 9 return A->stream_on_data(aTHX_ HM_ABI_ST_SH, hm_abi_st_stream_data, NULL);
468 }
469  
470 12 static int hm_abi_st_stream_close(pTHX) {
471 12 const hm_abi *A = &hm_abi_table;
472 int r;
473 /*
474 # uncoverable branch true
475 # uncoverable condition left count:1 class:ignore_covered_err */
476 12 ▶ if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE; 0 12 12
477 12 r = A->stream_close(aTHX_ HM_ABI_ST_SH);
478 12 HM_ABI_ST_SH = NULL;
479 12 return r;
480 }
481  
482 /* The other ending, so t/41-stream-abi.t can drive it over both transports.
483 * Releases the handle exactly as close does - a producer calls one or the
484 * other, and the selftest must not be the thing that gets that wrong. */
485 1 static int hm_abi_st_stream_do_abort(pTHX) {
486 1 const hm_abi *A = &hm_abi_table;
487 int r;
488 /*
489 # uncoverable branch true
490 # uncoverable condition left count:1 class:ignore_covered_err */
491 1 ▶ if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return HM_ABI_STREAM_STALE; 0 1 1
492 1 r = A->stream_abort(aTHX_ HM_ABI_ST_SH);
493 1 HM_ABI_ST_SH = NULL;
494 1 return r;
495 }
496  
497 /* ---- _abi_selftest: drive the whole table from C (t/22-abi.t) ----------- */
498  
499 1 static void hm_abi_st_ready(pTHX_ SV *f, void *ud) {
500 PERL_UNUSED_VAR(f);
501 1 *(int *)ud = 1;
502 1 }
503  
504 21 static void hm_abi_st_timer(pTHX_ void *ud) {
505 21 hm_abi_table.future_done(aTHX_ (SV *)ud, NULL, 0);
506 21 }
507  
508 typedef struct { SV *f; void *loop; } hm_abi_st_io;
509  
510 1 static void hm_abi_st_io_cb(pTHX_ int fd, int mask, void *ud) {
511 1 hm_abi_st_io *st = (hm_abi_st_io *)ud;
512 char b;
513 PERL_UNUSED_VAR(mask);
514 1 if (read(fd, &b, 1) < 0) { /* settle anyway; the test checks the future */ }
515 1 hm_abi_table.io_unwatch(aTHX_ st->loop, fd, HM_ABI_READ);
516 1 hm_abi_table.future_done(aTHX_ st->f, NULL, 0);
517 1 }
518  
519 /* The same-batch cancel case: the canceller cancels the victim only if the
520 * victim has not fired (a handle dies on fire, so cancelling one that has
521 * would itself be the misuse). */
522 typedef struct {
523 void *loop;
524 hm_abi_timer *victim;
525 SV *f;
526 int victim_fired;
527 int cancelled;
528 } hm_abi_st_cx;
529 10 static void hm_abi_st_cx_victim(pTHX_ void *ud) {
530 10 hm_abi_st_cx *cx = (hm_abi_st_cx *)ud;
531 PERL_UNUSED_CONTEXT;
532 10 cx->victim_fired = 1;
533 10 cx->victim = NULL;
534 10 }
535 20 static void hm_abi_st_cx_cancel(pTHX_ void *ud) {
536 20 hm_abi_st_cx *cx = (hm_abi_st_cx *)ud;
537 20 ▶ if (cx->victim && !cx->victim_fired) { /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (cx->victim && !cx->victim_fired) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 10 10 20
if (cx->victim && !cx->victim_fired) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 10 0 10
538 10 hm_abi_table.timer_cancel(aTHX_ cx->loop, cx->victim);
539 10 cx->victim = NULL;
540 10 cx->cancelled = 1;
541 }
542 20 hm_abi_table.future_done(aTHX_ cx->f, NULL, 0);
543 20 }
544  
545 1 static int hm_abi_selftest(pTHX) {
546 1 const hm_abi *A = &hm_abi_table;
547 1 int ok = 1;
548 /*
549 # uncoverable branch true
550 # uncoverable condition left count:1 class:ignore_covered_err */
551 1 ▶ if (A->abi_version != HM_ABI_VERSION) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->abi_version != HM_ABI_VERSION) return 0; 0 1 1
552  
553 /* future lifecycle: new -> pending -> on_ready (C) -> done -> fired */
554 {
555 1 SV *f = A->future_new(aTHX);
556 1 int fired = 0;
557 1 SV *val = sv_2mortal(newSViv(42));
558 /*
559 # uncoverable branch true class:ignore_covered_err
560 # uncoverable condition left count:1 class:ignore_covered_err */
561 1 ▶ if (!A->is_future(aTHX_ f)) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->is_future(aTHX_ f)) ok = 0; 0 1 1
562 /*
563 # uncoverable statement class:ignore_covered_err
564 # uncoverable branch true
565 # uncoverable condition left count:1 */
566 1 ▶ if (A->future_state(aTHX_ f) != HM_ABI_PENDING) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->future_state(aTHX_ f) != HM_ABI_PENDING) ok = 0; 0 1 1
567 1 A->future_on_ready(aTHX_ f, hm_abi_st_ready, &fired); /* # uncoverable statement class:ignore_covered_err */
568 1 A->future_done(aTHX_ f, &val, 1); /* # uncoverable statement class:ignore_covered_err */
569 1 A->future_done(aTHX_ f, &val, 1); /* second settle: no-op */ /* # uncoverable statement class:ignore_covered_err */
570 /*
571 # uncoverable statement class:ignore_covered_err
572 # uncoverable branch true
573 # uncoverable condition left count:1 */
574 1 ▶ if (!fired) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!fired) ok = 0; 0 1 1
575 /*
576 # uncoverable statement class:ignore_covered_err
577 # uncoverable branch true
578 # uncoverable condition left count:1 */
579 1 ▶ if (A->future_state(aTHX_ f) != HM_ABI_DONE) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->future_state(aTHX_ f) != HM_ABI_DONE) ok = 0; 0 1 1
580 1 SvREFCNT_dec(f); /* # uncoverable statement class:ignore_covered_err */
581 }
582  
583 /* failure path */
584 {
585 1 SV *f = A->future_new(aTHX); /* # uncoverable statement class:ignore_covered_err */
586 1 SV *err = sv_2mortal(newSVpvs("nope")); /* # uncoverable statement class:ignore_covered_err */
587 1 A->future_fail(aTHX_ f, err); /* # uncoverable statement class:ignore_covered_err */
588 /*
589 # uncoverable statement class:ignore_covered_err
590 # uncoverable branch true
591 # uncoverable condition left count:1 */
592 1 ▶ if (A->future_state(aTHX_ f) != HM_ABI_FAILED) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->future_state(aTHX_ f) != HM_ABI_FAILED) ok = 0; 0 1 1
593 1 SvREFCNT_dec(f);
594 }
595  
596 /* loop: C io watcher on a readable pipe, a cancelled timer that must not
597 * fire, and a live C timer settling the second future */
598 {
599 1 hm_loop *loop = hm_loop_new(aTHX_ NULL);
600 int fds[2];
601 /*
602 # uncoverable branch true
603 # uncoverable condition left count:1 class:ignore_covered_err */
604 1 ▶ if (!loop) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!loop) return 0; 0 1 1
605 /* hm_os_selfpipe, not pipe(2): on Windows the readiness backend
606 * polls sockets only, so the pair has to be a loopback connection
607 * there. hm_os_send/hm_os_close write and close either kind. */
608 /*
609 # uncoverable branch false
610 # uncoverable condition right count:1 class:ignore_covered_err */
611 1 ▶ if (hm_os_selfpipe(&fds[0], &fds[1]) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (hm_os_selfpipe(&fds[0], &fds[1]) == 0) { 1 0 1
612 1 SV *fio = A->future_new(aTHX);
613 1 SV *ftw = A->future_new(aTHX);
614 hm_abi_st_io st;
615 hm_abi_timer *dead;
616 1 st.f = fio;
617 1 st.loop = (void *)loop;
618 /*
619 # uncoverable branch true class:ignore_covered_err
620 # uncoverable condition left count:1 class:ignore_covered_err */
621 1 ▶ if (hm_os_send(fds[1], "x", 1) < 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (hm_os_send(fds[1], "x", 1) < 0) ok = 0; 0 1 1
622 1 A->io_watch(aTHX_ (void *)loop, fds[0], HM_ABI_READ, /* # uncoverable statement class:ignore_covered_err */
623 hm_abi_st_io_cb, &st);
624 1 dead = A->timer(aTHX_ (void *)loop, 3600.0, hm_abi_st_timer, ftw); /* # uncoverable statement class:ignore_covered_err */
625 1 A->timer_cancel(aTHX_ (void *)loop, dead); /* # uncoverable statement class:ignore_covered_err */
626 1 A->timer(aTHX_ (void *)loop, 0.01, hm_abi_st_timer, ftw); /* # uncoverable statement class:ignore_covered_err */
627 1 A->run_until(aTHX_ (void *)loop, fio); /* # uncoverable statement class:ignore_covered_err */
628 /*
629 # uncoverable statement class:ignore_covered_err
630 # uncoverable branch true
631 # uncoverable condition left count:1 */
632 1 ▶ if (A->future_state(aTHX_ fio) != HM_ABI_DONE) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->future_state(aTHX_ fio) != HM_ABI_DONE) ok = 0; 0 1 1
633 1 A->run_until(aTHX_ (void *)loop, ftw); /* # uncoverable statement class:ignore_covered_err */
634 /*
635 # uncoverable statement class:ignore_covered_err
636 # uncoverable branch true
637 # uncoverable condition left count:1 */
638 1 ▶ if (A->future_state(aTHX_ ftw) != HM_ABI_DONE) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->future_state(aTHX_ ftw) != HM_ABI_DONE) ok = 0; 0 1 1
639 1 SvREFCNT_dec(fio);
640 1 SvREFCNT_dec(ftw);
641 1 hm_os_close(fds[0]);
642 1 hm_os_close(fds[1]);
643 0 } else ok = 0; /* # uncoverable statement class:ignore_covered_err */
644  
645 /* timer_cancel from a callback in the SAME BATCH as the victim: two
646 * timers due together, the first to fire cancels the other. The
647 * other's event is already in the array the backend returned, so
648 * freeing it at cancel was a use after free at its dispatch (and a
649 * double free). Twenty rounds, alternating registration order,
650 * because which of two due timers a backend reports first is its
651 * business: the victim must never fire after the cancel, and under
652 * ASan the dispatch of a cancelled one must touch nothing freed. */
653 {
654 int round;
655 21 ▶ for (round = 0; round < 20 && ok; round++) { /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
for (round = 0; round < 20 && ok; round++) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 20 1 21
for (round = 0; round < 20 && ok; round++) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 20 0 20
656 hm_abi_st_cx cx;
657 20 SV *f = A->future_new(aTHX);
658 20 cx.loop = (void *)loop;
659 20 cx.f = f;
660 20 cx.victim_fired = 0;
661 20 cx.cancelled = 0;
662 20 ▶ if (round & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (round & 1) { 10 10 20
663 10 cx.victim = A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_victim, &cx);
664 10 A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_cancel, &cx);
665 } else {
666 10 A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_cancel, &cx);
667 10 cx.victim = A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_victim, &cx);
668 }
669 20 A->run_until(aTHX_ (void *)loop, f);
670 /* a second turn, so a victim wrongly left armed would fire */
671 {
672 20 SV *f2 = A->future_new(aTHX);
673 20 A->timer(aTHX_ (void *)loop, 0.005, hm_abi_st_timer, f2);
674 20 A->run_until(aTHX_ (void *)loop, f2);
675 20 SvREFCNT_dec(f2);
676 }
677 /*
678 # uncoverable branch true class:ignore_covered_err
679 # uncoverable condition left count:1 class:ignore_covered_err
680 # uncoverable condition left count:2 class:ignore_covered_err */
681 20 ▶ if (cx.cancelled && cx.victim_fired) ok = 0;
Branch: 2 branches
BranchTrueFalseTotal
if (cx.cancelled && cx.victim_fired) ok = 0; 10 10 20
if (cx.cancelled && cx.victim_fired) ok = 0; 0 10 10
682 20 SvREFCNT_dec(f);
683 }
684 }
685  
686 /* v2 conn_detach: the entry is present and rejects tickets that
687 * name no connection. The success path needs a live HTTP
688 * connection and is covered end to end by t/23-detach.t. */
689 /*
690 # uncoverable branch true
691 # uncoverable condition left count:1 class:ignore_covered_err */
692 1 ▶ if (!A->conn_detach) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->conn_detach) ok = 0; 0 1 1
693 /*
694 # uncoverable branch true class:ignore_covered_err
695 # uncoverable condition left count:1 class:ignore_covered_err */
696 1 ▶ else if (A->conn_detach(aTHX_ (void *)loop, 4094, 1) != -1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
else if (A->conn_detach(aTHX_ (void *)loop, 4094, 1) != -1) ok = 0; 0 1 1
697  
698 /* v6 stream handles. The success path needs a live request and is
699 * covered end to end by t/41-stream-abi.t, over HTTP/1.1 and over
700 * HTTP/2. What is provable with no connection is the half that
701 * matters most for memory safety: a ticket naming nothing hands
702 * back no handle, and every entry point given a pointer that is not
703 * a live handle SAYS SO instead of dereferencing it. The address
704 * below is deliberately a plausible-looking one. */
705 /*
706 # uncoverable branch true class:ignore_covered_err
707 # uncoverable condition left count:1 class:ignore_covered_err
708 # uncoverable condition left count:2 class:ignore_covered_err
709 # uncoverable condition left count:3 class:ignore_covered_err
710 # uncoverable condition left count:4 class:ignore_covered_err
711 # uncoverable condition left count:5 class:ignore_covered_err
712 # uncoverable condition left count:6 class:ignore_covered_err */
713 1 ▶ if (!A->stream_open || !A->stream_write || !A->stream_close
Branch: 3 branches
BranchTrueFalseTotal
if (!A->stream_open || !A->stream_write || !A->stream_close 1 0 1
if (!A->stream_open || !A->stream_write || !A->stream_close 1 0 1
if (!A->stream_open || !A->stream_write || !A->stream_close 1 0 1
714 1 ▶ || !A->stream_on_drain || !A->stream_on_abort
Branch: 2 branches
BranchTrueFalseTotal
|| !A->stream_on_drain || !A->stream_on_abort 1 0 1
|| !A->stream_on_drain || !A->stream_on_abort 1 0 1
715 1 ▶ || !A->stream_abort) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
|| !A->stream_abort) ok = 0; 0 1 1
716 else {
717 1 void *bogus = (void *)&hm_abi_table; /* real memory, no handle */
718 /*
719 # uncoverable branch true class:ignore_covered_err
720 # uncoverable condition left count:1 class:ignore_covered_err */
721 1 ▶ if (A->stream_abort(aTHX_ bogus) != HM_ABI_STREAM_STALE) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_abort(aTHX_ bogus) != HM_ABI_STREAM_STALE) ok = 0; 0 1 1
722 /*
723 # uncoverable statement class:ignore_covered_err
724 # uncoverable branch true
725 # uncoverable condition left count:1 */
726 1 ▶ if (A->stream_abort(aTHX_ NULL) != HM_ABI_STREAM_STALE) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_abort(aTHX_ NULL) != HM_ABI_STREAM_STALE) ok = 0; 0 1 1
727 /*
728 # uncoverable statement class:ignore_covered_err
729 # uncoverable branch true
730 # uncoverable condition left count:1 */
731 1 ▶ if (A->stream_open(aTHX_ (void *)loop, 4094, 1, -1, 200, NULL))
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_open(aTHX_ (void *)loop, 4094, 1, -1, 200, NULL)) 0 1 1
732 0 ok = 0; /* # uncoverable statement */
733 /*
734 # uncoverable statement class:ignore_covered_err
735 # uncoverable branch true
736 # uncoverable condition left count:1 */
737 1 ▶ if (A->stream_open(aTHX_ (void *)loop, 4094, 1, 3, 200, NULL))
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_open(aTHX_ (void *)loop, 4094, 1, 3, 200, NULL)) 0 1 1
738 0 ok = 0; /* # uncoverable statement */
739 /*
740 # uncoverable statement class:ignore_covered_err
741 # uncoverable branch true
742 # uncoverable condition left count:1 */
743 1 ▶ if (A->stream_write(aTHX_ bogus, "x", 1) != HM_ABI_STREAM_STALE)
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_write(aTHX_ bogus, "x", 1) != HM_ABI_STREAM_STALE) 0 1 1
744 0 ok = 0; /* # uncoverable statement */
745 /*
746 # uncoverable statement class:ignore_covered_err
747 # uncoverable branch true
748 # uncoverable condition left count:1 */
749 1 ▶ if (A->stream_write(aTHX_ NULL, "x", 1) != HM_ABI_STREAM_STALE)
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_write(aTHX_ NULL, "x", 1) != HM_ABI_STREAM_STALE) 0 1 1
750 0 ok = 0; /* # uncoverable statement */
751 /*
752 # uncoverable statement class:ignore_covered_err
753 # uncoverable branch true
754 # uncoverable condition left count:1 */
755 1 ▶ if (A->stream_close(aTHX_ bogus) != HM_ABI_STREAM_STALE) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_close(aTHX_ bogus) != HM_ABI_STREAM_STALE) ok = 0; 0 1 1
756 /*
757 # uncoverable statement class:ignore_covered_err
758 # uncoverable branch true
759 # uncoverable condition left count:1 */
760 1 ▶ if (A->stream_on_drain(aTHX_ bogus, NULL, NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_on_drain(aTHX_ bogus, NULL, NULL) 0 1 1
761 0 != HM_ABI_STREAM_STALE) ok = 0; /* # uncoverable statement */
762 /*
763 # uncoverable statement class:ignore_covered_err
764 # uncoverable branch true
765 # uncoverable condition left count:1 */
766 1 ▶ if (A->stream_on_abort(aTHX_ bogus, NULL, NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_on_abort(aTHX_ bogus, NULL, NULL) 0 1 1
767 0 != HM_ABI_STREAM_STALE) ok = 0; /* # uncoverable statement */
768 }
769  
770 1 hm_loop_free(aTHX_ loop);
771 }
772  
773 /* v3 abuse controls, driven through the table. Init the arena here so the
774 * selftest exercises them even with no server running (idempotent). */
775 {
776 1 IV rem = 0, rst = 0;
777 /* The Shared::Arena and its two maps, with the defaults: Punk's
778 * no-server tests get Hyperman->arena and a working ratelimit_hit
779 * from this call. Idempotent. */
780 1 hm_sa_open(aTHX_ NULL, 0, hm_sa_bytes(0, 0, 0, 0));
781 1 (void)hm_sa_abuse_open(0, 0, NULL, NULL);
782 /*
783 # uncoverable branch true class:ignore_covered_err
784 # uncoverable condition left count:1 class:ignore_covered_err
785 # uncoverable condition left count:2 class:ignore_covered_err
786 # uncoverable condition left count:3 class:ignore_covered_err
787 # uncoverable condition left count:4 class:ignore_covered_err */
788 1 ▶ if (!A->deny_check || !A->deny_add || !A->deny_remove
Branch: 3 branches
BranchTrueFalseTotal
if (!A->deny_check || !A->deny_add || !A->deny_remove 1 0 1
if (!A->deny_check || !A->deny_add || !A->deny_remove 1 0 1
if (!A->deny_check || !A->deny_add || !A->deny_remove 1 0 1
789 1 ▶ || !A->ratelimit_hit) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
|| !A->ratelimit_hit) ok = 0; 0 1 1
790 /*
791 # uncoverable branch true
792 # uncoverable condition left count:1 class:ignore_covered_err */
793 1 ▶ else if (!hm_sa_abuse_live()) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!hm_sa_abuse_live()) { 0 1 1
794 /* No arena: the contract is that every entry point FAILS OPEN,
795 * and that is what gets asserted. Anything else here would be
796 * testing a feature the build does not have. (Shared::Arena
797 * absent, or a compiler without the atomics it needs.) */
798 0 A->deny_add("203.0.113.7", 0); /* # uncoverable statement */
799 /*
800 # uncoverable statement
801 # uncoverable branch true
802 # uncoverable branch false
803 # uncoverable condition left count:1
804 # uncoverable condition right count:1 */
805 0 ▶ if (A->deny_check("203.0.113.7") != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->deny_check("203.0.113.7") != 0) ok = 0; 0 0 0
806 0 A->deny_remove("203.0.113.7"); /* # uncoverable statement */
807 /*
808 # uncoverable statement
809 # uncoverable branch true
810 # uncoverable branch false
811 # uncoverable condition left count:1
812 # uncoverable condition right count:1 */
813 0 ▶ if (A->ratelimit_hit("st", 2, 1, 60, &rem, &rst) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->ratelimit_hit("st", 2, 1, 60, &rem, &rst) != 1) ok = 0; 0 0 0
814 /*
815 # uncoverable statement
816 # uncoverable branch true
817 # uncoverable branch false
818 # uncoverable condition left count:1
819 # uncoverable condition right count:1 */
820 0 ▶ if (A->ratelimit_hit("st", 2, 1, 60, &rem, &rst) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->ratelimit_hit("st", 2, 1, 60, &rem, &rst) != 1) ok = 0; 0 0 0
821 }
822 else {
823 /*
824 # uncoverable branch true class:ignore_covered_err
825 # uncoverable condition left count:1 class:ignore_covered_err */
826 1 ▶ if (A->deny_check("203.0.113.7") != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->deny_check("203.0.113.7") != 0) ok = 0; 0 1 1
827 1 A->deny_add("203.0.113.7", 0); /* # uncoverable statement class:ignore_covered_err */
828 /*
829 # uncoverable statement class:ignore_covered_err
830 # uncoverable branch true
831 # uncoverable condition left count:1 */
832 1 ▶ if (A->deny_check("203.0.113.7") != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->deny_check("203.0.113.7") != 1) ok = 0; 0 1 1
833 /*
834 # uncoverable statement class:ignore_covered_err
835 # uncoverable branch true
836 # uncoverable condition left count:1 */
837 1 ▶ if (A->deny_check("203.0.113.8") != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->deny_check("203.0.113.8") != 0) ok = 0; 0 1 1
838 1 A->deny_remove("203.0.113.7"); /* # uncoverable statement class:ignore_covered_err */
839 /*
840 # uncoverable statement class:ignore_covered_err
841 # uncoverable branch true
842 # uncoverable condition left count:1 */
843 1 ▶ if (A->deny_check("203.0.113.7") != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->deny_check("203.0.113.7") != 0) ok = 0; 0 1 1
844  
845 /* 2 per window: two allowed, the third over */
846 /*
847 # uncoverable statement class:ignore_covered_err
848 # uncoverable branch true
849 # uncoverable condition left count:1 */
850 1 ▶ if (A->ratelimit_hit("st", 2, 2, 60, &rem, &rst) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->ratelimit_hit("st", 2, 2, 60, &rem, &rst) != 1) ok = 0; 0 1 1
851 /*
852 # uncoverable statement class:ignore_covered_err
853 # uncoverable branch true
854 # uncoverable condition left count:1 */
855 1 ▶ if (A->ratelimit_hit("st", 2, 2, 60, &rem, &rst) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->ratelimit_hit("st", 2, 2, 60, &rem, &rst) != 1) ok = 0; 0 1 1
856 /*
857 # uncoverable statement class:ignore_covered_err
858 # uncoverable branch true
859 # uncoverable condition left count:1 */
860 1 ▶ if (A->ratelimit_hit("st", 2, 2, 60, &rem, &rst) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->ratelimit_hit("st", 2, 2, 60, &rem, &rst) != 0) ok = 0; 0 1 1
861 /*
862 # uncoverable statement class:ignore_covered_err
863 # uncoverable branch true
864 # uncoverable condition left count:1 */
865 1 ▶ if (rem != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (rem != 0) ok = 0; 0 1 1
866 /*
867 # uncoverable statement class:ignore_covered_err
868 # uncoverable branch true
869 # uncoverable condition left count:1 */
870 1 ▶ if (rst <= 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (rst <= 0) ok = 0; 0 1 1
871 /* unlimited is always allowed */
872 /*
873 # uncoverable statement class:ignore_covered_err
874 # uncoverable branch true
875 # uncoverable condition left count:1 */
876 1 ▶ if (A->ratelimit_hit("st2", 3, 0, 60, &rem, &rst) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->ratelimit_hit("st2", 3, 0, 60, &rem, &rst) != 1) ok = 0; 0 1 1
877 }
878 }
879  
880 /* v5 the bus, driven through the table. The ring is opened here with the
881 * defaults when the arena exists (idempotent), so Punk's no-server tests
882 * get a working bus from this call as they get the maps. */
883 {
884 1 int e = 0;
885 1 (void)hm_sa_bus_open(0, 0, &e);
886 /*
887 # uncoverable branch true class:ignore_covered_err
888 # uncoverable condition left count:1 class:ignore_covered_err
889 # uncoverable condition left count:2 class:ignore_covered_err
890 # uncoverable condition left count:3 class:ignore_covered_err
891 # uncoverable condition left count:4 class:ignore_covered_err */
892 1 ▶ if (!A->bus_publish || !A->bus_subscribe || !A->bus_unsubscribe
Branch: 3 branches
BranchTrueFalseTotal
if (!A->bus_publish || !A->bus_subscribe || !A->bus_unsubscribe 1 0 1
if (!A->bus_publish || !A->bus_subscribe || !A->bus_unsubscribe 1 0 1
if (!A->bus_publish || !A->bus_subscribe || !A->bus_unsubscribe 1 0 1
893 1 ▶ || !A->bus_dispatch) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
|| !A->bus_dispatch) ok = 0; 0 1 1
894 /*
895 # uncoverable branch true
896 # uncoverable condition left count:1 class:ignore_covered_err */
897 1 ▶ else if (!hm_sa_bus_live()) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!hm_sa_bus_live()) { 0 1 1
898 /* No ring: publish is local-only, and says so. */
899 /*
900 # uncoverable statement
901 # uncoverable branch true
902 # uncoverable branch false
903 # uncoverable condition left count:1
904 # uncoverable condition right count:1 */
905 0 ▶ if (A->bus_publish("selft", 5, "x", 1) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_publish("selft", 5, "x", 1) != 0) ok = 0; 0 0 0
906 }
907 else {
908 static char big[HM_BUS_SLOT_SIZE + 64];
909 int id, g1, g2, i;
910 1 memset(big, 'x', sizeof big);
911  
912 /* fanout: one record, one subscriber, delivered once */
913 1 hm_abi_selftest_bus_n = 0;
914 1 id = A->bus_subscribe(aTHX_ "selft", 5, NULL, 0,
915 hm_abi_selftest_bus_cb, NULL);
916 /*
917 # uncoverable branch true class:ignore_covered_err
918 # uncoverable condition left count:1 class:ignore_covered_err */
919 1 ▶ if (id < 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) ok = 0; 0 1 1
920 /*
921 # uncoverable statement class:ignore_covered_err
922 # uncoverable branch true
923 # uncoverable condition left count:1 */
924 1 ▶ if (A->bus_publish("selft", 5, "one", 3) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_publish("selft", 5, "one", 3) != 1) ok = 0; 0 1 1
925 /* the ceiling: one byte over is refused, never truncated */
926 /*
927 # uncoverable statement class:ignore_covered_err
928 # uncoverable branch true
929 # uncoverable condition left count:1 */
930 1 ▶ if (A->bus_publish("selft", 5, big,
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_publish("selft", 5, big, 0 1 1
931 1 (STRLEN)hm_sa_bus_max_msg - 5 + 1) != -1) ok = 0; /* # uncoverable statement class:ignore_covered_err */
932 /*
933 # uncoverable statement class:ignore_covered_err
934 # uncoverable branch true
935 # uncoverable condition left count:1 */
936 1 ▶ if (A->bus_publish("selft", 5, big,
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_publish("selft", 5, big, 0 1 1
937 1 (STRLEN)hm_sa_bus_max_msg - 5) != 1) ok = 0; /* # uncoverable statement class:ignore_covered_err */
938 /*
939 # uncoverable branch true class:ignore_covered_err
940 # uncoverable condition left count:1 class:ignore_covered_err
941 # uncoverable condition left count:2 class:ignore_covered_err */
942 1 ▶ if (A->bus_dispatch(aTHX) < 2 || hm_abi_selftest_bus_n != 2) ok = 0;
Branch: 2 branches
BranchTrueFalseTotal
if (A->bus_dispatch(aTHX) < 2 || hm_abi_selftest_bus_n != 2) ok = 0; 1 0 1
if (A->bus_dispatch(aTHX) < 2 || hm_abi_selftest_bus_n != 2) ok = 0; 0 1 1
943 /*
944 # uncoverable statement class:ignore_covered_err
945 # uncoverable branch true
946 # uncoverable condition left count:1 */
947 1 ▶ if (!A->bus_unsubscribe(aTHX_ id)) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->bus_unsubscribe(aTHX_ id)) ok = 0; 0 1 1
948  
949 /* a queue group: ten records, two handles in this process, each
950 * record delivered exactly once between them */
951 1 hm_abi_selftest_bus_n = 0;
952 1 g1 = A->bus_subscribe(aTHX_ "selfg", 5, "pool", 4,
953 hm_abi_selftest_bus_cb, NULL);
954 1 g2 = A->bus_subscribe(aTHX_ "selfg", 5, "pool", 4,
955 hm_abi_selftest_bus_cb, NULL);
956 /*
957 # uncoverable branch true class:ignore_covered_err
958 # uncoverable condition left count:1 class:ignore_covered_err
959 # uncoverable condition left count:2 class:ignore_covered_err */
960 1 ▶ if (g1 < 0 || g2 < 0) ok = 0;
Branch: 2 branches
BranchTrueFalseTotal
if (g1 < 0 || g2 < 0) ok = 0; 1 0 1
if (g1 < 0 || g2 < 0) ok = 0; 0 1 1
961 11 ▶ for (i = 0; i < 10; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 10; i++) 10 1 11
962 /*
963 # uncoverable branch true class:ignore_covered_err
964 # uncoverable condition left count:1 class:ignore_covered_err */
965 10 ▶ if (A->bus_publish("selfg", 5, "job", 3) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_publish("selfg", 5, "job", 3) != 1) ok = 0; 0 10 10
966 /*
967 # uncoverable branch true class:ignore_covered_err
968 # uncoverable condition left count:1 class:ignore_covered_err
969 # uncoverable condition left count:2 class:ignore_covered_err */
970 1 ▶ if (A->bus_dispatch(aTHX) != 10 || hm_abi_selftest_bus_n != 10) ok = 0;
Branch: 2 branches
BranchTrueFalseTotal
if (A->bus_dispatch(aTHX) != 10 || hm_abi_selftest_bus_n != 10) ok = 0; 1 0 1
if (A->bus_dispatch(aTHX) != 10 || hm_abi_selftest_bus_n != 10) ok = 0; 0 1 1
971 /*
972 # uncoverable statement class:ignore_covered_err
973 # uncoverable branch true
974 # uncoverable condition left count:1 */
975 1 ▶ if (A->bus_dispatch(aTHX) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_dispatch(aTHX) != 0) ok = 0; 0 1 1
976 1 (void)A->bus_unsubscribe(aTHX_ g1);
977 1 (void)A->bus_unsubscribe(aTHX_ g2);
978 }
979 }
980  
981 /* v9: the arena and its table are handed out together or not at all,
982 * and the scoreboard sums once it exists. Opened here with two rows so
983 * a no-server process (t/22) sees the same board a server would. */
984 {
985 1 int e = 0;
986 hm_abi_pool_stats ps;
987 /*
988 # uncoverable branch true class:ignore_covered_err
989 # uncoverable condition left count:1 class:ignore_covered_err
990 # uncoverable condition left count:2 class:ignore_covered_err
991 # uncoverable condition left count:3 class:ignore_covered_err */
992 1 ▶ if (!A->arena_region || !A->arena_table || !A->pool_stats) ok = 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!A->arena_region || !A->arena_table || !A->pool_stats) ok = 0; 1 0 1
if (!A->arena_region || !A->arena_table || !A->pool_stats) ok = 0; 1 0 1
if (!A->arena_region || !A->arena_table || !A->pool_stats) ok = 0; 0 1 1
993 /*
994 # uncoverable branch true
995 # uncoverable condition left count:1 class:ignore_covered_err */
996 1 ▶ else if ((A->arena_region() != NULL) != (A->arena_table() != NULL)) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
else if ((A->arena_region() != NULL) != (A->arena_table() != NULL)) ok = 0; 0 1 1
997 /*
998 # uncoverable branch false
999 # uncoverable condition right count:1 class:ignore_covered_err */
1000 1 ▶ else if (A->arena_region()) {
Branch: 1 branch
BranchTrueFalseTotal
else if (A->arena_region()) { 1 0 1
1001 1 (void)hm_sa_board_open(2, &e);
1002 /*
1003 # uncoverable branch true
1004 # uncoverable condition left count:1 class:ignore_covered_err */
1005 1 ▶ if (!hm_sa_board_live()) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_sa_board_live()) ok = 0; 0 1 1
1006 else {
1007 /*
1008 # uncoverable branch true class:ignore_covered_err
1009 # uncoverable condition left count:1 class:ignore_covered_err */
1010 1 ▶ if (A->pool_stats(&ps) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->pool_stats(&ps) != 1) ok = 0; 0 1 1
1011 /*
1012 # uncoverable statement class:ignore_covered_err
1013 # uncoverable branch true
1014 # uncoverable condition left count:1 */
1015 1 ▶ if (hm_sa_board_take() < 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (hm_sa_board_take() < 0) ok = 0; 0 1 1
1016 1 hm_sa_board_mirror(7, 3, 1, 0, 512, 0, 0);
1017 /*
1018 # uncoverable branch true class:ignore_covered_err
1019 # uncoverable condition left count:1 class:ignore_covered_err
1020 # uncoverable condition left count:2 class:ignore_covered_err
1021 # uncoverable condition left count:3 class:ignore_covered_err
1022 # uncoverable condition left count:4 class:ignore_covered_err */
1023 1 ▶ if (A->pool_stats(&ps) != 1 || ps.workers < 1
Branch: 2 branches
BranchTrueFalseTotal
if (A->pool_stats(&ps) != 1 || ps.workers < 1 1 0 1
if (A->pool_stats(&ps) != 1 || ps.workers < 1 1 0 1
1024 1 ▶ || ps.requests < 7 || ps.alive < 1) ok = 0;
Branch: 2 branches
BranchTrueFalseTotal
|| ps.requests < 7 || ps.alive < 1) ok = 0; 1 0 1
|| ps.requests < 7 || ps.alive < 1) ok = 0; 0 1 1
1025 }
1026 }
1027 /*
1028 # uncoverable statement
1029 # uncoverable branch true
1030 # uncoverable branch false
1031 # uncoverable condition left count:1
1032 # uncoverable condition right count:1 */
1033 0 ▶ else if (A->pool_stats(&ps) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
else if (A->pool_stats(&ps) != 0) ok = 0; 0 0 0
1034 }
1035  
1036 1 return ok;
1037 }
1038  
1039 #endif /* HM_ABI_IMPL_H */
« include/hyperman/hm_compat.h ↑ Summary include/hyperman/hm_tls.h »