interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / tests / hardware / acceptance.mjs

92 lines · 6241 bytes Raw Blame History
1import fs from 'node:fs';
2import {spawnSync} from 'node:child_process';
3import {createHash} from 'node:crypto';
4import assert from 'node:assert/strict';
5const root = new URL('../../', import.meta.url).pathname;
6const executable = process.argv[2] || root + 'target/L558/hardware-map';
7const outdir = process.env.HW_EVIDENCE || root + 'qualification/evidence/L558';
8fs.mkdirSync(outdir, {recursive:true});
9import {discovery,intent,digest,names} from './fixtures.mjs';
10const rows=[];
11function run(name,r,d,code) {
12 const p=outdir+'/discovery.bin'; fs.writeFileSync(p,d);
13 const fd=fs.openSync(p,'r');
14 const x=spawnSync(executable,[],{input:r,stdio:['pipe','pipe','pipe',fd],timeout:3000}); fs.closeSync(fd);
15 assert.equal(x.error,undefined,`${name}: ${x.error}`);
16 assert.equal(x.status,code,`${name}: stderr=${x.stderr} stdout=${x.stdout}`);
17 if(code) {assert.equal(x.stdout.length,0,name); assert.equal(x.stderr.toString(),`hardware refusal ${code}\n`,name);}
18 else {
19 const result=JSON.parse(x.stdout);
20 const op=r[5];
21 assert.deepEqual(result, {kind:'capability_request',request_id:'hw-'+r.readBigUInt64LE(64),runtime:'aienux',capability:'hw_'+names[op-1].replaceAll('.','_'),arguments:{identifier:r.readUInt32LE(12),required_features:r[9],value:Number(r.readBigUInt64LE(16)),discovery_generation:r.readBigUInt64LE(24).toString()},tool:{namespace:'hardware',name:names[op-1]},mapping:{table_version:'hardware-1',rule_id:'alias:hardware.'+names[op-1],passthrough:false,catalog_digest:'sha256:'+digest.toString('hex')}});
22 if(name.startsWith('valid-')) fs.writeFileSync(outdir+`/mapped-${op}.json`,JSON.stringify(result)+'\n');
23 }
24 rows.push({name,exit:x.status,stdout_sha256:createHash('sha256').update(x.stdout).digest('hex'),stderr:x.stderr.toString()});
25}
26function test(name,code,change=()=>{},op=1) {const r=intent(op),d=discovery(); change(r,d);run(name,r,d,code);}
27for(let op=1;op<=5;op++)test('valid-'+names[op-1],0,()=>{},op);
28test('unsupported-wire-version',21,r=>r[4]=2);
29test('unsupported-discovery-version',21,(_,d)=>d[4]=2);
30for(const [name,offset] of [['profile',5],['profile-version',6],['vendor',7]])test('unsupported-'+name,22,(_,d)=>d[offset]=255);
31for(const [name,ri,di] of [['isa',6,8],['endianness',7,9],['granule',8,10]]) {
32 test('incompatible-'+name,23,r=>r[ri]=2);
33 test('unsupported-host-'+name,23,(_,d)=>d[di]=2);
34}
35test('required-cpu-feature-present',0,r=>r[9]=1);
36test('unknown-cpu-features',23,r=>r[9]=128);
37test('required-cpu-feature-absent',23,(r,d)=>{r[9]=1;d[11]=0;});
38test('unknown-host-feature',23,(_,d)=>d[11]=128);
39test('stale-generation',24,r=>r.writeBigUInt64LE(6n,24));
40test('future-generation',24,r=>r.writeBigUInt64LE(8n,24));
41test('zero-host-generation',24,(_,d)=>d.writeBigUInt64LE(0n,24));
42test('forged-catalog-digest',24,r=>r[32]^=1);
43test('zero-host-digest',24,(_,d)=>d.fill(0,32,64));
44test('unknown-timer',25,(_,d)=>d[12]=0);
45test('unknown-gic',25,(_,d)=>d[13]=2);
46test('unknown-iommu',25,(_,d)=>d[14]=2);
47test('unknown-coherency',25,(_,d)=>d[15]=0);
48test('contradictory-coherency',25,(_,d)=>{d[14]=0;d[15]=2;});
49test('unknown-firmware',25,(_,d)=>d[16]=255);
50test('unknown-conduit',25,(_,d)=>d[17]=0);
51test('raw-mmio-refused',26,r=>r[5]=6);
52test('unknown-capability',26,r=>r[5]=255);
53test('cpu-out-of-range-id',27,r=>r.writeUInt32LE(1,12));
54test('interrupt-sgi-refused',27,r=>r.writeUInt32LE(15,12),3);
55test('interrupt-reserved-refused',27,r=>r.writeUInt32LE(1020,12),3);
56test('identifier-u32-max',27,r=>r.writeUInt32LE(0xffffffff,12),3);
57test('timer-zero',27,r=>r.writeBigUInt64LE(0n,16),2);
58test('timer-overflow',27,r=>r.writeBigUInt64LE(1n<<63n,16),2);
59test('dma-no-isolation',28,(_,d)=>{d[14]=0;d[15]=1;},4);
60test('dma-zero-length',27,r=>r.writeBigUInt64LE(0n,16),4);
61test('dma-unaligned',27,r=>r.writeBigUInt64LE(4097n,16),4);
62test('dma-over-limit',27,r=>r.writeBigUInt64LE(1048577n,16),4);
63test('dma-aligned-over-limit',27,r=>r.writeBigUInt64LE(1052672n,16),4);
64test('dma-u64-max',27,r=>r.writeBigUInt64LE((1n<<64n)-1n,16),4);
65test('dma-identifier-out-of-range',27,r=>r.writeUInt32LE(65536,12),4);
66test('no-raw-power-address',27,r=>r.writeBigUInt64LE(0xffffffffffffffffn,16),5);
67test('unknown-power-function',27,r=>r.writeUInt32LE(3,12),5);
68test('zero-request-id',27,r=>r.writeBigUInt64LE(0n,64));
69test('generation-u64-max',0,(r,d)=>{r.writeBigUInt64LE((1n<<64n)-1n,24);d.writeBigUInt64LE((1n<<64n)-1n,24);});
70test('request-id-u64-max',0,r=>r.writeBigUInt64LE((1n<<64n)-1n,64));
71test('noncoherent-dma-explicit',0,(_,d)=>d[15]=1,4);
72test('hvc-and-smc',0,(_,d)=>d[17]=1,5);
73test('dma-max-length',0,r=>r.writeBigUInt64LE(1048576n,16),4);
74test('interrupt-upper-bound',0,r=>r.writeUInt32LE(1019,12),3);
75for(const n of [0,1,4,24,64,95])run('truncated-intent-'+n,intent().subarray(0,n),discovery(),20);
76for(const n of [0,1,24,64,95])run('truncated-discovery-'+n,intent(),discovery().subarray(0,n),20);
77run('trailing-intent',Buffer.concat([intent(),Buffer.from([0])]),discovery(),20);
78run('trailing-discovery',intent(),Buffer.concat([discovery(),Buffer.from([0])]),20);
79run('model-forged-discovery-on-stdin',discovery(),Buffer.alloc(0),20);
80for(const i of [10,11,72,95])test('intent-reserved-'+i,20,r=>r[i]=1);
81for(const i of [18,23,64,95])test('discovery-reserved-'+i,20,(_,d)=>d[i]=1);
82// Exhaust every enum spelling against this profile's closed sets.
83for(const [field,offset,allowed,code] of [
84 ['profile',5,[1],22],['profile-version',6,[1],22],['vendor',7,[0],22],
85 ['isa',8,[1],23],['endian',9,[1],23],['granule',10,[1],23],
86 ['features',11,[0,1],23],['timer',12,[1],25],['gic',13,[3],25],
87 ['iommu',14,[3],25],['coherency',15,[1,2],25],['firmware',16,[1],25],['conduit',17,[1,2],25]
88]) for(let value=0;value<256;value++) test('closed-'+field+'-'+value,allowed.includes(value)?0:code,(_,d)=>d[offset]=value);
89for(let i=72;i<96;i++)test('reserved-intent-byte-'+i,20,r=>r[i]=1);
90for(let i=64;i<96;i++)test('reserved-discovery-byte-'+i,20,(_,d)=>d[i]=1);
91fs.writeFileSync(outdir+'/acceptance.json',JSON.stringify({executable_sha256:createHash('sha256').update(fs.readFileSync(executable)).digest('hex'),source_sha256:createHash('sha256').update(fs.readFileSync(root+'omega/hardware/map.om')).digest('hex'),cases:rows},null,2)+'\n');
92console.log(`PASS ${rows.length} native behavior cases`);