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

[Telemetry SWX] Add nvme self test routine

Add implementation to chrome://.

Add implementation to chrome-untrusted://.

Add tests.

Bug: b:162051831
Change-Id: I3749503e240a14b1d4ff76cfd3c477470ae704c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2396089
Commit-Queue: Laurențiu Olteanu <lolteanu@google.com>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Cr-Commit-Position: refs/heads/master@{#806697}
parent 98cc07c2
......@@ -176,4 +176,18 @@ void DiagnosticsService::RunNvmeWearLevelRoutine(
std::move(callback)));
}
void DiagnosticsService::RunNvmeSelfTestRoutine(
health::mojom::NvmeSelfTestTypeEnum nvme_self_test_type,
RunNvmeSelfTestRoutineCallback callback) {
GetService()->RunNvmeSelfTestRoutine(
converters::Convert(nvme_self_test_type),
base::BindOnce(
[](health::mojom::DiagnosticsService::RunNvmeSelfTestRoutineCallback
callback,
cros_healthd::mojom::RunRoutineResponsePtr ptr) {
std::move(callback).Run(converters::ConvertPtr(std::move(ptr)));
},
std::move(callback)));
}
} // namespace chromeos
......@@ -54,6 +54,9 @@ class DiagnosticsService : public health::mojom::DiagnosticsService {
void RunNvmeWearLevelRoutine(
uint32_t wear_level_threshold,
RunNvmeWearLevelRoutineCallback callback) override;
void RunNvmeSelfTestRoutine(
health::mojom::NvmeSelfTestTypeEnum nvme_self_test_type,
RunNvmeSelfTestRoutineCallback callback) override;
// Ensures that |service_| created and connected to the
// CrosHealthdProbeService.
......
......@@ -188,5 +188,19 @@ cros_healthd::mojom::AcPowerStatusEnum Convert(
static_cast<int>(cros_healthd::mojom::AcPowerStatusEnum::kMaxValue) + 1);
}
cros_healthd::mojom::NvmeSelfTestTypeEnum Convert(
health::mojom::NvmeSelfTestTypeEnum input) {
switch (input) {
case health::mojom::NvmeSelfTestTypeEnum::kShortSelfTest:
return cros_healthd::mojom::NvmeSelfTestTypeEnum::kShortSelfTest;
case health::mojom::NvmeSelfTestTypeEnum::kLongSelfTest:
return cros_healthd::mojom::NvmeSelfTestTypeEnum::kLongSelfTest;
}
NOTREACHED();
return static_cast<cros_healthd::mojom::NvmeSelfTestTypeEnum>(
static_cast<int>(cros_healthd::mojom::NvmeSelfTestTypeEnum::kMaxValue) +
1);
}
} // namespace converters
} // namespace chromeos
......@@ -59,6 +59,9 @@ std::string Convert(mojo::ScopedHandle handle);
cros_healthd::mojom::AcPowerStatusEnum Convert(
health::mojom::AcPowerStatusEnum input);
cros_healthd::mojom::NvmeSelfTestTypeEnum Convert(
health::mojom::NvmeSelfTestTypeEnum input);
} // namespace converters
} // namespace chromeos
......
......@@ -76,5 +76,15 @@ TEST(DiagnosticsServiceConvertersTest, ConvertAcPowerStatusEnum) {
cros_healthd::AcPowerStatusEnum::kDisconnected);
}
TEST(DiagnosticsServiceConvertersTest, ConvertNvmeSelfTestTypeEnum) {
namespace cros_healthd = ::chromeos::cros_healthd::mojom;
namespace health = ::chromeos::health::mojom;
EXPECT_EQ(Convert(health::NvmeSelfTestTypeEnum::kShortSelfTest),
cros_healthd::NvmeSelfTestTypeEnum::kShortSelfTest);
EXPECT_EQ(Convert(health::NvmeSelfTestTypeEnum::kLongSelfTest),
cros_healthd::NvmeSelfTestTypeEnum::kLongSelfTest);
}
} // namespace converters
} // namespace chromeos
......@@ -168,6 +168,21 @@ interface DiagnosticsService {
// routine.
RunNvmeWearLevelRoutine(uint32 wear_level_threshold)
=> (RunRoutineResponse response);
// Requests that the NvmeSelfTest routine is created and started on the
// platform. This routine launches the NVMe self-test, a tool to perform
// necessary tests to observe the performance and the parameters. This routine
// is only available if GetAvailableRoutines returned kNvmeSelfTest.
//
// The request:
// * |nvme_self_test_type| - specifies the type of test for short period or
// extended version.
//
// The response:
// * |response| - contains a unique identifier and status for the created
// routine.
RunNvmeSelfTestRoutine(NvmeSelfTestTypeEnum nvme_self_test_type)
=> (RunRoutineResponse response);
};
// Enumeration of each of the diagnostics routines the platform may support.
......@@ -281,3 +296,10 @@ enum AcPowerStatusEnum {
kConnected = 0, // Power supply is connected.
kDisconnected = 1, // Power supply is disconnected.
};
// Enumeration of the self-test type in nvme_self_test routine
[Extensible]
enum NvmeSelfTestTypeEnum {
kShortSelfTest = 0, // Short time self-test.
kLongSelfTest = 1, // Long time self-test.
};
......@@ -33,6 +33,8 @@ dpsl_internal.Message = {
'DiagnosticsService.RunFloatingPointAccuraryRoutine',
DIAGNOSTICS_RUN_NVME_WEAR_LEVEL_ROUTINE:
'DiagnosticsService.RunNvmeWearLevelRoutine',
DIAGNOSTICS_RUN_NVME_SELF_TEST_ROUTINE:
'DiagnosticsService.RunNvmeSelfTestRoutine',
PROBE_TELEMETRY_INFO: 'ProbeService.ProbeTelemetryInfo',
};
......@@ -129,6 +131,13 @@ dpsl_internal.DiagnosticsRunFPAccuracyRoutineRequest;
*/
dpsl_internal.DiagnosticsRunNvmeWearLevelRoutineRequest;
/**
* Request message sent by the unprivileged context to the privileged
* context to run NVMe self test routine.
* @typedef {{ nvmeSelfTestType: !string }}
*/
dpsl_internal.DiagnosticsRunNvmeSelfTestRoutineRequest;
/**
* Response message sent by the privileged context containing routine
* information.
......
......@@ -146,6 +146,23 @@ class DiagnosticsProxy {
throw RangeError(
'acPowerStatusToEnum_ does not contain all items from enum!');
}
const nvmeSelfTestTypeEnum = chromeos.health.mojom.NvmeSelfTestTypeEnum;
/**
* @type { !Map<!string, !chromeos.health.mojom.NvmeSelfTestTypeEnum> }
* @const
*/
this.nvmeSelfTestTypeToEnum_ = new Map([
['short-self-test', nvmeSelfTestTypeEnum.kShortSelfTest],
['long-self-test', nvmeSelfTestTypeEnum.kLongSelfTest],
]);
if (this.nvmeSelfTestTypeToEnum_.size !==
nvmeSelfTestTypeEnum.MAX_VALUE + 1) {
throw RangeError(
'nvmeSelfTestTypeToEnum_ does not contain all items from enum!');
}
}
/**
......@@ -433,6 +450,33 @@ class DiagnosticsProxy {
return await getOrCreateDiagnosticsService().runNvmeWearLevelRoutine(
request.wearLevelThreshold);
};
/**
* Converts NVMe self test type string to NvmeSelfTestTypeEnum.
* @param { !string } nvmeSelfTestType
* @return { !chromeos.health.mojom.NvmeSelfTestTypeEnum }
*/
convertNvmeSelfTestTypeToEnum(nvmeSelfTestType) {
if (!this.nvmeSelfTestTypeToEnum_.has(nvmeSelfTestType)) {
throw TypeError(
`Diagnostic NVMe self test type '${nvmeSelfTestType}' is unknown.`);
}
return this.nvmeSelfTestTypeToEnum_.get(nvmeSelfTestType);
}
/**
* Runs NVMe self test routine.
* @param { !Object } message
* @return { !RunRoutineResponsePromise }
*/
async handleRunNvmeSelfTestRoutine(message) {
const request =
/** @type {!dpsl_internal.DiagnosticsRunNvmeSelfTestRoutineRequest} */
(message);
return await getOrCreateDiagnosticsService().runNvmeSelfTestRoutine(
this.convertNvmeSelfTestTypeToEnum(request.nvmeSelfTestType));
};
};
const diagnosticsProxy = new DiagnosticsProxy();
......@@ -761,6 +805,12 @@ untrustedMessagePipe.registerHandler(
(message) => diagnosticsProxy.handleRunNvmeWearLevelRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.DIAGNOSTICS_RUN_NVME_SELF_TEST_ROUTINE,
(message) => diagnosticsProxy.genericRunRoutineHandler(
(message) => diagnosticsProxy.handleRunNvmeSelfTestRoutine(message),
message));
untrustedMessagePipe.registerHandler(
dpsl_internal.Message.PROBE_TELEMETRY_INFO,
(message) => telemetryProxy.handleProbeTelemetryInfo(message));
......@@ -244,6 +244,28 @@ chromeos.test_support = {};
}
return response;
}
/**
* Requests NVMe self test routine to be run.
* @param { !string } nvmeSelfTestType
* @return { !Promise<!Object> }
* @public
*/
async runNvmeSelfTestRoutine(nvmeSelfTestType) {
const message =
/**
@type {!dpsl_internal.DiagnosticsRunNvmeSelfTestRoutineRequest}
*/
({nvmeSelfTestType: nvmeSelfTestType});
const response =
/** @type {!Object} */ (await messagePipe.sendMessage(
dpsl_internal.Message.DIAGNOSTICS_RUN_NVME_SELF_TEST_ROUTINE,
message));
if (response instanceof Error) {
throw response;
}
return response;
}
};
/**
......
......@@ -124,6 +124,15 @@ TEST_F('TelemetryExtensionUIBrowserTest', 'ConvertDiagnosticsEnums', () => {
diagnosticsProxy.convertPowerStatusToEnum('disconnected'),
acPowerStatusEnum.kDisconnected);
// Unit tests for convertNvmeSelfTestTypeToEnum
const nvmeSelfTestTypeEnum = chromeos.health.mojom.NvmeSelfTestTypeEnum;
assertEquals(
diagnosticsProxy.convertNvmeSelfTestTypeToEnum('short-self-test'),
nvmeSelfTestTypeEnum.kShortSelfTest);
assertEquals(
diagnosticsProxy.convertNvmeSelfTestTypeToEnum('long-self-test'),
nvmeSelfTestTypeEnum.kLongSelfTest);
testDone();
});
......@@ -447,6 +456,23 @@ TEST_F(
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunNvmeSelfTestRoutineInvalidInput',
async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunNvmeSelfTestRoutineInvalidInput');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedDiagnosticsRequestRunNvmeSelfTestRoutine', async () => {
await runTestInUntrusted(
'UntrustedDiagnosticsRequestRunNvmeSelfTestRoutine');
testDone();
});
TEST_F(
'TelemetryExtensionUIBrowserTest',
'UntrustedRequestTelemetryInfoUnknownCategory', async () => {
......
......@@ -265,6 +265,37 @@ UNTRUSTED_TEST(
assertDeepEquals(response, {id: 123456789, status: 'ready'});
});
// Tests that runNvmeSelfTestRoutine throws the correct error when invalid enum
// is passed as input.
UNTRUSTED_TEST(
'UntrustedDiagnosticsRequestRunNvmeSelfTestRoutineInvalidInput',
async () => {
let caughtError;
try {
await chromeos.diagnostics.runNvmeSelfTestRoutine(
'this-does-not-exist');
} catch (error) {
caughtError = error;
}
assertEquals(caughtError.name, 'TypeError');
assertEquals(
caughtError.message,
`Diagnostic NVMe self test type \'this-does-not-exist\' is unknown.`);
});
// Tests that runNvmeSelfTestRoutine returns the correct Object.
UNTRUSTED_TEST(
'UntrustedDiagnosticsRequestRunNvmeSelfTestRoutine', async () => {
const response1 =
await chromeos.diagnostics.runNvmeSelfTestRoutine('short-self-test');
assertDeepEquals(response1, {id: 123456789, status: 'ready'});
const response2 =
await chromeos.diagnostics.runNvmeSelfTestRoutine('long-self-test');
assertDeepEquals(response2, {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