<commit_before>/* Copyright 2022 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 <zephyr/zephyr.h>
#include <zephyr/ztest.h>
#include <sha256.h>

#include "ec_commands.h"
#include "host_command.h"
#include "test/drivers/test_state.h"

ZTEST_USER(vboot_hash, test_hostcmd)
{
	struct ec_params_vboot_hash params = {
		.cmd = EC_VBOOT_HASH_START,
		.offset = 0,
		.size = 0,
	};
	struct ec_response_vboot_hash response;
	struct host_cmd_handler_args args =
		BUILD_HOST_COMMAND(EC_CMD_VBOOT_HASH, 0, response, params);

	zassert_ok(host_command_process(&args), NULL);
	zassert_ok(args.result, NULL);
	zassert_equal(args.response_size, sizeof(response), NULL);
	zassert_equal(response.status, EC_VBOOT_HASH_STATUS_BUSY,
		      "response.status = %d", response.status);
}
<commit_msg>zephyr: test: Add vboot_hash host command test cases<commit_after>/* Copyright 2022 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 <zephyr/zephyr.h>
#include <zephyr/ztest.h>
#include <sha256.h>

#include "ec_commands.h"
#include "host_command.h"
#include "test/drivers/test_state.h"

ZTEST_USER(vboot_hash, test_hostcmd_abort)
{
	struct ec_response_vboot_hash response;
	struct ec_params_vboot_hash start_params = {
		.cmd = EC_VBOOT_HASH_START,
		.hash_type = EC_VBOOT_HASH_TYPE_SHA256,
		.offset = EC_VBOOT_HASH_OFFSET_RO,
		.size = 0,
	};
	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);

	/* 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);
}

{'fraction_non_alphanumeric': 0.10329018338727076, 'fraction_numerical': 0.009169363538295576, 'mean_word_length': 5.587921847246892, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5890959', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1392, 'n_words': 278}