include/hyperman/hm_abi_impl.h

filter: Statementstmt 93.5% 324 / 355 (39 uncoverable) Branchbran 82.9% 135 / 264 (97 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 89.0% 459 / 619 (136 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 hm_abi_stream_close_trailers, /* v10 - trailer fields after the body */
286 };
287  
288 /* ---- v4 on_worker_start, driven from C (t/33-worker-start.t) ------------ *
289 * A Perl test cannot register a C callback, so the observable half lives
290 * here: _abi_worker_hook_install registers this through the TABLE, and the
291 * worker it fires in reports the count back through an ordinary request. The
292 * count is a plain static, so it is inherited as 0 across the fork and each
293 * worker increments its own copy - which is exactly the property being
294 * tested. */
295 static IV HM_ABI_ST_WORKER_N = 0;
296 static int HM_ABI_ST_WORKER_LOOP_OK = 1;
297  
298 2 static void hm_abi_st_worker_cb(pTHX_ void *loop, void *ud) {
299 PERL_UNUSED_ARG(ud);
300 /*
301 # uncoverable branch true class:ignore_covered_err
302 # uncoverable condition left count:1 class:ignore_covered_err */
303 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
304 2 HM_ABI_ST_WORKER_N++;
305 2 }
306  
307 /* Register through the table, not by calling hm_worker_hook_add directly -
308 * the point of a selftest is to prove the function pointer works. */
309 3 static int hm_abi_worker_hook_install(pTHX) {
310 3 const hm_abi *A = INT2PTR(const hm_abi *, PTR2IV(&hm_abi_table));
311 /*
312 # uncoverable branch true class:ignore_covered_err
313 # uncoverable condition left count:1 class:ignore_covered_err
314 # uncoverable condition left count:2 class:ignore_covered_err */
315 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
316 3 return A->on_worker_start(aTHX_ hm_abi_st_worker_cb, NULL);
317 }
318  
319 /* ---- v6 stream handles, driven from C (t/41-stream-abi.t) --------------- *
320 *
321 * The static half - that the entries exist and that a stale handle is an
322 * error return rather than a crash - is in hm_abi_selftest below. This is the
323 * live half, which needs a real connection and therefore a real server: an
324 * application calls these from inside a request, the C side does everything
325 * through the TABLE, and a later request reads the counters back out.
326 *
327 * One handle at a time, in a process-global, because the tests that use it
328 * run with workers => 1 and a single handle is what makes "did the abort
329 * fire" answerable from Perl at all. */
330 static void *HM_ABI_ST_SH = NULL;
331 static IV HM_ABI_ST_SH_ABORTS = 0;
332 static IV HM_ABI_ST_SH_DRAINS = 0;
333 static IV HM_ABI_ST_SH_WRITES = 0;
334 static IV HM_ABI_ST_SH_TODO = 0; /* chunks still owed on the stream */
335 static IV HM_ABI_ST_SH_FULLS = 0; /* times the connection said stop */
336  
337 1 static void hm_abi_st_stream_abort(pTHX_ void *h, void *ud) {
338 PERL_UNUSED_CONTEXT;
339 PERL_UNUSED_ARG(ud);
340 1 HM_ABI_ST_SH_ABORTS++;
341 1 HM_ABI_ST_SH_TODO = 0; /* nobody is listening any more */
342 /* The handle survives an abort - only stream_close frees it - so it is
343 * deliberately NOT released here. The test's next request closes it and
344 * proves the release path copes with a stream that died first. */
345 (void)h;
346 1 }
347  
348 /* Produce until the connection says stop, then stop until it says go. This is
349 * the whole backpressure contract, and it is the only honest way to test it:
350 * a producer that only ever writes small chunks never reaches it. */
351 690 static void hm_abi_st_stream_pump(pTHX_ void *h) {
352 690 const hm_abi *A = &hm_abi_table;
353 char buf[4096];
354 690 memset(buf, 'x', sizeof buf);
355 2049 ▶ while (HM_ABI_ST_SH_TODO > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (HM_ABI_ST_SH_TODO > 0) { 2048 1 2049
356 2048 int r = A->stream_write(aTHX_ h, buf, sizeof(buf));
357 /*
358 # uncoverable branch true class:ignore_covered_err
359 # uncoverable condition left count:1 class:ignore_covered_err */
360 2737 ▶ 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
361 2048 HM_ABI_ST_SH_TODO--;
362 2048 HM_ABI_ST_SH_WRITES++;
363 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; } 689 1359 2048
364 }
365 /*
366 # uncoverable branch false class:ignore_covered_err
367 # uncoverable condition right count:1 class:ignore_covered_err */
368 1 ▶ if (HM_ABI_ST_SH == h) {
Branch: 1 branch
BranchTrueFalseTotal
if (HM_ABI_ST_SH == h) { 1 0 1
369 1 A->stream_close(aTHX_ h);
370 1 HM_ABI_ST_SH = NULL;
371 }
372 }
373  
374 689 static void hm_abi_st_stream_drain(pTHX_ void *h, void *ud) {
375 PERL_UNUSED_ARG(ud);
376 689 HM_ABI_ST_SH_DRAINS++;
377 689 hm_abi_st_stream_pump(aTHX_ h);
378 689 }
379  
380 /* Open a stream on the request this env names, over whichever transport it
381 * arrived on. 1 = open, 0 = refused. */
382 14 static int hm_abi_st_stream_open(pTHX_ SV *env, int status, SV *headers) {
383 14 const hm_abi *A = &hm_abi_table;
384 int fd;
385 UV id;
386 int64_t sid;
387 /*
388 # uncoverable branch true
389 # uncoverable condition left count:1 class:ignore_covered_err */
390 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
391 /*
392 # uncoverable branch true
393 # uncoverable condition left count:1 class:ignore_covered_err */
394 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
395 14 HM_ABI_ST_SH = A->stream_open(aTHX_ (void *)hm_cur_loop, fd, id, sid,
396 status, headers);
397 /*
398 # uncoverable branch true
399 # uncoverable condition left count:1 class:ignore_covered_err */
400 14 ▶ if (!HM_ABI_ST_SH) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return 0; 0 14 14
401 14 HM_ABI_ST_SH_WRITES = 0;
402 14 A->stream_on_abort(aTHX_ HM_ABI_ST_SH, hm_abi_st_stream_abort, NULL);
403 14 A->stream_on_drain(aTHX_ HM_ABI_ST_SH, hm_abi_st_stream_drain, NULL);
404 14 return 1;
405 }
406  
407 18 static int hm_abi_st_stream_write(pTHX_ SV *data) {
408 18 const hm_abi *A = &hm_abi_table;
409 STRLEN l;
410 const char *p;
411 int r;
412 /*
413 # uncoverable branch true
414 # uncoverable condition left count:1 class:ignore_covered_err */
415 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
416 18 p = SvPV(data, l);
417 18 r = A->stream_write(aTHX_ HM_ABI_ST_SH, p, l);
418 18 ▶ if (r >= 0) HM_ABI_ST_SH_WRITES++;
Branch: 1 branch
BranchTrueFalseTotal
if (r >= 0) HM_ABI_ST_SH_WRITES++; 17 1 18
419 18 return r;
420 }
421  
422 /* Owe the stream n chunks of 4KiB and start producing them. */
423 1 static void hm_abi_st_stream_produce(pTHX_ IV n) {
424 /*
425 # uncoverable branch true
426 # uncoverable condition left count:1 class:ignore_covered_err */
427 1 ▶ if (!HM_ABI_ST_SH) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!HM_ABI_ST_SH) return; 0 1 1
428 1 HM_ABI_ST_SH_TODO = n;
429 1 hm_abi_st_stream_pump(aTHX_ HM_ABI_ST_SH);
430 }
431  
432 /* v8: what the read half delivered, echoed back so a Perl test can see it.
433 * Bounded - this is a test hook on an unbounded stream, and an unbounded
434 * buffer behind a test hook is still an unbounded buffer. */
435 static char HM_ABI_ST_SH_RX[4096];
436 static IV HM_ABI_ST_SH_RXLEN = 0;
437 static IV HM_ABI_ST_SH_RXN = 0;
438  
439 15 static void hm_abi_st_stream_data(pTHX_ void *h, const char *buf, STRLEN len,
440 int fin, void *ud) {
441 PERL_UNUSED_CONTEXT;
442 PERL_UNUSED_ARG(ud);
443 (void)h; (void)fin;
444 15 HM_ABI_ST_SH_RXN++;
445 /*
446 # uncoverable branch true class:ignore_covered_err
447 # uncoverable condition left count:1 class:ignore_covered_err */
448 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
449 0 len = sizeof(HM_ABI_ST_SH_RX) - (size_t)HM_ABI_ST_SH_RXLEN; /* # uncoverable statement */
450 /*
451 # uncoverable branch false class:ignore_covered_err
452 # uncoverable condition right count:1 class:ignore_covered_err */
453 15 ▶ if (len) {
Branch: 1 branch
BranchTrueFalseTotal
if (len) { 15 0 15
454 15 memcpy(HM_ABI_ST_SH_RX + HM_ABI_ST_SH_RXLEN, buf, len);
455 15 HM_ABI_ST_SH_RXLEN += (IV)len;
456 }
457 15 }
458  
459 /* Register the read half on the open handle, through the TABLE. */
460 9 static int hm_abi_st_stream_read(pTHX) {
461 9 const hm_abi *A = &hm_abi_table;
462 /*
463 # uncoverable branch true
464 # uncoverable condition left count:1 class:ignore_covered_err */
465 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
466 9 HM_ABI_ST_SH_RXLEN = 0;
467 9 HM_ABI_ST_SH_RXN = 0;
468 9 return A->stream_on_data(aTHX_ HM_ABI_ST_SH, hm_abi_st_stream_data, NULL);
469 }
470  
471 12 static int hm_abi_st_stream_close(pTHX) {
472 12 const hm_abi *A = &hm_abi_table;
473 int r;
474 /*
475 # uncoverable branch true
476 # uncoverable condition left count:1 class:ignore_covered_err */
477 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
478 12 r = A->stream_close(aTHX_ HM_ABI_ST_SH);
479 12 HM_ABI_ST_SH = NULL;
480 12 return r;
481 }
482  
483 /* v10 through the TABLE. ARG means the list was refused and the handle is
484 * still open and still ours, which is the contract t/75 checks, so the
485 * handle is forgotten only when the call released it. */
486 0 static int hm_abi_st_stream_close_trailers(pTHX_ SV *trailers) {
487 0 const hm_abi *A = &hm_abi_table;
488 int r;
489 /*
490 # uncoverable branch true
491 # uncoverable condition left count:1 class:ignore_covered_err */
492 0 ▶ 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 0 0
493 0 r = A->stream_close_trailers(aTHX_ HM_ABI_ST_SH, trailers);
494 0 ▶ if (r != HM_ABI_STREAM_ARG) HM_ABI_ST_SH = NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (r != HM_ABI_STREAM_ARG) HM_ABI_ST_SH = NULL; 0 0 0
495 0 return r;
496 }
497  
498 /* The other ending, so t/41-stream-abi.t can drive it over both transports.
499 * Releases the handle exactly as close does - a producer calls one or the
500 * other, and the selftest must not be the thing that gets that wrong. */
501 1 static int hm_abi_st_stream_do_abort(pTHX) {
502 1 const hm_abi *A = &hm_abi_table;
503 int r;
504 /*
505 # uncoverable branch true
506 # uncoverable condition left count:1 class:ignore_covered_err */
507 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
508 1 r = A->stream_abort(aTHX_ HM_ABI_ST_SH);
509 1 HM_ABI_ST_SH = NULL;
510 1 return r;
511 }
512  
513 /* ---- _abi_selftest: drive the whole table from C (t/22-abi.t) ----------- */
514  
515 1 static void hm_abi_st_ready(pTHX_ SV *f, void *ud) {
516 PERL_UNUSED_VAR(f);
517 1 *(int *)ud = 1;
518 1 }
519  
520 21 static void hm_abi_st_timer(pTHX_ void *ud) {
521 21 hm_abi_table.future_done(aTHX_ (SV *)ud, NULL, 0);
522 21 }
523  
524 typedef struct { SV *f; void *loop; } hm_abi_st_io;
525  
526 1 static void hm_abi_st_io_cb(pTHX_ int fd, int mask, void *ud) {
527 1 hm_abi_st_io *st = (hm_abi_st_io *)ud;
528 char b;
529 PERL_UNUSED_VAR(mask);
530 1 if (read(fd, &b, 1) < 0) { /* settle anyway; the test checks the future */ }
531 1 hm_abi_table.io_unwatch(aTHX_ st->loop, fd, HM_ABI_READ);
532 1 hm_abi_table.future_done(aTHX_ st->f, NULL, 0);
533 1 }
534  
535 /* The same-batch cancel case: the canceller cancels the victim only if the
536 * victim has not fired (a handle dies on fire, so cancelling one that has
537 * would itself be the misuse). */
538 typedef struct {
539 void *loop;
540 hm_abi_timer *victim;
541 SV *f;
542 int victim_fired;
543 int cancelled;
544 } hm_abi_st_cx;
545 10 static void hm_abi_st_cx_victim(pTHX_ void *ud) {
546 10 hm_abi_st_cx *cx = (hm_abi_st_cx *)ud;
547 PERL_UNUSED_CONTEXT;
548 10 cx->victim_fired = 1;
549 10 cx->victim = NULL;
550 10 }
551 20 static void hm_abi_st_cx_cancel(pTHX_ void *ud) {
552 20 hm_abi_st_cx *cx = (hm_abi_st_cx *)ud;
553 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
554 10 hm_abi_table.timer_cancel(aTHX_ cx->loop, cx->victim);
555 10 cx->victim = NULL;
556 10 cx->cancelled = 1;
557 }
558 20 hm_abi_table.future_done(aTHX_ cx->f, NULL, 0);
559 20 }
560  
561 1 static int hm_abi_selftest(pTHX) {
562 1 const hm_abi *A = &hm_abi_table;
563 1 int ok = 1;
564 /*
565 # uncoverable branch true
566 # uncoverable condition left count:1 class:ignore_covered_err */
567 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
568  
569 /* future lifecycle: new -> pending -> on_ready (C) -> done -> fired */
570 {
571 1 SV *f = A->future_new(aTHX);
572 1 int fired = 0;
573 1 SV *val = sv_2mortal(newSViv(42));
574 /*
575 # uncoverable branch true class:ignore_covered_err
576 # uncoverable condition left count:1 class:ignore_covered_err */
577 1 ▶ if (!A->is_future(aTHX_ f)) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->is_future(aTHX_ f)) ok = 0; 0 1 1
578 /*
579 # uncoverable statement class:ignore_covered_err
580 # uncoverable branch true
581 # uncoverable condition left count:1 */
582 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
583 1 A->future_on_ready(aTHX_ f, hm_abi_st_ready, &fired); /* # uncoverable statement class:ignore_covered_err */
584 1 A->future_done(aTHX_ f, &val, 1); /* # uncoverable statement class:ignore_covered_err */
585 1 A->future_done(aTHX_ f, &val, 1); /* second settle: no-op */ /* # uncoverable statement class:ignore_covered_err */
586 /*
587 # uncoverable statement class:ignore_covered_err
588 # uncoverable branch true
589 # uncoverable condition left count:1 */
590 1 ▶ if (!fired) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!fired) ok = 0; 0 1 1
591 /*
592 # uncoverable statement class:ignore_covered_err
593 # uncoverable branch true
594 # uncoverable condition left count:1 */
595 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
596 1 SvREFCNT_dec(f); /* # uncoverable statement class:ignore_covered_err */
597 }
598  
599 /* failure path */
600 {
601 1 SV *f = A->future_new(aTHX); /* # uncoverable statement class:ignore_covered_err */
602 1 SV *err = sv_2mortal(newSVpvs("nope")); /* # uncoverable statement class:ignore_covered_err */
603 1 A->future_fail(aTHX_ f, err); /* # uncoverable statement class:ignore_covered_err */
604 /*
605 # uncoverable statement class:ignore_covered_err
606 # uncoverable branch true
607 # uncoverable condition left count:1 */
608 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
609 1 SvREFCNT_dec(f);
610 }
611  
612 /* loop: C io watcher on a readable pipe, a cancelled timer that must not
613 * fire, and a live C timer settling the second future */
614 {
615 1 hm_loop *loop = hm_loop_new(aTHX_ NULL);
616 int fds[2];
617 /*
618 # uncoverable branch true
619 # uncoverable condition left count:1 class:ignore_covered_err */
620 1 ▶ if (!loop) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!loop) return 0; 0 1 1
621 /* hm_os_selfpipe, not pipe(2): on Windows the readiness backend
622 * polls sockets only, so the pair has to be a loopback connection
623 * there. hm_os_send/hm_os_close write and close either kind. */
624 /*
625 # uncoverable branch false
626 # uncoverable condition right count:1 class:ignore_covered_err */
627 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
628 1 SV *fio = A->future_new(aTHX);
629 1 SV *ftw = A->future_new(aTHX);
630 hm_abi_st_io st;
631 hm_abi_timer *dead;
632 1 st.f = fio;
633 1 st.loop = (void *)loop;
634 /*
635 # uncoverable branch true class:ignore_covered_err
636 # uncoverable condition left count:1 class:ignore_covered_err */
637 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
638 1 A->io_watch(aTHX_ (void *)loop, fds[0], HM_ABI_READ, /* # uncoverable statement class:ignore_covered_err */
639 hm_abi_st_io_cb, &st);
640 1 dead = A->timer(aTHX_ (void *)loop, 3600.0, hm_abi_st_timer, ftw); /* # uncoverable statement class:ignore_covered_err */
641 1 A->timer_cancel(aTHX_ (void *)loop, dead); /* # uncoverable statement class:ignore_covered_err */
642 1 A->timer(aTHX_ (void *)loop, 0.01, hm_abi_st_timer, ftw); /* # uncoverable statement class:ignore_covered_err */
643 1 A->run_until(aTHX_ (void *)loop, fio); /* # uncoverable statement class:ignore_covered_err */
644 /*
645 # uncoverable statement class:ignore_covered_err
646 # uncoverable branch true
647 # uncoverable condition left count:1 */
648 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
649 1 A->run_until(aTHX_ (void *)loop, ftw); /* # uncoverable statement class:ignore_covered_err */
650 /*
651 # uncoverable statement class:ignore_covered_err
652 # uncoverable branch true
653 # uncoverable condition left count:1 */
654 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
655 1 SvREFCNT_dec(fio);
656 1 SvREFCNT_dec(ftw);
657 1 hm_os_close(fds[0]);
658 1 hm_os_close(fds[1]);
659 0 } else ok = 0; /* # uncoverable statement class:ignore_covered_err */
660  
661 /* timer_cancel from a callback in the SAME BATCH as the victim: two
662 * timers due together, the first to fire cancels the other. The
663 * other's event is already in the array the backend returned, so
664 * freeing it at cancel was a use after free at its dispatch (and a
665 * double free). Twenty rounds, alternating registration order,
666 * because which of two due timers a backend reports first is its
667 * business: the victim must never fire after the cancel, and under
668 * ASan the dispatch of a cancelled one must touch nothing freed. */
669 {
670 int round;
671 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
672 hm_abi_st_cx cx;
673 20 SV *f = A->future_new(aTHX);
674 20 cx.loop = (void *)loop;
675 20 cx.f = f;
676 20 cx.victim_fired = 0;
677 20 cx.cancelled = 0;
678 20 ▶ if (round & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (round & 1) { 10 10 20
679 10 cx.victim = A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_victim, &cx);
680 10 A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_cancel, &cx);
681 } else {
682 10 A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_cancel, &cx);
683 10 cx.victim = A->timer(aTHX_ (void *)loop, 0.0, hm_abi_st_cx_victim, &cx);
684 }
685 20 A->run_until(aTHX_ (void *)loop, f);
686 /* a second turn, so a victim wrongly left armed would fire */
687 {
688 20 SV *f2 = A->future_new(aTHX);
689 20 A->timer(aTHX_ (void *)loop, 0.005, hm_abi_st_timer, f2);
690 20 A->run_until(aTHX_ (void *)loop, f2);
691 20 SvREFCNT_dec(f2);
692 }
693 /*
694 # uncoverable branch true class:ignore_covered_err
695 # uncoverable condition left count:1 class:ignore_covered_err
696 # uncoverable condition left count:2 class:ignore_covered_err */
697 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
698 20 SvREFCNT_dec(f);
699 }
700 }
701  
702 /* v2 conn_detach: the entry is present and rejects tickets that
703 * name no connection. The success path needs a live HTTP
704 * connection and is covered end to end by t/23-detach.t. */
705 /*
706 # uncoverable branch true
707 # uncoverable condition left count:1 class:ignore_covered_err */
708 1 ▶ if (!A->conn_detach) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->conn_detach) ok = 0; 0 1 1
709 /*
710 # uncoverable branch true class:ignore_covered_err
711 # uncoverable condition left count:1 class:ignore_covered_err */
712 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
713  
714 /* v6 stream handles. The success path needs a live request and is
715 * covered end to end by t/41-stream-abi.t, over HTTP/1.1 and over
716 * HTTP/2. What is provable with no connection is the half that
717 * matters most for memory safety: a ticket naming nothing hands
718 * back no handle, and every entry point given a pointer that is not
719 * a live handle SAYS SO instead of dereferencing it. The address
720 * below is deliberately a plausible-looking one. */
721 /*
722 # uncoverable branch true class:ignore_covered_err
723 # uncoverable condition left count:1 class:ignore_covered_err
724 # uncoverable condition left count:2 class:ignore_covered_err
725 # uncoverable condition left count:3 class:ignore_covered_err
726 # uncoverable condition left count:4 class:ignore_covered_err
727 # uncoverable condition left count:5 class:ignore_covered_err
728 # uncoverable condition left count:6 class:ignore_covered_err */
729 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
730 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
731 1 ▶ || !A->stream_abort) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
|| !A->stream_abort) ok = 0; 0 1 1
732 else {
733 1 void *bogus = (void *)&hm_abi_table; /* real memory, no handle */
734 /*
735 # uncoverable branch true class:ignore_covered_err
736 # uncoverable condition left count:1 class:ignore_covered_err */
737 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
738 /*
739 # uncoverable statement class:ignore_covered_err
740 # uncoverable branch true
741 # uncoverable condition left count:1 */
742 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
743 /*
744 # uncoverable statement class:ignore_covered_err
745 # uncoverable branch true
746 # uncoverable condition left count:1 */
747 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
748 0 ok = 0; /* # uncoverable statement */
749 /*
750 # uncoverable statement class:ignore_covered_err
751 # uncoverable branch true
752 # uncoverable condition left count:1 */
753 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
754 0 ok = 0; /* # uncoverable statement */
755 /*
756 # uncoverable statement class:ignore_covered_err
757 # uncoverable branch true
758 # uncoverable condition left count:1 */
759 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
760 0 ok = 0; /* # uncoverable statement */
761 /*
762 # uncoverable statement class:ignore_covered_err
763 # uncoverable branch true
764 # uncoverable condition left count:1 */
765 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
766 0 ok = 0; /* # uncoverable statement */
767 /*
768 # uncoverable statement class:ignore_covered_err
769 # uncoverable branch true
770 # uncoverable condition left count:1 */
771 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
772 /*
773 # uncoverable statement class:ignore_covered_err
774 # uncoverable branch true
775 # uncoverable condition left count:1 */
776 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
777 0 != HM_ABI_STREAM_STALE) ok = 0; /* # uncoverable statement */
778 /*
779 # uncoverable statement class:ignore_covered_err
780 # uncoverable branch true
781 # uncoverable condition left count:1 */
782 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
783 0 != HM_ABI_STREAM_STALE) ok = 0; /* # uncoverable statement */
784 }
785  
786 1 hm_loop_free(aTHX_ loop);
787 }
788  
789 /* v3 abuse controls, driven through the table. Init the arena here so the
790 * selftest exercises them even with no server running (idempotent). */
791 {
792 1 IV rem = 0, rst = 0;
793 /* The Shared::Arena and its two maps, with the defaults: Punk's
794 * no-server tests get Hyperman->arena and a working ratelimit_hit
795 * from this call. Idempotent. */
796 1 hm_sa_open(aTHX_ NULL, 0, hm_sa_bytes(0, 0, 0, 0));
797 1 (void)hm_sa_abuse_open(0, 0, NULL, NULL);
798 /*
799 # uncoverable branch true class:ignore_covered_err
800 # uncoverable condition left count:1 class:ignore_covered_err
801 # uncoverable condition left count:2 class:ignore_covered_err
802 # uncoverable condition left count:3 class:ignore_covered_err
803 # uncoverable condition left count:4 class:ignore_covered_err */
804 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
805 1 ▶ || !A->ratelimit_hit) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
|| !A->ratelimit_hit) ok = 0; 0 1 1
806 /*
807 # uncoverable branch true
808 # uncoverable condition left count:1 class:ignore_covered_err */
809 1 ▶ else if (!hm_sa_abuse_live()) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!hm_sa_abuse_live()) { 0 1 1
810 /* No arena: the contract is that every entry point FAILS OPEN,
811 * and that is what gets asserted. Anything else here would be
812 * testing a feature the build does not have. (Shared::Arena
813 * absent, or a compiler without the atomics it needs.) */
814 0 A->deny_add("203.0.113.7", 0); /* # uncoverable statement */
815 /*
816 # uncoverable statement
817 # uncoverable branch true
818 # uncoverable branch false
819 # uncoverable condition left count:1
820 # uncoverable condition right count:1 */
821 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
822 0 A->deny_remove("203.0.113.7"); /* # uncoverable statement */
823 /*
824 # uncoverable statement
825 # uncoverable branch true
826 # uncoverable branch false
827 # uncoverable condition left count:1
828 # uncoverable condition right count:1 */
829 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
830 /*
831 # uncoverable statement
832 # uncoverable branch true
833 # uncoverable branch false
834 # uncoverable condition left count:1
835 # uncoverable condition right count:1 */
836 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
837 }
838 else {
839 /*
840 # uncoverable branch true class:ignore_covered_err
841 # uncoverable condition left count:1 class:ignore_covered_err */
842 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
843 1 A->deny_add("203.0.113.7", 0); /* # uncoverable statement class:ignore_covered_err */
844 /*
845 # uncoverable statement class:ignore_covered_err
846 # uncoverable branch true
847 # uncoverable condition left count:1 */
848 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
849 /*
850 # uncoverable statement class:ignore_covered_err
851 # uncoverable branch true
852 # uncoverable condition left count:1 */
853 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
854 1 A->deny_remove("203.0.113.7"); /* # uncoverable statement class:ignore_covered_err */
855 /*
856 # uncoverable statement class:ignore_covered_err
857 # uncoverable branch true
858 # uncoverable condition left count:1 */
859 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
860  
861 /* 2 per window: two allowed, the third over */
862 /*
863 # uncoverable statement class:ignore_covered_err
864 # uncoverable branch true
865 # uncoverable condition left count:1 */
866 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
867 /*
868 # uncoverable statement class:ignore_covered_err
869 # uncoverable branch true
870 # uncoverable condition left count:1 */
871 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
872 /*
873 # uncoverable statement class:ignore_covered_err
874 # uncoverable branch true
875 # uncoverable condition left count:1 */
876 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
877 /*
878 # uncoverable statement class:ignore_covered_err
879 # uncoverable branch true
880 # uncoverable condition left count:1 */
881 1 ▶ if (rem != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (rem != 0) ok = 0; 0 1 1
882 /*
883 # uncoverable statement class:ignore_covered_err
884 # uncoverable branch true
885 # uncoverable condition left count:1 */
886 1 ▶ if (rst <= 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (rst <= 0) ok = 0; 0 1 1
887 /* unlimited is always allowed */
888 /*
889 # uncoverable statement class:ignore_covered_err
890 # uncoverable branch true
891 # uncoverable condition left count:1 */
892 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
893 }
894 }
895  
896 /* v5 the bus, driven through the table. The ring is opened here with the
897 * defaults when the arena exists (idempotent), so Punk's no-server tests
898 * get a working bus from this call as they get the maps. */
899 {
900 1 int e = 0;
901 1 (void)hm_sa_bus_open(0, 0, &e);
902 /*
903 # uncoverable branch true class:ignore_covered_err
904 # uncoverable condition left count:1 class:ignore_covered_err
905 # uncoverable condition left count:2 class:ignore_covered_err
906 # uncoverable condition left count:3 class:ignore_covered_err
907 # uncoverable condition left count:4 class:ignore_covered_err */
908 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
909 1 ▶ || !A->bus_dispatch) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
|| !A->bus_dispatch) ok = 0; 0 1 1
910 /*
911 # uncoverable branch true
912 # uncoverable condition left count:1 class:ignore_covered_err */
913 1 ▶ else if (!hm_sa_bus_live()) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!hm_sa_bus_live()) { 0 1 1
914 /* No ring: publish is local-only, and says so. */
915 /*
916 # uncoverable statement
917 # uncoverable branch true
918 # uncoverable branch false
919 # uncoverable condition left count:1
920 # uncoverable condition right count:1 */
921 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
922 }
923 else {
924 static char big[HM_BUS_SLOT_SIZE + 64];
925 int id, g1, g2, i;
926 1 memset(big, 'x', sizeof big);
927  
928 /* fanout: one record, one subscriber, delivered once */
929 1 hm_abi_selftest_bus_n = 0;
930 1 id = A->bus_subscribe(aTHX_ "selft", 5, NULL, 0,
931 hm_abi_selftest_bus_cb, NULL);
932 /*
933 # uncoverable branch true class:ignore_covered_err
934 # uncoverable condition left count:1 class:ignore_covered_err */
935 1 ▶ if (id < 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) ok = 0; 0 1 1
936 /*
937 # uncoverable statement class:ignore_covered_err
938 # uncoverable branch true
939 # uncoverable condition left count:1 */
940 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
941 /* the ceiling: one byte over is refused, never truncated */
942 /*
943 # uncoverable statement class:ignore_covered_err
944 # uncoverable branch true
945 # uncoverable condition left count:1 */
946 1 ▶ if (A->bus_publish("selft", 5, big,
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_publish("selft", 5, big, 0 1 1
947 1 (STRLEN)hm_sa_bus_max_msg - 5 + 1) != -1) ok = 0; /* # uncoverable statement class:ignore_covered_err */
948 /*
949 # uncoverable statement class:ignore_covered_err
950 # uncoverable branch true
951 # uncoverable condition left count:1 */
952 1 ▶ if (A->bus_publish("selft", 5, big,
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_publish("selft", 5, big, 0 1 1
953 1 (STRLEN)hm_sa_bus_max_msg - 5) != 1) ok = 0; /* # uncoverable statement class:ignore_covered_err */
954 /*
955 # uncoverable branch true class:ignore_covered_err
956 # uncoverable condition left count:1 class:ignore_covered_err
957 # uncoverable condition left count:2 class:ignore_covered_err */
958 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
959 /*
960 # uncoverable statement class:ignore_covered_err
961 # uncoverable branch true
962 # uncoverable condition left count:1 */
963 1 ▶ if (!A->bus_unsubscribe(aTHX_ id)) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->bus_unsubscribe(aTHX_ id)) ok = 0; 0 1 1
964  
965 /* a queue group: ten records, two handles in this process, each
966 * record delivered exactly once between them */
967 1 hm_abi_selftest_bus_n = 0;
968 1 g1 = A->bus_subscribe(aTHX_ "selfg", 5, "pool", 4,
969 hm_abi_selftest_bus_cb, NULL);
970 1 g2 = A->bus_subscribe(aTHX_ "selfg", 5, "pool", 4,
971 hm_abi_selftest_bus_cb, NULL);
972 /*
973 # uncoverable branch true class:ignore_covered_err
974 # uncoverable condition left count:1 class:ignore_covered_err
975 # uncoverable condition left count:2 class:ignore_covered_err */
976 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
977 11 ▶ for (i = 0; i < 10; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 10; i++) 10 1 11
978 /*
979 # uncoverable branch true class:ignore_covered_err
980 # uncoverable condition left count:1 class:ignore_covered_err */
981 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
982 /*
983 # uncoverable branch true class:ignore_covered_err
984 # uncoverable condition left count:1 class:ignore_covered_err
985 # uncoverable condition left count:2 class:ignore_covered_err */
986 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
987 /*
988 # uncoverable statement class:ignore_covered_err
989 # uncoverable branch true
990 # uncoverable condition left count:1 */
991 1 ▶ if (A->bus_dispatch(aTHX) != 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->bus_dispatch(aTHX) != 0) ok = 0; 0 1 1
992 1 (void)A->bus_unsubscribe(aTHX_ g1);
993 1 (void)A->bus_unsubscribe(aTHX_ g2);
994 }
995 }
996  
997 /* v9: the arena and its table are handed out together or not at all,
998 * and the scoreboard sums once it exists. Opened here with two rows so
999 * a no-server process (t/22) sees the same board a server would. */
1000 {
1001 1 int e = 0;
1002 hm_abi_pool_stats ps;
1003 /*
1004 # uncoverable branch true class:ignore_covered_err
1005 # uncoverable condition left count:1 class:ignore_covered_err
1006 # uncoverable condition left count:2 class:ignore_covered_err
1007 # uncoverable condition left count:3 class:ignore_covered_err */
1008 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
1009 /*
1010 # uncoverable branch true
1011 # uncoverable condition left count:1 class:ignore_covered_err */
1012 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
1013 /*
1014 # uncoverable branch false
1015 # uncoverable condition right count:1 class:ignore_covered_err */
1016 1 ▶ else if (A->arena_region()) {
Branch: 1 branch
BranchTrueFalseTotal
else if (A->arena_region()) { 1 0 1
1017 1 (void)hm_sa_board_open(2, &e);
1018 /*
1019 # uncoverable branch true
1020 # uncoverable condition left count:1 class:ignore_covered_err */
1021 1 ▶ if (!hm_sa_board_live()) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_sa_board_live()) ok = 0; 0 1 1
1022 else {
1023 /*
1024 # uncoverable branch true class:ignore_covered_err
1025 # uncoverable condition left count:1 class:ignore_covered_err */
1026 1 ▶ if (A->pool_stats(&ps) != 1) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (A->pool_stats(&ps) != 1) ok = 0; 0 1 1
1027 /*
1028 # uncoverable statement class:ignore_covered_err
1029 # uncoverable branch true
1030 # uncoverable condition left count:1 */
1031 1 ▶ if (hm_sa_board_take() < 0) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (hm_sa_board_take() < 0) ok = 0; 0 1 1
1032 1 hm_sa_board_mirror(7, 3, 1, 0, 512, 0, 0);
1033 /*
1034 # uncoverable branch true class:ignore_covered_err
1035 # uncoverable condition left count:1 class:ignore_covered_err
1036 # uncoverable condition left count:2 class:ignore_covered_err
1037 # uncoverable condition left count:3 class:ignore_covered_err
1038 # uncoverable condition left count:4 class:ignore_covered_err */
1039 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
1040 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
1041 }
1042 }
1043 /*
1044 # uncoverable statement
1045 # uncoverable branch true
1046 # uncoverable branch false
1047 # uncoverable condition left count:1
1048 # uncoverable condition right count:1 */
1049 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
1050 }
1051  
1052 /* v10. The handle is checked before the list: a pointer that is not a
1053 * live handle is STALE even beside a malformed list, and is never
1054 * dereferenced. What a live handle does with a list, and that a refused
1055 * list leaves it open, is t/75-trailers.t on both transports. */
1056 {
1057 1 void *bogus = (void *)&hm_abi_table; /* real memory, no handle */
1058 1 AV *odd = newAV();
1059 SV *badrv;
1060 1 av_push(odd, newSVpvs("odd"));
1061 1 badrv = sv_2mortal(newRV_noinc((SV *)odd));
1062 /*
1063 # uncoverable branch true class:ignore_covered_err
1064 # uncoverable condition left count:1 class:ignore_covered_err */
1065 1 ▶ if (!A->stream_close_trailers) ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!A->stream_close_trailers) ok = 0; 0 1 1
1066 else {
1067 /*
1068 # uncoverable branch true class:ignore_covered_err
1069 # uncoverable condition left count:1 class:ignore_covered_err */
1070 1 ▶ if (A->stream_close_trailers(aTHX_ bogus, NULL) != HM_ABI_STREAM_STALE)
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_close_trailers(aTHX_ bogus, NULL) != HM_ABI_STREAM_STALE) 0 1 1
1071 0 ok = 0; /* # uncoverable statement */
1072 /*
1073 # uncoverable statement class:ignore_covered_err
1074 # uncoverable branch true
1075 # uncoverable condition left count:1 */
1076 1 ▶ if (A->stream_close_trailers(aTHX_ bogus, badrv) != HM_ABI_STREAM_STALE)
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_close_trailers(aTHX_ bogus, badrv) != HM_ABI_STREAM_STALE) 0 1 1
1077 0 ok = 0; /* # uncoverable statement */
1078 /*
1079 # uncoverable statement class:ignore_covered_err
1080 # uncoverable branch true
1081 # uncoverable condition left count:1 */
1082 1 ▶ if (A->stream_close_trailers(aTHX_ NULL, badrv) != HM_ABI_STREAM_STALE)
Branch: 1 branch
BranchTrueFalseTotal
if (A->stream_close_trailers(aTHX_ NULL, badrv) != HM_ABI_STREAM_STALE) 0 1 1
1083 0 ok = 0; /* # uncoverable statement */
1084 }
1085 }
1086  
1087 1 return ok;
1088 }
1089  
1090 #endif /* HM_ABI_IMPL_H */
« include/hyperman/hm_compat.h ↑ Summary include/hyperman/hm_tls.h »