summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2019-06-20 15:53:48 -0700
committerCommit Bot <commit-bot@chromium.org>2019-06-24 21:12:43 +0000
commitd28c0a87edee59d458b847fc5455b1c5cd698f15 (patch)
tree9dd24c1319c987d15522a43cdb4ddf2593dc9e21 /test
parent2a9ff55fe81d7fc7c86d62d5ca06aa4dbaf4f293 (diff)
downloadchrome-ec-d28c0a87edee59d458b847fc5455b1c5cd698f15.tar.gz
fpsensor: Add unit tests for fp_set_sensor_mode
BRANCH=nocturne BUG=b:124773209 TEST=make buildall -j Change-Id: I8337c708005c51435ce8a5ab5d536cccc604f850 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1670347 Reviewed-by: Nicolas Norvez <norvez@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/fpsensor.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/fpsensor.c b/test/fpsensor.c
index 66ca679b3d..fb60eec8df 100644
--- a/test/fpsensor.c
+++ b/test/fpsensor.c
@@ -239,12 +239,66 @@ test_static int test_fpsensor_seed(void)
return EC_SUCCESS;
}
+test_static int test_fp_set_sensor_mode(void)
+{
+ uint32_t requested_mode = 0;
+ uint32_t output_mode = 0;
+
+ /* Validate initial conditions */
+ TEST_ASSERT(FP_MAX_FINGER_COUNT == 5);
+ TEST_ASSERT(templ_valid == 0);
+ TEST_ASSERT(sensor_mode == 0);
+
+ /* GIVEN missing output parameter, THEN get error */
+ TEST_ASSERT(fp_set_sensor_mode(0, NULL) == EC_RES_INVALID_PARAM);
+ /* THEN sensor_mode is unchanged */
+ TEST_ASSERT(sensor_mode == 0);
+
+ /* GIVEN requested mode includes FP_MODE_DONT_CHANGE, THEN succeed */
+ TEST_ASSERT(sensor_mode == 0);
+ TEST_ASSERT(output_mode == 0);
+ requested_mode = FP_MODE_DONT_CHANGE;
+ TEST_ASSERT(fp_set_sensor_mode(requested_mode, &output_mode) ==
+ EC_RES_SUCCESS);
+ /* THEN sensor_mode is unchanged */
+ TEST_ASSERT(sensor_mode == 0);
+ /* THEN output_mode matches sensor_mode */
+ TEST_ASSERT(output_mode == sensor_mode);
+
+ /* GIVEN request to change to valid sensor mode */
+ TEST_ASSERT(sensor_mode == 0);
+ requested_mode = FP_MODE_ENROLL_SESSION;
+ /* THEN succeed */
+ TEST_ASSERT(fp_set_sensor_mode(requested_mode, &output_mode) ==
+ EC_RES_SUCCESS);
+ /* THEN requested mode is returned */
+ TEST_ASSERT(requested_mode == output_mode);
+ /* THEN sensor_mode is updated */
+ TEST_ASSERT(sensor_mode == requested_mode);
+
+ /* GIVEN max number of fingers already enrolled */
+ sensor_mode = 0;
+ output_mode = 0xdeadbeef;
+ templ_valid = FP_MAX_FINGER_COUNT;
+ requested_mode = FP_MODE_ENROLL_SESSION;
+ /* THEN additional enroll attempt will fail */
+ TEST_ASSERT(fp_set_sensor_mode(requested_mode, &output_mode) ==
+ EC_RES_INVALID_PARAM);
+ /* THEN output parameters is unchanged */
+ TEST_ASSERT(output_mode = 0xdeadbeef);
+ /* THEN sensor_mode is unchanged */
+ TEST_ASSERT(sensor_mode == 0);
+
+ return EC_SUCCESS;
+}
+
void run_test(void)
{
RUN_TEST(test_derive_encryption_key_failure_seed_not_set);
RUN_TEST(test_fpsensor_seed);
RUN_TEST(test_derive_encryption_key);
RUN_TEST(test_derive_encryption_key_failure_rollback_fail);
+ RUN_TEST(test_fp_set_sensor_mode);
test_print_result();
}