import assert from 'node:assert/strict'; import {spawnSync} from 'node:child_process'; import {frozenSnapshot} from './boot-contract-report.mjs'; import {readFileSync,writeFileSync,mkdtempSync,copyFileSync} from 'node:fs'; import {createHash} from 'node:crypto'; import {join,resolve,relative} from 'node:path'; import {fileURLToPath} from 'node:url'; import {FEATURE_PROFILES} from './k2150-native-guest-runner.mjs'; import {faultConfiguration} from './k2150-native-storage-fixture.mjs'; import {checkStorageComponent} from './features/k2150-native-check.mjs'; const [matrixPath,candidatePath]=process.argv.slice(2);assert.ok(matrixPath&&candidatePath&&process.argv.length===4); const read=p=>JSON.parse(readFileSync(p)),artifact=path=>({path,sha256:createHash('sha256').update(readFileSync(path)).digest('hex')}); const checked=a=>{assert.equal(artifact(a.path).sha256,a.sha256,a.path);return readFileSync(a.path);}; const directory=mkdtempSync('reports/os-implementation/K2150-native-storage-proof-'); copyFileSync(fileURLToPath(import.meta.url),join(directory,'harness.mjs.txt')); try{ const candidate=read(candidatePath),life=read(join(matrixPath,'scoped-lifecycle.json')),preflight=read(join(matrixPath,'preflight.json')); assert.equal(candidate.status,'COMPILED_FEATURE_CANDIDATE');assert.equal(candidate.slug,'shutdown-native-flush'); assert.equal(life.status,'RUNNER_PASSED');assert.equal(life.selection,'all');assert.equal(life.frozenStable,true); assert.deepEqual(life.candidate,artifact(candidatePath));assert.equal(life.profiles.length,54); assert.ok(candidate.imageSpan.bytes>0&&candidate.imageSpan.bytes<=8388608); for(const a of Object.values(candidate.artifacts))checked(a); for(const a of Object.values(candidate.sources))checked(a); checked(candidate.spec);checked(candidate.harness);checked(preflight.harness); assert.deepEqual(candidate.frozenBefore,candidate.frozenAfter); assert.deepEqual(frozenSnapshot(process.cwd()),candidate.frozenAfter); for(const a of [preflight.fixtures.rng,preflight.fixtures.block,preflight.fixtures.journal,...preflight.firmware,...Object.values(preflight.bases),preflight.loader,preflight.loader.log])checked(a); assert.equal(preflight.loader.imageSha256,candidate.artifacts.image.sha256); const fdtget=(...args)=>{const result=spawnSync('fdtget',args,{encoding:'utf8'});assert.equal(result.status,0,result.stderr);return result.stdout.trim();}; const seenBoots=new Set();let inheritedGates; const expected=new Set(FEATURE_PROFILES.flatMap(p=>[0,1,2].map(c=>p.id+':'+c))),seen=new Set(),profiles=[]; for(const row of life.profiles){ assert.equal(row.status,'GUEST_RETURNED');assert.equal(row.allOwnedGuestsStopped,true); const p=row.profile,id=p.baseProfile+':'+p.caseId;assert.ok(expected.has(id)&&!seen.has(id));seen.add(id); const expectedProfile=FEATURE_PROFILES.find(x=>x.id===p.baseProfile);assert.ok(expectedProfile); for(const key of ['route','memoryMiB','cpuCount'])assert.equal(p[key],expectedProfile[key]); const persisted=read(join(matrixPath,p.id,'result.json'));assert.deepEqual(persisted,row); assert.equal(row.storage.caseId,p.caseId); assert.equal(checked(row.storage.fault).toString(),faultConfiguration(p.caseId)); assert.deepEqual(row.storage.before,preflight.fixtures.block); checked(row.dtb); assert.ok(!seenBoots.has(row.bootId));seenBoots.add(row.bootId); const command=read(join(matrixPath,p.id,'qemu-command.json')),argv=command.argv; assert.equal(command.executable,'qemu-system-aarch64');assert.deepEqual(command.profile,p);assert.equal(command.bootId,row.bootId); assert.equal(argv[argv.indexOf('-smp')+1],String(p.cpuCount));assert.equal(argv[argv.indexOf('-m')+1],String(p.memoryMiB)); if(p.route==='direct'){ assert.equal(argv[argv.indexOf('-kernel')+1],candidate.artifacts.image.path);assert.ok(!argv.some(a=>a.startsWith('if=pflash'))); }else{assert.ok(!argv.includes('-kernel')&&argv.includes('-boot')&&argv.some(a=>a.startsWith('if=pflash')));} assert.ok(argv.some(a=>a.includes('id=k1405block')&&a.includes('file=blkdebug:')&&a.includes('werror=report')&&!a.includes('readonly=on'))); const dtb=row.dtb.path; assert.equal(Number(fdtget('-t','u',dtb,'/chosen','turkos,feature-experiment')),2150); assert.equal(Number(fdtget('-t','u',dtb,'/chosen','turkos,shutdown-flush-case')),p.caseId); assert.equal(Number(fdtget('-t','u',dtb,'/chosen','turkos,policy-probe-mode')),0); assert.equal(fdtget('-l',dtb,'/cpus').split('\n').filter(n=>/^cpu@/.test(n)).length,p.cpuCount); const memory=fdtget('-t','x',dtb,'/memory@40000000','reg').split(/\s+/).map(h=>BigInt('0x'+h)); assert.equal((memory[2]<<32n)|memory[3],BigInt(p.memoryMiB)*1048576n); assert.equal(fdtget('-t','x',dtb,'/chosen','turkos,boot-id').split(/\s+/).map(h=>h.padStart(8,'0')).join(''),row.bootId); inheritedGates??=row.gates;assert.deepEqual(row.gates,inheritedGates); const stages=row.experimentStages.map(s=>{ assert.equal(s.captures.length,1);assert.equal(s.captures[0].symbol,'OS_K2150_EVIDENCE'); for(const key of ['symbol','address','size'])assert.equal(s.captures[0][key],key==='symbol'?preflight.captures[0].name:preflight.captures[0][key]); const bytes=checked(s.captures[0]); const dmaPages=s.dmaPages.map((page,index)=>{ assert.equal(page.index,index);assert.ok(page.address>=0x40000000&&page.address+4096<=0x40000000+p.memoryMiB*1024*1024); return {...page,bytes:checked(page)}; });return {stage:s.stage,bytes,dmaPages}; }); assert.equal(row.final.length,1); const result=checkStorageComponent({caseId:p.caseId,stages,final:checked(row.final[0]),serial:checked(row.serial).toString(), before:checked(row.storage.before),after:checked(row.storage.after)}); profiles.push({profile:p,result,source:artifact(join(matrixPath,p.id,'result.json'))}); } assert.deepEqual(seen,expected); const report={status:'NATIVE_STORAGE_PHYSICAL_COMPONENT_PASSED',guestAccepted:false,productAccepted:false, scope:'All eighteen hardware/boot profiles, each with completed, metadata EIO and journal timeout cases. Actual DMA descriptors, available/used entries, request buffers and final disposable disks were checked. This component does not establish the complete EL0 shutdown flow or K2150 milestone admission.', candidate:artifact(candidatePath),lifecycle:artifact(join(matrixPath,'scoped-lifecycle.json')),preflight:artifact(join(matrixPath,'preflight.json')), checker:artifact('scripts/os-acceptance/features/k2150-native-check.mjs'),profiles}; const reportPath=join(directory,'report.json');writeFileSync(reportPath,JSON.stringify(report,null,2)+'\n'); console.log(JSON.stringify({status:report.status,report:reportPath,profiles:18,storageCases:54})); }catch(error){ const path=join(directory,'report.json');writeFileSync(path,JSON.stringify({status:'NATIVE_STORAGE_PHYSICAL_COMPONENT_FAILED',guestAccepted:false,productAccepted:false,error:error.stack},null,2)+'\n'); console.error(path);throw error; }