test: slightly rewrite getGPUInfo() tests (#14863)
Rewrite GPUInfo tests for linux and update `getGPUInfo` functionality for linux. `basic` and `complete` GPUInfo is same for linux.
This commit is contained in:
parent
f1b097024e
commit
c9edf77e8e
3 changed files with 89 additions and 34 deletions
|
@ -1154,15 +1154,25 @@ v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
|
||||||
const std::string& info_type) {
|
const std::string& info_type) {
|
||||||
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
|
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
|
||||||
scoped_refptr<util::Promise> promise = new util::Promise(isolate);
|
scoped_refptr<util::Promise> promise = new util::Promise(isolate);
|
||||||
if ((info_type != "basic" && info_type != "complete") ||
|
if (info_type != "basic" && info_type != "complete") {
|
||||||
!gpu_data_manager->GpuAccessAllowed(nullptr)) {
|
promise->RejectWithErrorMessage(
|
||||||
promise->Reject("Error fetching GPU Info");
|
"Invalid info type. Use 'basic' or 'complete'");
|
||||||
|
return promise->GetHandle();
|
||||||
|
}
|
||||||
|
std::string reason;
|
||||||
|
if (!gpu_data_manager->GpuAccessAllowed(&reason)) {
|
||||||
|
promise->RejectWithErrorMessage("GPU access not allowed. Reason: " +
|
||||||
|
reason);
|
||||||
return promise->GetHandle();
|
return promise->GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* const info_mgr = GPUInfoManager::GetInstance();
|
auto* const info_mgr = GPUInfoManager::GetInstance();
|
||||||
if (info_type == "complete") {
|
if (info_type == "complete") {
|
||||||
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
||||||
info_mgr->FetchCompleteInfo(promise);
|
info_mgr->FetchCompleteInfo(promise);
|
||||||
|
#else
|
||||||
|
info_mgr->FetchBasicInfo(promise);
|
||||||
|
#endif
|
||||||
} else /* (info_type == "basic") */ {
|
} else /* (info_type == "basic") */ {
|
||||||
info_mgr->FetchBasicInfo(promise);
|
info_mgr->FetchBasicInfo(promise);
|
||||||
}
|
}
|
||||||
|
|
|
@ -805,41 +805,69 @@ describe('app module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getGPUInfo() API', () => {
|
describe('getGPUInfo() API', () => {
|
||||||
before(function () {
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'gpu-info.js')
|
||||||
// TODO(alexeykuzmoin): Fails on linux. Enable them back.
|
|
||||||
// https://github.com/electron/electron/pull/14863
|
const getGPUInfo = async (type) => {
|
||||||
|
const appProcess = ChildProcess.spawn(remote.process.execPath, [appPath, type])
|
||||||
|
let gpuInfoData = ''
|
||||||
|
let errorData = ''
|
||||||
|
appProcess.stdout.on('data', (data) => {
|
||||||
|
gpuInfoData += data
|
||||||
|
})
|
||||||
|
appProcess.stderr.on('data', (data) => {
|
||||||
|
errorData += data
|
||||||
|
})
|
||||||
|
const [exitCode] = await emittedOnce(appProcess, 'exit')
|
||||||
|
if (exitCode === 0) {
|
||||||
|
// return info data on successful exit
|
||||||
|
return JSON.parse(gpuInfoData)
|
||||||
|
} else {
|
||||||
|
// return error if not clean exit
|
||||||
|
return Promise.reject(new Error(errorData))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const verifyBasicGPUInfo = async (gpuInfo) => {
|
||||||
|
// Devices information is always present in the available info.
|
||||||
|
expect(gpuInfo).to.have.own.property('gpuDevice')
|
||||||
|
.that.is.an('array')
|
||||||
|
.and.is.not.empty()
|
||||||
|
|
||||||
|
const device = gpuInfo.gpuDevice[0]
|
||||||
|
expect(device).to.be.an('object')
|
||||||
|
.and.to.have.property('deviceId')
|
||||||
|
.that.is.a('number')
|
||||||
|
.not.lessThan(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
it('succeeds with basic GPUInfo', async () => {
|
||||||
|
const gpuInfo = await getGPUInfo('basic')
|
||||||
|
await verifyBasicGPUInfo(gpuInfo)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('succeeds with complete GPUInfo', async () => {
|
||||||
|
const completeInfo = await getGPUInfo('complete')
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
this.skip()
|
// For linux complete info is same as basic info
|
||||||
|
await verifyBasicGPUInfo(completeInfo)
|
||||||
|
const basicInfo = await getGPUInfo('basic')
|
||||||
|
expect(completeInfo).to.deep.equal(basicInfo)
|
||||||
|
} else {
|
||||||
|
// Gl version is present in the complete info.
|
||||||
|
expect(completeInfo).to.have.own.property('auxAttributes')
|
||||||
|
.that.is.an('object')
|
||||||
|
expect(completeInfo.auxAttributes).to.have.own.property('glVersion')
|
||||||
|
.that.is.a('string')
|
||||||
|
.and.not.empty()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('succeeds with basic GPUInfo', (done) => {
|
it('fails for invalid info_type', () => {
|
||||||
app.getGPUInfo('basic').then((gpuInfo) => {
|
const invalidType = 'invalid'
|
||||||
// Devices information is always present in the available info
|
const errorMessage =
|
||||||
expect(gpuInfo.gpuDevice).to.be.an('array')
|
`app.getGPUInfo() didn't fail for the "${invalidType}" info type`
|
||||||
expect(gpuInfo.gpuDevice.length).to.be.greaterThan(0)
|
return app.getGPUInfo(invalidType).then(
|
||||||
const device = gpuInfo.gpuDevice[0]
|
() => Promise.reject(new Error(errorMessage)),
|
||||||
expect(device).to.be.an('object')
|
() => Promise.resolve())
|
||||||
expect(device)
|
|
||||||
.to.have.property('deviceId')
|
|
||||||
.that.is.a('number')
|
|
||||||
.not.lessThan(0)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('succeeds with complete GPUInfo', (done) => {
|
|
||||||
app.getGPUInfo('complete').then((completeInfo) => {
|
|
||||||
// Driver version is present in the complete info
|
|
||||||
expect(completeInfo.auxAttributes.glVersion).to.be.a('string').that.has.length.greaterThan(0)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('fails for invalid info_type', (done) => {
|
|
||||||
app.getGPUInfo('invalid').catch(() => {
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
17
spec/fixtures/api/gpu-info.js
vendored
Normal file
17
spec/fixtures/api/gpu-info.js
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
const { app } = require('electron')
|
||||||
|
|
||||||
|
app.commandLine.appendSwitch('--disable-software-rasterizer')
|
||||||
|
|
||||||
|
app.on('ready', () => {
|
||||||
|
const infoType = process.argv.pop()
|
||||||
|
app.getGPUInfo(infoType).then(
|
||||||
|
(gpuInfo) => {
|
||||||
|
console.log(JSON.stringify(gpuInfo))
|
||||||
|
app.exit(0)
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
console.error(error)
|
||||||
|
app.exit(1)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue