Commit ed88c72e authored by Andrei-Laurențiu Olteanu's avatar Andrei-Laurențiu Olteanu Committed by Commit Bot

[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: default avatarMahmoud Gawad <mgawad@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Cr-Commit-Position: refs/heads/master@{#805747}
parent 13b60e60
...@@ -148,4 +148,18 @@ void DiagnosticsService::RunCpuStressRoutine( ...@@ -148,4 +148,18 @@ void DiagnosticsService::RunCpuStressRoutine(
std::move(callback))); 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 } // namespace chromeos
...@@ -48,6 +48,9 @@ class DiagnosticsService : public health::mojom::DiagnosticsService { ...@@ -48,6 +48,9 @@ class DiagnosticsService : public health::mojom::DiagnosticsService {
RunCpuCacheRoutineCallback callback) override; RunCpuCacheRoutineCallback callback) override;
void RunCpuStressRoutine(uint32_t length_seconds, void RunCpuStressRoutine(uint32_t length_seconds,
RunCpuStressRoutineCallback callback) override; RunCpuStressRoutineCallback callback) override;
void RunFloatingPointAccuracyRoutine(
uint32_t length_seconds,
RunFloatingPointAccuracyRoutineCallback callback) override;
// Ensures that |service_| created and connected to the // Ensures that |service_| created and connected to the
// CrosHealthdProbeService. // CrosHealthdProbeService.
......
...@@ -134,6 +134,25 @@ interface DiagnosticsService { ...@@ -134,6 +134,25 @@ interface DiagnosticsService {
// routine. // routine.
RunCpuStressRoutine(uint32 length_seconds) RunCpuStressRoutine(uint32 length_seconds)
=> (RunRoutineResponse response); => (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. // Enumeration of each of the diagnostics routines the platform may support.
......
...@@ -29,6 +29,8 @@ dpsl_internal.Message = { ...@@ -29,6 +29,8 @@ dpsl_internal.Message = {
DIAGNOSTICS_RUN_AC_POWER_ROUTINE: 'DiagnosticsService.RunAcPowerRoutine', DIAGNOSTICS_RUN_AC_POWER_ROUTINE: 'DiagnosticsService.RunAcPowerRoutine',
DIAGNOSTICS_RUN_CPU_CACHE_ROUTINE: 'DiagnosticsService.RunCpuCacheRoutine', DIAGNOSTICS_RUN_CPU_CACHE_ROUTINE: 'DiagnosticsService.RunCpuCacheRoutine',
DIAGNOSTICS_RUN_CPU_STRESS_ROUTINE: 'DiagnosticsService.RunCpuStressRoutine', DIAGNOSTICS_RUN_CPU_STRESS_ROUTINE: 'DiagnosticsService.RunCpuStressRoutine',
DIAGNOSTICS_RUN_FP_ACCURACY_ROUTINE:
'DiagnosticsService.RunFloatingPointAccuraryRoutine',
PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo', PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo',
}; };
...@@ -111,6 +113,13 @@ dpsl_internal.DiagnosticsRunCpuCacheRoutineRequest; ...@@ -111,6 +113,13 @@ dpsl_internal.DiagnosticsRunCpuCacheRoutineRequest;
*/ */
dpsl_internal.DiagnosticsRunCpuStressRoutineRequest; 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 * Response message sent by the privileged context containing routine
* information. * information.
......
...@@ -406,6 +406,20 @@ class DiagnosticsProxy { ...@@ -406,6 +406,20 @@ class DiagnosticsProxy {
return await getOrCreateDiagnosticsService().runCpuStressRoutine( return await getOrCreateDiagnosticsService().runCpuStressRoutine(
request.duration); 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(); const diagnosticsProxy = new DiagnosticsProxy();
...@@ -721,6 +735,13 @@ untrustedMessagePipe.registerHandler( ...@@ -721,6 +735,13 @@ untrustedMessagePipe.registerHandler(
(message) => diagnosticsProxy.handleRunCpuStressRoutine(message), (message) => diagnosticsProxy.handleRunCpuStressRoutine(message),
message)); message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.DIAGNOSTICS_RUN_FP_ACCURACY_ROUTINE,
(message) => diagnosticsProxy.genericRunRoutineHandler(
(message) =>
diagnosticsProxy.handleRunFloatingPointAccuracyRoutine(message),
message));
untrustedMessagePipe.registerHandler( untrustedMessagePipe.registerHandler(
dpsl_internal.Message.PROBE_TELEMETRY_INFO, dpsl_internal.Message.PROBE_TELEMETRY_INFO,
(message) => telemetryProxy.handleProbeTelemetryInfo(message)); (message) => telemetryProxy.handleProbeTelemetryInfo(message));
...@@ -202,6 +202,26 @@ chromeos.test_support = {}; ...@@ -202,6 +202,26 @@ chromeos.test_support = {};
} }
return response; 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( ...@@ -423,6 +423,22 @@ TEST_F(
testDone(); testDone();
}); });
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunFPAccuracyRoutineInvalidInput', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunFPAccuracyRoutineInvalidInput');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunFPAccuracyRoutine', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunFPAccuracyRoutine');
testDone();
});
TEST_F( TEST_F(
'TelemetryExtensionUIBrowserTest', 'TelemetryExtensionUIBrowserTest',
'UntrustedRequestTelemetryInfoUnknownCategory', async () => { 'UntrustedRequestTelemetryInfoUnknownCategory', async () => {
......
...@@ -226,6 +226,38 @@ UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunCpuStressRoutine', async () => { ...@@ -226,6 +226,38 @@ UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunCpuStressRoutine', async () => {
assertDeepEquals(response, {id: 123456789, status: 'ready'}); 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 // Tests that TelemetryInfo can be successfully requested from
// from chrome-untrusted://. // from chrome-untrusted://.
UNTRUSTED_TEST('UntrustedRequestTelemetryInfo', async () => { UNTRUSTED_TEST('UntrustedRequestTelemetryInfo', async () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment