summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYicheng Li <yichengli@chromium.org>2019-10-16 16:52:27 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-17 20:37:41 +0000
commitf46eefcad2b32a171583c4f566c2efd0c0bd7127 (patch)
treec6c64e17d0d5f713555bb84771ef876430fb61d3
parentf409af3d4ac946a93819fd323d348ae3bdc4141f (diff)
downloadchrome-ec-f46eefcad2b32a171583c4f566c2efd0c0bd7127.tar.gz
fpsensor: Improve unit test for enable/disable positive match secret
Initialize the local struct so that the test is not flaky. Also extract helper function and add more asserts to make the logic more explicit to readers. BUG=none BRANCH=nocturne TEST=make -j buildall Change-Id: I84ccd097b64c3ff304f4af228121b2cb989e6ab7 Signed-off-by: Yicheng Li <yichengli@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1865956 Reviewed-by: Craig Hesling <hesling@chromium.org>
-rw-r--r--test/fpsensor.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/test/fpsensor.c b/test/fpsensor.c
index 81441295ae..490c903ba3 100644
--- a/test/fpsensor.c
+++ b/test/fpsensor.c
@@ -603,6 +603,21 @@ test_static int test_fp_set_sensor_mode(void)
return EC_SUCCESS;
}
+static int test_enable_positive_match_secret_once(
+ struct positive_match_secret_state *dumb_state)
+{
+ const int8_t kIndexToEnable = 0;
+ timestamp_t now = get_time();
+
+ TEST_ASSERT(fp_enable_positive_match_secret(
+ kIndexToEnable, dumb_state) == EC_SUCCESS);
+ TEST_ASSERT(dumb_state->template_matched == kIndexToEnable);
+ TEST_ASSERT(dumb_state->readable);
+ TEST_ASSERT(dumb_state->deadline.val == now.val + (5 * SECOND));
+
+ return EC_SUCCESS;
+}
+
test_static int test_enable_positive_match_secret(void)
{
struct positive_match_secret_state dumb_state = {
@@ -610,19 +625,15 @@ test_static int test_enable_positive_match_secret(void)
.readable = false,
.deadline.val = 0,
};
- timestamp_t now = get_time();
- TEST_ASSERT(fp_enable_positive_match_secret(0, &dumb_state) ==
- EC_SUCCESS);
- TEST_ASSERT(dumb_state.template_matched == 0);
- TEST_ASSERT(dumb_state.readable == true);
- TEST_ASSERT(dumb_state.deadline.val == now.val + (5 * SECOND));
+ TEST_ASSERT(test_enable_positive_match_secret_once(&dumb_state)
+ == EC_SUCCESS);
/* Trying to enable again before reading secret should fail. */
TEST_ASSERT(fp_enable_positive_match_secret(0, &dumb_state) ==
EC_ERROR_UNKNOWN);
TEST_ASSERT(dumb_state.template_matched == FP_NO_SUCH_TEMPLATE);
- TEST_ASSERT(dumb_state.readable == false);
+ TEST_ASSERT(!dumb_state.readable);
TEST_ASSERT(dumb_state.deadline.val == 0);
return EC_SUCCESS;
@@ -630,13 +641,18 @@ test_static int test_enable_positive_match_secret(void)
test_static int test_disable_positive_match_secret(void)
{
- struct positive_match_secret_state dumb_state;
+ struct positive_match_secret_state dumb_state = {
+ .template_matched = FP_NO_SUCH_TEMPLATE,
+ .readable = false,
+ .deadline.val = 0,
+ };
+
+ TEST_ASSERT(test_enable_positive_match_secret_once(&dumb_state)
+ == EC_SUCCESS);
- TEST_ASSERT(fp_enable_positive_match_secret(0, &dumb_state) ==
- EC_SUCCESS);
fp_disable_positive_match_secret(&dumb_state);
TEST_ASSERT(dumb_state.template_matched == FP_NO_SUCH_TEMPLATE);
- TEST_ASSERT(dumb_state.readable == false);
+ TEST_ASSERT(!dumb_state.readable);
TEST_ASSERT(dumb_state.deadline.val == 0);
return EC_SUCCESS;