| 1 |
|
| MODULE = Punk::Observe PACKAGE = Punk::Observe PREFIX = po_ |
| 2 |
|
| |
| 3 |
|
| # The contract surface. Nothing here is a feature; it exists so that |
| 4 |
|
| # t/0001-contracts.t can assert from Perl the things phase 0 promised, on every |
| 5 |
|
| # perl in the smoker matrix rather than only on the one that built it. |
| 6 |
|
| |
| 7 |
|
| # --- struct layout ---------------------------------------------------------- |
| 8 |
|
| |
| 9 |
|
| UV |
| 10 |
|
| po_rec_size(...) |
| 11 |
|
| CODE: |
| 12 |
3 |
▶ | RETVAL = (UV)sizeof(po_rec); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)sizeof(po_rec); |
0 |
3 |
3 |
|
| 13 |
|
| OUTPUT: |
| 14 |
|
| RETVAL |
| 15 |
|
| |
| 16 |
|
| UV |
| 17 |
|
| po_rec_declared_size(...) |
| 18 |
|
| CODE: |
| 19 |
1 |
▶ | RETVAL = (UV)PO_REC_SIZE; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)PO_REC_SIZE; |
0 |
1 |
1 |
|
| 20 |
|
| OUTPUT: |
| 21 |
|
| RETVAL |
| 22 |
|
| |
| 23 |
|
| # Every member's offset, so a padding surprise on an unusual ABI is a failing |
| 24 |
|
| # test naming the member rather than a silently misread segment. |
| 25 |
|
| void |
| 26 |
|
| po_rec_offsets(...) |
| 27 |
|
| PPCODE: |
| 28 |
|
| { |
| 29 |
|
| /* offsetof, not (char *)&((T *)0)->m - (char *)0. The hand-rolled |
| 30 |
|
| * form is undefined behaviour on a null pointer and clang says so |
| 31 |
|
| * under -Wnull-pointer-subtraction; stddef.h has had the correct |
| 32 |
|
| * spelling since C89. */ |
| 33 |
|
| #define OFF(name) \ |
| 34 |
|
| do { mXPUSHp(#name, sizeof(#name) - 1); \ |
| 35 |
|
| mXPUSHu((UV)offsetof(po_rec, name)); } while (0) |
| 36 |
1 |
▶ | OFF(t_unix_nano); OFF(series); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(t_unix_nano); OFF(series); |
0 |
1 |
1 |
| OFF(t_unix_nano); OFF(series); |
0 |
1 |
1 |
| OFF(t_unix_nano); OFF(series); |
0 |
1 |
1 |
| OFF(t_unix_nano); OFF(series); |
0 |
1 |
1 |
|
| 37 |
1 |
▶ | OFF(trace_id_hi); OFF(trace_id_lo); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(trace_id_hi); OFF(trace_id_lo); |
0 |
1 |
1 |
| OFF(trace_id_hi); OFF(trace_id_lo); |
0 |
1 |
1 |
| OFF(trace_id_hi); OFF(trace_id_lo); |
0 |
1 |
1 |
| OFF(trace_id_hi); OFF(trace_id_lo); |
0 |
1 |
1 |
|
| 38 |
1 |
▶ | OFF(span_id); OFF(parent_span_id); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(span_id); OFF(parent_span_id); |
0 |
1 |
1 |
| OFF(span_id); OFF(parent_span_id); |
0 |
1 |
1 |
| OFF(span_id); OFF(parent_span_id); |
0 |
1 |
1 |
| OFF(span_id); OFF(parent_span_id); |
0 |
1 |
1 |
|
| 39 |
1 |
▶ | OFF(dur_nano); OFF(value); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(dur_nano); OFF(value); |
0 |
1 |
1 |
| OFF(dur_nano); OFF(value); |
0 |
1 |
1 |
| OFF(dur_nano); OFF(value); |
0 |
1 |
1 |
| OFF(dur_nano); OFF(value); |
0 |
1 |
1 |
|
| 40 |
1 |
▶ | OFF(body_off); OFF(body_len); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(body_off); OFF(body_len); |
0 |
1 |
1 |
| OFF(body_off); OFF(body_len); |
0 |
1 |
1 |
| OFF(body_off); OFF(body_len); |
0 |
1 |
1 |
| OFF(body_off); OFF(body_len); |
0 |
1 |
1 |
|
| 41 |
1 |
▶ | OFF(attr_off); OFF(attr_len); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(attr_off); OFF(attr_len); |
0 |
1 |
1 |
| OFF(attr_off); OFF(attr_len); |
0 |
1 |
1 |
| OFF(attr_off); OFF(attr_len); |
0 |
1 |
1 |
| OFF(attr_off); OFF(attr_len); |
0 |
1 |
1 |
|
| 42 |
1 |
▶ | OFF(severity); OFF(flags); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(severity); OFF(flags); |
0 |
1 |
1 |
| OFF(severity); OFF(flags); |
0 |
1 |
1 |
| OFF(severity); OFF(flags); |
0 |
1 |
1 |
| OFF(severity); OFF(flags); |
0 |
1 |
1 |
|
| 43 |
1 |
▶ | OFF(kind); OFF(aux); |
Branch: 4 branches
| Branch | True | False | Total |
| OFF(kind); OFF(aux); |
0 |
1 |
1 |
| OFF(kind); OFF(aux); |
0 |
1 |
1 |
| OFF(kind); OFF(aux); |
0 |
1 |
1 |
| OFF(kind); OFF(aux); |
0 |
1 |
1 |
|
| 44 |
|
| #undef OFF |
| 45 |
|
| } |
| 46 |
|
| |
| 47 |
|
| # --- 64-bit fidelity -------------------------------------------------------- |
| 48 |
|
| |
| 49 |
|
| # Round-trip a value through po_rec's uint64_t field and back out through the |
| 50 |
|
| # documented Perl representation. On a 32-bit IV perl the return is a decimal |
| 51 |
|
| # string; the point of the test is that it is the SAME value either way. |
| 52 |
|
| SV * |
| 53 |
|
| po_u64_roundtrip(SV *in) |
| 54 |
|
| CODE: |
| 55 |
|
| { |
| 56 |
14 |
| po_u64 v = 0; |
| 57 |
|
| po_rec r; |
| 58 |
14 |
▶ | if (!po_sv_to_u64(aTHX_ in, &v)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_sv_to_u64(aTHX_ in, &v)) |
5 |
9 |
14 |
|
| 59 |
5 |
| croak("not a non-negative integer"); |
| 60 |
9 |
| po_rec_zero(&r); |
| 61 |
9 |
| r.t_unix_nano = v; /* through the real field */ |
| 62 |
9 |
| RETVAL = po_u64_to_sv(r.t_unix_nano); |
| 63 |
|
| } |
| 64 |
|
| OUTPUT: |
| 65 |
|
| RETVAL |
| 66 |
|
| |
| 67 |
|
| # Does this perl need the string path? The test asserts that it is actually |
| 68 |
|
| # taken where IVSIZE < 8, rather than assuming the branch is reachable. |
| 69 |
|
| UV |
| 70 |
|
| po_uvsize(...) |
| 71 |
|
| CODE: |
| 72 |
0 |
▶ | RETVAL = (UV)UVSIZE; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)UVSIZE; |
0 |
0 |
0 |
|
| 73 |
|
| OUTPUT: |
| 74 |
|
| RETVAL |
| 75 |
|
| |
| 76 |
|
| # The decimal formatter, called directly. |
| 77 |
|
| # |
| 78 |
|
| # On a 64-bit UV perl the string branch is never TAKEN - every po_u64 fits a |
| 79 |
|
| # UV - so po_u64_string_sv would ship untested everywhere except the 32-bit |
| 80 |
|
| # smokers, which is the wrong way round: it would be exercised for the first |
| 81 |
|
| # time on the platform least able to report why it broke. A branch that is |
| 82 |
|
| # never exercised is a branch that is wrong. |
| 83 |
|
| SV * |
| 84 |
|
| po_u64_to_string(SV *in) |
| 85 |
|
| CODE: |
| 86 |
|
| { |
| 87 |
8 |
| po_u64 v = 0; |
| 88 |
8 |
▶ | if (!po_sv_to_u64(aTHX_ in, &v)) croak("not an integer"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_sv_to_u64(aTHX_ in, &v)) croak("not an integer"); |
0 |
8 |
8 |
|
| 89 |
8 |
| RETVAL = po_u64_string_sv(aTHX_ v); |
| 90 |
|
| } |
| 91 |
|
| OUTPUT: |
| 92 |
|
| RETVAL |
| 93 |
|
| |
| 94 |
|
| int |
| 95 |
|
| po_u64_is_string(SV *in) |
| 96 |
|
| CODE: |
| 97 |
|
| { |
| 98 |
1 |
| po_u64 v = 0; |
| 99 |
|
| SV *out; |
| 100 |
1 |
▶ | if (!po_sv_to_u64(aTHX_ in, &v)) croak("not an integer"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_sv_to_u64(aTHX_ in, &v)) croak("not an integer"); |
0 |
1 |
1 |
|
| 101 |
1 |
| out = po_u64_to_sv(v); |
| 102 |
1 |
▶ | RETVAL = SvPOK(out) && !SvIOK(out) ? 1 : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = SvPOK(out) && !SvIOK(out) ? 1 : 0; |
0 |
1 |
1 |
| RETVAL = SvPOK(out) && !SvIOK(out) ? 1 : 0; |
0 |
0 |
0 |
|
| 103 |
1 |
| SvREFCNT_dec(out); |
| 104 |
|
| } |
| 105 |
|
| OUTPUT: |
| 106 |
|
| RETVAL |
| 107 |
|
| |
| 108 |
|
| # --- the clock seam --------------------------------------------------------- |
| 109 |
|
| |
| 110 |
|
| void |
| 111 |
|
| po_clock_freeze(SV *at) |
| 112 |
|
| CODE: |
| 113 |
|
| { |
| 114 |
1 |
| po_u64 v = 0; |
| 115 |
1 |
▶ | if (!po_sv_to_u64(aTHX_ at, &v)) croak("not an integer"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_sv_to_u64(aTHX_ at, &v)) croak("not an integer"); |
0 |
1 |
1 |
|
| 116 |
1 |
| po_clock_freeze(v); |
| 117 |
|
| } |
| 118 |
|
| |
| 119 |
|
| void |
| 120 |
|
| po_clock_step(SV *by) |
| 121 |
|
| CODE: |
| 122 |
|
| { |
| 123 |
1 |
| po_u64 v = 0; |
| 124 |
1 |
▶ | if (!po_sv_to_u64(aTHX_ by, &v)) croak("not an integer"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_sv_to_u64(aTHX_ by, &v)) croak("not an integer"); |
0 |
1 |
1 |
|
| 125 |
1 |
| po_clock_step(v); |
| 126 |
|
| } |
| 127 |
|
| |
| 128 |
|
| void |
| 129 |
|
| po_clock_real(...) |
| 130 |
|
| CODE: |
| 131 |
1 |
| po_clock_real(); |
| 132 |
|
| |
| 133 |
|
| SV * |
| 134 |
|
| po_now_ns(...) |
| 135 |
|
| CODE: |
| 136 |
24 |
| RETVAL = po_u64_to_sv(po_now_ns()); |
| 137 |
|
| OUTPUT: |
| 138 |
|
| RETVAL |
| 139 |
|
| |
| 140 |
|
| int |
| 141 |
|
| po_have_monotonic(...) |
| 142 |
|
| CODE: |
| 143 |
0 |
| RETVAL = po_have_monotonic(); |
| 144 |
|
| OUTPUT: |
| 145 |
|
| RETVAL |
| 146 |
|
| |
| 147 |
|
| SV * |
| 148 |
|
| po_block_start(SV *t) |
| 149 |
|
| CODE: |
| 150 |
|
| { |
| 151 |
4 |
| po_u64 v = 0; |
| 152 |
4 |
▶ | if (!po_sv_to_u64(aTHX_ t, &v)) croak("not an integer"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_sv_to_u64(aTHX_ t, &v)) croak("not an integer"); |
0 |
4 |
4 |
|
| 153 |
4 |
| RETVAL = po_u64_to_sv(po_block_start(v)); |
| 154 |
|
| } |
| 155 |
|
| OUTPUT: |
| 156 |
|
| RETVAL |
| 157 |
|
| |
| 158 |
|
| # A clock that stepped backwards gives end < start. In a uint64_t that is not |
| 159 |
|
| # a small negative number, it is about 1.8e19, so it clamps and is counted. |
| 160 |
|
| SV * |
| 161 |
|
| po_duration(SV *start, SV *end) |
| 162 |
|
| CODE: |
| 163 |
|
| { |
| 164 |
2 |
| po_u64 a = 0, b = 0; |
| 165 |
2 |
▶ | if (!po_sv_to_u64(aTHX_ start, &a) || !po_sv_to_u64(aTHX_ end, &b)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!po_sv_to_u64(aTHX_ start, &a) || !po_sv_to_u64(aTHX_ end, &b)) |
2 |
0 |
2 |
| if (!po_sv_to_u64(aTHX_ start, &a) || !po_sv_to_u64(aTHX_ end, &b)) |
0 |
2 |
2 |
|
| 166 |
0 |
| croak("not an integer"); |
| 167 |
2 |
| RETVAL = po_u64_to_sv(po_duration(a, b)); |
| 168 |
|
| } |
| 169 |
|
| OUTPUT: |
| 170 |
|
| RETVAL |
| 171 |
|
| |
| 172 |
|
| # --- the tenant boundary ---------------------------------------------------- |
| 173 |
|
| |
| 174 |
|
| int |
| 175 |
|
| po_tenant_ok(SV *id) |
| 176 |
|
| CODE: |
| 177 |
|
| { |
| 178 |
|
| STRLEN len; |
| 179 |
|
| const char *p; |
| 180 |
21 |
▶ | if (!SvOK(id)) { RETVAL = 0; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(id)) { RETVAL = 0; } |
0 |
21 |
21 |
|
| 181 |
|
| else { |
| 182 |
21 |
| p = SvPV(id, len); /* on its own line, deliberately: */ |
| 183 |
21 |
| RETVAL = po_tenant_ok(p, len); /* f(SvPV(sv,n), n) is UB */ |
| 184 |
|
| } |
| 185 |
|
| } |
| 186 |
|
| OUTPUT: |
| 187 |
|
| RETVAL |
| 188 |
|
| |
| 189 |
|
| # Returns the constructed root, or undef if the id was refused. The test |
| 190 |
|
| # asserts on the STRING, not on the filesystem: a path for tenant A must not |
| 191 |
|
| # resolve inside tenant B whether or not either directory exists. |
| 192 |
|
| SV * |
| 193 |
|
| po_store_root(SV *data, SV *tenant) |
| 194 |
|
| CODE: |
| 195 |
|
| { |
| 196 |
|
| po_store s; |
| 197 |
4 |
| STRLEN dlen, tlen = 0; |
| 198 |
4 |
| const char *d, *t = NULL; |
| 199 |
4 |
| d = SvPV(data, dlen); |
| 200 |
7 |
▶ | if (SvOK(tenant)) t = SvPV(tenant, tlen); |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(tenant)) t = SvPV(tenant, tlen); |
3 |
1 |
4 |
|
| 201 |
4 |
▶ | if (!po_store_init(&s, d, t, tlen)) RETVAL = &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_store_init(&s, d, t, tlen)) RETVAL = &PL_sv_undef; |
2 |
2 |
4 |
|
| 202 |
2 |
| else RETVAL = newSVpv(s.root, 0); |
| 203 |
|
| } |
| 204 |
|
| OUTPUT: |
| 205 |
|
| RETVAL |
| 206 |
|
| |
| 207 |
|
| SV * |
| 208 |
|
| po_store_join(SV *data, SV *tenant, SV *rel) |
| 209 |
|
| CODE: |
| 210 |
|
| { |
| 211 |
|
| po_store s; |
| 212 |
|
| char out[PO_PATH_MAX]; |
| 213 |
2 |
| STRLEN dlen, tlen = 0, rlen; |
| 214 |
2 |
| const char *d, *t = NULL, *r; |
| 215 |
|
| size_t n; |
| 216 |
2 |
| d = SvPV(data, dlen); |
| 217 |
4 |
▶ | if (SvOK(tenant)) t = SvPV(tenant, tlen); |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(tenant)) t = SvPV(tenant, tlen); |
2 |
0 |
2 |
|
| 218 |
2 |
| r = SvPV(rel, rlen); |
| 219 |
2 |
▶ | if (!po_store_init(&s, d, t, tlen)) RETVAL = &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_store_init(&s, d, t, tlen)) RETVAL = &PL_sv_undef; |
0 |
2 |
2 |
|
| 220 |
2 |
▶ | else if (!(n = po_store_path(&s, r, out, sizeof(out)))) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (!(n = po_store_path(&s, r, out, sizeof(out)))) |
0 |
2 |
2 |
|
| 221 |
0 |
| RETVAL = &PL_sv_undef; |
| 222 |
2 |
| else RETVAL = newSVpvn(out, n); |
| 223 |
|
| } |
| 224 |
|
| OUTPUT: |
| 225 |
|
| RETVAL |
| 226 |
|
| |
| 227 |
|
| # --- the arena -------------------------------------------------------------- |
| 228 |
|
| |
| 229 |
|
| # Round-trip bytes through the arena, so that the offset discipline po_rec |
| 230 |
|
| # depends on is exercised rather than assumed. |
| 231 |
|
| SV * |
| 232 |
|
| po_arena_roundtrip(SV *in) |
| 233 |
|
| CODE: |
| 234 |
|
| { |
| 235 |
|
| po_arena a; |
| 236 |
|
| STRLEN len; |
| 237 |
|
| const char *p; |
| 238 |
|
| uint32_t off; |
| 239 |
5 |
| p = SvPV(in, len); |
| 240 |
5 |
▶ | if (!po_arena_init(&a, 16)) croak("arena"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!po_arena_init(&a, 16)) croak("arena"); |
0 |
5 |
5 |
|
| 241 |
5 |
| off = po_arena_put(&a, p, (size_t)len); |
| 242 |
5 |
▶ | if (off == PO_ARENA_ERR) { po_arena_free(&a); croak("arena full"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (off == PO_ARENA_ERR) { po_arena_free(&a); croak("arena full"); } |
0 |
5 |
5 |
|
| 243 |
5 |
| RETVAL = newSVpvn(a.base + off, len); |
| 244 |
5 |
| po_arena_free(&a); |
| 245 |
|
| } |
| 246 |
|
| OUTPUT: |
| 247 |
|
| RETVAL |
| 248 |
|
| |
| 249 |
|
| # --- build facts ------------------------------------------------------------ |
| 250 |
|
| |
| 251 |
|
| void |
| 252 |
|
| po_build_info(...) |
| 253 |
|
| PPCODE: |
| 254 |
|
| { |
| 255 |
|
| #define FACT(k, v) \ |
| 256 |
|
| do { mXPUSHp(k, sizeof(k) - 1); mXPUSHi(v); } while (0) |
| 257 |
|
| #ifdef PO_HAVE_CLOCK_GETTIME |
| 258 |
1 |
▶ | FACT("clock_gettime", 1); |
Branch: 2 branches
| Branch | True | False | Total |
| FACT("clock_gettime", 1); |
0 |
1 |
1 |
| FACT("clock_gettime", 1); |
0 |
1 |
1 |
|
| 259 |
|
| #else |
| 260 |
|
| FACT("clock_gettime", 0); |
| 261 |
|
| #endif |
| 262 |
|
| #ifdef PO_HAVE_CLOCK_MONOTONIC |
| 263 |
1 |
▶ | FACT("clock_monotonic", 1); |
Branch: 2 branches
| Branch | True | False | Total |
| FACT("clock_monotonic", 1); |
0 |
1 |
1 |
| FACT("clock_monotonic", 1); |
0 |
1 |
1 |
|
| 264 |
|
| #else |
| 265 |
|
| FACT("clock_monotonic", 0); |
| 266 |
|
| #endif |
| 267 |
|
| #ifdef PO_HAVE_ATOMICS |
| 268 |
1 |
▶ | FACT("atomics", 1); |
Branch: 2 branches
| Branch | True | False | Total |
| FACT("atomics", 1); |
0 |
1 |
1 |
| FACT("atomics", 1); |
0 |
1 |
1 |
|
| 269 |
|
| #else |
| 270 |
|
| FACT("atomics", 0); |
| 271 |
|
| #endif |
| 272 |
|
| #ifdef PO_BIG_ENDIAN |
| 273 |
|
| FACT("big_endian", 1); |
| 274 |
|
| #else |
| 275 |
1 |
▶ | FACT("big_endian", 0); |
Branch: 2 branches
| Branch | True | False | Total |
| FACT("big_endian", 0); |
0 |
1 |
1 |
| FACT("big_endian", 0); |
0 |
1 |
1 |
|
| 276 |
|
| #endif |
| 277 |
|
| #undef FACT |
| 278 |
|
| } |