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
omega-mv / seed / host / tests / peername.om
| 1 | note Real TCP loopback endpoints; no external address, proxy claims or policy activation. |
| 2 | text ok "PASS native peername: accepted peer, truncation, empty slices, errno and bounds\n" |
| 3 | global server uchar 16 |
| 4 | global client uchar 16 |
| 5 | global output uchar 32 |
| 6 | global pipes uchar 8 |
| 7 | global mode uchar 1 |
| 8 | fn pcheck yes bool to void |
| 9 | if not yes |
| 10 | exit 1 |
| 11 | end |
| 12 | end |
| 13 | fn pfd off ulong to int |
| 14 | a = uint get pipes off |
| 15 | b = shl uint get pipes add off 1 8 |
| 16 | c = shl uint get pipes add off 2 16 |
| 17 | d = shl uint get pipes add off 3 24 |
| 18 | ret int or or or a b c d |
| 19 | end |
| 20 | fn main to int |
| 21 | if eq argcnt 2 |
| 22 | r = argread 1 mode 0 1 |
| 23 | if eq get mode 0 49 |
| 24 | ret int peername neg int 1 output 33 0 |
| 25 | end |
| 26 | if eq get mode 0 50 |
| 27 | ret int peername neg int 1 output 31 2 |
| 28 | end |
| 29 | if eq get mode 0 51 |
| 30 | ret int peername neg int 1 output 18446744073709551615 1 |
| 31 | end |
| 32 | end |
| 33 | put server 0 2 |
| 34 | put server 4 127 |
| 35 | put server 7 1 |
| 36 | listener = socknew 2 1 0 |
| 37 | pcheck ge listener 0 |
| 38 | pcheck eq bind int listener server 0 16 0 |
| 39 | pcheck eq sockname int listener server 0 16 16 |
| 40 | pcheck eq listen int listener 1 0 |
| 41 | pcheck eq peername int listener output 0 32 neg long 107 |
| 42 | local = socknew 2 1 0 |
| 43 | pcheck ge local 0 |
| 44 | pcheck eq peername int local output 0 32 neg long 107 |
| 45 | pcheck eq connect int local server 0 16 0 |
| 46 | pcheck eq sockname int local client 0 16 16 |
| 47 | pcheck eq waitio int listener 1 1000000000 1 |
| 48 | remote = accept int listener 0 |
| 49 | pcheck ge remote 0 |
| 50 | for i ulong 32 |
| 51 | put output i 165 |
| 52 | end |
| 53 | pcheck eq peername int remote output 3 16 16 |
| 54 | for i ulong 16 |
| 55 | pcheck eq get output add i 3 get client i |
| 56 | end |
| 57 | pcheck eq get output 2 165 |
| 58 | pcheck eq get output 19 165 |
| 59 | if eq get output 5 get server 2 |
| 60 | pcheck ne get output 6 get server 3 |
| 61 | end |
| 62 | for i ulong 32 |
| 63 | put output i 165 |
| 64 | end |
| 65 | pcheck eq peername int remote output 4 3 16 |
| 66 | for i ulong 3 |
| 67 | pcheck eq get output add i 4 get client i |
| 68 | end |
| 69 | pcheck eq get output 3 165 |
| 70 | pcheck eq get output 7 165 |
| 71 | for i ulong 32 |
| 72 | put output i 165 |
| 73 | end |
| 74 | pcheck eq peername int remote output 0 0 16 |
| 75 | pcheck eq peername int remote output 32 0 16 |
| 76 | for i ulong 32 |
| 77 | pcheck eq get output i 165 |
| 78 | end |
| 79 | pcheck eq pipefds pipes 0 8 0 0 |
| 80 | pipefd = pfd 0 |
| 81 | pcheck eq peername pipefd output 0 32 neg long 88 |
| 82 | pcheck eq fclose pipefd 0 |
| 83 | pipefd = pfd 4 |
| 84 | pcheck eq fclose pipefd 0 |
| 85 | pcheck eq fclose int remote 0 |
| 86 | pcheck eq peername int remote output 0 32 neg long 9 |
| 87 | pcheck eq peername neg int 1 output 0 32 neg long 9 |
| 88 | pcheck eq fclose int local 0 |
| 89 | pcheck eq fclose int listener 0 |
| 90 | r = write 1 ok 0 len ok |
| 91 | pcheck eq r long len ok |
| 92 | ret 0 |
| 93 | end |