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:
Alexey Kuzmin 2018-10-02 03:34:52 +02:00 committed by Nitish Sakhawalkar
parent f1b097024e
commit c9edf77e8e
3 changed files with 89 additions and 34 deletions

View file

@ -1154,15 +1154,25 @@ v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
const std::string& info_type) {
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
scoped_refptr<util::Promise> promise = new util::Promise(isolate);
if ((info_type != "basic" && info_type != "complete") ||
!gpu_data_manager->GpuAccessAllowed(nullptr)) {
promise->Reject("Error fetching GPU Info");
if (info_type != "basic" && info_type != "complete") {
promise->RejectWithErrorMessage(
"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();
}
auto* const info_mgr = GPUInfoManager::GetInstance();
if (info_type == "complete") {
#if defined(OS_MACOSX) || defined(OS_WIN)
info_mgr->FetchCompleteInfo(promise);
#else
info_mgr->FetchBasicInfo(promise);
#endif
} else /* (info_type == "basic") */ {
info_mgr->FetchBasicInfo(promise);
}

View file

@ -805,41 +805,69 @@ describe('app module', () => {
})
describe('getGPUInfo() API', () => {
before(function () {
// TODO(alexeykuzmoin): Fails on linux. Enable them back.
// https://github.com/electron/electron/pull/14863
const appPath = path.join(__dirname, 'fixtures', 'api', 'gpu-info.js')
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') {
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) => {
app.getGPUInfo('basic').then((gpuInfo) => {
// Devices information is always present in the available info
expect(gpuInfo.gpuDevice).to.be.an('array')
expect(gpuInfo.gpuDevice.length).to.be.greaterThan(0)
const device = gpuInfo.gpuDevice[0]
expect(device).to.be.an('object')
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()
})
it('fails for invalid info_type', () => {
const invalidType = 'invalid'
const errorMessage =
`app.getGPUInfo() didn't fail for the "${invalidType}" info type`
return app.getGPUInfo(invalidType).then(
() => Promise.reject(new Error(errorMessage)),
() => Promise.resolve())
})
})

17
spec/fixtures/api/gpu-info.js vendored Normal file
View 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)
}
)
})