import assert from'node:assert/strict';import{readFileSync}from'node:fs';const text=p=>readFileSync(p,'utf8'); export const metricsLayoutFields=[ 'size_of::()',...['issuer','epoch','generation','cpu'].map(n=>`offset_of!(Binding,${n})`), 'size_of::()',...['binding','sequence','contended','polls','requested','acquired','released'].map(n=>`offset_of!(Sample,${n})`), 'size_of::()',...['count','minimum','maximum','total'].map(n=>`offset_of!(Distribution,${n})`), 'size_of::()',...['wait','hold'].map(n=>`offset_of!(Pair,${n})`), 'size_of::()',...['root','frequency','bindings','sequences','last_release','groups'].map(n=>`offset_of!(Meter,${n})`) ]; export function metricsRuntimeSource(){return text('os-lock-metrics/src/metrics.rs')+`\npub const fn os_k2090_layout()->[u64;${metricsLayoutFields.length}]{use core::mem::{size_of,offset_of};[${metricsLayoutFields.map(s=>`(${s})as u64`).join(',')}] }\n`;} export function metricsProgressGuestSource(base){const from='if cmd==3{return Ok(())}';assert.equal(base.split(from).length,2);return base.replace(from,'if cmd==99{return Ok(())}');} export function metricsBackendSource(base){return base+`\n// Read-only telemetry of the existing ownership word. This neither loans State\n// nor changes custody; the existing handoff and with_state rules remain intact.\nimpl Shared<'_>{pub fn os_k2090_owner(&self)->u64{self.owner.load(Ordering::Acquire)}}\n`;} export function metricsProbeSource(base){for(const[a,b]of[ ['#[path="k2055-thread-migration-full-backend.rs"]mod backend;','#[path="k2090-lock-metrics-backend.rs"]mod backend;'], ['#[path="k2085-smp-progress-guest.rs"]mod progress;','#[path="k2090-smp-progress-guest.rs"]mod progress;\n#[path="k2090-lock-metrics-guest.rs"]mod metrics;'], ['progress::cycle(&q,shared,c)?;','progress::cycle(&q,shared,c)?;metrics::cycle(&q,shared,c)?;'], ['progress::drive(&shared)?;','progress::drive(&shared)?;metrics::drive(&shared)?;'] ]){assert.equal(base.split(a).length,2,a);base=base.replace(a,b);}return base;} export function metricsGuestSource(){return text('scripts/os-acceptance/k2090-lock-metrics-guest.rs')+`\n#[unsafe(no_mangle)]pub static OS_K2090_MODEL_LAYOUT:[u64;${metricsLayoutFields.length}]=lm::os_k2090_layout();\n`;} export const metricsMainReplacements=[['#[path="k2085-smp-progress.rs"]\nmod k2085_smp_progress;','#[path="k2090-lock-metrics.rs"]\nmod k2090_lock_metrics;'],['mode>208 || (144..=207)','mode>209 || (144..=208)'],['os_k1100_product_probe_mode(boot)?==208','os_k1100_product_probe_mode(boot)?==209'],['k2085_smp_progress::run(boot,tables,&mut memory.allocator)?','k2090_lock_metrics::run(boot,tables,&mut memory.allocator)?'],['write_line("TURKOS/OS/K2085: PASS")','write_line("TURKOS/OS/K2090: PASS")']];