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 / gpu / nvidia / checks / leftovers.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/nvidia/checks/leftovers.om: the Omega port of CUDApp tests/leftovers_test.c. Composed after |
| 3 | note gpu/nvidia/om/components/pathcopy.om, gpu/nvidia/om/components/leftovers.om and gpu/nvidia/checks/lib.om; |
| 4 | note run with gpu/nvidia/checks/leftovers.tsv, whose expected values the C oracle wrote (see that file's header). |
| 5 | note byte C EXPECT leftovers 0 C 0 0 0 is EXPECT (256: not a path byte) |
| 6 | note path HEX CAP R OUT the path copy the C binding of src/omega_path_check.h makes from the Omega units: |
| 7 | note cap 0 refuses; else n = pathlen (the source within cap); n = cap refuses; else pathcopy of the |
| 8 | note n + 1 bytes into cap bytes must return 1. R is 1 for a refusal; on acceptance the copied string |
| 9 | note (to its 0) is OUT. A NULL source or destination is the C binding's own refusal, not Omega's, |
| 10 | note and is not a case here. |
| 11 | note op OP A B C D E leftovers OP A B C D is E |
| 12 | text t_name "LEFTOVERS" |
| 13 | text t_kbyte "byte" |
| 14 | text t_kpath "path" |
| 15 | text t_kop "op" |
| 16 | fn cname to void |
| 17 | for i ulong len t_name bound 64 |
| 18 | ckoc ulong get t_name i |
| 19 | end |
| 20 | end |
| 21 | note the same copy decided by the scalar stepper leftovers op 1 (src/cudapp_freest_leftovers.c's half of the |
| 22 | note path check): 1 when it refuses, 0 when it reaches the terminator |
| 23 | fn lwalk a view uchar * cap ulong to ulong |
| 24 | state = ulong 0 |
| 25 | for i ulong len a bound 4096 |
| 26 | next = leftovers 1 state ulong get a i i cap |
| 27 | if eq next 4 |
| 28 | ret 1 |
| 29 | end |
| 30 | if eq next 5 |
| 31 | ret 0 |
| 32 | end |
| 33 | state = next |
| 34 | end |
| 35 | ret 1 |
| 36 | end |
| 37 | fn lpath to bool |
| 38 | if ne ckcnt 5 |
| 39 | ret false |
| 40 | end |
| 41 | note a path case is at most 4095 bytes and its cap at most 4096 (Linux PATH_MAX); a longer case is ckbad (exit 2) |
| 42 | src = new uchar 4096 0 |
| 43 | dst = new uchar 4096 85 |
| 44 | l = ckhexn 1 |
| 45 | cap = cknum 2 |
| 46 | if or ge l 4096 gt cap 4096 |
| 47 | ckbad |
| 48 | end |
| 49 | for j ulong l bound 4096 |
| 50 | put src j uchar ckhex 1 j |
| 51 | end |
| 52 | refused = ulong 1 |
| 53 | walked = ulong 1 |
| 54 | if gt cap 0 |
| 55 | n = pathlen part src 0 cap |
| 56 | if ne n cap |
| 57 | w = pathcopy part src 0 add n 1 part dst 0 cap |
| 58 | if eq w 1 |
| 59 | refused = 0 |
| 60 | end |
| 61 | walked = lwalk part src 0 add n 1 cap |
| 62 | end |
| 63 | end |
| 64 | if or ne refused cknum 3 ne walked refused |
| 65 | ret false |
| 66 | end |
| 67 | if eq refused 1 |
| 68 | ret true |
| 69 | end |
| 70 | m = ckhexn 4 |
| 71 | if ge m cap |
| 72 | ret false |
| 73 | end |
| 74 | for j ulong m bound 4096 |
| 75 | if ne ulong get dst j ckhex 4 j |
| 76 | ret false |
| 77 | end |
| 78 | end |
| 79 | ret eq get dst m 0 |
| 80 | end |
| 81 | fn crow to bool |
| 82 | if and ckis 0 t_kbyte eq ckcnt 3 |
| 83 | ret eq leftovers 0 cknum 1 0 0 0 cknum 2 |
| 84 | end |
| 85 | if ckis 0 t_kpath |
| 86 | ret lpath |
| 87 | end |
| 88 | if and ckis 0 t_kop eq ckcnt 7 |
| 89 | r = leftovers cknum 1 cknum 2 cknum 3 cknum 4 cknum 5 |
| 90 | ret eq r cknum 6 |
| 91 | end |
| 92 | ckbad |
| 93 | ret false |
| 94 | end |