xref: /aosp_15_r20/external/flashrom/tests/mediatek_i2c_spi.c (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1 /*
2  * This file is part of the flashrom project.
3  *
4  * Copyright 2022 Google LLC
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15 
16 #include "lifecycle.h"
17 
18 #if CONFIG_MEDIATEK_I2C_SPI == 1
19 
mediatek_i2c_spi_basic_lifecycle_test_success(void ** state)20 void mediatek_i2c_spi_basic_lifecycle_test_success(void **state)
21 {
22 	struct io_mock_fallback_open_state mediatek_i2c_spi_fallback_open_state = {
23 		.noc = 0,
24 		.paths = { LOCK_FILE, "/dev/i2c-254", NULL },
25 		.flags = { O_RDWR, O_RDWR },
26 	};
27 	const struct io_mock mediatek_i2c_spi_io = {
28 		.fallback_open_state = &mediatek_i2c_spi_fallback_open_state,
29 	};
30 
31 	run_basic_lifecycle(state, &mediatek_i2c_spi_io, &programmer_mediatek_i2c_spi, "bus=254,allow_brick=yes");
32 }
33 
mediatek_i2c_no_allow_brick_test_success(void ** state)34 void mediatek_i2c_no_allow_brick_test_success(void **state)
35 {
36 	struct io_mock_fallback_open_state mediatek_i2c_spi_fallback_open_state = {
37 		.noc = 0,
38 		.paths = { LOCK_FILE, "/dev/i2c-254", NULL },
39 		.flags = { O_RDWR, O_RDWR },
40 	};
41 	const struct io_mock mediatek_i2c_spi_io = {
42 		.fallback_open_state = &mediatek_i2c_spi_fallback_open_state,
43 	};
44 
45 	run_init_error_path(state, &mediatek_i2c_spi_io, &programmer_mediatek_i2c_spi,
46 				"bus=254", SPI_GENERIC_ERROR);
47 }
48 
49 #else
50 	SKIP_TEST(mediatek_i2c_spi_basic_lifecycle_test_success)
51 	SKIP_TEST(mediatek_i2c_no_allow_brick_test_success)
52 #endif /* CONFIG_MEDIATEK_I2C_SPI */
53