include/store/store_abi_selftest.h

filter: Statementstmt 100% 84 / 84 Branchbran 50.0% 81 / 162 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 67.0% 165 / 246 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/arch/State/Store/Install/Files.pm ↑ Summary xs/abi.xs »
1 #ifndef STORE_ABI_SELFTEST_H
2 #define STORE_ABI_SELFTEST_H
3  
4 /* Walks the table. Every entry is called THROUGH the table, with its answer
5 * checked, so an entry that points at the wrong function, or sits in the
6 * wrong place, fails here by number and not in some consumer's hands.
7 * 0 when every check passed, or the number of the first that failed. */
8  
9 #define STORE_ST(n, cond) do { if (!(cond)) { step = (n); goto done; } } while (0)
10  
11 typedef struct store_st_log { int calls; IV last_was, last_now; } store_st_log;
12  
13 255 static void store_st_watch(pTHX_ void *ud, SV *was, SV *now, SV *st) {
14 255 store_st_log *l = (store_st_log *)ud;
15 PERL_UNUSED_ARG(st);
16 255 l->calls++;
17 255 ▶ l->last_was = SvOK(was) ? SvIV(was) : -1;
Branch: 1 branch
BranchTrueFalseTotal
l->last_was = SvOK(was) ? SvIV(was) : -1; 255 0 255
18 255 ▶ l->last_now = SvOK(now) ? SvIV(now) : -1;
Branch: 1 branch
BranchTrueFalseTotal
l->last_now = SvOK(now) ? SvIV(now) : -1; 255 0 255
19 255 }
20 306 static int store_st_below_100(pTHX_ void *ud, SV *proposed, SV *held, SV *st) {
21 PERL_UNUSED_ARG(held); PERL_UNUSED_ARG(st);
22 306 (*(int *)ud)++;
23 306 return SvIV(proposed) < 100;
24 }
25 51 static SV *store_st_double(pTHX_ void *ud, SV *current) {
26 PERL_UNUSED_ARG(ud);
27 51 return sv_2mortal(newSViv(SvIV(current) * 2));
28 }
29 51 static SV *store_st_nothing(pTHX_ void *ud, SV *current) {
30 PERL_UNUSED_CONTEXT; PERL_UNUSED_ARG(ud); PERL_UNUSED_ARG(current);
31 51 return NULL;
32 }
33 51 static int store_st_count_names(pTHX_ void *ud, const char *name, STRLEN len, int utf8, SV *value) {
34 PERL_UNUSED_CONTEXT; PERL_UNUSED_ARG(name); PERL_UNUSED_ARG(len); PERL_UNUSED_ARG(utf8);
35 51 ▶ if (value) (*(int *)ud)++;
Branch: 1 branch
BranchTrueFalseTotal
if (value) (*(int *)ud)++; 51 0 51
36 51 return 0;
37 }
38  
39 /* `out`, when the test passes, gets the store it built: for the Perl side
40 * to read back. */
41 51 static int store_abi_selftest(pTHX_ SV **out) {
42 51 const state_store_abi *T = &STORE_ABI;
43 51 SV *st = NULL, *v;
44 51 state_store_txn *outer = NULL, *inner = NULL;
45 51 store_st_log log = { 0, 0, 0 };
46 51 size_t taken = 9, limit = 9;
47 51 int step = 0, asked = 0, names = 0, status = 99;
48 UV id;
49  
50 51 *out = NULL;
51 51 ▶ STORE_ST(1, T->abi_version == STATE_STORE_ABI_VERSION);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(1, T->abi_version == STATE_STORE_ABI_VERSION); 0 51 51
52  
53 51 v = sv_2mortal(newSViv(1));
54 51 st = (T->store_new)(aTHX_ v);
55 51 ▶ STORE_ST(2, st && (T->is_store)(aTHX_ st));
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(2, st && (T->is_store)(aTHX_ st)); 51 0 51
STORE_ST(2, st && (T->is_store)(aTHX_ st)); 0 51 51
56 51 ▶ STORE_ST(3, !(T->is_store)(aTHX_ v) && !(T->is_store)(aTHX_ &PL_sv_undef));
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(3, !(T->is_store)(aTHX_ v) && !(T->is_store)(aTHX_ &PL_sv_undef)); 51 0 51
STORE_ST(3, !(T->is_store)(aTHX_ v) && !(T->is_store)(aTHX_ &PL_sv_undef)); 0 51 51
57 51 ▶ STORE_ST(4, SvIV((T->current)(aTHX_ st)) == 1 && (T->current)(aTHX_ v) == NULL);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(4, SvIV((T->current)(aTHX_ st)) == 1 && (T->current)(aTHX_ v) == NULL); 51 0 51
STORE_ST(4, SvIV((T->current)(aTHX_ st)) == 1 && (T->current)(aTHX_ v) == NULL); 0 51 51
58  
59 51 ▶ STORE_ST(5, (T->set)(aTHX_ st, sv_2mortal(newSViv(2))) == 1);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(5, (T->set)(aTHX_ st, sv_2mortal(newSViv(2))) == 1); 0 51 51
60 51 ▶ STORE_ST(6, (T->set)(aTHX_ st, sv_2mortal(newSVpvs("2"))) == 0);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(6, (T->set)(aTHX_ st, sv_2mortal(newSVpvs("2"))) == 0); 0 51 51
61 51 ▶ STORE_ST(7, (T->set)(aTHX_ v, v) == STATE_STORE_NOTSTORE);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(7, (T->set)(aTHX_ v, v) == STATE_STORE_NOTSTORE); 0 51 51
62 51 ▶ STORE_ST(8, (T->swap)(aTHX_ st, store_st_double, NULL) == 1 && SvIV((T->current)(aTHX_ st)) == 4);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(8, (T->swap)(aTHX_ st, store_st_double, NULL) == 1 && SvIV((T->current)(aTHX_ st)) == 4); 51 0 51
STORE_ST(8, (T->swap)(aTHX_ st, store_st_double, NULL) == 1 && SvIV((T->current)(aTHX_ st)) == 4); 0 51 51
63 51 ▶ STORE_ST(9, (T->swap)(aTHX_ st, store_st_nothing, NULL) == STATE_STORE_STOPPED);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(9, (T->swap)(aTHX_ st, store_st_nothing, NULL) == STATE_STORE_STOPPED); 0 51 51
64  
65 51 ▶ STORE_ST(10, (T->undo_count)(aTHX_ st) == 2 && (T->redo_count)(aTHX_ st) == 0);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(10, (T->undo_count)(aTHX_ st) == 2 && (T->redo_count)(aTHX_ st) == 0); 51 0 51
STORE_ST(10, (T->undo_count)(aTHX_ st) == 2 && (T->redo_count)(aTHX_ st) == 0); 0 51 51
66 51 ▶ STORE_ST(11, (T->undo)(aTHX_ st, 5, &taken) == STATE_STORE_OK && taken == 2);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(11, (T->undo)(aTHX_ st, 5, &taken) == STATE_STORE_OK && taken == 2); 51 0 51
STORE_ST(11, (T->undo)(aTHX_ st, 5, &taken) == STATE_STORE_OK && taken == 2); 0 51 51
67 51 ▶ STORE_ST(12, SvIV((T->current)(aTHX_ st)) == 1 && (T->redo_count)(aTHX_ st) == 2);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(12, SvIV((T->current)(aTHX_ st)) == 1 && (T->redo_count)(aTHX_ st) == 2); 51 0 51
STORE_ST(12, SvIV((T->current)(aTHX_ st)) == 1 && (T->redo_count)(aTHX_ st) == 2); 0 51 51
68 51 ▶ STORE_ST(13, (T->redo)(aTHX_ st, 1, &taken) == STATE_STORE_OK && taken == 1
Branch: 3 branches
BranchTrueFalseTotal
STORE_ST(13, (T->redo)(aTHX_ st, 1, &taken) == STATE_STORE_OK && taken == 1 51 0 51
STORE_ST(13, (T->redo)(aTHX_ st, 1, &taken) == STATE_STORE_OK && taken == 1 51 0 51
STORE_ST(13, (T->redo)(aTHX_ st, 1, &taken) == STATE_STORE_OK && taken == 1 0 51 51
69 && SvIV((T->current)(aTHX_ st)) == 2);
70 51 ▶ STORE_ST(14, (T->clear_history)(aTHX_ st) == STATE_STORE_OK
Branch: 3 branches
BranchTrueFalseTotal
STORE_ST(14, (T->clear_history)(aTHX_ st) == STATE_STORE_OK 51 0 51
STORE_ST(14, (T->clear_history)(aTHX_ st) == STATE_STORE_OK 51 0 51
STORE_ST(14, (T->clear_history)(aTHX_ st) == STATE_STORE_OK 0 51 51
71 && (T->undo_count)(aTHX_ st) == 0 && (T->redo_count)(aTHX_ st) == 0);
72  
73 51 ▶ STORE_ST(15, (T->history_limit)(aTHX_ st, &limit) == 0 && limit == 0);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(15, (T->history_limit)(aTHX_ st, &limit) == 0 && limit == 0); 51 0 51
STORE_ST(15, (T->history_limit)(aTHX_ st, &limit) == 0 && limit == 0); 0 51 51
74 51 ▶ STORE_ST(16, (T->set_history_limit)(aTHX_ st, 1, 3) == STATE_STORE_OK);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(16, (T->set_history_limit)(aTHX_ st, 1, 3) == STATE_STORE_OK); 0 51 51
75 51 ▶ STORE_ST(17, (T->history_limit)(aTHX_ st, &limit) == 1 && limit == 3);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(17, (T->history_limit)(aTHX_ st, &limit) == 1 && limit == 3); 51 0 51
STORE_ST(17, (T->history_limit)(aTHX_ st, &limit) == 1 && limit == 3); 0 51 51
76  
77 51 id = (T->watch)(aTHX_ st, store_st_watch, &log);
78 51 ▶ STORE_ST(18, id != 0 && (T->watchers)(aTHX_ st) == 1);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(18, id != 0 && (T->watchers)(aTHX_ st) == 1); 51 0 51
STORE_ST(18, id != 0 && (T->watchers)(aTHX_ st) == 1); 0 51 51
79 51 (T->set)(aTHX_ st, sv_2mortal(newSViv(7)));
80 51 ▶ STORE_ST(19, log.calls == 1 && log.last_was == 2 && log.last_now == 7);
Branch: 3 branches
BranchTrueFalseTotal
STORE_ST(19, log.calls == 1 && log.last_was == 2 && log.last_now == 7); 51 0 51
STORE_ST(19, log.calls == 1 && log.last_was == 2 && log.last_now == 7); 51 0 51
STORE_ST(19, log.calls == 1 && log.last_was == 2 && log.last_now == 7); 0 51 51
81  
82 51 ▶ STORE_ST(20, (T->set_validator)(aTHX_ st, store_st_below_100, &asked) == STATE_STORE_OK);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(20, (T->set_validator)(aTHX_ st, store_st_below_100, &asked) == STATE_STORE_OK); 0 51 51
83 51 ▶ STORE_ST(21, (T->set)(aTHX_ st, sv_2mortal(newSViv(500))) == STATE_STORE_REFUSED
Branch: 4 branches
BranchTrueFalseTotal
STORE_ST(21, (T->set)(aTHX_ st, sv_2mortal(newSViv(500))) == STATE_STORE_REFUSED 51 0 51
STORE_ST(21, (T->set)(aTHX_ st, sv_2mortal(newSViv(500))) == STATE_STORE_REFUSED 51 0 51
STORE_ST(21, (T->set)(aTHX_ st, sv_2mortal(newSViv(500))) == STATE_STORE_REFUSED 51 0 51
STORE_ST(21, (T->set)(aTHX_ st, sv_2mortal(newSViv(500))) == STATE_STORE_REFUSED 0 51 51
84 && SvIV((T->current)(aTHX_ st)) == 7 && asked == 1 && log.calls == 1);
85 51 ▶ STORE_ST(22, (T->set)(aTHX_ st, sv_2mortal(newSViv(8))) == 1 && asked == 2);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(22, (T->set)(aTHX_ st, sv_2mortal(newSViv(8))) == 1 && asked == 2); 51 0 51
STORE_ST(22, (T->set)(aTHX_ st, sv_2mortal(newSViv(8))) == 1 && asked == 2); 0 51 51
86  
87 51 outer = (T->txn_begin)(aTHX_ st, &status);
88 51 ▶ STORE_ST(23, outer && status == STATE_STORE_OK && (T->in_txn)(aTHX_ st) == 1);
Branch: 3 branches
BranchTrueFalseTotal
STORE_ST(23, outer && status == STATE_STORE_OK && (T->in_txn)(aTHX_ st) == 1); 51 0 51
STORE_ST(23, outer && status == STATE_STORE_OK && (T->in_txn)(aTHX_ st) == 1); 51 0 51
STORE_ST(23, outer && status == STATE_STORE_OK && (T->in_txn)(aTHX_ st) == 1); 0 51 51
89 51 inner = (T->txn_begin)(aTHX_ st, NULL);
90 51 ▶ STORE_ST(24, inner != NULL);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(24, inner != NULL); 0 51 51
91 51 ▶ STORE_ST(25, (T->txn_commit)(aTHX_ outer) == STATE_STORE_ORDER);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(25, (T->txn_commit)(aTHX_ outer) == STATE_STORE_ORDER); 0 51 51
92 51 ▶ STORE_ST(26, (T->undo)(aTHX_ st, 1, NULL) == STATE_STORE_BUSY);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(26, (T->undo)(aTHX_ st, 1, NULL) == STATE_STORE_BUSY); 0 51 51
93 51 (T->set)(aTHX_ st, sv_2mortal(newSViv(30)));
94 51 ▶ STORE_ST(27, (T->txn_abort)(aTHX_ inner) == STATE_STORE_OK && SvIV((T->current)(aTHX_ st)) == 8);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(27, (T->txn_abort)(aTHX_ inner) == STATE_STORE_OK && SvIV((T->current)(aTHX_ st)) == 8); 51 0 51
STORE_ST(27, (T->txn_abort)(aTHX_ inner) == STATE_STORE_OK && SvIV((T->current)(aTHX_ st)) == 8); 0 51 51
95 51 inner = NULL;
96 51 (T->set)(aTHX_ st, sv_2mortal(newSViv(40)));
97 51 (T->set)(aTHX_ st, sv_2mortal(newSViv(41)));
98 51 ▶ STORE_ST(28, log.calls == 2);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(28, log.calls == 2); 0 51 51
99 51 ▶ STORE_ST(29, (T->txn_commit)(aTHX_ outer) == STATE_STORE_OK);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(29, (T->txn_commit)(aTHX_ outer) == STATE_STORE_OK); 0 51 51
100 51 outer = NULL;
101 51 ▶ STORE_ST(30, log.calls == 3 && log.last_was == 8 && log.last_now == 41
Branch: 4 branches
BranchTrueFalseTotal
STORE_ST(30, log.calls == 3 && log.last_was == 8 && log.last_now == 41 51 0 51
STORE_ST(30, log.calls == 3 && log.last_was == 8 && log.last_now == 41 51 0 51
STORE_ST(30, log.calls == 3 && log.last_was == 8 && log.last_now == 41 51 0 51
STORE_ST(30, log.calls == 3 && log.last_was == 8 && log.last_now == 41 0 51 51
102 && (T->in_txn)(aTHX_ st) == 0);
103  
104 51 ▶ STORE_ST(31, (T->checkpoint)(aTHX_ st, "here", 4, 0) == STATE_STORE_OK);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(31, (T->checkpoint)(aTHX_ st, "here", 4, 0) == STATE_STORE_OK); 0 51 51
105 51 ▶ STORE_ST(32, (T->has_checkpoint)(aTHX_ st, "here", 4, 0) == 1
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(32, (T->has_checkpoint)(aTHX_ st, "here", 4, 0) == 1 51 0 51
STORE_ST(32, (T->has_checkpoint)(aTHX_ st, "here", 4, 0) == 1 0 51 51
106 && (T->has_checkpoint)(aTHX_ st, "there", 5, 0) == 0);
107 51 ▶ STORE_ST(33, SvIV((T->checkpoint_value)(aTHX_ st, "here", 4, 0)) == 41);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(33, SvIV((T->checkpoint_value)(aTHX_ st, "here", 4, 0)) == 41); 0 51 51
108 51 (T->set)(aTHX_ st, sv_2mortal(newSViv(50)));
109 51 ▶ STORE_ST(34, (T->restore)(aTHX_ st, "here", 4, 0) == 1 && SvIV((T->current)(aTHX_ st)) == 41);
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(34, (T->restore)(aTHX_ st, "here", 4, 0) == 1 && SvIV((T->current)(aTHX_ st)) == 41); 51 0 51
STORE_ST(34, (T->restore)(aTHX_ st, "here", 4, 0) == 1 && SvIV((T->current)(aTHX_ st)) == 41); 0 51 51
110 51 ▶ STORE_ST(35, (T->restore)(aTHX_ st, "there", 5, 0) == STATE_STORE_NOTFOUND);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(35, (T->restore)(aTHX_ st, "there", 5, 0) == STATE_STORE_NOTFOUND); 0 51 51
111 51 ▶ STORE_ST(36, (T->checkpoint_count)(aTHX_ st) == 1);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(36, (T->checkpoint_count)(aTHX_ st) == 1); 0 51 51
112 51 ▶ STORE_ST(37, (T->checkpoint_walk)(aTHX_ st, store_st_count_names, &names) == STATE_STORE_OK
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(37, (T->checkpoint_walk)(aTHX_ st, store_st_count_names, &names) == STATE_STORE_OK 51 0 51
STORE_ST(37, (T->checkpoint_walk)(aTHX_ st, store_st_count_names, &names) == STATE_STORE_OK 0 51 51
113 && names == 1);
114 51 ▶ STORE_ST(38, (T->drop_checkpoint)(aTHX_ st, "here", 4, 0) == STATE_STORE_OK
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(38, (T->drop_checkpoint)(aTHX_ st, "here", 4, 0) == STATE_STORE_OK 51 0 51
STORE_ST(38, (T->drop_checkpoint)(aTHX_ st, "here", 4, 0) == STATE_STORE_OK 0 51 51
115 && (T->checkpoint_count)(aTHX_ st) == 0);
116 51 ▶ STORE_ST(39, (T->drop_checkpoint)(aTHX_ st, "here", 4, 0) == STATE_STORE_NOTFOUND);
Branch: 1 branch
BranchTrueFalseTotal
STORE_ST(39, (T->drop_checkpoint)(aTHX_ st, "here", 4, 0) == STATE_STORE_NOTFOUND); 0 51 51
117  
118 51 ▶ STORE_ST(40, (T->unwatch)(aTHX_ st, id) == 1 && (T->watchers)(aTHX_ st) == 0
Branch: 3 branches
BranchTrueFalseTotal
STORE_ST(40, (T->unwatch)(aTHX_ st, id) == 1 && (T->watchers)(aTHX_ st) == 0 51 0 51
STORE_ST(40, (T->unwatch)(aTHX_ st, id) == 1 && (T->watchers)(aTHX_ st) == 0 51 0 51
STORE_ST(40, (T->unwatch)(aTHX_ st, id) == 1 && (T->watchers)(aTHX_ st) == 0 0 51 51
119 && (T->unwatch)(aTHX_ st, id) == 0);
120 51 ▶ STORE_ST(41, (T->set_validator)(aTHX_ st, NULL, NULL) == STATE_STORE_OK
Branch: 2 branches
BranchTrueFalseTotal
STORE_ST(41, (T->set_validator)(aTHX_ st, NULL, NULL) == STATE_STORE_OK 51 0 51
STORE_ST(41, (T->set_validator)(aTHX_ st, NULL, NULL) == STATE_STORE_OK 51 0 51
121 && (T->set)(aTHX_ st, sv_2mortal(newSViv(1000))) == 1);
122  
123 51 done:
124 51 ▶ if (inner) (T->txn_abort)(aTHX_ inner);
Branch: 1 branch
BranchTrueFalseTotal
if (inner) (T->txn_abort)(aTHX_ inner); 0 51 51
125 51 ▶ if (outer) (T->txn_abort)(aTHX_ outer);
Branch: 1 branch
BranchTrueFalseTotal
if (outer) (T->txn_abort)(aTHX_ outer); 0 51 51
126 51 ▶ if (st) {
Branch: 1 branch
BranchTrueFalseTotal
if (st) { 51 0 51
127 51 ▶ if (step) SvREFCNT_dec(st);
Branch: 1 branch
BranchTrueFalseTotal
if (step) SvREFCNT_dec(st); 0 51 51
128 51 else *out = st;
129 }
130 51 return step;
131 }
132  
133 #endif
« blib/arch/State/Store/Install/Files.pm ↑ Summary xs/abi.xs »