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 / ui / tests / mind_phases_test.c

138 lines · 7754 bytes Raw Blame History
1/* Production-renderer regression: native pixel crops, not rescaled previews.
2 * A hotspot is an Allen-changed final pixel with both red and green >=192
3 * (the upper sRGB quarter; white includes blue>=192, yellow has lower blue).
4 * On black, any red/green-dominant warm pixel also fails at any brightness.
5 * On sky, count new/worsened hotspots, not an unchanged background star.
6 * Cool points must fit a 5x5 native footprint including coverage; the heart
7 * fits the same footprint. These are geometric contracts, not area allowances.
8 */
9#include <fcntl.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include "../mind.h"
14#include "../night.h"
15
16enum { W=3840, H=2160, K=512, CX=1920, CY=864, CROP=768 };
17static uint32_t *sky, *image;
18static unsigned failures, frames, yellow_pixels, white_pixels;
19static const char *directory;
20static int halo_control;
21static void check(int good, const char *name) { if (!good) { failures++; if (failures<20) fprintf(stderr,"FAIL %s\n",name); } }
22static int hot(uint32_t c) { return ck_ch(c,16)>=192 && ck_ch(c,8)>=192; }
23static void save(const char *name, const uint32_t *p) {
24 if (!directory) return;
25 char path[1024]; snprintf(path,sizeof path,"%s/%s.ppm",directory,name);
26 int f_fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
27 FILE *f = f_fd < 0 ? NULL : fdopen(f_fd, "wb"); if (!f) { check(0,"frame open"); return; }
28 fprintf(f,"P6\n%d %d\n255\n",CROP,CROP);
29 for(int y=CY-CROP/2;y<CY+CROP/2;y++) for(int x=CX-CROP/2;x<CX+CROP/2;x++) {
30 uint32_t c=p[(size_t)y*W+x]; unsigned char rgb[3]={c>>16,c>>8,c}; fwrite(rgb,1,3,f);
31 }
32 fclose(f);
33}
34static unsigned measure(const ck_mind *m, const uint32_t *base, unsigned *lit, unsigned *annulus) {
35 unsigned bad=0; *lit=*annulus=0;
36 int64_t radius=0;
37 for(unsigned i=0;i<CK_MIND_NODES;i++) {
38 int64_t dx=m->px[i]-m->hx,dy=m->py[i]-m->hy;
39 int64_t d=ck_isqrt((uint64_t)(dx*dx+dy*dy)); if(d>radius) radius=d;
40 }
41 radius+=192; /* historical largest point plus coverage: annulus control only */
42 ck_rect box=ck_grow(m->box,16), canvas={0,0,W,H}; ck_clip(&box,&canvas);
43 for(int y=box.y;y<box.y+box.h;y++) for(int x=box.x;x<box.x+box.w;x++) {
44 size_t p=(size_t)y*W+x; uint32_t a=image[p],b=base?base[p]:0;
45 if(a==b) continue;
46 (*lit)++;
47 int64_t dx=x*16+8-m->hx,dy=y*16+8-m->hy;
48 if(dx*dx+dy*dy>radius*radius) (*annulus)++;
49 /* Inspect final composite, not merely the subtracted light's colour. */
50 int warm_black=!base && ck_ch(a,16)>ck_ch(a,0) && ck_ch(a,8)>ck_ch(a,0);
51 if(warm_black || (hot(a) && (!hot(b) || ck_ch(a,16)>ck_ch(b,16) || ck_ch(a,8)>ck_ch(b,8)))) {
52 bad++;
53 if(ck_ch(a,0)>=192) white_pixels++; else yellow_pixels++;
54 }
55 }
56 return bad;
57}
58static void render(const ck_mind *m,const uint32_t *base) {
59 ck_rect box=ck_grow(m->box,16),canvas={0,0,W,H}; ck_clip(&box,&canvas);
60 for(int y=box.y;y<box.y+box.h;y++) {
61 uint32_t *p=image+(size_t)y*W+box.x;
62 if(base) memcpy(p,base+(size_t)y*W+box.x,(size_t)box.w*4); else memset(p,0,(size_t)box.w*4);
63 }
64 ck_canvas cv={image,W,H}; ck_mind_draw(m,&cv,&canvas);
65 if(halo_control)
66 ck_glow(&cv,&canvas,m->hx,m->hy,m->R*16*2,CK_RGB(60,74,210),64);
67}
68static void isolated(int control) {
69 ck_mind m; ck_mind_init(&m,CX,CY,K,0); ck_mind_at(&m,6000);
70 int32_t heart_radius=m.hr;
71 m.ne=m.nspark=0; memset(m.lum,0,sizeof m.lum); m.hr=0;
72 for(unsigned i=0;i<CK_MIND_NODES;i++) {m.px[i]=CX*16+8;m.py[i]=CY*16+8;}
73 m.lum[0]=256; m.near[0]=256; m.act[0]=0;
74 render(&m,0);
75 unsigned lit,ann; unsigned bad=measure(&m,0,&lit,&ann);
76 check(!bad,"isolated whole-point brightness"); check(lit>0 && lit<=25,"native point footprint <=5x5, visible");
77 printf("POINT lit=%u hot=%u\n",lit,bad);
78 m.lum[0]=0; m.hr=control==2?160:heart_radius; m.heart=256; render(&m,0);
79 bad=measure(&m,0,&lit,&ann); check(!bad,"isolated white heart"); check(lit>0 && lit<=25,"native heart footprint <=5x5, visible");
80 printf("HEART lit=%u hot=%u\n",lit,bad);
81 /* Isolate real moving spark head/tail geometry as well as heart/nodes. */
82 m.hr=0; m.nspark=1; m.spark[0].e=0; m.spark[0].dur=240; m.spark[0].t0=m.t;
83 render(&m,0); bad=measure(&m,0,&lit,&ann);
84 check(!bad && lit>0 && lit<=25,"native cool spark/tail footprint <=5x5");
85 printf("SPARK lit=%u hot=%u\n",lit,bad);
86 m.nspark=0; m.hr=heart_radius;
87 /* Synthetic maximum-overlap raster stress, not a reachable-history claim. */
88 for(unsigned i=0;i<CK_MIND_NODES;i++) m.lum[i]=m.act[i]=256;
89 render(&m,0); bad=measure(&m,0,&lit,&ann);
90 check(!bad && lit<=25,"overlapping points do not accumulate white or broaden");
91 if(control==1) {
92 ck_canvas cv={image,W,H}; ck_rect clip={0,0,W,H};
93 ck_glow(&cv,&clip,m.hx,m.hy,160,CK_RGB(255,250,240),256);
94 bad=measure(&m,0,&lit,&ann); check(!bad,"explicit warm/white injected control (must fail)");
95 }
96}
97int main(int argc,char **argv) {
98 directory=argc>1 && strcmp(argv[1],"-")?argv[1]:0;
99 int control=argc>2 && !strcmp(argv[2],"--warm-control")?1:
100 argc>2 && !strcmp(argv[2],"--large-disc-control")?2:0;
101 int suppressed=argc>2 && !strcmp(argv[2],"--suppressed-control");
102 halo_control=argc>2 && !strcmp(argv[2],"--halo-control");
103 size_t bytes=(size_t)W*H*4;
104 sky=calloc(1,bytes); image=calloc(1,bytes);
105 size_t nb=ck_night_mem_bytes(W,H,K); void *storage=malloc(nb); static ck_night n;
106 if(!sky||!image||!storage) return 2;
107 check(!ck_night_init(&n,W,H,K,CX,CY,storage,nb),"galaxy init");
108 ck_canvas bg={sky,W,H}; ck_rect clip={0,0,W,H}; ck_night_at(&n,30000); ck_night_base(&n,&bg,&clip); ck_night_lights(&n,&bg,&clip,0,0);
109 isolated(control);
110 for(unsigned seed=0;seed<2;seed++) for(int initial=0;initial<4;initial++) {
111 ck_mind m; ck_mind_init(&m,CX,CY,K,0); m.rng^=seed; ck_mind_mode(&m,initial,0);
112 unsigned badblack=0,badsky=0,annuli=0,visible=0,sparks=0;
113 for(uint32_t t=0;t<=12000;t+=30) {
114 /* Formation, settled cadence, then each transition with live residual sparks. */
115 if(t>=7500 && t%1500==0) ck_mind_mode(&m,(m.mode+1)&3,t);
116 ck_mind_voice(&m,(t/300)%3*128);
117 if(t%300==0) {ck_mind_word(&m,t);ck_mind_key(&m,t);}
118 ck_mind_at(&m,t); sparks+=m.nspark;
119 if(suppressed) m.alpha=0;
120 unsigned lit,ann; render(&m,0); unsigned b=measure(&m,0,&lit,&ann); badblack+=b; annuli+=ann;
121 if(t>=3000) {check(lit>CK_MIND_NODES,"meaningful visible network, not alpha zero"); visible+=lit;}
122 render(&m,sky); badsky+=measure(&m,sky,&lit,&ann); annuli+=ann;
123 if(seed==0 && t==6000) {
124 char name[64];
125 memcpy(image,sky,bytes); render(&m,sky);
126 snprintf(name,sizeof name,"mode-%d-galaxy-native",initial);save(name,image);
127 memset(image,0,bytes);render(&m,0);
128 snprintf(name,sizeof name,"mode-%d-black-native",initial);save(name,image);
129 }
130 frames++;
131 }
132 printf("PHASE seed=%u initial=%d black_hot=%u sky_hot=%u annulus=%u visible=%u sparks=%u\n",seed,initial,badblack,badsky,annuli,visible,sparks);
133 check(!badblack,"no interior warm/white on black");check(!badsky,"no new/worsened final-composite warm/white on identical sky");check(!annuli,"no exterior light");check(sparks>0 && visible>0,"live sparks and network retained");
134 }
135 printf("MIND_PHASES %s frames=%u yellow_pixels=%u white_pixels=%u failures=%u\n",
136 failures?"FAIL":"PASS",frames,yellow_pixels,white_pixels,failures);
137 free(storage);free(sky);free(image);return failures?1:0;
138}