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 / authority / store-test.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Store checks: exact read/write, torn file refusal, generation mismatch and atomic replace. |
| 3 | global checks ulong 1 |
| 4 | global fails ulong 1 |
| 5 | global report uchar 64 |
| 6 | text title "store checks=" |
| 7 | text dir "build/authority-store" |
| 8 | fn check got ulong want ulong to void |
| 9 | put checks 0 add get checks 0 1 |
| 10 | if ne got want |
| 11 | put fails 0 add get fails 0 1 |
| 12 | end |
| 13 | end |
| 14 | fn fill r edit ulong 32 seed ulong gen ulong to void |
| 15 | for i ulong 32 |
| 16 | put r i add seed i |
| 17 | end |
| 18 | put r 0 1 |
| 19 | put r 1 1 |
| 20 | put r 3 8 |
| 21 | put r 4 gen |
| 22 | end |
| 23 | fn summary to int |
| 24 | for i ulong len title |
| 25 | put report i get title i |
| 26 | end |
| 27 | n = get checks 0 |
| 28 | at = len title |
| 29 | put report at uchar add 48 div n 100 |
| 30 | put report add at 1 uchar add 48 rem div n 10 10 |
| 31 | put report add at 2 uchar add 48 rem n 10 |
| 32 | put report add at 3 32 |
| 33 | put report add at 4 uchar add 48 div get fails 0 100 |
| 34 | put report add at 5 uchar add 48 rem div get fails 0 10 10 |
| 35 | put report add at 6 uchar add 48 rem get fails 0 10 |
| 36 | put report add at 7 10 |
| 37 | w = write 1 report 0 add at 8 |
| 38 | if ne w long add at 8 |
| 39 | ret 2 |
| 40 | end |
| 41 | if ne get fails 0 0 |
| 42 | ret 1 |
| 43 | end |
| 44 | ret 0 |
| 45 | end |
| 46 | fn main to int |
| 47 | if ne makedir dir 0 len dir 448 0 |
| 48 | put sb 0 0 |
| 49 | end |
| 50 | r = new ulong 32 0 |
| 51 | q = new ulong 32 0 |
| 52 | fill r 100 1 |
| 53 | check writerec r 0 |
| 54 | fill q 0 0 |
| 55 | check readrec q 0 |
| 56 | for i ulong 32 |
| 57 | check get q i get r i |
| 58 | end |
| 59 | check storevalid q 1 0 |
| 60 | check writegen 1 0 |
| 61 | check readgen 1 |
| 62 | check storevalid q 2 52 |
| 63 | setrec |
| 64 | fd = fopen spath 0 get splen 0 577 384 |
| 65 | if lt fd 0 |
| 66 | check 0 1 |
| 67 | else |
| 68 | n = write int fd sb 0 3 |
| 69 | if ne fclose int fd 0 |
| 70 | check 0 1 |
| 71 | end |
| 72 | check readrec q 22 |
| 73 | end |
| 74 | check writerec r 0 |
| 75 | check writegen 2 0 |
| 76 | check readgen 2 |
| 77 | fill r 200 2 |
| 78 | check writerec r 0 |
| 79 | check readrec q 0 |
| 80 | for i ulong 32 |
| 81 | check get q i get r i |
| 82 | end |
| 83 | check storevalid q 2 0 |
| 84 | ret summary |
| 85 | end |