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

[Telemetry SWX] Add cpu cache routine

Add implementation to chrome://.

Add implementation to chrome-untrusted://.

Add tests.

Bug: b:162051831
Change-Id: I6b8b702b1e4e335786b365ce4ca00c29195ae191
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375285
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@{#804934}
parent d1001b89
......@@ -120,4 +120,18 @@ void DiagnosticsService::RunAcPowerRoutine(
std::move(callback)));
}
void DiagnosticsService::RunCpuCacheRoutine(
uint32_t length_seconds,
RunCpuCacheRoutineCallback callback) {
GetService()->RunCpuCacheRoutine(
length_seconds,
base::BindOnce(
[](health::mojom::DiagnosticsService::RunCpuCacheRoutineCallback
callback,
cros_healthd::mojom::RunRoutineResponsePtr ptr) {
std::move(callback).Run(converters::ConvertPtr(std::move(ptr)));
},
std::move(callback)));
}
} // namespace chromeos
......@@ -44,6 +44,8 @@ class DiagnosticsService : public health::mojom::DiagnosticsService {
void RunAcPowerRoutine(health::mojom::AcPowerStatusEnum expected_status,
const base::Optional<std::string>& expected_power_type,
RunAcPowerRoutineCallback callback) override;
void RunCpuCacheRoutine(uint32_t length_seconds,
RunCpuCacheRoutineCallback callback) override;
// Ensures that |service_| created and connected to the
// CrosHealthdProbeService.
......
......@@ -102,6 +102,22 @@ interface DiagnosticsService {
RunAcPowerRoutine(AcPowerStatusEnum expected_status,
string? expected_power_type)
=> (RunRoutineResponse response);
// Requests that the CPU cache routine is created and started on the
// platform. This routine runs the stressapptest to test the CPU caches.
// The routine will pass if the stressapptest returns zero. This routine is
// only available if GetAvailableRoutines returned kCpuCache.
//
// The request:
// * |length_seconds| - length of time, in seconds, to run the CPU cache
// routine. This parameter needs to be strictly greater
// than zero.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunCpuCacheRoutine(uint32 length_seconds)
=> (RunRoutineResponse response);
};
// Enumeration of each of the diagnostics routines the platform may support.
......
......@@ -27,6 +27,7 @@ dpsl_internal.Message = {
DIAGNOSTICS_RUN_SMARTCTL_CHECK_ROUTINE:
'DiagnosticsService.RunSmartctlCheckRoutine',
DIAGNOSTICS_RUN_AC_POWER_ROUTINE: 'DiagnosticsService.RunAcPowerRoutine',
DIAGNOSTICS_RUN_CPU_CACHE_ROUTINE: 'DiagnosticsService.RunCpuCacheRoutine',
PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo',
};
......@@ -95,6 +96,13 @@ dpsl_internal.DiagnosticsRunSmartctlCheckRoutineRequest;
*/
dpsl_internal.DiagnosticsRunAcPowerRoutineRequest;
/**
* Request message sent by the unprivileged context to the privileged
* context to run cpu cache routine.
* @typedef {{ duration: !number }}
*/
dpsl_internal.DiagnosticsRunCpuCacheRoutineRequest;
/**
* Response message sent by the privileged context containing routine
* information.
......
......@@ -369,6 +369,29 @@ class DiagnosticsProxy {
return await getOrCreateDiagnosticsService().runAcPowerRoutine(
expectedStatus, request.expectedPowerType);
};
/**
* @param { !number } number
*/
assertNumberIsPositive(number) {
if (number <= 0) {
throw RangeError(`Parameter must be positive.`);
}
}
/**
* Runs cpu cache routine.
* @param { !Object } message
* @return { !RunRoutineResponsePromise }
*/
async handleRunCpuCacheRoutine(message) {
const request =
/** @type {!dpsl_internal.DiagnosticsRunCpuCacheRoutineRequest} */ (
message);
this.assertNumberIsPositive(request.duration);
return await getOrCreateDiagnosticsService().runCpuCacheRoutine(
request.duration);
};
};
const diagnosticsProxy = new DiagnosticsProxy();
......@@ -672,6 +695,12 @@ untrustedMessagePipe.registerHandler(
(message) => diagnosticsProxy.handleRunAcPowerRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.DIAGNOSTICS_RUN_CPU_CACHE_ROUTINE,
(message) => diagnosticsProxy.genericRunRoutineHandler(
(message) => diagnosticsProxy.handleRunCpuCacheRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.PROBE_TELEMETRY_INFO,
(message) => telemetryProxy.handleProbeTelemetryInfo(message));
......@@ -162,6 +162,26 @@ chromeos.test_support = {};
}
return response;
}
/**
* Requests cpu cache routine to be run for duration seconds.
* @param { !number } duration
* @return { !Promise<!Object> }
* @public
*/
async runCpuCacheRoutine(duration) {
const message =
/** @type {!dpsl_internal.DiagnosticsRunCpuCacheRoutineRequest} */ (
{duration: duration});
const response =
/** @type {!Object} */ (await messagePipe.sendMessage(
dpsl_internal.Message.DIAGNOSTICS_RUN_CPU_CACHE_ROUTINE,
message));
if (response instanceof Error) {
throw response;
}
return response;
}
};
/**
......
......@@ -392,6 +392,21 @@ TEST_F(
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunCpuCacheRoutineInvalidInput', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunCpuCacheRoutineInvalidInput');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunCpuCacheRoutine', async () => {
await runTestInUntrusted('UntrustedDiagnosticsRequestRunCpuCacheRoutine');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedRequestTelemetryInfoUnknownCategory', async () => {
......
......@@ -184,6 +184,27 @@ UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunAcPowerRoutine', async () => {
assertDeepEquals(response3, {id: 123456789, status: 'ready'});
});
// Tests that runCpuCacheRoutine throws the correct error
// when invalid number is passed as input.
UNTRUSTED_TEST(
'UntrustedDiagnosticsRequestRunCpuCacheRoutineInvalidInput', async () => {
let caughtError;
try {
await chromeos.diagnostics.runCpuCacheRoutine(0);
} catch (error) {
caughtError = error;
}
assertEquals(caughtError.name, 'RangeError');
assertEquals(caughtError.message, `Parameter must be positive.`);
});
// Tests that runCpuCacheRoutine returns the correct Object.
UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunCpuCacheRoutine', async () => {
const response = await chromeos.diagnostics.runCpuCacheRoutine(10);
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