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 / flock.om
| 1 | note flock fd op (Linux flock, ARM64 syscall 32): an exclusive lock held on one open file blocks a |
| 2 | note LOCK_EX|LOCK_NB from a second open of the same file in a child (-EWOULDBLOCK, 11); after LOCK_UN |
| 3 | note the child gets it; shared locks coexist; an unknown op is -EINVAL (22); a closed fd is -EBADF (9). |
| 4 | text path "flock.tmp" |
| 5 | global status uchar 4 |
| 6 | fn child want long to int |
| 7 | fd = fopen path 0 len path 524290 0 |
| 8 | if lt fd 0 |
| 9 | ret 50 |
| 10 | end |
| 11 | r = flock int fd 6 |
| 12 | if ne r want |
| 13 | ret 51 |
| 14 | end |
| 15 | ret 0 |
| 16 | end |
| 17 | fn waitkid want long to int |
| 18 | pid = fork |
| 19 | if lt pid 0 |
| 20 | ret 40 |
| 21 | end |
| 22 | if eq pid 0 |
| 23 | exit child want |
| 24 | end |
| 25 | r = waitpid int pid status 0 len status 0 |
| 26 | if ne r pid |
| 27 | ret 41 |
| 28 | end |
| 29 | if or ne get status 0 0 ne get status 1 0 |
| 30 | ret int add 60 ulong get status 1 |
| 31 | end |
| 32 | ret 0 |
| 33 | end |
| 34 | fn main to int |
| 35 | fd = fopen path 0 len path 524866 384 |
| 36 | if lt fd 0 |
| 37 | ret 1 |
| 38 | end |
| 39 | r = flock int fd 6 |
| 40 | if ne r 0 |
| 41 | ret 2 |
| 42 | end |
| 43 | k = waitkid neg long 11 |
| 44 | if ne k 0 |
| 45 | ret k |
| 46 | end |
| 47 | r = flock int fd 8 |
| 48 | if ne r 0 |
| 49 | ret 3 |
| 50 | end |
| 51 | k = waitkid 0 |
| 52 | if ne k 0 |
| 53 | ret k |
| 54 | end |
| 55 | r = flock int fd 1 |
| 56 | if ne r 0 |
| 57 | ret 4 |
| 58 | end |
| 59 | s = fopen path 0 len path 524290 0 |
| 60 | r = flock int s 5 |
| 61 | if ne r 0 |
| 62 | ret 5 |
| 63 | end |
| 64 | r = flock int fd 3 |
| 65 | if ne r neg long 22 |
| 66 | ret 6 |
| 67 | end |
| 68 | c = fclose int s |
| 69 | c = fclose int fd |
| 70 | r = flock int fd 2 |
| 71 | if ne r neg long 9 |
| 72 | ret 7 |
| 73 | end |
| 74 | r = unlink path 0 len path |
| 75 | ret int r |
| 76 | end |