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

[Telemetry SWX] Add prime search routine

Add implementation to chrome://.

Add implementation to chrome-untrusted://.

Add tests.

Bug: b:162051831
Change-Id: I2e2ab47f24ea29929a38a1d4ca406d15f2845ccb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414279Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Commit-Queue: Laurențiu Olteanu <lolteanu@google.com>
Cr-Commit-Position: refs/heads/master@{#809242}
parent c31527fa
......@@ -190,4 +190,19 @@ void DiagnosticsService::RunNvmeSelfTestRoutine(
std::move(callback)));
}
void DiagnosticsService::RunPrimeSearchRoutine(
uint32_t length_seconds,
uint64_t max_num,
RunPrimeSearchRoutineCallback callback) {
GetService()->RunPrimeSearchRoutine(
length_seconds, max_num,
base::BindOnce(
[](health::mojom::DiagnosticsService::RunPrimeSearchRoutineCallback
callback,
cros_healthd::mojom::RunRoutineResponsePtr ptr) {
std::move(callback).Run(converters::ConvertPtr(std::move(ptr)));
},
std::move(callback)));
}
} // namespace chromeos
......@@ -63,6 +63,9 @@ class DiagnosticsService : public health::mojom::DiagnosticsService {
void RunNvmeSelfTestRoutine(
health::mojom::NvmeSelfTestTypeEnum nvme_self_test_type,
RunNvmeSelfTestRoutineCallback callback) override;
void RunPrimeSearchRoutine(uint32_t length_seconds,
uint64_t max_num,
RunPrimeSearchRoutineCallback callback) override;
// Pointer to real implementation.
mojo::Remote<cros_healthd::mojom::CrosHealthdDiagnosticsService> service_;
......
......@@ -183,6 +183,24 @@ interface DiagnosticsService {
// routine.
RunNvmeSelfTestRoutine(NvmeSelfTestTypeEnum nvme_self_test_type)
=> (RunRoutineResponse response);
// Requests that the PrimeSearch routine is created and started on the
// platform. Calculate prime numbers between 2 to max_num and verify the
// calculation repeatedly in a duration. This routine is only available
// if GetAvailableRoutines returned kPrimeSearch.
//
// The request:
// * |length_seconds| - length of time, in seconds, to run the PrimeSearch
// routine for. This parameter needs to be strictly
// greater than zero.
// * |max_num| - largest number that routine will calculate prime numbers up
// to.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunPrimeSearchRoutine(uint32 length_seconds, uint64 max_num)
=> (RunRoutineResponse response);
};
// Enumeration of each of the diagnostics routines the platform may support.
......
......@@ -35,6 +35,8 @@ dpsl_internal.Message = {
'DiagnosticsService.RunNvmeWearLevelRoutine',
DIAGNOSTICS_RUN_NVME_SELF_TEST_ROUTINE:
'DiagnosticsService.RunNvmeSelfTestRoutine',
DIAGNOSTICS_RUN_PRIME_SEARCH_ROUTINE:
'DiagnosticsService.RunPrimeSearchRoutine',
PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo',
};
......@@ -138,6 +140,15 @@ dpsl_internal.DiagnosticsRunNvmeWearLevelRoutineRequest;
*/
dpsl_internal.DiagnosticsRunNvmeSelfTestRoutineRequest;
/**
* Request message sent by the unprivileged context to the privileged
* context to run prime search routine.
* @typedef {{
* lengthSeconds: !number,
* maximumNumber: !number}}
*/
dpsl_internal.DiagnosticsRunPrimeSearchRoutineRequest;
/**
* Response message sent by the privileged context containing routine
* information.
......
......@@ -476,6 +476,20 @@ class DiagnosticsProxy {
return await getOrCreateDiagnosticsService().runNvmeSelfTestRoutine(
this.convertNvmeSelfTestTypeToEnum(request.nvmeSelfTestType));
};
/**
* Runs prime search routine.
* @param { !Object } message
* @return { !RunRoutineResponsePromise }
*/
async handleRunPrimeSearchRoutine(message) {
const request =
/** @type {!dpsl_internal.DiagnosticsRunPrimeSearchRoutineRequest} */
(message);
this.assertNumberIsPositive(request.lengthSeconds);
return await getOrCreateDiagnosticsService().runPrimeSearchRoutine(
request.lengthSeconds, request.maximumNumber);
};
};
const diagnosticsProxy = new DiagnosticsProxy();
......@@ -810,6 +824,12 @@ untrustedMessagePipe.registerHandler(
(message) => diagnosticsProxy.handleRunNvmeSelfTestRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.DIAGNOSTICS_RUN_PRIME_SEARCH_ROUTINE,
(message) => diagnosticsProxy.genericRunRoutineHandler(
(message) => diagnosticsProxy.handleRunPrimeSearchRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.PROBE_TELEMETRY_INFO,
(message) => telemetryProxy.handleProbeTelemetryInfo(message));
......@@ -266,6 +266,29 @@ chromeos.test_support = {};
}
return response;
}
/**
* Requests prime search routine to be run.
* @param { !number } lengthSeconds
* @param { !number } maximumNumber
* @return { !Promise<!Object> }
* @public
*/
async runPrimeSearchRoutine(lengthSeconds, maximumNumber) {
const message =
/**
@type {!dpsl_internal.DiagnosticsRunPrimeSearchRoutineRequest}
*/
({lengthSeconds: lengthSeconds, maximumNumber: maximumNumber});
const response =
/** @type {!Object} */ (await messagePipe.sendMessage(
dpsl_internal.Message.DIAGNOSTICS_RUN_PRIME_SEARCH_ROUTINE,
message));
if (response instanceof Error) {
throw response;
}
return response;
}
};
/**
......
......@@ -391,6 +391,8 @@ const untrustedTests = [
['UntrustedDiagnosticsRequestRunNvmeWearLevelRoutine'],
['UntrustedDiagnosticsRequestRunNvmeSelfTestRoutineInvalidInput'],
['UntrustedDiagnosticsRequestRunNvmeSelfTestRoutine'],
['UntrustedDiagnosticsRequestRunPrimeSearchRoutineInvalidInput'],
['UntrustedDiagnosticsRequestRunPrimeSearchRoutine'],
['UntrustedRequestTelemetryInfoUnknownCategory'],
['UntrustedRequestTelemetryInfo'],
[
......
......@@ -295,6 +295,39 @@ UNTRUSTED_TEST('UntrustedRequestTelemetryInfoUnknownCategory', async () => {
'Telemetry category \'unknown-category\' is unknown.');
});
// Tests that runPrimeSearchRoutine throws the correct error when invalid enum
// is passed as input.
UNTRUSTED_TEST(
'UntrustedDiagnosticsRequestRunPrimeSearchRoutineInvalidInput',
async () => {
let caughtError1;
try {
await chromeos.diagnostics.runPrimeSearchRoutine(0, 10);
} catch (error) {
caughtError1 = error;
}
assertEquals(caughtError1.name, 'RangeError');
assertEquals(caughtError1.message, `Parameter must be positive.`);
let caughtError2;
try {
await chromeos.diagnostics.runPrimeSearchRoutine(-2147483648, 128);
} catch (error) {
caughtError2 = error;
}
assertEquals(caughtError2.name, 'RangeError');
assertEquals(caughtError2.message, `Parameter must be positive.`);
});
// Tests that runPrimeSearchRoutine returns the correct Object.
UNTRUSTED_TEST('UntrustedDiagnosticsRequestRunPrimeSearchRoutine', async () => {
const response =
await chromeos.diagnostics.runPrimeSearchRoutine(12, 1110987654321);
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