0

[Telemetry SWX] Add floating point accuracy routine

Add implementation to chrome://.

Add implementation to chrome-untrusted://.

Add tests.

Bug: b:162051831
Change-Id: I3b4442e611378935cbd9f88736f1871ad1971f43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375287
Commit-Queue: Laurențiu Olteanu <lolteanu@google.com>
Reviewed-by: Mahmoud Gawad <mgawad@google.com>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Oleh Lamzin <lamzin@google.com>
Cr-Commit-Position: refs/heads/master@{#805747}
This commit is contained in:
Andrei-Laurențiu Olteanu
2020-09-10 15:12:42 +00:00
committed by Commit Bot
parent 13b60e60ee
commit ed88c72ebf
8 changed files with 134 additions and 0 deletions

@ -148,4 +148,18 @@ void DiagnosticsService::RunCpuStressRoutine(
std::move(callback)));
}
void DiagnosticsService::RunFloatingPointAccuracyRoutine(
uint32_t length_seconds,
RunFloatingPointAccuracyRoutineCallback callback) {
GetService()->RunFloatingPointAccuracyRoutine(
length_seconds,
base::BindOnce(
[](health::mojom::DiagnosticsService::
RunFloatingPointAccuracyRoutineCallback callback,
cros_healthd::mojom::RunRoutineResponsePtr ptr) {
std::move(callback).Run(converters::ConvertPtr(std::move(ptr)));
},
std::move(callback)));
}
} // namespace chromeos

@ -48,6 +48,9 @@ class DiagnosticsService : public health::mojom::DiagnosticsService {
RunCpuCacheRoutineCallback callback) override;
void RunCpuStressRoutine(uint32_t length_seconds,
RunCpuStressRoutineCallback callback) override;
void RunFloatingPointAccuracyRoutine(
uint32_t length_seconds,
RunFloatingPointAccuracyRoutineCallback callback) override;
// Ensures that |service_| created and connected to the
// CrosHealthdProbeService.

@ -134,6 +134,25 @@ interface DiagnosticsService {
// routine.
RunCpuStressRoutine(uint32 length_seconds)
=> (RunRoutineResponse response);
// Requests that the FloatingPointAccuracy routine is created and started
// on the platform. This routine executes millions of floating-point
// operations by SSE instructions for a specified amount of time. The routine
// will pass if the result values of the operations and known accurate result
// are the same.
//
// The request:
// * |length_seconds| - length of time, in seconds, to run the floating-point
// routine for. Test will executes millions of
// floating-point operations in length seconds and get
// the result to compare with known accurate results.
// This parameter needs to be strictly greater than zero.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunFloatingPointAccuracyRoutine(uint32 length_seconds)
=> (RunRoutineResponse response);
};
// Enumeration of each of the diagnostics routines the platform may support.

@ -29,6 +29,8 @@ dpsl_internal.Message = {
DIAGNOSTICS_RUN_AC_POWER_ROUTINE: 'DiagnosticsService.RunAcPowerRoutine',
DIAGNOSTICS_RUN_CPU_CACHE_ROUTINE: 'DiagnosticsService.RunCpuCacheRoutine',
DIAGNOSTICS_RUN_CPU_STRESS_ROUTINE: 'DiagnosticsService.RunCpuStressRoutine',
DIAGNOSTICS_RUN_FP_ACCURACY_ROUTINE:
'DiagnosticsService.RunFloatingPointAccuraryRoutine',
PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo',
};
@ -111,6 +113,13 @@ dpsl_internal.DiagnosticsRunCpuCacheRoutineRequest;
*/
dpsl_internal.DiagnosticsRunCpuStressRoutineRequest;
/**
* Request message sent by the unprivileged context to the privileged
* context to run floating point accuracy routine.
* @typedef {{ duration: !number }}
*/
dpsl_internal.DiagnosticsRunFPAccuracyRoutineRequest;
/**
* Response message sent by the privileged context containing routine
* information.

@ -406,6 +406,20 @@ class DiagnosticsProxy {
return await getOrCreateDiagnosticsService().runCpuStressRoutine(
request.duration);
};
/**
* Runs floating point accuracy routine.
* @param { !Object } message
* @return { !RunRoutineResponsePromise }
*/
async handleRunFloatingPointAccuracyRoutine(message) {
const request =
/** @type {!dpsl_internal.DiagnosticsRunFPAccuracyRoutineRequest} */
(message);
this.assertNumberIsPositive(request.duration);
return await getOrCreateDiagnosticsService()
.runFloatingPointAccuracyRoutine(request.duration);
};
};
const diagnosticsProxy = new DiagnosticsProxy();
@ -721,6 +735,13 @@ untrustedMessagePipe.registerHandler(
(message) => diagnosticsProxy.handleRunCpuStressRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.DIAGNOSTICS_RUN_FP_ACCURACY_ROUTINE,
(message) => diagnosticsProxy.genericRunRoutineHandler(
(message) =>
diagnosticsProxy.handleRunFloatingPointAccuracyRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.PROBE_TELEMETRY_INFO,
(message) => telemetryProxy.handleProbeTelemetryInfo(message));

@ -202,6 +202,26 @@ chromeos.test_support = {};
}
return response;
}
/**
* Requests floating point accuracy routine to be run for duration seconds.
* @param { !number } duration
* @return { !Promise<!Object> }
* @public
*/
async runFloatingPointAccuracyRoutine(duration) {
const message =
/** @type {!dpsl_internal.DiagnosticsRunFPAccuracyRoutineRequest} */
({duration: duration});
const response =
/** @type {!Object} */ (await messagePipe.sendMessage(
dpsl_internal.Message.DIAGNOSTICS_RUN_FP_ACCURACY_ROUTINE,
message));
if (response instanceof Error) {
throw response;
}
return response;
}
};
/**

@ -423,6 +423,22 @@ TEST_F(
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunFPAccuracyRoutineInvalidInput', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunFPAccuracyRoutineInvalidInput');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunFPAccuracyRoutine', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunFPAccuracyRoutine');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedRequestTelemetryInfoUnknownCategory', async () => {

@ -226,6 +226,38 @@ UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunCpuStressRoutine', async () => {
assertDeepEquals(response, {id: 123456789, status: 'ready'});
});
// Tests that runFloatingPointAccuracyRoutine throws the correct error when
// invalid number is passed as input.
UNTRUSTED_TEST(
'UntrustedDiagnosticsRequestRunFPAccuracyRoutineInvalidInput', async () => {
let caughtError1;
try {
await chromeos.diagnostics.runFloatingPointAccuracyRoutine(0);
} catch (error) {
caughtError1 = error;
}
assertEquals(caughtError1.name, 'RangeError');
assertEquals(caughtError1.message, `Parameter must be positive.`);
let caughtError2;
try {
await chromeos.diagnostics.runFloatingPointAccuracyRoutine(-2147483648);
} catch (error) {
caughtError2 = error;
}
assertEquals(caughtError2.name, 'RangeError');
assertEquals(caughtError2.message, `Parameter must be positive.`);
});
// Tests that runFloatingPointAccuracyRoutine returns the correct Object.
UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunFPAccuracyRoutine', async () => {
const response =
await chromeos.diagnostics.runFloatingPointAccuracyRoutine(5);
assertDeepEquals(response, {id: 123456789, status: 'ready'});
});
// Tests that TelemetryInfo can be successfully requested from
// from chrome-untrusted://.
UNTRUSTED_TEST('UntrustedRequestTelemetryInfo', async () => {