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 / aienux / net / core / net_test.om

247 lines · 5695 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/net/core/net_test.om: Behavioral self-test for Pure-Omega AIENOS Net Core, Boot Report, and Virtio-Net.
3note Compose with: si/directives/om2.om aienux/net/core/net.om aienux/net/core/virtio.om aienux/net/core/net_test.om
4
5text nt_pass "PASS "
6text nt_fail "FAIL "
7text nt_nl "\n"
8text nt_t1 "checksum_and_eth_arp_ipv4_udp"
9text nt_t2 "arp_cache_learn_lookup_and_expiry"
10text nt_t3 "boot_report_broadcast_roundtrip"
11text nt_t4 "virtio_pci_caps_discovery_and_loop"
12text nt_t5 "virtio_net_iommu_and_untrusted_ring_failstop"
13
14fn nt_say t view uchar * to void
15k = write 1 t 0 len t
16end
17
18fn nt_run name view uchar * ok bool to uint
19if ok
20nt_say nt_pass
21nt_say name
22nt_say nt_nl
23ret 0
24end
25nt_say nt_fail
26nt_say name
27nt_say nt_nl
28ret 1
29end
30
31fn test_01_parse frame edit uchar * fw ulong to bool
32eh = new NetEthHdr 0 0 0 0 0 0 0
33if ne net_eth_parse frame fw eh NET_OK
34ret false
35end
36if ne get eh ethertype NET_ETHERTYPE_IPV4
37ret false
38end
39ih = new NetIpv4 0 0 0 0 0 0 0 0 0 0 0 0
40if ne net_ipv4_parse frame get eh pay_off get eh pay_len ih NET_OK
41ret false
42end
43if or ne get ih src 0x0a000001 ne get ih dst 0x0a000002
44ret false
45end
46uh = new NetUdp 0 0 0 0 0 0
47if ne net_udp_parse frame get ih pay_off get ih pay_len uh NET_OK
48ret false
49end
50if or ne get uh sport 1234 ne get uh dport 5678
51ret false
52end
53if ne get uh pay_len 5
54ret false
55end
56note Corrupt IPv4 TTL byte (frame[22] = ipv4[8]) -> checksum invalid
57put frame 22 xor get frame 22 1
58if ne net_ipv4_parse frame get eh pay_off get eh pay_len ih NET_ERR_INVALID
59ret false
60end
61ret true
62end
63
64fn test_01_proto to bool
65note RFC 1071 odd-length checksum + IPv4 + UDP + Eth roundtrip
66pay = new uchar 5 0
67put pay 0 0x48
68put pay 1 0x45
69put pay 2 0x4c
70put pay 3 0x4c
71put pay 4 0x4f
72ubuf = new uchar 64 0
73ul = net_udp_build 1234 5678 pay ubuf
74if ne ul 13
75ret false
76end
77ip_meta = new uint 4 0
78put ip_meta 0 0x0a000001
79put ip_meta 1 0x0a000002
80put ip_meta 2 uint NET_IPPROTO_UDP
81put ip_meta 3 64
82ipbuf = new uchar 128 0
83ipl = net_ipv4_build ip_meta part ubuf 0 ul ipbuf
84if ne ipl 33
85ret false
86end
87macs = new uchar 12 0xff
88for i ulong 6
89put macs add 6 i 0x02
90end
91frame = new uchar 128 0
92fw = net_eth_build macs NET_ETHERTYPE_IPV4 part ipbuf 0 ipl frame
93if eq fw 0
94ret false
95end
96ret test_01_parse frame fw
97end
98
99fn test_02_arp_cache to bool
100net_arp_cache_reset
101m1 = new uchar 6 0xaa
102m2 = new uchar 6 0xbb
103outm = new uchar 6 0
104if ne net_arp_cache_learn 0x0a000001 m1 100 50 NET_OK
105ret false
106end
107if not net_arp_cache_lookup 0x0a000001 120 outm
108ret false
109end
110if ne get outm 0 0xaa
111ret false
112end
113note Expired at t=150
114if net_arp_cache_lookup 0x0a000001 150 outm
115ret false
116end
117note Reuses expired slot
118if ne net_arp_cache_learn 0x0a000002 m2 150 50 NET_OK
119ret false
120end
121if not net_arp_cache_lookup 0x0a000002 180 outm
122ret false
123end
124ret eq get outm 0 0xbb
125end
126
127fn test_03_boot_report to bool
128if ne net_report_parts 0 0
129ret false
130end
131if ne net_report_parts 1025 2
132ret false
133end
134mac = new uchar 6 0x12
135rmeta = new ulong 3 0
136put rmeta 0 0x0123456789abcdef
137put rmeta 1 1
138put rmeta 2 2
139chunk = new uchar 16 0x5a
140frame = new uchar 1280 0
141flen = net_report_build_frame mac rmeta chunk frame
142if eq flen 0
143ret false
144end
145meta = new ulong 4 0
146if ne net_report_parse_frame frame flen meta 0
147ret false
148end
149if ne get meta 0 0x0123456789abcdef
150ret false
151end
152if or ne get meta 1 1 ne get meta 2 2
153ret false
154end
155ret eq get meta 3 16
156end
157
158fn test_04_vpci_caps to bool
159cfg = new uchar 256 0
160put cfg 6 0x10
161put cfg 52 0x40
162note Cap 1 at 0x40: COMMON (len=16, bar=4, off=0x1000, next=0x50)
163put cfg 0x40 VPCI_CAP_VENDOR
164put cfg 0x41 0x50
165put cfg 0x42 16
166put cfg 0x43 VPCI_CFG_COMMON
167put cfg 0x44 4
168put cfg 0x49 0x10
169note Cap 2 at 0x50: NOTIFY (len=20, bar=4, off=0x2000, mult=4, next=0x64)
170put cfg 0x50 VPCI_CAP_VENDOR
171put cfg 0x51 0x64
172put cfg 0x52 20
173put cfg 0x53 VPCI_CFG_NOTIFY
174put cfg 0x54 4
175put cfg 0x59 0x20
176put cfg 0x60 4
177note Cap 3 at 0x64: ISR (len=16, bar=4, off=0x3000, next=0x74)
178put cfg 0x64 VPCI_CAP_VENDOR
179put cfg 0x65 0x74
180put cfg 0x66 16
181put cfg 0x67 VPCI_CFG_ISR
182put cfg 0x68 4
183put cfg 0x6d 0x30
184note Cap 4 at 0x74: DEVICE (len=16, bar=4, off=0x4000, next=0)
185put cfg 0x74 VPCI_CAP_VENDOR
186put cfg 0x75 0
187put cfg 0x76 16
188put cfg 0x77 VPCI_CFG_DEVICE
189put cfg 0x78 4
190put cfg 0x7d 0x40
191caps = new uint 10 0
192if ne vpci_parse_caps cfg caps VPCI_OK
193ret false
194end
195if or ne get caps 1 0x1000 ne get caps 4 4
196ret false
197end
198note Introduce capability cycle -> VPCI_ERR_LOOP
199put cfg 0x75 0x40
200ret eq vpci_parse_caps cfg caps VPCI_ERR_LOOP
201end
202
203fn test_05_virtio_net to bool
204note Fail closed if ACCESS_PLATFORM required but not offered
205if ne vnet_init VNET_F_VERSION_1 8 VNET_INIT_REQUIRE_ACCESS_PLATFORM VNET_ERR_ACCESS_PLATFORM
206ret false
207end
208note Succeed when both VERSION_1 and ACCESS_PLATFORM offered
209feats = or VNET_F_VERSION_1 or VNET_F_ACCESS_PLATFORM VNET_F_MAC
210if ne vnet_init feats 8 VNET_INIT_REQUIRE_ACCESS_PLATFORM VNET_OK
211ret false
212end
213pkt = new uchar 64 0x42
214if ne vnet_tx_submit pkt VNET_OK
215ret false
216end
217if ne vnet_tx_complete 0 VNET_OK
218ret false
219end
220if ne vnet_rx_post VNET_OK
221ret false
222end
223if ne vnet_rx_complete 0 add VNET_HDR_LEN 64 pkt VNET_OK
224ret false
225end
226note Untrusted device reports duplicate/unposted completion -> sticky BROKEN
227if ne vnet_rx_complete 0 add VNET_HDR_LEN 64 pkt VNET_ERR_BROKEN
228ret false
229end
230if not vnet_is_broken
231ret false
232end
233ret eq vnet_tx_submit pkt VNET_ERR_BROKEN
234end
235
236fn main to int
237failed = uint 0
238failed = add failed nt_run nt_t1 test_01_proto
239failed = add failed nt_run nt_t2 test_02_arp_cache
240failed = add failed nt_run nt_t3 test_03_boot_report
241failed = add failed nt_run nt_t4 test_04_vpci_caps
242failed = add failed nt_run nt_t5 test_05_virtio_net
243if ne failed 0
244ret 1
245end
246ret 0
247end