aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / tools / name-check / gate.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gate: the ARCH-NAME-CHECK gate runner (ADR 0038), seeded native Omega. |
| 3 | note usage: gate OMC DIFF (run from tools/name-check; writes under build/) |
| 4 | note Builds ../zero-legacy/sha256.om with OMC, hashes OMC with it and compares the hash with |
| 5 | note ../zero-legacy/omega.pin, builds namecheck.om, then runs build/namecheck on six fixtures |
| 6 | note (red 1, green 0, long 1, refuse 2, nohdr 2, pathmax 2: the exit, and stdout exactly the .out |
| 7 | note file), counts those that pass, and finally runs it on DIFF, the added lines of the |
| 8 | note change under review, with this process's stdout. Exit: 0 PASS; 1 a fixture differs, a build |
| 9 | note fails or DIFF names a retired word; 2 DIFF unreadable; 3 OMC missing or not the pinned |
| 10 | note compiler (NOT_RUN). The process helpers below are copied unchanged from ../doctrine/gate.om. |
| 11 | |
| 12 | text tbl "../zero-legacy/sha256.om\nbuild/sha256\nnamecheck.om\nbuild/namecheck\nbuild/omc.sha\nbuild/namecheck.sha\n../zero-legacy/omega.pin\nbuild\nfixtures/red.diff\nbuild/red.out\nfixtures/red.out\nfixtures/green.diff\nbuild/green.out\nfixtures/green.out\nfixtures/long.diff\nbuild/long.out\nfixtures/long.out\nfixtures/refuse.diff\nbuild/refuse.out\nfixtures/refuse.out\nfixtures/nohdr.diff\nbuild/nohdr.out\nfixtures/nohdr.out\nfixtures/pathmax.diff\nbuild/pathmax.out\nfixtures/pathmax.out\n" |
| 13 | text tobs "AIEN-OBS " |
| 14 | text tsha "name_check_sha256 \"" |
| 15 | text tq "\"\n" |
| 16 | text texit "name_check_exit " |
| 17 | text tfx "name_check_fixtures " |
| 18 | text tnl "\n" |
| 19 | text tuse "usage: gate OMC DIFF\n" |
| 20 | text tnot "gate: OMC missing or not the pinned compiler (NOT_RUN)\n" |
| 21 | text tcf "gate: compile failed\n" |
| 22 | text tfxf "gate: a name-check fixture gave another exit or other output (FAIL)\n" |
| 23 | text tkey "omc_sha256: " |
| 24 | |
| 25 | global omcp uchar 4096 |
| 26 | global omcl ulong 1 |
| 27 | global rootp uchar 4096 |
| 28 | global rootl ulong 1 |
| 29 | global pk uchar 4096 |
| 30 | global pkn ulong 1 |
| 31 | global pkc ulong 1 |
| 32 | global arg uchar 4096 |
| 33 | global argl ulong 1 |
| 34 | global fin uchar 4096 |
| 35 | global finl ulong 1 |
| 36 | global fout uchar 256 |
| 37 | global foutl ulong 1 |
| 38 | global status uchar 4 |
| 39 | global pin uchar 4096 |
| 40 | global pinl ulong 1 |
| 41 | global sha uchar 128 |
| 42 | global nb uchar 24 |
| 43 | global fa uchar 65536 |
| 44 | global fb uchar 65536 |
| 45 | global fxn ulong 1 |
| 46 | |
| 47 | note ---- text table ---- |
| 48 | |
| 49 | fn pick i ulong to void |
| 50 | s = ulong 0 |
| 51 | k = ulong 0 |
| 52 | while lt k i bound 4096 |
| 53 | if eq get tbl s 10 |
| 54 | k = add k 1 |
| 55 | end |
| 56 | s = add s 1 |
| 57 | end |
| 58 | n = ulong 0 |
| 59 | while ne get tbl add s n 10 bound 256 |
| 60 | put arg n get tbl add s n |
| 61 | n = add n 1 |
| 62 | end |
| 63 | put argl 0 n |
| 64 | end |
| 65 | |
| 66 | note ---- packets for execprog ---- |
| 67 | |
| 68 | fn pk0 to void |
| 69 | put pkn 0 2 |
| 70 | put pkc 0 0 |
| 71 | end |
| 72 | |
| 73 | fn pka to void |
| 74 | n = get pkn 0 |
| 75 | m = get argl 0 |
| 76 | put pk n uchar rem m 256 |
| 77 | put pk add n 1 uchar div m 256 |
| 78 | for i ulong m |
| 79 | put pk add n add 2 i get arg i |
| 80 | end |
| 81 | put pkn 0 add n add 2 m |
| 82 | c = add get pkc 0 1 |
| 83 | put pkc 0 c |
| 84 | put pk 0 uchar rem c 256 |
| 85 | put pk 1 uchar div c 256 |
| 86 | end |
| 87 | |
| 88 | fn pkt i ulong to void |
| 89 | pick i |
| 90 | pka |
| 91 | end |
| 92 | |
| 93 | fn pkomc to void |
| 94 | for i ulong get omcl 0 |
| 95 | put arg i get omcp i |
| 96 | end |
| 97 | put argl 0 get omcl 0 |
| 98 | pka |
| 99 | end |
| 100 | |
| 101 | fn pkroot to void |
| 102 | for i ulong get rootl 0 |
| 103 | put arg i get rootp i |
| 104 | end |
| 105 | put argl 0 get rootl 0 |
| 106 | pka |
| 107 | end |
| 108 | |
| 109 | fn setin i ulong to void |
| 110 | pick i |
| 111 | for j ulong get argl 0 |
| 112 | put fin j get arg j |
| 113 | end |
| 114 | put finl 0 get argl 0 |
| 115 | end |
| 116 | |
| 117 | fn setout i ulong to void |
| 118 | pick i |
| 119 | for j ulong get argl 0 |
| 120 | put fout j get arg j |
| 121 | end |
| 122 | put foutl 0 get argl 0 |
| 123 | end |
| 124 | |
| 125 | fn noio to void |
| 126 | put finl 0 0 |
| 127 | put foutl 0 0 |
| 128 | end |
| 129 | |
| 130 | note ---- run the packet; stdin/stdout redirected when set; returns exit code or -1 ---- |
| 131 | |
| 132 | fn child to void |
| 133 | if gt get finl 0 0 |
| 134 | fd = fopen fin 0 get finl 0 0 0 |
| 135 | if lt fd 0 |
| 136 | exit 126 |
| 137 | end |
| 138 | r = dupfd int fd 0 0 |
| 139 | end |
| 140 | if gt get foutl 0 0 |
| 141 | fd = fopen fout 0 get foutl 0 577 420 |
| 142 | if lt fd 0 |
| 143 | exit 126 |
| 144 | end |
| 145 | r = dupfd int fd 1 0 |
| 146 | end |
| 147 | r = execprog pk 0 get pkn 0 |
| 148 | exit 127 |
| 149 | end |
| 150 | |
| 151 | fn run to long |
| 152 | pid = fork |
| 153 | if lt pid 0 |
| 154 | ret -1 |
| 155 | end |
| 156 | if eq pid 0 |
| 157 | child |
| 158 | end |
| 159 | r = waitpid int pid status 0 4 0 |
| 160 | if ne r pid |
| 161 | ret -1 |
| 162 | end |
| 163 | if ne get status 0 0 |
| 164 | ret -1 |
| 165 | end |
| 166 | ret long get status 1 |
| 167 | end |
| 168 | |
| 169 | note ---- steps ---- |
| 170 | |
| 171 | fn compile src ulong dst ulong to bool |
| 172 | pk0 |
| 173 | pkomc |
| 174 | setin src |
| 175 | setout dst |
| 176 | r = run |
| 177 | if ne r 0 |
| 178 | ret false |
| 179 | end |
| 180 | pick dst |
| 181 | r = chmod arg 0 get argl 0 493 |
| 182 | ret eq r 0 |
| 183 | end |
| 184 | |
| 185 | note hash the file named by table entry f into table entry out; read 64 hex into sha |
| 186 | fn hashto f ulong out ulong to bool |
| 187 | pk0 |
| 188 | pkt 1 |
| 189 | pkt f |
| 190 | put finl 0 0 |
| 191 | setout out |
| 192 | r = run |
| 193 | if ne r 0 |
| 194 | ret false |
| 195 | end |
| 196 | ret readsha out |
| 197 | end |
| 198 | |
| 199 | fn hashomc to bool |
| 200 | pk0 |
| 201 | pkt 1 |
| 202 | pkomc |
| 203 | put finl 0 0 |
| 204 | setout 4 |
| 205 | r = run |
| 206 | if ne r 0 |
| 207 | ret false |
| 208 | end |
| 209 | ret readsha 4 |
| 210 | end |
| 211 | |
| 212 | fn readsha out ulong to bool |
| 213 | pick out |
| 214 | fd = fopen arg 0 get argl 0 0 0 |
| 215 | if lt fd 0 |
| 216 | ret false |
| 217 | end |
| 218 | r = read int fd sha 0 128 |
| 219 | c = fclose int fd |
| 220 | ret ge r 64 |
| 221 | end |
| 222 | |
| 223 | fn loadpin to bool |
| 224 | pick 6 |
| 225 | fd = fopen arg 0 get argl 0 0 0 |
| 226 | if lt fd 0 |
| 227 | ret false |
| 228 | end |
| 229 | r = read int fd pin 0 4096 |
| 230 | c = fclose int fd |
| 231 | if le r 0 |
| 232 | ret false |
| 233 | end |
| 234 | put pinl 0 ulong r |
| 235 | ret true |
| 236 | end |
| 237 | |
| 238 | note does sha[0..64) equal the 64 bytes after "omc_sha256: " in the pin |
| 239 | fn pinok to bool |
| 240 | n = get pinl 0 |
| 241 | m = len tkey |
| 242 | if lt n add m 64 |
| 243 | ret false |
| 244 | end |
| 245 | e = sub n add m 64 |
| 246 | i = ulong 0 |
| 247 | while le i e bound 4096 |
| 248 | j = ulong 0 |
| 249 | while lt j m bound 16 |
| 250 | if ne get pin add i j get tkey j |
| 251 | break |
| 252 | end |
| 253 | j = add j 1 |
| 254 | end |
| 255 | if eq j m |
| 256 | ret same add i m |
| 257 | end |
| 258 | i = add i 1 |
| 259 | end |
| 260 | ret false |
| 261 | end |
| 262 | |
| 263 | fn same p ulong to bool |
| 264 | for j ulong 64 |
| 265 | if ne get pin add p j get sha j |
| 266 | ret false |
| 267 | end |
| 268 | end |
| 269 | ret true |
| 270 | end |
| 271 | |
| 272 | note ---- output ---- |
| 273 | |
| 274 | fn wnum v long to void |
| 275 | if lt v 0 |
| 276 | put nb 22 45 |
| 277 | put nb 23 49 |
| 278 | r = write 1 nb 22 2 |
| 279 | ret |
| 280 | end |
| 281 | x = ulong v |
| 282 | n = ulong 0 |
| 283 | if eq x 0 |
| 284 | put nb 23 48 |
| 285 | n = 1 |
| 286 | end |
| 287 | while gt x 0 bound 20 |
| 288 | put nb sub 23 n uchar add 48 rem x 10 |
| 289 | x = div x 10 |
| 290 | n = add n 1 |
| 291 | end |
| 292 | r = write 1 nb sub 24 n n |
| 293 | end |
| 294 | |
| 295 | fn obs1 to void |
| 296 | r = write 1 tobs 0 len tobs |
| 297 | r = write 1 tsha 0 len tsha |
| 298 | r = write 1 sha 0 64 |
| 299 | r = write 1 tq 0 len tq |
| 300 | end |
| 301 | |
| 302 | fn obs2 v long to void |
| 303 | r = write 1 tobs 0 len tobs |
| 304 | r = write 1 texit 0 len texit |
| 305 | wnum v |
| 306 | r = write 1 tnl 0 1 |
| 307 | end |
| 308 | |
| 309 | note ---- name-check steps ---- |
| 310 | |
| 311 | note read table entry f into fa (which 0) or fb (which 1); returns the byte count, or -1 |
| 312 | fn slurp f ulong which ulong to long |
| 313 | pick f |
| 314 | fd = fopen arg 0 get argl 0 0 0 |
| 315 | if lt fd 0 |
| 316 | ret -1 |
| 317 | end |
| 318 | r = long 0 |
| 319 | if eq which 0 |
| 320 | r = read int fd fa 0 65536 |
| 321 | else |
| 322 | r = read int fd fb 0 65536 |
| 323 | end |
| 324 | c = fclose int fd |
| 325 | ret r |
| 326 | end |
| 327 | |
| 328 | note do files a and b (table entries) hold the same bytes (each under 65536 bytes) |
| 329 | fn sameb a ulong b ulong to bool |
| 330 | na = slurp a 0 |
| 331 | nb2 = slurp b 1 |
| 332 | if or lt na 0 lt nb2 0 |
| 333 | ret false |
| 334 | end |
| 335 | if ne na nb2 |
| 336 | ret false |
| 337 | end |
| 338 | if ge na 65536 |
| 339 | ret false |
| 340 | end |
| 341 | n = ulong na |
| 342 | i = ulong 0 |
| 343 | while lt i n bound 65536 |
| 344 | if ne get fa i get fb i |
| 345 | ret false |
| 346 | end |
| 347 | i = add i 1 |
| 348 | end |
| 349 | ret true |
| 350 | end |
| 351 | |
| 352 | note run build/namecheck with stdin table entry src and stdout table entry dst; want its exit |
| 353 | fn fixture src ulong dst ulong want long to bool |
| 354 | pk0 |
| 355 | pkt 3 |
| 356 | setin src |
| 357 | setout dst |
| 358 | r = run |
| 359 | ret eq r want |
| 360 | end |
| 361 | |
| 362 | note build/namecheck < DIFF (the path in rootp), stdout inherited |
| 363 | fn rundiff to long |
| 364 | pk0 |
| 365 | pkt 3 |
| 366 | j = ulong 0 |
| 367 | while lt j get rootl 0 bound 4096 |
| 368 | put fin j get rootp j |
| 369 | j = add j 1 |
| 370 | end |
| 371 | put finl 0 get rootl 0 |
| 372 | put foutl 0 0 |
| 373 | ret run |
| 374 | end |
| 375 | |
| 376 | note fixture t: table entries t (input), t+1 (build output), t+2 (recorded output); want its exit |
| 377 | fn fxcase t ulong want long to bool |
| 378 | ok = fixture t add t 1 want |
| 379 | if not ok |
| 380 | ret false |
| 381 | end |
| 382 | if not sameb add t 1 add t 2 |
| 383 | ret false |
| 384 | end |
| 385 | put fxn 0 add get fxn 0 1 |
| 386 | ret true |
| 387 | end |
| 388 | |
| 389 | fn obs3 to void |
| 390 | r = write 1 tobs 0 len tobs |
| 391 | r = write 1 tfx 0 len tfx |
| 392 | wnum long get fxn 0 |
| 393 | r = write 1 tnl 0 1 |
| 394 | end |
| 395 | |
| 396 | fn main to int |
| 397 | if lt argcnt 3 |
| 398 | r = write 2 tuse 0 len tuse |
| 399 | ret 64 |
| 400 | end |
| 401 | n = argread 1 omcp 0 4095 |
| 402 | if lt n 1 |
| 403 | r = write 2 tuse 0 len tuse |
| 404 | ret 64 |
| 405 | end |
| 406 | put omcl 0 ulong n |
| 407 | n = argread 2 rootp 0 4095 |
| 408 | if lt n 1 |
| 409 | r = write 2 tuse 0 len tuse |
| 410 | ret 64 |
| 411 | end |
| 412 | put rootl 0 ulong n |
| 413 | pick 7 |
| 414 | r = makedir arg 0 get argl 0 493 |
| 415 | if not compile 0 1 |
| 416 | r = write 2 tnot 0 len tnot |
| 417 | ret 3 |
| 418 | end |
| 419 | if not loadpin |
| 420 | r = write 2 tnot 0 len tnot |
| 421 | ret 3 |
| 422 | end |
| 423 | if not hashomc |
| 424 | r = write 2 tnot 0 len tnot |
| 425 | ret 3 |
| 426 | end |
| 427 | if not pinok |
| 428 | r = write 2 tnot 0 len tnot |
| 429 | ret 3 |
| 430 | end |
| 431 | if not compile 2 3 |
| 432 | r = write 2 tcf 0 len tcf |
| 433 | ret 1 |
| 434 | end |
| 435 | if not hashto 3 5 |
| 436 | r = write 2 tcf 0 len tcf |
| 437 | ret 1 |
| 438 | end |
| 439 | obs1 |
| 440 | ok1 = fxcase 8 1 |
| 441 | ok2 = fxcase 11 0 |
| 442 | ok3 = fxcase 14 1 |
| 443 | ok4 = fxcase 17 2 |
| 444 | ok5 = fxcase 20 2 |
| 445 | ok6 = fxcase 23 2 |
| 446 | if ne get fxn 0 6 |
| 447 | obs3 |
| 448 | r = write 2 tfxf 0 len tfxf |
| 449 | ret 1 |
| 450 | end |
| 451 | obs3 |
| 452 | e = rundiff |
| 453 | obs2 e |
| 454 | if lt e 0 |
| 455 | ret 1 |
| 456 | end |
| 457 | ret int e |
| 458 | end |