import assert from'node:assert/strict';import{inspectPhysicalCheckpoint}from'./physical-checkpoint-proof.mjs';import{inspectMetricsSnapshots,metricsPhysicalPlan}from'./cpu-watchdog-metrics-proof.mjs';import{progressPhysicalPlan}from'./cpu-watchdog-progress-proof.mjs';import{publicationPhysicalPlan}from'./cpu-watchdog-publication-proof.mjs';import{frameServicePhysicalPlan}from'./cpu-watchdog-frame-proof.mjs';import{asidPhysicalPlan}from'./asid-barrier-proof.mjs';import{tlbPhysicalPlan}from'./tlb-shootdown-proof.mjs';import{affinityPhysicalPlan}from'./cpu-affinity-proof.mjs';import{migrationPhysicalPlan}from'./thread-migration-proof.mjs';import{remoteWakePhysicalPlan}from'./remote-wake-proof.mjs';import{metricsGlobals}from'./lock-metrics-capture.mjs';import{watchdogGlobals}from'./cpu-watchdog-capture.mjs';import{inspectWatchdogInputs}from'./cpu-watchdog-inputs-proof.mjs';import{inspectWatchdogModel}from'./cpu-watchdog-model-proof.mjs'; export{inspectWatchdogInputs}from'./cpu-watchdog-inputs-proof.mjs';const u=(b,p)=>b.readBigUInt64LE(p),W=b=>Array.from({length:b.length/8},(_,i)=>u(b,i*8)),zero=b=>assert.ok(b.every(v=>v===0)); export function watchdogPhysicalPlan(data,symbols){const e=W(data.OS_K2095_EVIDENCE);return[...watchdogGlobals.map(([name,symbol])=>({name,symbol,val:symbols[symbol].address,size:symbols[symbol].size})),{name:'watchdogSupervisor',val:Number(e[10]),size:Number(e[11])},...metricsPhysicalPlan(data,symbols).slice(metricsGlobals.length+1)];} export function inspectWatchdogSnapshots(base,migration,affinity,tlb,asid,frames,publication,progress,metrics,snapshots,memoryMiB,bootId,symbols,compiled,bootDtb,cpus){ assert.equal(snapshots.length,6);const inherited=inspectMetricsSnapshots(base,migration,affinity,tlb,asid,frames,publication,progress,metrics,memoryMiB,bootId,symbols,compiled,bootDtb,cpus),input=inspectWatchdogInputs(compiled,symbols),original=base[3],prior=metrics[5],b=W(original.OS_K2045_EVIDENCE);const validSp=(sp,cpu)=>assert.ok(sp%16n===0n&&sp>=b[32+cpu]+16n&&sp=3?1:0],[20,index===5?3:0],[21,index===5?4:0],[22,index===5?1:0],[23,index===5?3:0],[24,index===5?1:0],[25,index===5?2:0]])expected[i]=BigInt(v);assert.deepEqual(e,expected); for(const name of['authority','lifecycle','shared','dtb','kernelRoot','kernelL2','deviceL2','gicL3',...Object.keys(prior).filter(n=>n.startsWith('OS_')&&!['OS_K2045_COMMANDS','OS_K2045_PRIMARY_STACK'].includes(n)),...Object.keys(prior).filter(n=>n.startsWith('thread')||n.startsWith('reservation')||n.startsWith('kernelL3-')||n.startsWith('irq')||n.startsWith('mailbox')||n.startsWith('framePage'))])assert.deepEqual(data[name],prior[name],name+' retains custody during absent response'); assert.deepEqual(W(data.OS_K2095_ACKS),state.commands.map(BigInt)); for(let cpu=1;cpu<=3;cpu++){ const n=cpu-1,graph=W(data.OS_K2095_GRAPH.subarray(n*128,cpu*128));assert.deepEqual(graph.slice(0,4),[BigInt(state.commands[n]),BigInt(cpu),b[6],0x3c0n]);validSp(graph[4],cpu);assert.ok(graph[5]>=state.issued);if(index)assert.ok(graph[5]>=u(snapshots[index-1].OS_K2095_GRAPH,n*128+40));assert.deepEqual(graph.slice(6),[BigInt(index>=3&&cpu<3?1:0),0n,0n,0n,0n,0n,0n,0n,0n,0n]); if(index===2||cpu===3&&index>0&&index<4||cpu<3&&index===4)assert.deepEqual(data.OS_K2095_GRAPH.subarray(n*128,cpu*128),snapshots[index-1].OS_K2095_GRAPH.subarray(n*128,cpu*128),'no fabricated response from waiting CPU'); if(index>0&&cpu<3||index>=4)assert.ok(graph[5]>=state.completed[n]);if(index>=3&&cpu<3)assert.ok(graph[5]>=state.polled);if(index===5)assert.ok(graph[5]>=state.completed[2]); const command=index===0?109:index<=2?110:index<=4?(cpu<3?111:110):112;assert.equal(u(data.OS_K2045_COMMANDS,n*128),BigInt(command));zero(data.OS_K2045_COMMANDS.subarray(n*128+8,cpu*128)); assert.deepEqual(data['local'+n],prior['local'+n]);const at=Number(u(prior.OS_K2060_GRAPH,n*512)-b[33+n]);assert.deepEqual(data['local'+n],data['executive'+n].subarray(at,at+6144));assert.equal(u(data['executive'+n],0),0x2045455845434c4fn^BigInt(n));assert.equal(u(data['executive'+n],131064),0x2045455845434849n^BigInt(n)); assert.ok(state.completed[n]>=u(snapshots[0].OS_K2095_GRAPH,n*128+40));if(cpu<3)assert.ok(state.completed[2]>=u(snapshots[3].OS_K2095_GRAPH,n*128+40)); } for(const n of['OS_K2095_MODEL_LAYOUT','OS_K2095_SLOT_LAYOUT'])assert.deepEqual(data[n],compiled[n]); } return{...inherited,physicalCheckpoints:78,watchdogCheckpoints:6,watchdogPrivateSupervisorViews:6,watchdogTargets:3,watchdogRealResponses:3,watchdogDelayedCpu:3,watchdogTimedOutCpuMask:4,watchdogTimedOutCpus:1,watchdogCloseRefusals:1,watchdogOtherCpuHeartbeats:2,watchdogReceiversRetired:3,watchdogLiveReceiptViews:3,watchdogLiveRequestRetainedAcrossDeadline:true,watchdogMissingResponseCannotClose:true,watchdogDegradedStateExplicit:true,watchdogTimeoutHistoryRetained:true,watchdogAuthorityUnchanged:true,watchdogNormalTeardownAfterRealResponses:true,boundedSecondaryDelayAccepted:true,permanentCpuLossRecoveryAccepted:false,watchdogCompiledCodeBytes:input.watchdogCompiledCodeBytes,watchdogCompiledModelBytes:input.watchdogCompiledModelBytes,watchdogMetadataPackedWithoutOverlap:true,productAccepted:false}; } export function inspectWatchdogEvidence(p){const{captures,migration,affinity,tlb,asid,frameService,publication,progress,metrics,watchdog,symbols,qmp,timeline,wholeRsp,readArtifact}=p;assert.equal(captures.length,9);assert.equal(migration.length,5);assert.equal(affinity.length,6);assert.equal(tlb.length,9);assert.equal(asid.length,11);assert.equal(frameService.length,12);assert.equal(publication.length,8);assert.equal(progress.length,6);assert.equal(metrics.length,6);assert.equal(watchdog.length,6);const base=[],mig=[],aff=[],shoot=[],tags=[],frames=[],pub=[],workers=[],measurements=[],responses=[];let lastQmp=-1,lastRsp=-1;for(const c of[...captures.slice(0,4),...migration,...affinity,...tlb,...asid,...frameService,...publication,...progress,...metrics,...watchdog,...captures.slice(4)]){const data=Object.fromEntries(Object.entries(c.dumps).map(([n,a])=>[n,readArtifact(a)]));let target,expected,gate;if(c.stage>=110){target=responses;expected=watchdogPhysicalPlan(data,symbols);gate='OS_K2095_CAPTURE_GATE'}else if(c.stage>=100){target=measurements;expected=metricsPhysicalPlan(data,symbols);gate='OS_K2090_CAPTURE_GATE'}else if(c.stage>=90){target=workers;expected=progressPhysicalPlan(data,symbols);gate='OS_K2085_CAPTURE_GATE'}else if(c.stage>=80){target=pub;expected=publicationPhysicalPlan(data,symbols);gate='OS_K2080_CAPTURE_GATE'}else if(c.stage>=60){target=frames;expected=frameServicePhysicalPlan(data,symbols);gate='OS_K2075_CAPTURE_GATE'}else if(c.stage>=40){target=tags;expected=asidPhysicalPlan(data,symbols);gate='OS_K2070_CAPTURE_GATE'}else if(c.stage>=30){target=shoot;expected=tlbPhysicalPlan(data,symbols);gate='OS_K2065_CAPTURE_GATE'}else if(c.stage>=20){target=aff;expected=affinityPhysicalPlan(data,symbols);gate='OS_K2060_CAPTURE_GATE'}else if(c.stage>=10){target=mig;expected=migrationPhysicalPlan(data,symbols);gate='OS_K2055_CAPTURE_GATE'}else{target=base;expected=remoteWakePhysicalPlan(data,symbols);gate='OS_K2045_CAPTURE_GATE'}const stage=20950+c.stage,snapshot=inspectPhysicalCheckpoint({capture:c,expected,stage,qmp,timeline,wholeRsp,readArtifact,gateAddress:symbols[gate].address}),steps=timeline.filter(r=>r.stage===stage),start=qmp.findIndex(r=>r.direction==='tx'&&r.message.id===steps[0].id),end=qmp.findIndex(r=>r.direction==='rx'&&r.message.id===steps.at(-1).id);assert.ok(start>lastQmp);lastQmp=end;const rsp=c.rsp.filter(r=>r.id!==null),rs=wholeRsp.findIndex(r=>r.id===rsp[0].id&&r.direction==='tx'),re=wholeRsp.findIndex(r=>r.id===rsp.at(-1).id&&r.direction==='rx');assert.ok(rs>lastRsp);lastRsp=re;target.push(snapshot);}return inspectWatchdogSnapshots(base,mig,aff,shoot,tags,frames,pub,workers,measurements,responses,p.memoryMiB,p.bootId,symbols,p.compiled,p.bootDtb,p.cpus);}