interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / protocol / omnet / om / quantity / test / driver.om

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