| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- // Boot plans & Multi-Profile Test Queue (ICT + RMT + AMT + MT full profile library & batch runner)
- (() => {
- const $ = id => document.getElementById(id);
- const esc = v => String(v ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
- const stages = [
- ['uip1','ICT Stage 1','自动应用 ICT Stage 1 内存/电压/时序/RMT 参数并发送 exit 继续'],
- ['amt','AMT 测试菜单','按 AMT 页配置执行 tp 测试序列或发送 exit 跳过'],
- ['uip2','ICT Stage 2','自动应用 ICT Stage 2 参数并发送 exit 进入 DXE / UEFI'],
- ['uefi','UEFI 阶段','等待或继续进入 MT 内存测试'],
- ['mt','MT 内存测试','通过标准 PXE 自动运行 118.efi (mt86.cfg) 或在 Shell 启动'],
- ];
- document.querySelector('[data-page="testing"]').insertAdjacentHTML('afterend','<button class="workspace-tab" role="tab" data-page="plan">5. Profile 库与多计划队列</button>');
- document.querySelector('.phase-actions-panel').insertAdjacentHTML('beforebegin',`
- <section class="firmware-panel task-batch-panel" data-pages="plan" aria-labelledby="task-batch-title">
- <div class="panel-heading">
- <div>
- <h3 id="task-batch-title">测试 Profile 配置库 & 多计划循环测试队列</h3>
- <p>标准三步使用流程:<strong>① 在第 2/3/4 页配置好 ICT、AMT、MT 详细参数并保存</strong> → <strong>② 在下方将当前完整配置保存为一个命名 Profile</strong> → <strong>③ 组合多个 Profile 与各自重复次数,一键启动多计划循环测试队列</strong>(每轮日志与 JSON 报告独立落盘)。</p>
- </div>
- <span class="badge" id="task-batch-state-badge">空闲</span>
- </div>
- <div style="background:#f8fafc;border:1px solid #dbe4ee;border-radius:8px;padding:12px;margin-bottom:14px">
- <div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;margin-bottom:8px">
- <strong>第一步:当前工位已保存的 ICT / AMT / MT 详细配置快照(将被打包进新 Profile)</strong>
- <div style="display:flex;gap:6px">
- <button type="button" class="btn btn-quiet btn-xs" data-plan-nav="uip">去改 2. ICT 参数</button>
- <button type="button" class="btn btn-quiet btn-xs" data-plan-nav="amt">去改 3. AMT 参数</button>
- <button type="button" class="btn btn-quiet btn-xs" data-plan-nav="testing">去改 4. PXE/MT 参数</button>
- </div>
- </div>
- <div id="tb-current-config-preview" style="display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:8px;font-size:13px"></div>
- <div class="connection-form-grid" style="margin-top:10px">
- <label>保存为 Profile 名称<input id="tb-profile-name" value="Profile-1 (ICT+AMT+MT)" placeholder="如:低温5600-快测 / 高温VDD1100" spellcheck="false"></label>
- <label>默认循环次数 (Repeat)<input id="tb-profile-repeat" type="number" min="1" max="100" value="1"></label>
- <label>AMT 快捷模式覆盖<select id="tb-profile-amt-mode">
- <option value="current">沿用第 3 页已保存的 AMT 详细配置</option>
- <option value="fast24">24 项算法极速全覆盖 (tp end_step=0 · 短地址快测)</option>
- <option value="tp0">仅跑 AMT 第 1 项 (tp 0,1,0,0,0,255 · 极速验证)</option>
- <option value="all24">跑 AMT 全量 24 项完整长度</option>
- <option value="skip">本 Profile 跳过 AMT (发送 exit)</option>
- </select></label>
- <label>MT (118.efi) 快捷覆盖<select id="tb-profile-mt-mode">
- <option value="current">沿用第 4 页已保存的 PXE/MT 详细配置</option>
- <option value="fast64m">短地址极速验证 (TSTLIST=0..25 · 仅测 64MB 区间)</option>
- <option value="test0_64m">仅测 Test 0 + 64MB 短地址 (10秒极速)</option>
- <option value="test0_all">仅测 Test 0 (全内存)</option>
- <option value="skip">本 Profile 跳过 MT (到 UEFI Shell 即完成)</option>
- </select></label>
- </div>
- <div class="plan-checks" style="margin-top:8px">
- <label class="check-label"><input id="tb-profile-rmt" type="checkbox" checked>在本 Profile 中开启 ICT RMT 裕量扫描 (<code>rmt enable</code>)</label>
- </div>
- <div class="form-actions" style="margin-top:8px">
- <button type="button" class="btn btn-primary btn-sm" id="btn-tb-save-library">保存到后端 Profile 库</button>
- <button type="button" class="btn btn-secondary btn-sm" id="btn-tb-add-profile">直接加入右侧待执行测试队列</button>
- <span class="field-note" id="tb-library-status"></span>
- </div>
- </div>
- <div class="plan-layout">
- <div class="plan-editor">
- <div class="subpanel-title">
- <h4>第二步:工位已保存的 Profile 库(可查看详细 ICT/AMT/MT 参数、加载回编辑器或加入队列)</h4>
- <span class="badge" id="tb-library-count">0 个已存 Profile</span>
- </div>
- <div id="tb-saved-profiles-list" style="display:grid;gap:8px;margin-bottom:14px"></div>
- <div class="subpanel-title" style="border-top:1px solid #e2e8f0;padding-top:10px">
- <h4>第三步:待执行的多计划组合队列(按顺序依次执行各 Profile 指定次数)</h4>
- <span class="field-note" id="tb-draft-summary">待下发队列:0 组 Profile</span>
- </div>
- <div id="tb-draft-list" style="margin-top:8px;display:grid;gap:6px"></div>
- <div class="plan-checks" style="margin-top:8px">
- <label class="check-label"><input id="tb-stop-on-fail" type="checkbox" checked>任一轮次出现 FAIL / BLOCK 时立即停止后续队列</label>
- </div>
- <div class="form-actions" style="margin-top:8px">
- <button type="button" class="btn btn-quiet btn-sm" id="btn-tb-clear-draft">清空待下发队列</button>
- </div>
- </div>
- <aside class="plan-live-card">
- <div class="subpanel-title"><h3>多计划队列运行控制</h3><span class="badge" id="tb-live-progress">0 / 0 轮</span></div>
- <strong id="tb-live-title" class="execution-stage">尚无活动批次队列</strong>
- <p id="tb-live-detail" class="execution-reason">从左侧 Profile 库添加组合(如 Profile-A × 2 次 + Profile-B × 3 次)后,点击下方按钮立即自动按序重启执行。</p>
- <div class="plan-launch-actions" style="display:grid;gap:6px">
- <button type="button" class="btn btn-primary" id="btn-tb-submit-start">后端托管队列 · 提交并立即重启执行</button>
- <button type="button" class="btn btn-secondary" id="btn-tb-client-queue-start">前端自维护队列 · 逐项监听 complete 自动推进</button>
- </div>
- <div class="form-actions">
- <button type="button" class="btn btn-secondary" id="btn-tb-pause">暂停队列</button>
- <button type="button" class="btn btn-primary" id="btn-tb-resume">继续队列</button>
- <button type="button" class="btn btn-quiet" id="btn-tb-stop">停止队列</button>
- </div>
- </aside>
- </div>
- <div style="margin-top:14px">
- <h4 style="margin:6px 0">各轮测试执行进度与独立落盘归档记录</h4>
- <div class="events-container"><table class="events-table"><thead><tr><th>轮次编号</th><th>执行 Profile</th><th>循环进度</th><th>启动 ID</th><th>状态 / 结论</th><th>独立归档路径 (sol.raw / sol.clean.log / summary.json)</th></tr></thead><tbody id="tb-runs-tbody"><tr><td colspan="6">尚无批次运行记录</td></tr></tbody></table></div>
- </div>
- </section>
- <section class="firmware-panel startup-plan-panel" data-pages="plan" aria-labelledby="plan-title" style="margin-top:16px">
- <div class="panel-heading"><div><h3 id="plan-title">单次启动计划控制(按当前激活配置单轮运行)</h3><p>配置单次开机各阶段(ICT Stage 1 / AMT / ICT Stage 2 / UEFI / MT)自动或手动执行方式。</p></div><span class="badge" id="boot-plan-save-state">读取中</span></div>
- <div class="plan-layout"><div class="plan-editor">
- <label class="plan-preset-label">执行模式<select id="boot-plan-preset"><option value="auto">全自动执行</option><option value="custom">按阶段自定义</option><option value="manual">全手动(仅观察串口)</option></select></label><p class="field-note hidden" id="boot-plan-preset-note"></p>
- <div class="plan-stage-table">${stages.map(([key,name,note]) => `<div class="plan-stage-row"><div><strong>${name}</strong><small>${note}</small></div><select data-plan-stage="${key}" aria-label="${name}执行方式"><option value="auto">自动执行</option><option value="manual">手动操作</option></select></div>`).join('')}</div>
- <div class="plan-checks"><label class="check-label"><input id="boot-plan-mt-enabled" type="checkbox">到达 UEFI 后继续执行 MT 内存测试</label><label class="check-label"><input id="boot-plan-use-in-runs" type="checkbox">高温测试轮次默认使用此启动计划</label></div>
- <div class="form-actions"><button class="btn btn-primary" id="btn-save-boot-plan">保存启动计划</button><button class="btn btn-quiet" id="btn-reload-boot-plan">重置</button><span class="field-note" id="boot-plan-edit-note"></span></div>
- </div><aside class="plan-live-card"><div class="subpanel-title"><h3>单轮运行控制</h3><span class="badge" id="boot-execution-state">未开始</span></div><strong id="boot-execution-stage" class="execution-stage">等待启动</strong><p id="boot-execution-reason" class="execution-reason"></p><div id="boot-execution-identity" class="execution-identifiers"></div><div class="plan-launch-actions"><button class="btn btn-primary" id="btn-restart-boot-plan">重启并单轮执行</button><button class="btn btn-secondary" id="btn-start-boot-plan">从当前阶段开始</button></div><div class="form-actions"><button class="btn btn-secondary" id="btn-pause-boot-plan">暂停 / 人工接管</button><button class="btn btn-primary" id="btn-resume-boot-plan">继续执行</button><button class="btn btn-quiet" id="btn-stop-boot-plan">停止计划</button></div><p id="boot-plan-launch-note" class="field-note"></p><button class="inline-link hidden" id="btn-plan-open-input">跳转当前阶段</button></aside></div>
- <div id="boot-plan-dependencies" class="plan-dependencies"></div>
- <details class="observation-details"><summary>单轮计划执行记录 <span id="boot-execution-count">0 条</span></summary><ol id="boot-execution-history"><li>无记录</li></ol></details>
- </section>`);
- let api, formStation = '', tbSeq = 1;
- const drafts = new Map(), tbDrafts = new Map();
- const getTbDraft = () => {
- const id = api ? api.stationId() : 'S1';
- if (!tbDrafts.has(id)) tbDrafts.set(id, []);
- return tbDrafts.get(id);
- };
- const clone = x => JSON.parse(JSON.stringify(x));
- const defaults = () => ({preset:'manual',stages:Object.fromEntries(stages.map(([key]) => [key,'manual'])),mt_enabled:false,use_in_runs:false});
- const control = () => window.stlFirmware.snapshot(api.stationId());
- const current = () => drafts.get(api.stationId());
- const stateNames = {idle:'尚未开始',queued:'已排队',running:'自动观察 / 执行',waiting_boot:'等待新启动',waiting_user:'等待人工操作',paused:'已暂停 / 人工接管',completed:'已完成',blocked:'流程被阻止',failed:'执行失败',stopped:'自动执行已停止'};
- const stageNames = Object.fromEntries(stages.map(([key,name]) => [key,name]));
- function enable(id, yes, reason='') { const b=$(id); if(!b)return; b.disabled=!yes || b.dataset.busy==='1'; b.title=yes?'':reason; }
- async function awaitCommand(method,args,name) {
- let item=await api.command(method,args,name); const deadline=Date.now()+20000;
- while (!['succeeded','failed','interrupted'].includes(item.state)) {
- if(Date.now()>deadline) throw new Error('操作仍在后端队列中,请查看操作队列;没有重新发送。');
- await new Promise(resolve=>setTimeout(resolve,180));
- try { item=await api.callApi('GetQueueItem',{command_id:item.command_id}); }
- catch(error) { if(!/NOT_FOUND|not found/i.test(error.message))throw error; }
- }
- if(item.state!=='succeeded')throw new Error(item.detail || item.error_code || '操作未完成');
- return item;
- }
- function summarizeProfile(p) {
- const uipOvs = (p.uip_overrides || []).filter(x => x.mode === 'override');
- const uipRaws = p.uip_raw_commands || [];
- const ictText = uipOvs.map(x => `${x.id}=${x.value}`).concat(uipRaws).join(', ') || '全部默认';
- const amt = p.amt || p.amt_settings || {};
- const runAmt = p.run_amt !== undefined ? p.run_amt : amt.action === 'run';
- const amtOvs = (amt.overrides || []).map(x => `${x.name} ${x.value}`.trim()).join('; ');
- const amtText = !runAmt ? '跳过 (exit)' : `${amt.test_command || 'amemdiag 1'}${amtOvs ? ' · ' + amtOvs : ' · 默认全量'}`;
- const mt = p.mt || p.mt_selection || {};
- const runMt = p.run_mt !== undefined ? p.run_mt : true;
- const mtRange = mt.memory_range === 'custom' ? `${mt.addr_lim_lo || '0x0'}~${mt.addr_lim_hi || ''}` : '全内存';
- const mtText = !runMt ? '跳过' : `TSTLIST=${mt.tstlist || (mt.only_tests ? mt.only_tests.join(',') : '0..25')} · ${mtRange}`;
- return { ictText, amtText, mtText, uipCount: uipOvs.length + uipRaws.length };
- }
- function fill() {
- const d=current();if(!d)return;
- $('boot-plan-preset').value=d.plan.preset;
- for(const select of document.querySelectorAll('[data-plan-stage]'))select.value=d.plan.stages[select.dataset.planStage] || 'manual';
- $('boot-plan-mt-enabled').checked=!!d.plan.mt_enabled;
- $('boot-plan-use-in-runs').checked=!!d.plan.use_in_runs;
- }
- function edit() {
- const d=current();if(!d)return;
- d.plan={preset:$('boot-plan-preset').value,stages:Object.fromEntries([...document.querySelectorAll('[data-plan-stage]')].map(s=>[s.dataset.planStage,s.value])),mt_enabled:$('boot-plan-mt-enabled').checked,use_in_runs:$('boot-plan-use-in-runs').checked};
- d.dirty=true;render();
- }
- function render() {
- if(!api)return;
- const c=control();if(!c.boot_plan)return;
- const id=api.stationId(), saved=JSON.stringify(c.boot_plan);
- if(!drafts.has(id))drafts.set(id,{plan:{...defaults(),...clone(c.boot_plan)},saved,dirty:false});
- const d=current();
- if(!d.dirty && d.saved!==saved){d.plan={...defaults(),...clone(c.boot_plan)};d.saved=saved;formStation='';}
- if(formStation!==id){formStation=id;fill();}
- const custom=d.plan.preset==='custom';
- for(const select of document.querySelectorAll('[data-plan-stage]'))select.disabled=!custom || ['uefi','mt'].includes(select.dataset.planStage)&&!d.plan.mt_enabled;
- $('boot-plan-preset-note').textContent={auto:'自动执行每个可操作节点;测试开关和参数取各参数页已保存的设置。',custom:'只在选择“等待我操作”的节点停下,其余节点按已保存参数自动执行。',manual:'各输入节点由你手动操作,后端持续观察并保存输出。'}[d.plan.preset] || '';
- $('boot-plan-save-state').textContent=d.dirty?'有未保存修改':'已保存配置';
- $('boot-plan-edit-note').textContent=d.dirty?'此处修改尚未保存;执行仍以已保存配置为准。':'保存不会立即写固件;执行时复制一份配置快照。';
- const x=c.boot_execution || {}, state=x.state || 'idle', live=['running','waiting_boot','waiting_user','paused'].includes(state);
- $('boot-execution-state').textContent=stateNames[state] || state;
- $('boot-execution-state').classList.toggle('error',['failed','blocked'].includes(state));
- $('boot-execution-stage').textContent=stageNames[x.current_stage] || x.current_stage || '等待开始计划';
- $('boot-execution-reason').textContent=x.waiting_reason || x.error || (state==='completed'?'本次启动计划已结束,后端继续采集状态。':state==='paused'?'可在参数页或控制台手动操作,完成后点“继续计划”。':state==='running'?'后端按实际固件输出推进,不需要保持页面打开。':'保存好配置后,选择重启执行或从当前节点开始。');
- $('boot-execution-identity').textContent=[x.id&&'执行 '+x.id,c.firmware?.boot_id&&'启动 '+c.firmware.boot_id].filter(Boolean).join(' · ');
- const unsaved=[d.dirty&&'启动计划',window.stlFirmware.isDirty?.()&&'ICT / MT',window.stlAmt?.isDirty?.()&&'AMT'].filter(Boolean);
- const launch=api.connected()&&!live&&!unsaved.length&&!api.station()?.run_id;
- const reason=unsaved.length?'请先保存:'+unsaved.join('、'):api.station()?.run_id?'当前高温轮次正在使用服务器':'当前已有计划在执行';
- enable('btn-restart-boot-plan',launch,reason);enable('btn-start-boot-plan',launch,reason);
- enable('btn-save-boot-plan',api.connected());enable('btn-reload-boot-plan',api.connected());
- enable('btn-pause-boot-plan',api.connected()&&['running','waiting_boot','waiting_user'].includes(state));
- enable('btn-resume-boot-plan',api.connected()&&state==='paused');enable('btn-stop-boot-plan',api.connected()&&live);
- $('boot-plan-launch-note').textContent=unsaved.length?'未保存:'+unsaved.join('、')+'。请先保存对应页面。':!c.capabilities?.bmc_power?'未启用 BMC 电源控制:开始计划后按后端提示人工开机 / 复位。停止自动执行不会关闭电源。':'停止自动执行只停止后续自动命令;不代替测试程序退出或主板关机。';
- const fw=c.firmware_settings || {}, rmt=(fw.uip_overrides||[]).find(v=>v.id==='rmt'&&v.mode==='override');
- $('boot-plan-dependencies').innerHTML=[['uip','ICT / RMT',`${(fw.uip_overrides||[]).filter(v=>v.mode==='override').length} 项覆盖 · RMT ${rmt?.value || '默认 / 不覆盖'}`],['amt','AMT',`${c.amt_settings?.action==='run'?'执行测试':'退出菜单'} · ${(c.amt_settings?.overrides||[]).length} 项配置`],['testing','PXE / 外部 MT',d.plan.mt_enabled?(fw.mt_selection?.efi_path || '118.efi'):'未启用 · 到 UEFI 结束']].map(([page,title,text])=>`<button class="plan-dependency" data-plan-nav="${page}"><strong>${title}</strong><span>${esc(text)}</span><small>查看已保存参数 →</small></button>`).join('');
- for(const button of document.querySelectorAll('[data-plan-nav]'))button.onclick=()=>window.stlNavigation.show(button.dataset.planNav);
- const history=Array.isArray(x.history)?x.history:[];
- $('boot-execution-count').textContent=history.length+' 条';
- $('boot-execution-history').innerHTML=history.slice(-40).reverse().map(row=>`<li><time>${api.time(row.observed_unix_ms || row.unix_ms || row.created_unix_ms)}</time><span>${esc(row.stage || row.action || row.kind || '')}</span><code>${esc(row.message || row.detail || JSON.stringify(row))}</code></li>`).join('') || '<li>尚无本次计划记录</li>';
- renderTaskBatch(c);
- }
- function renderTaskBatch(c) {
- const fw = c.firmware_settings || {}, amtSaved = c.amt_settings || {}, pxeCfg = c.pxe_control?.mt86_cfg || {};
- const curSummary = summarizeProfile({
- uip_overrides: fw.uip_overrides || [],
- uip_raw_commands: fw.uip_raw_commands || [],
- amt: amtSaved,
- mt: { ...pxeCfg, ...(fw.mt_selection || {}) },
- });
- if ($('tb-current-config-preview')) {
- $('tb-current-config-preview').innerHTML = `
- <div style="background:#fff;padding:8px 10px;border:1px solid #e2e8f0;border-radius:6px"><strong>ICT 阶段配置 (${curSummary.uipCount} 项)</strong><div style="color:#475569;margin-top:4px;word-break:break-all">${esc(curSummary.ictText)}</div></div>
- <div style="background:#fff;padding:8px 10px;border:1px solid #e2e8f0;border-radius:6px"><strong>AMT 阶段配置</strong><div style="color:#475569;margin-top:4px;word-break:break-all">${esc(curSummary.amtText)}</div></div>
- <div style="background:#fff;padding:8px 10px;border:1px solid #e2e8f0;border-radius:6px"><strong>PXE / MT 阶段配置</strong><div style="color:#475569;margin-top:4px;word-break:break-all">${esc(curSummary.mtText)}</div></div>
- `;
- }
- const savedProfiles = Array.isArray(c.saved_profiles) ? c.saved_profiles : [];
- if ($('tb-library-count')) $('tb-library-count').textContent = `${savedProfiles.length} 个已存 Profile`;
- if ($('tb-saved-profiles-list')) {
- $('tb-saved-profiles-list').innerHTML = savedProfiles.map((p, idx) => {
- const s = summarizeProfile(p);
- return `<div style="padding:8px 10px;background:#fff;border:1px solid #cbd5e1;border-radius:6px;font-size:13px">
- <div style="display:flex;justify-content:space-between;align-items:center;gap:6px;flex-wrap:wrap">
- <strong>${esc(p.name || 'Profile-' + (idx + 1))} <span class="badge">默认 ×${esc(p.repeat || 1)} 次</span></strong>
- <div style="display:flex;gap:4px">
- <button type="button" class="btn btn-secondary btn-xs" data-prof-enqueue="${idx}">+ 加入待执行队列</button>
- <button type="button" class="btn btn-quiet btn-xs" data-prof-load="${esc(p.profile_id || p.name)}">加载到当前编辑器</button>
- <button type="button" class="btn btn-quiet btn-xs" data-prof-del="${esc(p.profile_id || p.name)}">删除</button>
- </div>
- </div>
- <div style="color:#475569;margin-top:4px;font-size:12px">
- <span><b>ICT:</b> ${esc(s.ictText)}</span> · <span><b>AMT:</b> ${esc(s.amtText)}</span> · <span><b>MT:</b> ${esc(s.mtText)}</span>
- </div>
- </div>`;
- }).join('') || '<p class="field-note">当前工位尚未保存命名 Profile。在上方输入名称并点“保存到后端 Profile 库”即可永久保存。</p>';
- document.querySelectorAll('[data-prof-enqueue]').forEach(btn => {
- btn.onclick = () => {
- const p = savedProfiles[Number(btn.dataset.profEnqueue)];
- if (p) {
- getTbDraft().push(clone(p));
- renderTaskBatch(control());
- }
- };
- });
- document.querySelectorAll('[data-prof-load]').forEach(btn => {
- btn.onclick = async () => {
- const pid = btn.dataset.profLoad;
- await awaitCommand('LoadProfileToWorkspace', { station_id: api.stationId(), profile_id: pid }, `加载 Profile ${pid}`);
- await window.stlFirmware.refresh();
- api.status(`已将 Profile ${pid} 加载为当前工位激活配置。`);
- };
- });
- document.querySelectorAll('[data-prof-del]').forEach(btn => {
- btn.onclick = async () => {
- const pid = btn.dataset.profDel;
- await awaitCommand('DeleteProfile', { station_id: api.stationId(), profile_id: pid, name: pid }, `删除 Profile ${pid}`);
- await window.stlFirmware.refresh();
- };
- });
- }
- const list = getTbDraft();
- const totalDraftRuns = list.reduce((acc, p) => acc + Number(p.repeat || 1), 0);
- if ($('tb-draft-summary')) $('tb-draft-summary').textContent = `待下发队列:${list.length} 组 Profile · 合计将连续执行 ${totalDraftRuns} 轮测试`;
- if ($('tb-draft-list')) {
- $('tb-draft-list').innerHTML = list.map((p, idx) => {
- const s = summarizeProfile(p);
- return `<div style="display:flex;justify-content:space-between;align-items:center;padding:6px 10px;background:#f0f9ff;border:1px solid #bae6fd;border-radius:6px;font-size:13px;gap:8px">
- <div>
- <strong>步骤 #${idx + 1}:${esc(p.name)}</strong>
- <div style="font-size:12px;color:#334155">ICT: ${esc(s.ictText)} | AMT: ${esc(s.amtText)} | MT: ${esc(s.mtText)}</div>
- </div>
- <div style="display:flex;align-items:center;gap:6px;white-space:nowrap">
- <label style="font-size:12px">重复次数 <input type="number" min="1" max="100" value="${esc(p.repeat || 1)}" data-tb-rep="${idx}" style="width:56px;padding:2px 4px"></label>
- <button type="button" class="btn btn-quiet btn-xs" data-tb-del="${idx}">移除</button>
- </div>
- </div>`;
- }).join('') || '<p class="field-note">队列为空:可从上方 Profile 库点“+ 加入待执行队列”,或点“直接加入右侧待执行测试队列”。</p>';
- document.querySelectorAll('[data-tb-del]').forEach(btn => {
- btn.onclick = () => { list.splice(Number(btn.dataset.tbDel), 1); renderTaskBatch(control()); };
- });
- document.querySelectorAll('[data-tb-rep]').forEach(inp => {
- inp.onchange = () => {
- const i = Number(inp.dataset.tbRep);
- if (list[i]) list[i].repeat = Math.max(1, Number(inp.value || 1));
- renderTaskBatch(control());
- };
- });
- }
- const tb = c.task_batch || {}, tbState = tb.state || 'idle';
- const done = Number(tb.total_runs_completed || 0), planned = Number(tb.total_runs_planned || 0);
- if ($('task-batch-state-badge')) {
- $('task-batch-state-badge').textContent = stateNames[tbState] || tbState;
- $('task-batch-state-badge').classList.toggle('error', ['failed', 'blocked'].includes(tbState));
- }
- if ($('tb-live-progress')) $('tb-live-progress').textContent = `${done} / ${planned} 轮`;
- if ($('tb-live-title')) {
- $('tb-live-title').textContent = tb.batch_id ? `${tb.current_profile_name || 'Profile'} (第 ${tb.current_repeat || 1}/${tb.current_profile_repeats || 1} 次)` : '尚无活动批次队列';
- }
- if ($('tb-live-detail')) {
- const fmtElapsed = api.formatElapsed ? api.formatElapsed(c.elapsed_ms || 0) : `${Math.floor((Number(c.elapsed_ms || 0)) / 1000)}s`;
- $('tb-live-detail').textContent = tb.batch_id ? `批次编号 ${tb.batch_id} · 状态 ${stateNames[tbState] || tbState} · 已完成 ${done}/${planned} 轮 · 总用时 ${fmtElapsed}` : '添加 1 组或多组 Profile 后,点击下方按钮立即按序自动重启并执行。';
- }
- const tbRuns = Array.isArray(tb.runs) ? tb.runs : [];
- const histRuns = Array.isArray(c.task_history) ? c.task_history : [];
- const seenIds = new Set(tbRuns.map(r => r.run_id).filter(Boolean));
- const runs = tbRuns.length
- ? histRuns.filter(r => r.run_id && !seenIds.has(r.run_id)).concat(tbRuns).slice(-20)
- : histRuns.slice(-20);
- if ($('tb-runs-tbody')) {
- $('tb-runs-tbody').innerHTML = runs.slice().reverse().map(r => `<tr>
- <td><code>${esc(r.run_id || '-')}</code></td>
- <td><strong>${esc(r.profile_name || '-')}</strong></td>
- <td>第 ${esc(r.repeat_index || 1)} / ${esc(r.repeat_total || 1)} 次</td>
- <td><code>${esc(r.boot_id || '-')}</code></td>
- <td><span class="badge ${r.verdict === 'pass' ? 'connected' : r.verdict === 'fail' ? 'error' : ''}">${esc(r.verdict || r.state || '-')}</span></td>
- <td><small>${esc(r.log_path || r.log_raw_path || '运行中 (完成后自动归档 sol.raw & summary.json)')}</small></td>
- </tr>`).join('') || '<tr><td colspan="6">尚无批次运行记录</td></tr>';
- }
- }
- function init(services) {
- api=services;
- $('boot-plan-preset').onchange=()=>{const value=$('boot-plan-preset').value;if(value!=='custom')for(const s of document.querySelectorAll('[data-plan-stage]'))s.value=value==='auto'?'auto':'manual';edit();};
- for(const input of document.querySelectorAll('[data-plan-stage],#boot-plan-mt-enabled,#boot-plan-use-in-runs'))input.onchange=edit;
- api.bind('btn-save-boot-plan',async()=>{const id=api.stationId(), d=current();if(!d)throw new Error('等待配置加载');const plan=clone(d.plan);await awaitCommand('SaveBootPlan',{station_id:id,plan},'保存启动计划');d.dirty=false;formStation='';await window.stlFirmware.refresh();api.status('启动计划已保存,尚未开始执行。');});
- api.bind('btn-reload-boot-plan',async()=>{const id=api.stationId();await window.stlFirmware.refresh();drafts.delete(id);formStation='';render();});
- for(const [id,action,name] of [['btn-restart-boot-plan','restart','重启并执行已保存计划'],['btn-start-boot-plan','start','从当前阶段执行计划'],['btn-pause-boot-plan','pause','暂停计划并人工接管'],['btn-resume-boot-plan','resume','继续启动计划'],['btn-stop-boot-plan','stop','停止自动执行']])api.bind(id,()=>{if(['start','restart'].includes(action))api.useLiveConsole?.();return api.command('ControlBootPlan',{action},name);});
- $('btn-plan-open-input').onclick=()=>{api.useLiveConsole?.();const x=control(),p=x.firmware?.console_prompt?.kind || x.boot_execution?.current_stage;window.stlNavigation.show(p==='amt'?'amt':['uip','uip1','uip2'].includes(p)?'uip':'testing');};
- const buildProfileFromForm = () => {
- const c = control(), fw = c.firmware_settings || {}, amtSaved = clone(c.amt_settings || {}), pxeCfg = c.pxe_control?.mt86_cfg || {};
- const name = ($('tb-profile-name')?.value || '').trim() || `Profile-${tbSeq++}`;
- const repeat = Math.max(1, Number($('tb-profile-repeat')?.value || 1));
- const amtMode = $('tb-profile-amt-mode')?.value || 'current';
- const mtMode = $('tb-profile-mt-mode')?.value || 'current';
- const runRmt = $('tb-profile-rmt') ? $('tb-profile-rmt').checked : true;
- let runAmt = true;
- const amt = { ...amtSaved, test_command: amtSaved.test_command || 'amemdiag 1', exit_after: true };
- if (amtMode === 'skip') {
- runAmt = false;
- amt.action = 'skip';
- } else if (amtMode === 'fast24') {
- runAmt = true;
- amt.action = 'run';
- amt.tp_end_step = 0;
- amt.only_tests = Array.from({ length: 24 }, (_, i) => i + 1);
- } else if (amtMode === 'tp0') {
- runAmt = true;
- amt.action = 'run';
- amt.tp_end_step = 0;
- amt.only_tests = [1];
- amt.overrides = [{ name: 'tp', value: '0,1,0,0,0,255' }];
- } else if (amtMode === 'all24') {
- runAmt = true;
- amt.action = 'run';
- amt.overrides = (amt.overrides || []).filter(x => x.name !== 'tp');
- } else {
- runAmt = amt.action === 'run';
- }
- let runMt = true;
- const mt = { ...pxeCfg, ...(fw.mt_selection || {}), efi_path: 'FS0:\\EFI\\118.efi', exit_mode: 2 };
- if (mtMode === 'skip') {
- runMt = false;
- } else if (mtMode === 'fast64m') {
- mt.tstlist = '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25';
- mt.memory_range = 'custom';
- mt.addr_lim_lo = '0x10000000';
- mt.addr_lim_hi = '0x14000000';
- } else if (mtMode === 'test0_64m') {
- mt.tstlist = '0';
- mt.memory_range = 'custom';
- mt.addr_lim_lo = '0x10000000';
- mt.addr_lim_hi = '0x14000000';
- } else if (mtMode === 'test0_all') {
- mt.tstlist = '0';
- mt.memory_range = 'all';
- }
- return {
- profile_id: `PRF-${Date.now()}`,
- name,
- repeat,
- run_rmt: runRmt,
- run_amt: runAmt,
- run_mt: runMt,
- uip_overrides: clone(fw.uip_overrides || []),
- uip_raw_commands: clone(fw.uip_raw_commands || []),
- amt,
- mt,
- };
- };
- if ($('btn-tb-save-library')) {
- api.bind('btn-tb-save-library', async () => {
- const profile = buildProfileFromForm();
- await awaitCommand('SaveProfile', { station_id: api.stationId(), profile }, `保存 Profile ${profile.name}`);
- await window.stlFirmware.refresh();
- if ($('tb-library-status')) $('tb-library-status').textContent = `已存入后端 Profile 库:${profile.name}`;
- render();
- });
- }
- if ($('btn-tb-add-profile')) {
- $('btn-tb-add-profile').onclick = () => {
- const p = buildProfileFromForm();
- getTbDraft().push(p);
- tbSeq += 1;
- if ($('tb-profile-name')) $('tb-profile-name').value = `Profile-${tbSeq}`;
- renderTaskBatch(control());
- };
- }
- if ($('btn-tb-clear-draft')) {
- $('btn-tb-clear-draft').onclick = () => {
- tbDrafts.set(api.stationId(), []);
- renderTaskBatch(control());
- };
- }
- if ($('btn-tb-submit-start')) {
- api.bind('btn-tb-submit-start', async () => {
- const list = getTbDraft();
- const profiles = list.length ? clone(list) : [buildProfileFromForm()];
- const stopOnFail = $('tb-stop-on-fail') ? $('tb-stop-on-fail').checked : true;
- api.useLiveConsole?.();
- await awaitCommand('SubmitTaskBatch', { station_id: api.stationId(), profiles, stop_on_fail: stopOnFail, auto_start: true }, '提交并启动多计划测试队列');
- await window.stlFirmware.refresh();
- render();
- });
- }
- for (const [btnId, act, label] of [['btn-tb-pause', 'pause', '暂停任务队列'], ['btn-tb-resume', 'resume', '继续任务队列'], ['btn-tb-stop', 'stop', '停止任务队列']]) {
- if ($(btnId)) api.bind(btnId, async () => {
- if (act === 'stop') clientQueueByStation.delete(api.stationId());
- await api.command('ControlTaskBatch', { station_id: api.stationId(), action: act }, label);
- await window.stlFirmware.refresh();
- render();
- });
- }
- // Frontend Self-Maintained Queue Mode (listens to active `task_complete` push + `GetTaskStatus`)
- const clientQueueByStation = new Map();
- const expandProfilesToSteps = profiles => {
- const steps = [];
- for (const p of profiles) {
- const rep = Math.max(1, Number(p.repeat || 1));
- for (let r = 1; r <= rep; r++) {
- steps.push({ ...clone(p), repeat: 1, _stepLabel: `${p.name} (${r}/${rep})` });
- }
- }
- return steps;
- };
- const dispatchNextClientStep = async sid => {
- const q = clientQueueByStation.get(sid);
- if (!q || !q.active) return;
- if (q.index >= q.steps.length) {
- q.active = false;
- api.status(`[前端自维护队列] ${sid} 全部 ${q.steps.length} 轮任务已执行完毕!`);
- await window.stlFirmware.refresh();
- render();
- return;
- }
- const step = q.steps[q.index];
- api.status(`[前端自维护队列] ${sid} 正在下发第 ${q.index + 1}/${q.steps.length} 轮:${step._stepLabel}`);
- await awaitCommand('SubmitTaskBatch', { station_id: sid, profiles: [step], stop_on_fail: q.stopOnFail, auto_start: true, continue_timer: q.index > 0 }, `前端队列第 ${q.index + 1}/${q.steps.length} 轮`);
- await window.stlFirmware.refresh();
- render();
- };
- if ($('btn-tb-client-queue-start')) {
- api.bind('btn-tb-client-queue-start', async () => {
- const sid = api.stationId();
- const list = getTbDraft();
- const profiles = list.length ? clone(list) : [buildProfileFromForm()];
- const steps = expandProfilesToSteps(profiles);
- const stopOnFail = $('tb-stop-on-fail') ? $('tb-stop-on-fail').checked : true;
- clientQueueByStation.set(sid, { active: true, steps, index: 0, stopOnFail, lastHandledRunId: '' });
- api.useLiveConsole?.();
- await dispatchNextClientStep(sid);
- });
- }
- window.addEventListener('stl:server-event', async ev => {
- const msg = ev.detail || {};
- if (msg.event !== 'task_complete') return;
- const res = msg.result || {};
- const sid = res.station_id || '';
- const q = clientQueueByStation.get(sid);
- if (!q || !q.active) return;
- if (res.run_id && q.lastHandledRunId === res.run_id) return;
- q.lastHandledRunId = res.run_id || String(Date.now());
- let tstat = res;
- try { tstat = await api.callApi('GetTaskStatus', { station_id: sid }); } catch (_) {}
- const failed = res.verdict === 'fail' || res.task_status === 'failed' || tstat.awaiting_dimm_replacement === true;
- if (failed && q.stopOnFail) {
- q.active = false;
- api.status(`[前端自维护队列] ${sid} 第 ${q.index + 1}/${q.steps.length} 轮出现异常停机保护,后续队列已暂停等待更换内存条。`, true);
- await window.stlFirmware.refresh();
- render();
- return;
- }
- q.index += 1;
- setTimeout(() => { dispatchNextClientStep(sid).catch(e => api.status(e.message, true)); }, 1200);
- });
- }
- window.stlBootPlan={init,render,awaitCommand,isDirty:()=>!!current()?.dirty};
- })();
|