include/context_vars/context_vars_ctx_selftest.h

filter: Statementstmt 100% 106 / 106 Branchbran 50.0% 54 / 108 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.7% 160 / 214 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/test.xs ↑ Summary include/context_vars/context_vars_abi_impl.h »
1 #ifndef CONTEXT_VARS_CTX_SELFTEST_H
2 #define CONTEXT_VARS_CTX_SELFTEST_H
3  
4 /* The core, exercised from C with no Perl code in between. Returns 0, or the
5 * number of the first check that did not hold. It must be called with
6 * nothing entered, and leaves nothing entered. A croak cannot be provoked
7 * from here without losing the count, so the checks that need one are in
8 * t/02-core.t, through the doors in xs/test.xs. */
9  
10 #define CONTEXT_VARS_STEP(n, cond) do { if (!(cond)) return (n); } while (0)
11  
12 22 static IV context_vars_st_iv(pTHX_ const char *name) {
13 22 SV *sv = context_vars_fetch(aTHX_ name, strlen(name));
14 22 ▶ return sv ? SvIV(sv) : -1;
Branch: 1 branch
BranchTrueFalseTotal
return sv ? SvIV(sv) : -1; 22 0 22
15 }
16  
17 16 static void context_vars_st_put(pTHX_ const char *name, IV v) {
18 16 SV *sv = sv_2mortal(newSViv(v));
19 16 context_vars_writable(aTHX);
20 16 context_vars_store(aTHX_ name, strlen(name), sv);
21 16 }
22  
23 2 static int context_vars_ctx_selftest(pTHX) {
24 dMY_CXT;
25 2 context_vars_ctx *empty = MY_CXT.empty;
26 context_vars_ctx *h1, *c;
27 2 IV live0 = MY_CXT.live;
28 2 UV empty0 = empty->refcnt;
29  
30 2 ▶ CONTEXT_VARS_STEP(1, MY_CXT.cur == empty);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(1, MY_CXT.cur == empty); 0 2 2
31 2 ▶ CONTEXT_VARS_STEP(2, MY_CXT.depth == 0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(2, MY_CXT.depth == 0); 0 2 2
32 2 ▶ CONTEXT_VARS_STEP(3, context_vars_fetch(aTHX_ "a", 1) == NULL);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(3, context_vars_fetch(aTHX_ "a", 1) == NULL); 0 2 2
33  
34 /* A scope over nothing shares the empty context and allocates nothing,
35 * until the first store gives it a holder of its own. Leaving it puts
36 * back the very pointer that was current. */
37 2 ENTER;
38 2 context_vars_scope(aTHX);
39 2 ▶ CONTEXT_VARS_STEP(10, MY_CXT.cur == empty);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(10, MY_CXT.cur == empty); 0 2 2
40 2 ▶ CONTEXT_VARS_STEP(11, MY_CXT.depth == 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(11, MY_CXT.depth == 1); 0 2 2
41 2 ▶ CONTEXT_VARS_STEP(12, MY_CXT.live == live0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(12, MY_CXT.live == live0); 0 2 2
42 2 ▶ CONTEXT_VARS_STEP(19, empty->refcnt == empty0 + 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(19, empty->refcnt == empty0 + 1); 0 2 2
43 2 context_vars_st_put(aTHX_ "a", 1);
44 2 ▶ CONTEXT_VARS_STEP(9, MY_CXT.cur != empty && MY_CXT.live == live0 + 1);
Branch: 2 branches
BranchTrueFalseTotal
CONTEXT_VARS_STEP(9, MY_CXT.cur != empty && MY_CXT.live == live0 + 1); 2 0 2
CONTEXT_VARS_STEP(9, MY_CXT.cur != empty && MY_CXT.live == live0 + 1); 0 2 2
45 2 ▶ CONTEXT_VARS_STEP(8, empty->refcnt == empty0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(8, empty->refcnt == empty0); 0 2 2
46 2 ▶ CONTEXT_VARS_STEP(13, context_vars_st_iv(aTHX_ "a") == 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(13, context_vars_st_iv(aTHX_ "a") == 1); 0 2 2
47 2 ▶ CONTEXT_VARS_STEP(14, context_vars_count(aTHX) == 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(14, context_vars_count(aTHX) == 1); 0 2 2
48 2 LEAVE;
49 2 ▶ CONTEXT_VARS_STEP(15, MY_CXT.cur == empty);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(15, MY_CXT.cur == empty); 0 2 2
50 2 ▶ CONTEXT_VARS_STEP(16, MY_CXT.depth == 0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(16, MY_CXT.depth == 0); 0 2 2
51 2 ▶ CONTEXT_VARS_STEP(17, MY_CXT.live == live0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(17, MY_CXT.live == live0); 0 2 2
52 2 ▶ CONTEXT_VARS_STEP(18, context_vars_fetch(aTHX_ "a", 1) == NULL);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(18, context_vars_fetch(aTHX_ "a", 1) == NULL); 0 2 2
53  
54 /* Nested scopes: the inner one starts with what the outer holds, its
55 * store does not reach the outer, and they unwind in order. */
56 2 ENTER;
57 2 context_vars_scope(aTHX);
58 2 context_vars_st_put(aTHX_ "a", 1);
59 2 context_vars_st_put(aTHX_ "b", 7);
60 2 h1 = MY_CXT.cur;
61 2 ENTER;
62 2 context_vars_scope(aTHX);
63 2 ▶ CONTEXT_VARS_STEP(20, MY_CXT.cur != h1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(20, MY_CXT.cur != h1); 0 2 2
64 2 ▶ CONTEXT_VARS_STEP(21, context_vars_st_iv(aTHX_ "a") == 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(21, context_vars_st_iv(aTHX_ "a") == 1); 0 2 2
65 2 context_vars_st_put(aTHX_ "a", 2);
66 2 context_vars_remove(aTHX_ "b", 1);
67 2 ▶ CONTEXT_VARS_STEP(22, context_vars_st_iv(aTHX_ "a") == 2);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(22, context_vars_st_iv(aTHX_ "a") == 2); 0 2 2
68 2 ▶ CONTEXT_VARS_STEP(23, context_vars_fetch(aTHX_ "b", 1) == NULL);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(23, context_vars_fetch(aTHX_ "b", 1) == NULL); 0 2 2
69 2 ▶ CONTEXT_VARS_STEP(24, MY_CXT.depth == 2);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(24, MY_CXT.depth == 2); 0 2 2
70 2 LEAVE;
71 2 ▶ CONTEXT_VARS_STEP(25, MY_CXT.cur == h1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(25, MY_CXT.cur == h1); 0 2 2
72 2 ▶ CONTEXT_VARS_STEP(26, context_vars_st_iv(aTHX_ "a") == 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(26, context_vars_st_iv(aTHX_ "a") == 1); 0 2 2
73 2 ▶ CONTEXT_VARS_STEP(27, context_vars_st_iv(aTHX_ "b") == 7);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(27, context_vars_st_iv(aTHX_ "b") == 7); 0 2 2
74 2 context_vars_remove(aTHX_ "nothere", 7);
75 2 ▶ CONTEXT_VARS_STEP(28, context_vars_count(aTHX) == 2);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(28, context_vars_count(aTHX) == 2); 0 2 2
76 2 LEAVE;
77 2 ▶ CONTEXT_VARS_STEP(29, MY_CXT.cur == empty && MY_CXT.live == live0);
Branch: 2 branches
BranchTrueFalseTotal
CONTEXT_VARS_STEP(29, MY_CXT.cur == empty && MY_CXT.live == live0); 2 0 2
CONTEXT_VARS_STEP(29, MY_CXT.cur == empty && MY_CXT.live == live0); 0 2 2
78  
79 /* A capture with nothing entered is the empty context, and costs no
80 * holder. */
81 2 c = context_vars_capture(aTHX);
82 2 ▶ CONTEXT_VARS_STEP(30, c == empty);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(30, c == empty); 0 2 2
83 2 ▶ CONTEXT_VARS_STEP(31, MY_CXT.live == live0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(31, MY_CXT.live == live0); 0 2 2
84 2 ▶ CONTEXT_VARS_STEP(32, empty->refcnt == empty0 + 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(32, empty->refcnt == empty0 + 1); 0 2 2
85 2 context_vars_release(aTHX_ c);
86 2 ▶ CONTEXT_VARS_STEP(33, empty->refcnt == empty0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(33, empty->refcnt == empty0); 0 2 2
87  
88 /* A capture of something is a holder of its own onto the same values.
89 * A later store on either side stays on that side. */
90 2 ENTER;
91 2 context_vars_scope(aTHX);
92 2 context_vars_st_put(aTHX_ "a", 1);
93 2 h1 = MY_CXT.cur;
94 2 c = context_vars_capture(aTHX);
95 2 ▶ CONTEXT_VARS_STEP(40, c != h1 && c != empty);
Branch: 2 branches
BranchTrueFalseTotal
CONTEXT_VARS_STEP(40, c != h1 && c != empty); 2 0 2
CONTEXT_VARS_STEP(40, c != h1 && c != empty); 0 2 2
96 2 ▶ CONTEXT_VARS_STEP(41, MY_CXT.live == live0 + 2);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(41, MY_CXT.live == live0 + 2); 0 2 2
97 2 context_vars_st_put(aTHX_ "a", 2);
98  
99 2 ENTER;
100 2 context_vars_enter(aTHX_ c);
101 2 ▶ CONTEXT_VARS_STEP(42, MY_CXT.cur == c);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(42, MY_CXT.cur == c); 0 2 2
102 2 ▶ CONTEXT_VARS_STEP(43, context_vars_st_iv(aTHX_ "a") == 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(43, context_vars_st_iv(aTHX_ "a") == 1); 0 2 2
103 2 context_vars_st_put(aTHX_ "c", 5);
104 2 LEAVE;
105 2 ▶ CONTEXT_VARS_STEP(44, MY_CXT.cur == h1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(44, MY_CXT.cur == h1); 0 2 2
106 2 ▶ CONTEXT_VARS_STEP(45, context_vars_st_iv(aTHX_ "a") == 2);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(45, context_vars_st_iv(aTHX_ "a") == 2); 0 2 2
107 2 ▶ CONTEXT_VARS_STEP(46, context_vars_fetch(aTHX_ "c", 1) == NULL);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(46, context_vars_fetch(aTHX_ "c", 1) == NULL); 0 2 2
108  
109 /* enter makes the holder itself current, so its second run sees what
110 * its first stored. */
111 2 ENTER;
112 2 context_vars_enter(aTHX_ c);
113 2 ▶ CONTEXT_VARS_STEP(47, context_vars_st_iv(aTHX_ "c") == 5);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(47, context_vars_st_iv(aTHX_ "c") == 5); 0 2 2
114 2 LEAVE;
115  
116 /* enter_copy makes a fresh one each time, so a second run does not. */
117 2 ENTER;
118 2 context_vars_enter_copy(aTHX_ c);
119 2 ▶ CONTEXT_VARS_STEP(50, MY_CXT.cur != c);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(50, MY_CXT.cur != c); 0 2 2
120 2 ▶ CONTEXT_VARS_STEP(51, context_vars_st_iv(aTHX_ "c") == 5);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(51, context_vars_st_iv(aTHX_ "c") == 5); 0 2 2
121 2 context_vars_st_put(aTHX_ "d", 9);
122 2 ▶ CONTEXT_VARS_STEP(52, MY_CXT.live == live0 + 3);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(52, MY_CXT.live == live0 + 3); 0 2 2
123 2 LEAVE;
124 2 ▶ CONTEXT_VARS_STEP(53, MY_CXT.live == live0 + 2);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(53, MY_CXT.live == live0 + 2); 0 2 2
125 2 ENTER;
126 2 context_vars_enter_copy(aTHX_ c);
127 2 ▶ CONTEXT_VARS_STEP(54, context_vars_fetch(aTHX_ "d", 1) == NULL);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(54, context_vars_fetch(aTHX_ "d", 1) == NULL); 0 2 2
128 2 LEAVE;
129  
130 /* A capture outlives the scope it was taken in. */
131 2 LEAVE;
132 2 ▶ CONTEXT_VARS_STEP(60, MY_CXT.cur == empty);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(60, MY_CXT.cur == empty); 0 2 2
133 2 ▶ CONTEXT_VARS_STEP(61, MY_CXT.live == live0 + 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(61, MY_CXT.live == live0 + 1); 0 2 2
134 2 ENTER;
135 2 context_vars_enter(aTHX_ c);
136 2 ▶ CONTEXT_VARS_STEP(62, context_vars_st_iv(aTHX_ "a") == 1);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(62, context_vars_st_iv(aTHX_ "a") == 1); 0 2 2
137 2 ▶ CONTEXT_VARS_STEP(63, context_vars_st_iv(aTHX_ "c") == 5);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(63, context_vars_st_iv(aTHX_ "c") == 5); 0 2 2
138 2 LEAVE;
139 2 context_vars_release(aTHX_ c);
140  
141 2 ▶ CONTEXT_VARS_STEP(70, MY_CXT.cur == empty);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(70, MY_CXT.cur == empty); 0 2 2
142 2 ▶ CONTEXT_VARS_STEP(71, MY_CXT.depth == 0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(71, MY_CXT.depth == 0); 0 2 2
143 2 ▶ CONTEXT_VARS_STEP(72, MY_CXT.live == live0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(72, MY_CXT.live == live0); 0 2 2
144 2 ▶ CONTEXT_VARS_STEP(73, empty->refcnt == empty0);
Branch: 1 branch
BranchTrueFalseTotal
CONTEXT_VARS_STEP(73, empty->refcnt == empty0); 0 2 2
145 2 return 0;
146 }
147  
148 #endif
« xs/test.xs ↑ Summary include/context_vars/context_vars_abi_impl.h »