mirror of
				https://review.coreboot.org/flashrom.git
				synced 2025-10-31 13:20:42 +01:00 
			
		
		
		
	 5363f35fa0
			
		
	
	5363f35fa0
	
	
	
		
			
			Programmer param can be NULL and this is a valid case which can be covered by unit test. `run_lifecycle` needs an adjustment to handle NULL as programmer param, which is also included in the patch. Change-Id: I409f1c9ac832943e54107f7cf8652d1f46ac67df Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67642 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Thomas Heijligen <src@posteo.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
		
			
				
	
	
		
			135 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			135 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * This file is part of the flashrom project.
 | |
|  *
 | |
|  * Copyright 2021 Google LLC
 | |
|  *
 | |
|  * This program is free software; you can redistribute it and/or modify
 | |
|  * it under the terms of the GNU General Public License as published by
 | |
|  * the Free Software Foundation; version 2 of the License.
 | |
|  *
 | |
|  * This program is distributed in the hope that it will be useful,
 | |
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
|  * GNU General Public License for more details.
 | |
|  */
 | |
| 
 | |
| #include "lifecycle.h"
 | |
| 
 | |
| #if CONFIG_DUMMY == 1
 | |
| void dummy_basic_lifecycle_test_success(void **state)
 | |
| {
 | |
| 	struct io_mock_fallback_open_state dummy_fallback_open_state = {
 | |
| 		.noc = 0,
 | |
| 		.paths = { NULL },
 | |
| 	};
 | |
| 	const struct io_mock dummy_io = {
 | |
| 		.fallback_open_state = &dummy_fallback_open_state,
 | |
| 	};
 | |
| 
 | |
| 	run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=parallel+lpc+fwh+spi+prog");
 | |
| }
 | |
| 
 | |
| void dummy_probe_lifecycle_test_success(void **state)
 | |
| {
 | |
| 	struct io_mock_fallback_open_state dummy_fallback_open_state = {
 | |
| 		.noc = 0,
 | |
| 		.paths = { NULL },
 | |
| 	};
 | |
| 	const struct io_mock dummy_io = {
 | |
| 		.fallback_open_state = &dummy_fallback_open_state,
 | |
| 	};
 | |
| 
 | |
| 	run_probe_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=W25Q128FV", "W25Q128.V");
 | |
| }
 | |
| 
 | |
| void dummy_probe_variable_size_test_success(void **state)
 | |
| {
 | |
| 	struct io_mock_fallback_open_state dummy_fallback_open_state = {
 | |
| 		.noc = 0,
 | |
| 		.paths = { NULL },
 | |
| 	};
 | |
| 	const struct io_mock dummy_io = {
 | |
| 		.fallback_open_state = &dummy_fallback_open_state,
 | |
| 	};
 | |
| 
 | |
| 	run_probe_lifecycle(state, &dummy_io, &programmer_dummy, "size=8388608,emulate=VARIABLE_SIZE", "Opaque flash chip");
 | |
| }
 | |
| 
 | |
| void dummy_init_fails_unhandled_param_test_success(void **state)
 | |
| {
 | |
| 	struct io_mock_fallback_open_state dummy_fallback_open_state = {
 | |
| 		.noc = 0,
 | |
| 		.paths = { NULL },
 | |
| 	};
 | |
| 	const struct io_mock dummy_io = {
 | |
| 		.fallback_open_state = &dummy_fallback_open_state,
 | |
| 	};
 | |
| 
 | |
| 	/*
 | |
| 	 * Programmer init should fail due to `dummy_init` failure caused by
 | |
| 	 * invalid value of `emulate` param. There is unhandled param left
 | |
| 	 * at the end of param string.
 | |
| 	 */
 | |
| 	run_init_error_path(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=INVALID,unhandled=value", 1);
 | |
| }
 | |
| 
 | |
| void dummy_init_success_invalid_param_test_success(void **state)
 | |
| {
 | |
| 	struct io_mock_fallback_open_state dummy_fallback_open_state = {
 | |
| 		.noc = 0,
 | |
| 		.paths = { NULL },
 | |
| 	};
 | |
| 	const struct io_mock dummy_io = {
 | |
| 		.fallback_open_state = &dummy_fallback_open_state,
 | |
| 	};
 | |
| 
 | |
| 	/*
 | |
| 	 * Programmer init should fail despite of the fact that `dummy_init`
 | |
| 	 * is successful, due to invalid param at the end of param string.
 | |
| 	 */
 | |
| 	run_init_error_path(state, &dummy_io, &programmer_dummy,
 | |
| 				"bus=spi,emulate=W25Q128FV,invalid=value", ERROR_FATAL);
 | |
| }
 | |
| 
 | |
| void dummy_init_success_unhandled_param_test_success(void **state)
 | |
| {
 | |
| 	struct io_mock_fallback_open_state dummy_fallback_open_state = {
 | |
| 		.noc = 0,
 | |
| 		.paths = { NULL },
 | |
| 	};
 | |
| 	const struct io_mock dummy_io = {
 | |
| 		.fallback_open_state = &dummy_fallback_open_state,
 | |
| 	};
 | |
| 
 | |
| 	/*
 | |
| 	 * Programmer init should fail despite of the fact that `dummy_init`
 | |
| 	 * is successful, due to unhandled param at the end of param string.
 | |
| 	 * Unhandled param `voltage` is not used for dummyflasher.
 | |
| 	 */
 | |
| 	run_init_error_path(state, &dummy_io, &programmer_dummy,
 | |
| 				"bus=spi,emulate=W25Q128FV,voltage=3.5V", ERROR_FATAL);
 | |
| }
 | |
| 
 | |
| void dummy_null_prog_param_test_success(void **state)
 | |
| {
 | |
| 	struct io_mock_fallback_open_state dummy_fallback_open_state = {
 | |
| 		.noc = 0,
 | |
| 		.paths = { NULL },
 | |
| 	};
 | |
| 	const struct io_mock dummy_io = {
 | |
| 		.fallback_open_state = &dummy_fallback_open_state,
 | |
| 	};
 | |
| 
 | |
| 	run_basic_lifecycle(state, &dummy_io, &programmer_dummy, NULL);
 | |
| }
 | |
| 
 | |
| #else
 | |
| 	SKIP_TEST(dummy_basic_lifecycle_test_success)
 | |
| 	SKIP_TEST(dummy_probe_lifecycle_test_success)
 | |
| 	SKIP_TEST(dummy_probe_variable_size_test_success)
 | |
| 	SKIP_TEST(dummy_init_fails_unhandled_param_test_success)
 | |
| 	SKIP_TEST(dummy_init_success_invalid_param_test_success)
 | |
| 	SKIP_TEST(dummy_init_success_unhandled_param_test_success)
 | |
| 	SKIP_TEST(dummy_null_prog_param_test_success)
 | |
| #endif /* CONFIG_DUMMY */
 |