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 / tests / fabric / fabric_living_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * fabric_living_test.c -- Fabric F5-0 used by the COMPOSITION-2 causal path |
| 19 | * (Lane 13). Runs the scenario of fab_living_phase.h on a composition that |
| 20 | * owns its World and authority, twice in fresh directories, and requires |
| 21 | * equal Cortex record and Fabric state digests (deterministic). |
| 22 | * The same scenario runs inside the R13 test-build variant (rx_r13_living.c |
| 23 | * built with -DAIEN_TEST_BUILD=1; the production program has no Fabric). |
| 24 | * One worker, as the COMPOSITION-2 gate: with more, the candidates finish in |
| 25 | * varying order and the record order (not its content) varies. |
| 26 | * Prints FABRIC_LIVING_PASS on success. |
| 27 | */ |
| 28 | #include "fab_living_phase.h" |
| 29 | |
| 30 | #include <ftw.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <unistd.h> |
| 34 | |
| 35 | static Fx g_fx; /* only for its authority start/stop */ |
| 36 | |
| 37 | static int rm_one(const char *p, const struct stat *sb, int flag, struct FTW *ftw) { |
| 38 | (void)sb; (void)flag; (void)ftw; |
| 39 | return remove(p); |
| 40 | } |
| 41 | |
| 42 | static int own_attach(void *ctx, RxCompose *c, const char *dir, const AienMachineId *self, |
| 43 | const SrRouter *router) { |
| 44 | Fx *f = ctx; |
| 45 | f->self = *self; |
| 46 | if (aienos_cap_start(&f->admin, &f->view) != 0) return -100; |
| 47 | f->owns_authority = 1; |
| 48 | int rc = rx_compose_open(c, dir, self, FX_SESSION, router, fx_contract, f->admin, f->view, 1); |
| 49 | if (rc != RX_OK) { |
| 50 | aienos_cap_stop(f->admin, f->view); |
| 51 | f->admin = NULL; |
| 52 | } |
| 53 | return rc; |
| 54 | } |
| 55 | |
| 56 | static void own_close(void *ctx, RxCompose *c) { fx_close(ctx, c); } |
| 57 | |
| 58 | int main(void) { |
| 59 | char base[64] = "/tmp/fabric_living_test.XXXXXX"; |
| 60 | if (!mkdtemp(base)) { perror("mkdtemp"); return 1; } |
| 61 | AienMachineId self = fx_mid(1); |
| 62 | FlReceipt g[2]; |
| 63 | unsigned checks = 0, failures = 0; |
| 64 | for (int run = 0; run < 2; run++) { |
| 65 | char dir[128]; |
| 66 | snprintf(dir, sizeof dir, "%s/run%d", base, run); |
| 67 | memset(&g_fx, 0, sizeof g_fx); |
| 68 | int rc = fl_run(&self, dir, own_attach, own_close, &g_fx, &g[run]); |
| 69 | checks += g[run].checks; |
| 70 | failures += g[run].failures; |
| 71 | printf("run %d: %s (%u checks, %u failed; remote wins %u, dispatched %llu)\n", run, |
| 72 | rc == 0 ? "PASS" : "FAIL", g[run].checks, g[run].failures, g[run].remote_wins, |
| 73 | (unsigned long long)g[run].dispatched); |
| 74 | } |
| 75 | int same = memcmp(g[0].record_digest, g[1].record_digest, 32) == 0 && |
| 76 | memcmp(g[0].fabric_digest, g[1].fabric_digest, 32) == 0 && |
| 77 | memcmp(g[0].result, g[1].result, sizeof g[0].result) == 0 && |
| 78 | memcmp(g[0].winner, g[1].winner, sizeof g[0].winner) == 0; |
| 79 | checks++; |
| 80 | if (!same) { |
| 81 | failures++; |
| 82 | fprintf(stderr, "FABRIC-LIVING FAIL: the two runs differ\n"); |
| 83 | } |
| 84 | char hx[65]; |
| 85 | for (int run = 0; run < 2; run++) { |
| 86 | fx_hex(g[run].record_digest, 32, hx); |
| 87 | printf("run %d record digest %s\n", run, hx); |
| 88 | fx_hex(g[run].fabric_digest, 32, hx); |
| 89 | printf("run %d fabric digest %s\n", run, hx); |
| 90 | } |
| 91 | nftw(base, rm_one, 16, FTW_DEPTH | FTW_PHYS); |
| 92 | printf("checks %u, failures %u\n", checks, failures); |
| 93 | if (failures) { printf("FABRIC_LIVING_FAIL\n"); return 1; } |
| 94 | printf("FABRIC_LIVING_PASS\n"); |
| 95 | return 0; |
| 96 | } |