Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omnet/blob/main/om/quantity/test/driver.om # omnet aien-dev/omnet Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omnet / om / quantity / test / driver.om` 214 lines ยท 5076 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Native contract test for om/quantity: one result byte, 0 means every case passed, 3 note otherwise the number of the first case that failed. Refusals must leave the 4 note output struct unchanged, which is what the store's charging path relies on. 5 fn testresult code int to int 6 b = new uchar 65536 0 7 put b 0 uchar code 8 r = write int 1 b ulong 0 ulong 1 9 ret 0 10 end 11 fn setq o edit qty v ulong c ulong to int 12 put o val v 13 put o cap c 14 ret 0 15 end 16 fn main to int 17 out = new qty ulong 17 ulong 19 18 a = new qty ulong 0 ulong 0 19 b = new qty ulong 0 ulong 0 20 21 note 1: qword accepts an in-cap value and records value and cap. 22 r0 = setq out ulong 17 ulong 19 23 rc = qword out ulong 5 ulong 7 24 if ne rc int 0 25 ret testresult 1 26 end 27 if not and eq get out val ulong 5 eq get out cap ulong 7 28 ret testresult 1 29 end 30 31 note 2: qword refuses above the cap with 3 and leaves the output unchanged. 32 r0 = setq out ulong 17 ulong 19 33 rc = qword out ulong 8 ulong 7 34 if ne rc int 3 35 ret testresult 2 36 end 37 if not and eq get out val ulong 17 eq get out cap ulong 19 38 ret testresult 2 39 end 40 41 note 3: qword accepts the boundary value equal to the cap. 42 rc = qword out ulong 7 ulong 7 43 if ne rc int 0 44 ret testresult 3 45 end 46 47 note 4: qsigned refuses negative ingress with 2 and leaves the output unchanged. 48 r0 = setq out ulong 17 ulong 19 49 rc = qsigned out long -1 ulong 7 50 if ne rc int 2 51 ret testresult 4 52 end 53 if not and eq get out val ulong 17 eq get out cap ulong 19 54 ret testresult 4 55 end 56 57 note 5: qsigned accepts a non-negative value. 58 rc = qsigned out long 5 ulong 7 59 if ne rc int 0 60 ret testresult 5 61 end 62 if not and eq get out val ulong 5 eq get out cap ulong 7 63 ret testresult 5 64 end 65 66 note 6: qadd sums equal-cap operands that fit. 67 r0 = setq a ulong 3 ulong 7 68 r0 = setq b ulong 4 ulong 7 69 r0 = setq out ulong 17 ulong 19 70 rc = qadd out a b 71 if ne rc int 0 72 ret testresult 6 73 end 74 if not and eq get out val ulong 7 eq get out cap ulong 7 75 ret testresult 6 76 end 77 78 note 7: qadd refuses overflow with 3 and leaves the output unchanged. 79 r0 = setq a ulong 7 ulong 7 80 r0 = setq b ulong 1 ulong 7 81 r0 = setq out ulong 17 ulong 19 82 rc = qadd out a b 83 if ne rc int 3 84 ret testresult 7 85 end 86 if not and eq get out val ulong 17 eq get out cap ulong 19 87 ret testresult 7 88 end 89 90 note 8: qadd refuses unequal caps with 2. 91 r0 = setq a ulong 3 ulong 7 92 r0 = setq b ulong 1 ulong 8 93 rc = qadd out a b 94 if ne rc int 2 95 ret testresult 8 96 end 97 98 note 9: qsub refuses underflow with 3 and leaves the output unchanged. 99 r0 = setq a ulong 1 ulong 7 100 r0 = setq b ulong 2 ulong 7 101 r0 = setq out ulong 17 ulong 19 102 rc = qsub out a b 103 if ne rc int 3 104 ret testresult 9 105 end 106 if not and eq get out val ulong 17 eq get out cap ulong 19 107 ret testresult 9 108 end 109 110 note 10: qsub difference fits. 111 r0 = setq a ulong 5 ulong 7 112 r0 = setq b ulong 2 ulong 7 113 rc = qsub out a b 114 if ne rc int 0 115 ret testresult 10 116 end 117 if not and eq get out val ulong 3 eq get out cap ulong 7 118 ret testresult 10 119 end 120 121 note 11: qmul refuses a wrapping product with 3. 122 r0 = setq a ulong `18446744073709551615` ulong `18446744073709551615` 123 r0 = setq b ulong 2 ulong `18446744073709551615` 124 rc = qmul out a b 125 if ne rc int 3 126 ret testresult 11 127 end 128 129 note 12: qmul accepts a zero operand without dividing by zero. 130 r0 = setq a ulong 0 ulong `18446744073709551615` 131 r0 = setq b ulong `18446744073709551615` ulong `18446744073709551615` 132 rc = qmul out a b 133 if ne rc int 0 134 ret testresult 12 135 end 136 if ne get out val ulong 0 137 ret testresult 12 138 end 139 140 note 13: qnarrow refuses a target cap above the source cap with 2. 141 r0 = setq a ulong 5 ulong 10 142 r0 = setq out ulong 17 ulong 19 143 rc = qnarrow out a ulong 20 144 if ne rc int 2 145 ret testresult 13 146 end 147 148 note 14: qnarrow refuses a value that does not fit the target cap with 3. 149 r0 = setq a ulong 9 ulong 10 150 rc = qnarrow out a ulong 8 151 if ne rc int 3 152 ret testresult 14 153 end 154 155 note 15: qnarrow accepts a fitting value and records the narrower cap. 156 r0 = setq a ulong 5 ulong 10 157 rc = qnarrow out a ulong 7 158 if ne rc int 0 159 ret testresult 15 160 end 161 if not and eq get out val ulong 5 eq get out cap ulong 7 162 ret testresult 15 163 end 164 165 note 16: qnext increments up to the cap. 166 r0 = setq a ulong 6 ulong 7 167 rc = qnext out a 168 if ne rc int 0 169 ret testresult 16 170 end 171 if not and eq get out val ulong 7 eq get out cap ulong 7 172 ret testresult 16 173 end 174 175 note 17: qnext refuses at exhaustion with 3 and leaves the output unchanged. 176 r0 = setq out ulong 17 ulong 19 177 r0 = setq a ulong 7 ulong 7 178 rc = qnext out a 179 if ne rc int 3 180 ret testresult 17 181 end 182 if not and eq get out val ulong 17 eq get out cap ulong 19 183 ret testresult 17 184 end 185 186 note 18: qvalid refuses a value above its cap with 1. 187 r0 = setq a ulong 8 ulong 7 188 rc = qvalid a 189 if ne rc int 1 190 ret testresult 18 191 end 192 193 note 19: qpair refuses unequal caps with 2. 194 r0 = setq a ulong 1 ulong 7 195 r0 = setq b ulong 1 ulong 8 196 rc = qpair a b 197 if ne rc int 2 198 ret testresult 19 199 end 200 201 note 20: the store's frame cap refuses one byte more than the 65536 buffer. 202 rc = qword out ulong 65537 ulong 65536 203 if ne rc int 3 204 ret testresult 20 205 end 206 207 note 21: the store's byte cap admits exactly `33554432`. 208 rc = qword out ulong `33554432` ulong `33554432` 209 if ne rc int 0 210 ret testresult 21 211 end 212 213 ret testresult 0 214 end