Files
planet/client/tests/gpu-policy.test.ts
T
linkong e53c3af355
ci / backend (push) Canceled after 0s
ci / frontend (push) Canceled after 0s
ci / delivery (push) Canceled after 0s
release / images (push) Canceled after 0s
release / client_release (push) Canceled after 0s
release: bump version to 0.79.0
2026-11-24 15:40:10 +08:00

73 lines
2.7 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { isGpuProcessCrash, resolveChromiumGpuSwitches } from '../src/main/gpu-policy'
import { computeSplashCanvasSize } from '../src/preload/splash'
describe('chromium GPU switch policy and splash pixel budget', () => {
test('win32 hardware mode avoids risky zero-copy and forced GPU switches', () => {
const switches = resolveChromiumGpuSwitches({
platform: 'win32',
headlessSmoke: false,
softwareGl: false,
})
const names = switches.map((entry) => entry.name)
expect(names).not.toContain('enable-zero-copy')
expect(names).not.toContain('enable-gpu-rasterization')
expect(names).not.toContain('force_high_performance_gpu')
expect(names).toContain('disable-renderer-backgrounding')
expect(names).not.toContain('ozone-platform-hint')
})
test('linux hardware mode adds ozone auto hint without enable-zero-copy', () => {
const switches = resolveChromiumGpuSwitches({
platform: 'linux',
headlessSmoke: false,
softwareGl: false,
})
expect(switches).toEqual([
{ name: 'disable-renderer-backgrounding' },
{ name: 'ozone-platform-hint', value: 'auto' },
])
})
test('headless smoke and explicit software-gl select SwiftShader safely', () => {
for (const flags of [
{ headlessSmoke: true, softwareGl: false },
{ headlessSmoke: false, softwareGl: true },
]) {
const switches = resolveChromiumGpuSwitches({ platform: 'win32', ...flags })
expect(switches).toEqual([
{ name: 'disable-gpu' },
{ name: 'use-gl', value: 'angle' },
{ name: 'use-angle', value: 'swiftshader' },
{ name: 'enable-unsafe-swiftshader' },
])
}
})
test('isGpuProcessCrash detects unexpected GPU exits and ignores clean exits', () => {
expect(isGpuProcessCrash({ type: 'GPU', reason: 'crashed' })).toBe(true)
expect(isGpuProcessCrash({ type: 'GPU', reason: 'killed' })).toBe(true)
expect(isGpuProcessCrash({ type: 'GPU', reason: 'clean-exit' })).toBe(false)
expect(isGpuProcessCrash({ type: 'Utility', reason: 'crashed' })).toBe(false)
expect(isGpuProcessCrash(null)).toBe(false)
})
test('computeSplashCanvasSize preserves 1080p clarity while capping 4K splash buffers', () => {
expect(computeSplashCanvasSize(1920, 1080, 1)).toEqual({
dpr: 1,
width: 1920,
height: 1080,
})
const qhdScaled4k = computeSplashCanvasSize(2560, 1440, 1.5)
expect(qhdScaled4k.dpr).toBeLessThan(1.5)
expect(qhdScaled4k.width * qhdScaled4k.height).toBeLessThanOrEqual(1920 * 1080)
const native4k = computeSplashCanvasSize(3840, 2160, 1)
expect(native4k.dpr).toBe(0.75)
expect(native4k.width).toBe(2880)
expect(native4k.height).toBe(1620)
})
})