summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYicheng Li <yichengli@chromium.org>2019-05-22 13:47:14 -0700
committerCommit Bot <commit-bot@chromium.org>2019-06-07 22:45:22 +0000
commit8e7a7fb6cf9e7afcd1b80911c14ae76e8b9860fc (patch)
treed7b36abb4f7c6f9e4244f8c022b6f0119e070073 /test
parent9985215ea27b059e83870d4f7f93918ae058c2dd (diff)
downloadchrome-ec-8e7a7fb6cf9e7afcd1b80911c14ae76e8b9860fc.tar.gz
fpsensor: Add API to check FP sensor encryption status.
Add EC command for the host to query FP sensor encryption status. Currently it's just FP TPM seed has been set or not. Add unit test for this command. Also add ectool command for querying encryption status. BRANCH=nocturne BUG=chromium:952275 TEST=ran unittests TEST=tested enrollment, matching and multifinger on DUT nocturne. TEST=tested querying sensor encryption status using ectool. Change-Id: I07d1e471ead85a517105b38d1ddd793c3046ce8f Signed-off-by: Yicheng Li <yichengli@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1633272 Reviewed-by: Nicolas Norvez <norvez@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk2
-rw-r--r--test/fpsensor.c105
-rw-r--r--test/fpsensor.tasklist11
3 files changed, 118 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk
index 93ae9d405a..f3fc169bc0 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -32,6 +32,7 @@ test-list-host += flash
test-list-host += flash_log
test-list-host += float
test-list-host += fp
+test-list-host += fpsensor
test-list-host += hooks
test-list-host += host_command
test-list-host += inductive_charging
@@ -98,6 +99,7 @@ extpwr_gpio-y=extpwr_gpio.o
fan-y=fan.o
flash-y=flash.o
flash_log-y=flash_log.o
+fpsensor-y=fpsensor.o
hooks-y=hooks.o
host_command-y=host_command.o
inductive_charging-y=inductive_charging.o
diff --git a/test/fpsensor.c b/test/fpsensor.c
new file mode 100644
index 0000000000..82e68ffe94
--- /dev/null
+++ b/test/fpsensor.c
@@ -0,0 +1,105 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+#include "ec_commands.h"
+#include "fpsensor_state.h"
+#include "host_command.h"
+#include "test_util.h"
+#include "util.h"
+
+static int check_fp_enc_status_valid_flags(const uint32_t expected)
+{
+ int rv;
+ struct ec_response_fp_encryption_status resp = { 0 };
+
+ rv = test_send_host_command(EC_CMD_FP_ENC_STATUS, 0,
+ NULL, 0,
+ &resp, sizeof(resp));
+ if (rv != EC_RES_SUCCESS) {
+ ccprintf("%s:%s(): failed to get encryption status. rv = %d\n",
+ __FILE__, __func__, rv);
+ return -1;
+ }
+
+ if (resp.valid_flags != expected) {
+ ccprintf("%s:%s(): expected valid flags 0x%08x, got 0x%08x\n",
+ __FILE__, __func__, expected, resp.valid_flags);
+ return -1;
+ }
+
+ return EC_RES_SUCCESS;
+}
+
+static int check_fp_tpm_seed_not_set(void)
+{
+ int rv;
+ struct ec_response_fp_encryption_status resp = { 0 };
+
+ /* Initially the seed should not have been set. */
+ rv = test_send_host_command(EC_CMD_FP_ENC_STATUS, 0,
+ NULL, 0,
+ &resp, sizeof(resp));
+ if (rv != EC_RES_SUCCESS || resp.status & FP_ENC_STATUS_SEED_SET) {
+ ccprintf("%s:%s(): rv = %d, seed is set: %d\n", __FILE__,
+ __func__, rv, resp.status & FP_ENC_STATUS_SEED_SET);
+ return -1;
+ }
+
+ return EC_RES_SUCCESS;
+}
+
+static int set_fp_tpm_seed(void)
+{
+ /*
+ * TODO(yichengli): test setting the seed twice:
+ * the second time fails;
+ * the seed is still set.
+ */
+ int rv;
+ struct ec_params_fp_seed params;
+ struct ec_response_fp_encryption_status resp = { 0 };
+
+ params.struct_version = FP_TEMPLATE_FORMAT_VERSION;
+ params.seed[0] = 0;
+
+ rv = test_send_host_command(EC_CMD_FP_SEED, 0,
+ &params, sizeof(params),
+ NULL, 0);
+ if (rv != EC_RES_SUCCESS) {
+ ccprintf("%s:%s(): rv = %d, set seed failed\n",
+ __FILE__, __func__, rv);
+ return -1;
+ }
+
+ /* Now seed should have been set. */
+ rv = test_send_host_command(EC_CMD_FP_ENC_STATUS, 0,
+ NULL, 0,
+ &resp, sizeof(resp));
+ if (rv != EC_RES_SUCCESS || !(resp.status & FP_ENC_STATUS_SEED_SET)) {
+ ccprintf("%s:%s(): rv = %d, seed is set: %d\n", __FILE__,
+ __func__, rv, resp.status & FP_ENC_STATUS_SEED_SET);
+ return -1;
+ }
+
+ return EC_RES_SUCCESS;
+}
+
+test_static int test_fpsensor(void)
+{
+ TEST_ASSERT(check_fp_enc_status_valid_flags(FP_ENC_STATUS_SEED_SET) ==
+ EC_RES_SUCCESS);
+ TEST_ASSERT(check_fp_tpm_seed_not_set() == EC_RES_SUCCESS);
+ TEST_ASSERT(set_fp_tpm_seed() == EC_RES_SUCCESS);
+
+ return EC_SUCCESS;
+}
+
+void run_test(void)
+{
+ RUN_TEST(test_fpsensor);
+
+ test_print_result();
+}
diff --git a/test/fpsensor.tasklist b/test/fpsensor.tasklist
new file mode 100644
index 0000000000..bee999ff6b
--- /dev/null
+++ b/test/fpsensor.tasklist
@@ -0,0 +1,11 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST \
+ TASK_TEST(FPSENSOR, fp_task_simulate, NULL, TASK_STACK_SIZE)
+