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 / om / tls / test / bench / bench.om

239 lines · 4924 bytes Raw Blame History
1note bench.om: HTTPS benchmark client for om/tls (program mode, composed after every om/tls unit).
2note usage: bench MODE PORT N PATH STOREFILE
3note MODE h: N full handshakes to 127.0.0.1:PORT (TLS name bench.test), close_notify after each;
4note sample = ns from before the TCP connect to the end of tls_connect
5note MODE g: N HTTPS GETs of PATH (HTTP/1.0, one connection each, read to close_notify);
6note sample = ns from before the TCP connect to the end of the response
7note MODE b: N bulk reads of PATH; sample = ns from the request write to the end of the response
8note (the handshake is excluded)
9note MODE d: one GET of PATH, the decrypted response bytes go to stdout (correctness gate)
10note Every sample prints "S NANOSECONDS BYTES" on stdout. No resumption, no tickets are used.
11note Exit 0 on success, 10 + code on a TLS failure, 2 usage, 3 connect failure, 4 short body.
12
13text bnusage "usage: bench h|g|b|d PORT N PATH STOREFILE\n"
14text bnhost "bench.test"
15text bnip "127.0.0.1"
16text bnget1 "GET /"
17text bnget2 " HTTP/1.0"
18text bnerr "TLSERR "
19text bnnl "\n"
20const BNERR ulong 4611686018427387904
21
22fn bn_arg i ulong a edit uchar * to ulong
23n = argread i a 0 len a
24if lt n 0
25ret 0
26end
27ret ulong n
28end
29
30fn bn_num a view uchar * to ulong
31v = ulong 0
32for i ulong len a
33d = ulong get a i
34if or lt d 48 gt d 57
35ret 0
36end
37v = add mul v 10 sub d 48
38if gt v 99999999
39ret 0
40end
41end
42ret v
43end
44
45fn bn_dec v ulong o edit uchar * p ulong to ulong
46t = new uchar 24 0
47n = ulong 0
48x = v
49while true bound 24
50put t n uchar add 48 rem x 10
51n = add n 1
52x = div x 10
53if eq x 0
54break
55end
56end
57for i ulong n
58put o add p i get t sub sub n 1 i
59end
60ret add p n
61end
62
63note "S ns bytes\n"
64fn bn_emit ns ulong by ulong to void
65o = new uchar 64 0
66put o 0 83
67put o 1 32
68p = bn_dec ns o 2
69put o p 32
70p = bn_dec by o add p 1
71put o p 10
72w = write 1 o 0 add p 1
73end
74
75note request "GET /PATH HTTP/1.0\r\n\r\n" into w[4096..) from the path w[256..256+pl);
76note returns its length
77fn bn_req w edit uchar * pl ulong to ulong
78p = ulong 4096
79for i ulong len bnget1
80put w p get bnget1 i
81p = add p 1
82end
83for i ulong pl
84put w p get w add 256 i
85p = add p 1
86end
87for i ulong len bnget2
88put w p get bnget2 i
89p = add p 1
90end
91put w p 13
92put w add p 1 10
93put w add p 2 13
94put w add p 3 10
95ret sub add p 4 4096
96end
97
98note read to close_notify; bytes received, or 1 shl 62 plus the code on error. dump 1 copies to stdout
99fn bn_drain c edit uchar * dump ulong to ulong
100b = new uchar 16384 0
101t = ulong 0
102while true bound 999999
103r = tls_read c b
104if eq r 0
105ret t
106end
107if lt r 0
108ret add BNERR ulong neg r
109end
110t = add t ulong r
111if eq dump 1
112w = write 1 b 0 ulong r
113end
114end
115ret t
116end
117
118fn bn_fail e ulong to int
119m = new uchar 256 0
120w = write 2 bnerr 0 len bnerr
121n = tls_errname e m
122w = write 2 m 0 n
123w = write 2 bnnl 0 1
124ret int add 10 e
125end
126
127note s: 0 mode (104 h, 103 g, 98 b, 100 d), 1 port, 2 fd, 3 start ns, 4 sample ns, 5 bytes
128note connect and handshake; 0, 1000 on a connect failure, or a TLS code
129fn bn_hs c edit uchar * st view uchar * s edit ulong * to ulong
130e = tls_init c bnhost 0
131if ne e 0
132ret e
133end
134t0 = monons
135fd = tls_dial bnip get s 1
136if lt fd 0
137ret 1000
138end
139e = tls_connect c st int fd
140t1 = monons
141put s 2 ulong fd
142put s 3 ulong t0
143put s 4 sub ulong t1 ulong t0
144put s 5 0
145if ne e 0
146x = fclose int fd
147ret e
148end
149ret 0
150end
151
152note after the handshake: close (h) or send the request and read the response; s[6] = request time
153fn bn_xfer c edit uchar * rq view uchar * s edit ulong * to ulong
154if eq get s 0 104
155tls_close c
156x = fclose int get s 2
157ret 0
158end
159put s 6 ulong monons
160r = tls_write c rq
161if lt r 0
162x = fclose int get s 2
163ret ulong neg r
164end
165dump = ulong 0
166if eq get s 0 100
167dump = 1
168end
169n = bn_drain c dump
170put s 7 ulong monons
171tls_close c
172x = fclose int get s 2
173if ge n BNERR
174ret sub n BNERR
175end
176put s 5 n
177put s 4 sub get s 7 get s 3
178if eq get s 0 98
179put s 4 sub get s 7 get s 6
180end
181ret 0
182end
183
184note arguments into s: 0 mode, 1 port, 8 count, 9 request length (request at w[4096..)); 0 or 2
185fn bn_args w edit uchar * s edit ulong * to ulong
186if ne argcnt 6
187ret 2
188end
189if ne bn_arg 1 part w 0 256 1
190ret 2
191end
192put s 0 ulong get w 0
193put s 1 bn_num part w 0 bn_arg 2 part w 0 256
194put s 8 bn_num part w 0 bn_arg 3 part w 0 256
195if or eq get s 1 0 eq get s 8 0
196ret 2
197end
198md = get s 0
199if and and ne md 104 ne md 103 and ne md 98 ne md 100
200ret 2
201end
202put s 9 bn_req w bn_arg 4 part w 256 1024
203ret 0
204end
205
206fn bn_main c edit uchar * st edit uchar * w edit uchar * to int
207s = new ulong 12 0
208if ne bn_args w s 0
209x = write 2 bnusage 0 len bnusage
210ret 2
211end
212e = tls_storef st part w 0 bn_arg 5 part w 0 256
213if ne e 0
214ret bn_fail e
215end
216for i ulong get s 8
217e = bn_hs c st s
218if eq e 0
219e = bn_xfer c part w 4096 get s 9 s
220end
221if eq e 1000
222ret 3
223end
224if ne e 0
225ret bn_fail e
226end
227if ne get s 0 100
228bn_emit get s 4 get s 5
229end
230end
231ret 0
232end
233
234fn main to int
235c = new uchar 119296 0
236st = new uchar 262144 0
237w = new uchar 8192 0
238ret bn_main c st w
239end