diff options
author | Wai-Hong Tam <waihong@google.com> | 2022-08-16 08:48:28 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-16 18:55:03 +0000 |
commit | e6096667e75006de0a0a74b1a923d51131998b75 (patch) | |
tree | 10e27c50963662df5006e852df5ebf1fa749a01d | |
parent | bcdbf844e44ff72137d49cca296bab2ea5120572 (diff) | |
download | chrome-ec-e6096667e75006de0a0a74b1a923d51131998b75.tar.gz |
zephyr: test: Add vboot_hash host command test cases
Add the following vboot_hash test cases:
* Use the host commands to start the hashing, abort it, and get the
result (should be None).
* Use the host command to recalculate the hash. The command waits to
finish and returns the hash result.
BRANCH=None
BUG=b:236161107
TEST=./twister -s zephyr/test/drivers/drivers.default
Change-Id: I0ba05b1da0f35d5e79f147eb0a5a16113b22b498
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3834326
Reviewed-by: Yuval Peress <peress@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | zephyr/test/drivers/default/src/vboot_hash.c | 66 |
1 files changed, 57 insertions, 9 deletions
diff --git a/zephyr/test/drivers/default/src/vboot_hash.c b/zephyr/test/drivers/default/src/vboot_hash.c index a6fad0161d..a0b5ddc3fe 100644 --- a/zephyr/test/drivers/default/src/vboot_hash.c +++ b/zephyr/test/drivers/default/src/vboot_hash.c @@ -11,22 +11,70 @@ #include "host_command.h" #include "test/drivers/test_state.h" -ZTEST_USER(vboot_hash, test_hostcmd) +ZTEST_USER(vboot_hash, test_hostcmd_abort) { - struct ec_params_vboot_hash params = { + struct ec_response_vboot_hash response; + struct ec_params_vboot_hash start_params = { .cmd = EC_VBOOT_HASH_START, - .offset = 0, + .hash_type = EC_VBOOT_HASH_TYPE_SHA256, + .offset = EC_VBOOT_HASH_OFFSET_RO, .size = 0, }; - struct ec_response_vboot_hash response; - struct host_cmd_handler_args args = - BUILD_HOST_COMMAND(EC_CMD_VBOOT_HASH, 0, response, params); + struct host_cmd_handler_args start_args = BUILD_HOST_COMMAND( + EC_CMD_VBOOT_HASH, 0, response, start_params); + struct ec_params_vboot_hash abort_params = { + .cmd = EC_VBOOT_HASH_ABORT, + }; + struct host_cmd_handler_args abort_args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_VBOOT_HASH, 0, abort_params); + struct ec_params_vboot_hash get_params = { + .cmd = EC_VBOOT_HASH_GET, + }; + struct host_cmd_handler_args get_args = + BUILD_HOST_COMMAND(EC_CMD_VBOOT_HASH, 0, response, get_params); - zassert_ok(host_command_process(&args), NULL); - zassert_ok(args.result, NULL); - zassert_equal(args.response_size, sizeof(response), NULL); + /* Start hashing. The command doesn't wait to finish. */ + zassert_ok(host_command_process(&start_args), NULL); + zassert_ok(start_args.result, NULL); + zassert_equal(start_args.response_size, sizeof(response), NULL); zassert_equal(response.status, EC_VBOOT_HASH_STATUS_BUSY, "response.status = %d", response.status); + + /* Abort it immediately */ + zassert_ok(host_command_process(&abort_args), NULL); + zassert_ok(abort_args.result, NULL); + + /* Give it a bit time. The abort is being processed in the background */ + k_msleep(20); + + /* Get the hash result. Should be NONE. */ + zassert_ok(host_command_process(&get_args), NULL); + zassert_ok(get_args.result, NULL); + zassert_equal(get_args.response_size, sizeof(response), NULL); + zassert_equal(response.status, EC_VBOOT_HASH_STATUS_NONE, + "response.status = %d", response.status); +} + +ZTEST_USER(vboot_hash, test_hostcmd_recalc) +{ + struct ec_response_vboot_hash response; + struct ec_params_vboot_hash recalc_params = { + .cmd = EC_VBOOT_HASH_RECALC, + .hash_type = EC_VBOOT_HASH_TYPE_SHA256, + .offset = EC_VBOOT_HASH_OFFSET_RO, + .size = 0, + }; + struct host_cmd_handler_args recalc_args = BUILD_HOST_COMMAND( + EC_CMD_VBOOT_HASH, 0, response, recalc_params); + + /* Recalculate the hash. The command waits to finish. */ + zassert_ok(host_command_process(&recalc_args), NULL); + zassert_ok(recalc_args.result, NULL); + zassert_equal(recalc_args.response_size, sizeof(response), NULL); + zassert_equal(response.status, EC_VBOOT_HASH_STATUS_DONE, + "response.status = %d", response.status); + zassert_equal(response.digest_size, SHA256_DIGEST_SIZE, + "response.digest_size = %d", response.digest_size); } ZTEST_SUITE(vboot_hash, drivers_predicate_post_main, NULL, NULL, NULL, NULL); |