// 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 {checkIrqDmaSnapshots,irqPhysicalSpans,IRQ_FORGERIES,irqForgery,DMA_FORGERIES} from './features/k2155-irq-dma-check.mjs'; import {irqBindingsFromDtb} from './features/k2155-irq-dtb-check.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-irq-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-irq-dma-guest-runner.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 activeSymbols=Object.entries(symbols).filter(([name,value])=>name.endsWith('18OS_K660_IRQ_ACTIVE')&&value.size===4);assert.equal(activeSymbols.length,1);symbols.OS_K660_IRQ_ACTIVE=activeSymbols[0][1]; const compiled={};for(const name of ['OS_K1000_AUTHORITY_LAYOUT_EXPECTED','OS_K2155_IRQ_LAYOUT']){ 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-irq-dma-matrix-check-'); const sources=['scripts/os-acceptance/k2155-irq-dma-matrix-check.mjs','scripts/os-acceptance/k2155-irq-dma-guest-runner.mjs','scripts/os-acceptance/features/k2155-dma-check-v2.mjs','scripts/os-acceptance/features/k2155-irq-dma-check.mjs','scripts/os-acceptance/features/k2155-irq-dtb-check.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.equal(r.experimentStages.length,14);const stages=r.experimentStages.map(s=>s.stage);assert.equal(new Set(stages).size,14); 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]); } expected.push(...irqPhysicalSpans(data)); 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 if(span.name.startsWith('gic-'))assert.ok([1,4,8].includes(span.size)&&span.address>=0x8000000&&span.address+span.size<=0x8010000&&span.address%span.size===0); else assert.ok(span.address>=0x40000000&&span.address+span.size<=ramEnd&&span.address%Math.min(span.size,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, bindings:irqBindingsFromDtb((bytes(r.dtb),r.dtb.path)),sector:bytes(preflight.fixtures.block).subarray(111*512,112*512),exchange:r.dmaExchange,baseline:r.dmaNetworkBaseline}; const verified=checkIrqDmaSnapshots(input); const controls=DMA_FORGERIES; for(const [name,step,key,offset]of controls){const at=step>=2?step+4:step,altered=snapshots.map(s=>({...s}));altered[at][key]=Buffer.from(altered[at][key]);altered[at][key][offset]^=1;assert.throws(()=>checkIrqDmaSnapshots({...input,snapshots:altered}),name);} for(const entry of IRQ_FORGERIES)assert.throws(()=>checkIrqDmaSnapshots({...input,snapshots:irqForgery(snapshots,entry,compiled)}),entry[0]); report.negativeControls.push({profile:r.profile.id,rejected:[...controls,...IRQ_FORGERIES].map(x=>x[0])}); report.profiles.push({profile:r.profile,result:artifact(path),verified,protocol}); } report.status='K2155_IRQ_DMA_COMPONENT_MATRIX_VALIDATED';report.physicalDmaVerified=true;report.physicalIrqVerified=true; report.fullHardwareMatrix=report.profiles.length===18&&life.selection==='all'; report.scope='Actual CPU0 IRQ entry/live exception frames/device ACK/EOI/ERET and two owned SPI masks tied to native disk and RX/TX DMA, device resets and exact twelve-page reclamation. Worker and EL0 integration and failure matrix remain required for K2155 admission.'; }catch(error){report.status='K2155_IRQ_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}));