Skip to content

Windows 上的安卓应用运行器:双击 APK 即装,应用以独立窗口与桌面图标运行,自持 QEMU 运行时

test(doctor): 同步 GPU 候选断言到 host 优先设计,修复 CI 红灯

RoutineMiku44453527d096
diff --git a/dist.lnk b/dist.lnk
new file mode 100644
index 0000000..043c1d3
Binary files /dev/null and b/dist.lnk differ
diff --git a/test/auto-test.js b/test/auto-test.js
index 424f311..4f4f0b2 100644
--- a/test/auto-test.js
+++ b/test/auto-test.js
@@ -28,11 +28,16 @@ const { friendlyInstallError, friendlyLaunchError } = require('../src/core/adb')
(async () => {
console.log('\n[doctor.js 自动参数]');
- await test('GPU 后端按 emulator 版本选择(37.x 用 software,老版本用 swiftshader_indirect)', () => {
- assert(doctor.gpuCandidates('37.3.8.0')[0] === 'software');
- assert(doctor.gpuCandidates('36.4.9.0')[0] === 'software');
- assert(doctor.gpuCandidates('35.1.4.0')[0] === 'swiftshader_indirect');
+ await test('GPU 后端按 emulator 版本选择(新版本 host 优先 + 软件渲染兜底,老版本 swiftshader_indirect)', () => {
+ // 新版本(37.x/36.4.9+):host 最跟手,失败会自动降级到 software/swangle
+ assert(doctor.gpuCandidates('37.3.8.0')[0] === 'host', '37.x 首选应为 host');
+ assert(doctor.gpuCandidates('36.4.9.0')[0] === 'host');
+ assert(doctor.gpuCandidates('37.3.8.0').includes('software'), '新版本必须有软件渲染兜底');
+ // 37.x 上传 swiftshader_indirect 会 GL 初始化失败,绝不能出现在候选里
assert(!doctor.gpuCandidates('37.3.8.0').includes('swiftshader_indirect'));
+ // 老版本仍走 swiftshader_indirect
+ assert(doctor.gpuCandidates('35.1.4.0')[0] === 'host');
+ assert(doctor.gpuCandidates('35.1.4.0').includes('swiftshader_indirect'));
});
await test('小内存机器自动降配(不再是写死 4GB / 4 核)', () => {
@@ -42,7 +47,10 @@ const { friendlyInstallError, friendlyLaunchError } = require('../src/core/adb')
assert(p.cores === 2, `核心应为 2,实际 ${p.cores}`);
assert(p.accel === 'off', '无硬件加速应自动回退软件模拟');
assert(p.bootTimeoutMs > 240000, '软件模拟应给更长的开机超时');
- assert(p.gpu === 'software', `渲染应为 software,实际 ${p.gpu}`);
+ assert(p.gpu === 'host', `首选渲染应为 host(失败由 planVariants 降级),实际 ${p.gpu}`);
+ // accel 关闭时的保底参数必须是软件渲染,否则 TCG 下无 GPU 可用
+ const lastResort = doctor.planVariants(p).find((v) => v.lastResort);
+ assert(lastResort && /software|swiftshader/.test(lastResort.gpu), '保底方案必须用软件渲染');
assert(p.dataMB <= 4096, '数据分区不应再是 16G');
});
@@ -92,14 +100,14 @@ const { friendlyInstallError, friendlyLaunchError } = require('../src/core/adb')
const common = { accel: { ok: true }, emulatorVersion: '37.3.8.0', diskMB: 50000, port: 5562, adbPort: 5044 };
const p = doctor.autoProfile({ ...common, settings: { engine: { autoMemory: true, gpuMode: 'auto', memoryMB: 0, cores: 0 } } });
const text = doctor.describeProfile(p);
- assert(p.gpu === 'software', `应为 software,实际 ${p.gpu}`);
+ assert(p.gpu === 'host', `应为 host(失败降级),实际 ${p.gpu}`);
assert(p.accelOk === true && text.includes('硬件加速'), text);
assert(!text.includes('swiftshader_indirect'), text);
assert(text.includes('端口 5562'), text);
// 老引擎仍应用老后端;用户手动填的高级参数仍然生效
const old = doctor.autoProfile({ ...common, emulatorVersion: '35.1.4.0', settings: {} });
- assert(old.gpu === 'swiftshader_indirect');
+ assert(old.gpu === 'host' && doctor.gpuCandidates('35.1.4.0').includes('swiftshader_indirect'));
const manual = doctor.autoProfile({ ...common, settings: { engine: { autoMemory: false, memoryMB: 6144, cores: 6, gpuMode: 'swiftshader' } } });
assert(manual.memoryMB === 6144 && manual.cores === 6 && manual.gpu === 'swiftshader', JSON.stringify(manual));
const zero = doctor.overridesFromSettings({ autoMemory: false, memoryMB: 0, cores: 0, gpuMode: 'auto' });
diff --git a/test/engine-test.js b/test/engine-test.js
index af3c521..d679fd3 100644
--- a/test/engine-test.js
+++ b/test/engine-test.js
@@ -226,7 +226,7 @@ function assert(cond, msg) { if (!cond) throw new Error(msg || '断言失败');
const cfg = fs.readFileSync(path.join(r.avdDir, 'config.ini'), 'utf8');
assert(/^hw\.cpu\.arch=x86_64$/m.test(cfg), `hw.cpu.arch 应为 x86_64,实际:${cfg.match(/^hw\.cpu\.arch=.*$/m)}`);
assert(/^abi\.type=x86_64$/m.test(cfg), 'abi.type 应为 x86_64');
- assert(/^image\.sysdir\.1=system-images\//m.test(cfg), 'image.sysdir.1 缺失');
+ assert(/^image\.sysdir\.1=\S*system-images\//m.test(cfg), 'image.sysdir.1 缺失');
});
await test('安装失败原因翻译:NO_MATCHING_ABIS 给出中文指引', async () => {