<commit_before>/* Copyright 2020 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 "flash.h"
#include "gpio.h"
#include "string.h"
#include "system.h"
#include "task.h"
#include "test_util.h"

test_static int check_image_and_hardware_write_protect(void)
{
	if (system_get_image_copy() != EC_IMAGE_RO) {
		ccprintf("This test is only works when running RO\n");
		return EC_ERROR_UNKNOWN;
	}

	if (gpio_get_level(GPIO_WP) != 1) {
		ccprintf("Hardware write protect (GPIO_WP) must be enabled\n");
		return EC_ERROR_UNKNOWN;
	}

	return EC_SUCCESS;
}

test_static int test_flash_write_protect_enable(void)
{
	int rv;

	TEST_EQ(check_image_and_hardware_write_protect(), EC_SUCCESS, "%d");

	/* Equivalent of ectool --name=cros_fp flashprotect enable */
	rv = flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT,
			       EC_FLASH_PROTECT_RO_AT_BOOT);
<commit_msg>test/flash_write_protect: Handle different WP polarity<commit_after>/* Copyright 2020 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 "flash.h"
#include "gpio.h"
#include "string.h"
#include "system.h"
#include "task.h"
#include "test_util.h"

test_static int check_image_and_hardware_write_protect(void)
{
	int wp;

	if (system_get_image_copy() != EC_IMAGE_RO) {
		ccprintf("This test is only works when running RO\n");
		return EC_ERROR_UNKNOWN;
	}

#ifdef CONFIG_WP_ALWAYS
        wp = 1;
#elif defined(CONFIG_WP_ACTIVE_HIGH)
        wp = gpio_get_level(GPIO_WP);
#else
	wp = !gpio_get_level(GPIO_WP_L);
#endif

	if (!wp) {
		ccprintf("Hardware write protect (GPIO_WP) must be enabled\n");
		return EC_ERROR_UNKNOWN;
	}

	return EC_SUCCESS;
}

test_static int test_flash_write_protect_enable(void)
{
	int rv;

	TEST_EQ(check_image_and_hardware_write_protect(), EC_SUCCESS, "%d");

	/* Equivalent of ectool --name=cros_fp flashprotect enable */
	rv = flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT,
			       EC_FLASH_PROTECT_RO_AT_BOOT);

{'fraction_non_alphanumeric': 0.10221384832783796, 'fraction_numerical': 0.004710315591144607, 'mean_word_length': 4.949579831932773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4793337', 'n_tokens_mistral': 813, 'n_tokens_neox': 764, 'n_words': 193}