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 / seed / authority / lock-test.om

138 lines · 2398 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Lock checks: exclusive acquire, busy refusal, release, a forked waiter, stale-pid reclaim, failed release,
3note an owner pid equal to an old lread error code (32), and the lacq retry cap.
4text passm "lock checks=10 fails=0\n"
5global checks ulong 1
6global fails ulong 1
7global lbuf uchar 8
8global rb uchar 8
9text childf "build/authority-store/lock.child"
10text bd "build"
11text ad "build/authority-store"
12fn check got ulong want ulong to void
13put checks 0 add get checks 0 1
14if ne got want
15put fails 0 add get fails 0 1
16end
17end
18fn cbyte c uchar to void
19r = fopen childf 0 len childf 0 0
20if lt r 0
21put rb 0 255
22ret
23end
24n = read int r rb 0 1
25if ne fclose int r 0
26ret
27end
28end
29fn main to int
30r = makedir bd 0 len bd 448
31if or eq r 0 eq r -17
32else
33ret 90
34end
35r = makedir ad 0 len ad 448
36if or eq r 0 eq r -17
37else
38ret 91
39end
40u = lrel
41u = ltry ulong getpid
42check u 0
43u = ltry ulong getpid
44check u 20
45u = lrel
46if ne u 0
47ret 92
48end
49u = ltry ulong getpid
50check u 0
51pid = fork
52if lt pid 0
53ret 93
54end
55if eq pid 0
56u = lacq ulong getpid 1000
57put lbuf 0 uchar u
58fd = fopen childf 0 len childf 577 384
59if lt fd 0
60exit 94
61end
62n = write int fd lbuf 0 1
63if ne n 1
64exit 95
65end
66exit 0
67end
68if ne sleepns 50000000 0
69ret 96
70end
71u = lrel
72if ne u 0
73ret 97
74end
75wr = waitpid int pid lbuf 0 8 0
76if ne wr long pid
77ret 98
78end
79cbyte 0
80check ulong get rb 0 0
81note Owner pid 32 was once read back as lread error 32 and refused with 40; it is a real pid now.
82lpid 32
83fd = fopen lpath 0 len lpath 577 384
84if lt fd 0
85ret 103
86end
87n = write int fd lb 0 8
88if ne n 8
89ret 104
90end
91if ne fclose int fd 0
92ret 105
93end
94want = ulong 20
95if eq killpid 32 0 -3
96want = ulong 0
97end
98u = ltry ulong getpid
99check u want
100u = lacq ulong getpid 1001
101check u 43
102lpid 999999
103fd = fopen lpath 0 len lpath 577 384
104if lt fd 0
105ret 99
106end
107n = write int fd lb 0 8
108if ne n 8
109ret 100
110end
111u = ltry ulong getpid
112check u 0
113u = lrel
114check u 0
115note A directory cannot be unlinked as a regular file, even when run as root.
116note Refuse a pre-existing fixture rather than replacing anything at this path.
117r = makedir lpath 0 len lpath 448
118if ne r 0
119ret 101
120end
121u = lrel
122check u 41
123r = rmdir lpath 0 len lpath
124if ne r 0
125ret 102
126end
127note Missing-path removal is also a failure, not an idempotent success.
128u = lrel
129check u 41
130if ne get fails 0 0
131ret 1
132end
133nw = write 1 passm 0 len passm
134if ne nw long len passm
135ret 2
136end
137ret 0
138end