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

[Telemetry SWX] Add cpu stress routine

Add implementation to chrome://.

Add implementation to chrome-untrusted://.

Add tests.

Bug: b:162051831
Change-Id: Ib74ab98c7f04208b2206f8fe0988a79ee0aa87e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375286
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@{#805308}
parent 6ff3114a
......@@ -134,4 +134,18 @@ void DiagnosticsService::RunCpuCacheRoutine(
std::move(callback)));
}
void DiagnosticsService::RunCpuStressRoutine(
uint32_t length_seconds,
RunCpuStressRoutineCallback callback) {
GetService()->RunCpuStressRoutine(
length_seconds,
base::BindOnce(
[](health::mojom::DiagnosticsService::RunCpuStressRoutineCallback
callback,
cros_healthd::mojom::RunRoutineResponsePtr ptr) {
std::move(callback).Run(converters::ConvertPtr(std::move(ptr)));
},
std::move(callback)));
}
} // namespace chromeos
......@@ -46,6 +46,8 @@ class DiagnosticsService : public health::mojom::DiagnosticsService {
RunAcPowerRoutineCallback callback) override;
void RunCpuCacheRoutine(uint32_t length_seconds,
RunCpuCacheRoutineCallback callback) override;
void RunCpuStressRoutine(uint32_t length_seconds,
RunCpuStressRoutineCallback callback) override;
// Ensures that |service_| created and connected to the
// CrosHealthdProbeService.
......
......@@ -118,6 +118,22 @@ interface DiagnosticsService {
// routine.
RunCpuCacheRoutine(uint32 length_seconds)
=> (RunRoutineResponse response);
// Requests that the CPU stress routine is created and started on the
// platform. This routine runs the stressapptest to stress test the CPU.
// The routine will pass if the stressapptest returns zero. This routine is
// only available if GetAvailableRoutines returned kCpuStress.
//
// The request:
// * |length_seconds| - length of time, in seconds, to run the CPU stress
// routine. This parameter needs to be strictly greater
// than zero.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunCpuStressRoutine(uint32 length_seconds)
=> (RunRoutineResponse response);
};
// Enumeration of each of the diagnostics routines the platform may support.
......
......@@ -28,6 +28,7 @@ dpsl_internal.Message = {
'DiagnosticsService.RunSmartctlCheckRoutine',
DIAGNOSTICS_RUN_AC_POWER_ROUTINE: 'DiagnosticsService.RunAcPowerRoutine',
DIAGNOSTICS_RUN_CPU_CACHE_ROUTINE: 'DiagnosticsService.RunCpuCacheRoutine',
DIAGNOSTICS_RUN_CPU_STRESS_ROUTINE: 'DiagnosticsService.RunCpuStressRoutine',
PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo',
};
......@@ -103,6 +104,13 @@ dpsl_internal.DiagnosticsRunAcPowerRoutineRequest;
*/
dpsl_internal.DiagnosticsRunCpuCacheRoutineRequest;
/**
* Request message sent by the unprivileged context to the privileged
* context to run cpu stress routine.
* @typedef {{ duration: !number }}
*/
dpsl_internal.DiagnosticsRunCpuStressRoutineRequest;
/**
* Response message sent by the privileged context containing routine
* information.
......
......@@ -392,6 +392,20 @@ class DiagnosticsProxy {
return await getOrCreateDiagnosticsService().runCpuCacheRoutine(
request.duration);
};
/**
* Runs cpu stress routine.
* @param { !Object } message
* @return { !RunRoutineResponsePromise }
*/
async handleRunCpuStressRoutine(message) {
const request =
/** @type {!dpsl_internal.DiagnosticsRunCpuStressRoutineRequest} */ (
message);
this.assertNumberIsPositive(request.duration);
return await getOrCreateDiagnosticsService().runCpuStressRoutine(
request.duration);
};
};
const diagnosticsProxy = new DiagnosticsProxy();
......@@ -701,6 +715,12 @@ untrustedMessagePipe.registerHandler(
(message) => diagnosticsProxy.handleRunCpuCacheRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.DIAGNOSTICS_RUN_CPU_STRESS_ROUTINE,
(message) => diagnosticsProxy.genericRunRoutineHandler(
(message) => diagnosticsProxy.handleRunCpuStressRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.PROBE_TELEMETRY_INFO,
(message) => telemetryProxy.handleProbeTelemetryInfo(message));
......@@ -182,6 +182,26 @@ chromeos.test_support = {};
}
return response;
}
/**
* Requests cpu stress routine to be run for duration seconds.
* @param { !number } duration
* @return { !Promise<!Object> }
* @public
*/
async runCpuStressRoutine(duration) {
const message =
/** @type {!dpsl_internal.DiagnosticsRunCpuStressRoutineRequest} */ (
{duration: duration});
const response =
/** @type {!Object} */ (await messagePipe.sendMessage(
dpsl_internal.Message.DIAGNOSTICS_RUN_CPU_STRESS_ROUTINE,
message));
if (response instanceof Error) {
throw response;
}
return response;
}
};
/**
......
......@@ -407,6 +407,22 @@ TEST_F(
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunCpuStressRoutineInvalidInput', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunCpuStressRoutineInvalidInput');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunCpuStressRoutine', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunCpuStressRoutine');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedRequestTelemetryInfoUnknownCategory', async () => {
......
......@@ -205,6 +205,27 @@ UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunCpuCacheRoutine', async () => {
assertDeepEquals(response, {id: 123456789, status: 'ready'});
});
// Tests that runCpuStressRoutine throws the correct error when invalid number
// is passed as input.
UNTRUSTED_TEST(
'UntrustedDiagnosticsRequestRunCpuStressRoutineInvalidInput', async () => {
let caughtError;
try {
await chromeos.diagnostics.runCpuStressRoutine(0);
} catch (error) {
caughtError = error;
}
assertEquals(caughtError.name, 'RangeError');
assertEquals(caughtError.message, `Parameter must be positive.`);
});
// Tests that runCpuStressRoutine returns the correct Object.
UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunCpuStressRoutine', async () => {
const response = await chromeos.diagnostics.runCpuStressRoutine(5);
assertDeepEquals(response, {id: 123456789, status: 'ready'});
});
// Tests that TelemetryInfo can be successfully requested from
// from chrome-untrusted://.
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