// Strict component proof. This cannot admit the full K2155 native device drain. import assert from 'node:assert/strict'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync} from 'node:fs'; import {join} from 'node:path'; import {createHash} from 'node:crypto'; import {checkDmaSnapshots,DMA_STAGES,DMA_FORGERIES} from './features/k2155-dma-check-v2.mjs'; import {checkCaptureProtocol} from './features/k2155-worker-capture-check.mjs'; const [matrix,candidatePath]=process.argv.slice(2);assert.equal(process.argv.length,4); const hash=b=>createHash('sha256').update(b).digest('hex'),artifact=path=>({path,sha256:hash(readFileSync(path))}); function bytes(item){const value=readFileSync(item.path);assert.equal(hash(value),item.sha256,item.path);return value;} const read=p=>JSON.parse(readFileSync(p)); const c=read(candidatePath),life=read(join(matrix,'scoped-lifecycle.json')),preflight=read(join(matrix,'preflight.json')); assert.equal(c.status,'COMPILED_FEATURE_CANDIDATE');assert.equal(c.slug,'shutdown-dma-component'); assert.deepEqual(c.frozenAfter,c.frozenBefore);assert.ok(c.imageSpan.bytes>0&&c.imageSpan.bytes<=8*1024*1024); assert.deepEqual(preflight.harness,artifact('scripts/os-acceptance/k2155-dma-guest-runner-v2.mjs')); const spec=JSON.parse(bytes(c.spec));assert.equal(spec.componentOnly,true);assert.equal(spec.guestAccepted,false); assert.equal(life.status,'RUNNER_PASSED');assert.equal(life.frozenStable,true);assert.deepEqual(life.candidate,artifact(candidatePath)); const image=bytes(c.artifacts.image),nm=bytes(c.artifacts.nm).toString(),symbols={}; for(const line of nm.split('\n')){const m=line.match(/^([a-f0-9]{16}) (?:([a-f0-9]{16}) )?[A-Za-z] (\S+)$/);if(m)symbols[m[3]]={address:parseInt(m[1],16),size:m[2]?parseInt(m[2],16):0};} const compiled={};for(const name of ['OS_K1000_AUTHORITY_LAYOUT_EXPECTED']){ const s=symbols[name];assert.ok(s&&s.size);const at=s.address-c.imageSpan.start;assert.ok(at>=0&&at+s.size<=image.length);compiled[name]=image.subarray(at,at+s.size); } const selected=life.selection==='all'?['direct','uefi'].flatMap(route=>[256,512,1024].flatMap(memoryMiB=>[1,2,4].map(cpuCount=>`${route}-${memoryMiB}-cpu-${cpuCount}`))) :life.selection==='smoke'?['direct-256-cpu-1']:life.selection.split(','); assert.equal(new Set(selected).size,selected.length);assert.deepEqual(life.profiles.map(r=>r.profile.id),selected); assert.equal(new Set(c.captures).size,c.captures.length); const directory=mkdtempSync('reports/os-implementation/K2155-dma-matrix-check-'); const sources=['scripts/os-acceptance/k2155-dma-matrix-check-v2.mjs','scripts/os-acceptance/k2155-dma-guest-runner-v2.mjs','scripts/os-acceptance/features/k2155-dma-check-v2.mjs','scripts/os-acceptance/features/k2155-dma-authority-check.mjs','scripts/os-acceptance/features/k2155-worker-capture-check.mjs']; const report={status:'RUNNING',guestAccepted:false,productAccepted:false,componentOnly:true,candidate:artifact(candidatePath),lifecycle:artifact(join(matrix,'scoped-lifecycle.json')),preflight:artifact(join(matrix,'preflight.json')),profiles:[],negativeControls:[]}; report.sources=sources.map((p,i)=>{const out=join(directory,`${i}-${p.split('/').at(-1)}.txt`);copyFileSync(p,out);return artifact(out);}); try{ for(const profile of life.profiles){ assert.equal(profile.status,'GUEST_RETURNED');assert.equal(profile.allOwnedGuestsStopped,true); const path=join(matrix,profile.profile.id,'result.json'),r=read(path);assert.deepEqual(r,profile); assert.deepEqual(r.experimentStages.map(s=>s.stage),DMA_STAGES); assert.equal(r.exit.code,0);assert.equal(r.exit.signal,null); const command=read(join(matrix,r.profile.id,'qemu-command.json'));assert.deepEqual(command.profile,r.profile);assert.equal(command.bootId,r.bootId); const serial=bytes(r.serial).toString();assert.ok(serial.includes('TURKOS/OS/K2155-DMA:'));assert.ok(serial.includes('TURKOS/OS/K2155: PASS'));assert.ok(!/PANIC|REJECTED|FATAL/.test(serial)); const protocol=checkCaptureProtocol({audit:JSON.parse(bytes(r.captureAudit)),qmp:JSON.parse(bytes(r.qmpTranscript)),stages:r.experimentStages,serial}); const snapshots=[]; for(const stage of r.experimentStages){ const data={};assert.deepEqual(stage.captures.map(x=>x.symbol),c.captures); for(const span of stage.captures){assert.equal(span.address,symbols[span.symbol].address);assert.equal(span.size,symbols[span.symbol].size);const b=bytes(span);assert.equal(b.length,span.size);data[span.symbol]=b;} const meta=Array.from({length:4},(_,i)=>Number(data.OS_K2155_DMA_AUTHORITY.readBigUInt64LE(i*8))); const devices=Array.from({length:128},(_,i)=>Number(data.OS_K2155_DMA_DEVICES.readBigUInt64LE(i*8))); assert.equal(new Set(stage.physical.map(p=>p.name)).size,stage.physical.length); const expected=[['authority',meta[0],meta[1]]]; for(let d=0;d<2;d++){ for(const [name,offset]of [['magic',0],['version',4],['device',8],['vendor',12],['ready',0x44],['interrupt',0x60],['status',0x70]])expected.push([`mmio-${d}-${name}`,devices[d*64]+offset,4]); for(let q=0;q<(d===0?1:2);q++)for(let p=0;p<4;p++)expected.push([`dma-${d}-${q}-${p}`,devices[d*64+12+q*20+p],4096]); } assert.deepEqual(stage.physical.map(p=>[p.name,p.address,p.size]),expected); const ramEnd=0x40000000+r.profile.memoryMiB*1048576; for(const span of stage.physical){ assert.ok(!data[span.name]);assert.ok(Number.isSafeInteger(span.address)&&Number.isSafeInteger(span.size)&&span.size>0&&span.size<=65536); if(span.name.startsWith('mmio-'))assert.ok(span.size===4&&span.address>=0xa000000&&span.address<0xa004000&&span.address%4===0); else assert.ok(span.address>=0x40000000&&span.address+span.size<=ramEnd&&span.address%8===0); const b=bytes(span);assert.equal(b.length,span.size);data[span.name]=b; } const spans=[...stage.captures,...stage.physical];assert.equal(stage.confirmations.length,spans.length); for(const [i,confirmation]of stage.confirmations.entries())assert.deepEqual(bytes(confirmation),bytes(spans[i])); snapshots.push(data); } for(const item of r.final)assert.deepEqual(bytes(item),snapshots.at(-1)[item.symbol]); const input={snapshots,compiled,symbols,memoryMiB:r.profile.memoryMiB,bootId:r.bootId, sector:bytes(preflight.fixtures.block).subarray(111*512,112*512),exchange:r.dmaExchange,baseline:r.dmaNetworkBaseline}; const verified=checkDmaSnapshots(input); const controls=DMA_FORGERIES; for(const [name,step,key,offset]of controls){const altered=snapshots.map(s=>({...s}));altered[step][key]=Buffer.from(altered[step][key]);altered[step][key][offset]^=1;assert.throws(()=>checkDmaSnapshots({...input,snapshots:altered}),name);} report.negativeControls.push({profile:r.profile.id,rejected:controls.map(x=>x[0])}); report.profiles.push({profile:r.profile,result:artifact(path),verified,protocol}); } report.status='K2155_DMA_COMPONENT_MATRIX_VALIDATED';report.physicalDmaVerified=true; report.fullHardwareMatrix=report.profiles.length===18&&life.selection==='all'; report.scope='Actual native disk read and RX/TX DMA completion, both-device reset, twelve-page erasure and exact allocator return. IRQ, worker and EL0 integration plus full K2155 admission remain required.'; }catch(error){report.status='K2155_DMA_COMPONENT_MATRIX_FAILED';report.error=error.stack;process.exitCode=1;} writeFileSync(join(directory,'report.json'),JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:join(directory,'report.json'),profiles:report.profiles.length}));