// Deliberately narrow verifier for the actual QEMU virt fixtures. dtc decodes // the binary; guest-reported INTIDs never define their own expected values. import assert from 'node:assert/strict'; import {spawnSync} from 'node:child_process'; export function irqBindingsFromDtb(path){ const r=spawnSync('dtc',['-I','dtb','-O','dts',path],{encoding:'utf8',timeout:30000});assert.ifError(r.error);assert.equal(r.status,0,r.stderr); const text=r.stdout,value=(name,body)=>{const m=body.match(new RegExp('\\n\\t\\t'+name+' = <([^>]+)>;'));assert.ok(m,name);return m[1].split(/\s+/).map(Number);}; const parent=Number(text.match(/\n\tinterrupt-parent = <(0x[0-9a-f]+)>;/)?.[1]);assert.ok(Number.isInteger(parent)&&parent>0); const controllers=[...text.matchAll(/\n\tintc@[^\n]+ \{(.*?)\n\t\};/gs)];assert.equal(controllers.length,1);const g=controllers[0][1]; assert.ok(g.includes('compatible = "arm,gic-v3";'));assert.deepEqual(value('#interrupt-cells',g),[3]);assert.deepEqual(value('phandle',g),[parent]); const gr=value('reg',g);assert.equal(gr.length,8);assert.equal(gr[0],0);assert.equal(gr[2],0);assert.equal(gr[3],65536); const slots=[]; for(const m of text.matchAll(/\n\tvirtio_mmio@[^\n]+ \{([^{}]*)\n\t\};/g)){ const b=m[1];assert.ok(b.includes('compatible = "virtio,mmio";'));assert.ok(!/interrupt-parent|interrupt-map|iommus|status =/.test(b)); const reg=value('reg',b),irq=value('interrupts',b);assert.equal(reg.length,4);assert.equal(irq.length,3);assert.equal(reg[0],0);assert.equal(reg[2],0);assert.equal(reg[3],512); assert.equal(irq[0],0);assert.ok(irq[1]>=0&&irq[1]<=987&&[1,4].includes(irq[2]));slots.push({base:reg[1],bytes:reg[3],intid:irq[1]+32,trigger:irq[2]}); } assert.equal(slots.length,32);assert.equal(new Set(slots.map(s=>s.base)).size,32);assert.equal(new Set(slots.map(s=>s.intid)).size,32); return {distributor:gr[1],parent,slots}; }