import assert from 'node:assert/strict'; import {spawnSync} from 'node:child_process'; // DTB register regions are device windows, not allocator pages. Validate the // exact named device region instead of imposing a 4 KiB page-alignment rule. export function checkNetworkMmio(fixturePath, address) { assert.ok(Number.isSafeInteger(address) && address > 0 && address % 4 === 0); const node = '/virtio_mmio@' + address.toString(16); const property = (type, name) => { const r = spawnSync('fdtget', ['-t', type, fixturePath, node, name], {encoding: 'utf8'}); assert.equal(r.status, 0, `DTB ${node} ${name}`); return r.stdout.trim(); }; assert.equal(property('s', 'compatible'), 'virtio,mmio'); const reg = property('x', 'reg').split(/\s+/).map(n => Number.parseInt(n, 16)); assert.equal(reg.length, 4); assert.equal(reg[0] * 2 ** 32 + reg[1], address); assert.ok(reg[2] * 2 ** 32 + reg[3] >= 0x106, 'MAC register lies inside device window'); return {node, address, bytes: reg[2] * 2 ** 32 + reg[3]}; }