interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / x86 / model / tests.inc

93 lines · 4692 bytes Raw Blame History
1/* Test-only raw-code admission is absent from the deployable image. */
2static void model_reclaimed(void)
3{
4 reclaimed();
5 check(!model_running && zeroed(model_pt, sizeof model_pt) &&
6 zeroed(model_code, sizeof model_code) && zeroed(model_work, sizeof model_work),
7 "model scratch/code/translations reclaimed");
8}
9static void model_run_done(void)
10{
11 uint64_t report_at = ck_rdtsc() + 10 * hz;
12 while (running) {
13 ck_local_step(); /* production elapsed quota bounds this */
14 if (running && ck_rdtsc() >= report_at) {
15 uint32_t progress; memcpy(&progress, model_work, 4);
16 ck_printf("local_model_test: progress=%u cpu_ms=%llu\n", progress,
17 (unsigned long long)(cpu_used / (hz / 1000)));
18 report_at = ck_rdtsc() + 10 * hz;
19 }
20 }
21 model_reclaimed();
22}
23static void model_begin_test(void)
24{
25 ck_local_begin(0); wipe(&model_result, sizeof model_result);
26 running = &model_result; running->state = CK_LOCAL_RUNNING;
27 check(!model_prepare(), "signed model prepared");
28}
29static void model_fault_probe(uint64_t address, int write, int execute)
30{
31 model_begin_test();
32 uint8_t b[16] = {0x48,0xb8};
33 memcpy(b+2, &address, 8);
34 b[10] = execute ? 0xff : 0x48;
35 b[11] = execute ? 0xe0 : write ? 0x89 : 0x8b;
36 b[12] = 0; b[13] = 0xc3;
37 memcpy(model_code, b, sizeof b);
38 model_run_done();
39 check(model_result.state == CK_LOCAL_ABNORMAL && model_result.reason == CK_LOCAL_FAULT &&
40 !model_result.length, "model forbidden memory access contained");
41}
42static void model_selftest(void)
43{
44 check(model_ok, "owner-signed native model admitted");
45 model_begin_test();
46 model_run_done();
47 static const uint32_t expected[] = {9038,2501,263,931,29892,727,471,263,
48 2217,7826,4257,365,2354,29889,2296,18012,304,1708,5377,297,278,6575,
49 845,457,29889,3118,2462,29892,1183,4446,263,4802};
50 uint32_t count; memcpy(&count, model_result.output, 4);
51 ck_printf("local_model_test: state=%u reason=%u count=%u bytes=%u cpu_ms=%llu elapsed_ms=%llu\n",
52 model_result.state, model_result.reason, count, model_result.length,
53 (unsigned long long)model_cpu_ms, (unsigned long long)model_elapsed_ms);
54 check(model_result.state == CK_LOCAL_RETURNED && model_result.length == 192 && count == 32 &&
55 equal(model_result.output+64, (const void *)expected, sizeof expected),
56 "15M native Omega tokens exactly match independent reference");
57 char text[768];
58 check(model_decode(&model_result, text, sizeof text) == 32, "signed tokenizer decoded real output");
59 ck_printf("local_model_test: generation PASS tokens=32 cpu_ms=%llu elapsed_ms=%llu real_cpl3=yes\n",
60 (unsigned long long)model_cpu_ms, (unsigned long long)model_elapsed_ms);
61 ck_printf("local_model_test: sample=%s\n", text);
62 model_fault_probe(MODEL_WEIGHTS, 1, 0);
63 model_fault_probe(MODEL_WEIGHTS, 0, 1);
64 model_fault_probe(MODEL_CODE, 1, 0);
65 model_fault_probe(MODEL_WORK, 0, 1);
66 model_fault_probe(MODEL_WORK - PAGE, 0, 0);
67 model_fault_probe(MODEL_WORK + sizeof model_work, 0, 0);
68 model_fault_probe(kernel_root, 0, 0);
69 model_begin_test();
70 ((uint64_t *)input)[3] = 32000;
71 model_run_done();
72 check(model_result.state == CK_LOCAL_TRAPPED && model_result.reason == 3 && !model_result.length,
73 "out-of-vocabulary input fails closed");
74 model_begin_test();
75 ((uint64_t *)input)[2]--;
76 model_run_done();
77 check(model_result.state == CK_LOCAL_TRAPPED && model_result.reason == 3 && !model_result.length,
78 "wrong checkpoint length fails closed");
79 model_begin_test(); ck_local_step(); ck_local_cancel(); model_reclaimed();
80 check(model_result.reason == CK_LOCAL_CANCELLED, "model can cancel after one slice");
81 model_begin_test(); started = ck_rdtsc() - 181 * hz; ck_local_step(); model_reclaimed();
82 check(model_result.reason == CK_LOCAL_ELAPSED, "model elapsed ceiling enforced");
83 model_begin_test(); cpu_used = 121 * hz; ck_local_step(); model_reclaimed();
84 check(model_result.reason == CK_LOCAL_CPU, "model CPU ceiling enforced");
85 int64_t arithmetic[] = {3,123,456};
86 ck_local_begin(919);
87 const struct ck_local_result *r = ck_local_start(919, 1, 1, arithmetic, sizeof arithmetic);
88 run_done(); int64_t result; memcpy(&result, r->output, 8);
89 check(r->state == CK_LOCAL_RETURNED && result == 56088, "small tools still work after model faults");
90 ck_local_begin(0);
91 model_demo_state = 2; /* no duplicate diagnostic run in fixture images */
92 ck_puts("local_model_test: PASS isolation=1 quotas=1 cancellation=1 cleanup=1\n");
93}