| 1 |
/* |
| 2 |
* This file is part of the flashrom project. |
| 3 |
* |
| 4 |
* Copyright 2021 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_DUMMY == 1 |
| 19 |
void dummy_basic_lifecycle_test_success(void **state) |
| 20 |
{ |
| 21 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 22 |
.noc = 0, |
| 23 |
.paths = { NULL }, |
| 24 |
}; |
| 25 |
const struct io_mock dummy_io = { |
| 26 |
.fallback_open_state = &dummy_fallback_open_state, |
| 27 |
}; |
| 28 |
|
| 29 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=parallel+lpc+fwh+spi+prog"); |
| 30 |
} |
| 31 |
|
| 32 |
void dummy_probe_lifecycle_test_success(void **state) |
| 33 |
{ |
| 34 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 35 |
.noc = 0, |
| 36 |
.paths = { NULL }, |
| 37 |
}; |
| 38 |
const struct io_mock dummy_io = { |
| 39 |
.fallback_open_state = &dummy_fallback_open_state, |
| 40 |
}; |
| 41 |
|
| 42 |
const char *expected_matched_names[1] = {"W25Q128.V"}; |
| 43 |
run_probe_v2_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=W25Q128FV", "W25Q128.V", |
| 44 |
expected_matched_names, 1); |
| 45 |
} |
| 46 |
|
| 47 |
void dummy_probe_v2_one_match_for_W25Q128FV(void **state) |
| 48 |
{ |
| 49 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 50 |
.noc = 0, |
| 51 |
.paths = { NULL }, |
| 52 |
}; |
| 53 |
const struct io_mock dummy_io = { |
| 54 |
.fallback_open_state = &dummy_fallback_open_state, |
| 55 |
}; |
| 56 |
|
| 57 |
const char *expected_matched_names[1] = {"W25Q128.V"}; |
| 58 |
run_probe_v2_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=W25Q128FV", |
| 59 |
NULL, /* any chip name */ |
| 60 |
expected_matched_names, 1); |
| 61 |
} |
| 62 |
|
| 63 |
void dummy_probe_v2_six_matches_for_MX25L6436(void **state) |
| 64 |
{ |
| 65 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 66 |
.noc = 0, |
| 67 |
.paths = { NULL }, |
| 68 |
}; |
| 69 |
const struct io_mock dummy_io = { |
| 70 |
.fallback_open_state = &dummy_fallback_open_state, |
| 71 |
}; |
| 72 |
|
| 73 |
const char *expected_matched_names[6] = {"MX25L6405", |
| 74 |
"MX25L6405D", |
| 75 |
"MX25L6406E/MX25L6408E", |
| 76 |
"MX25L6436E/MX25L6445E/MX25L6465E", |
| 77 |
"MX25L6473E", |
| 78 |
"MX25L6473F"}; |
| 79 |
run_probe_v2_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=MX25L6436", |
| 80 |
NULL, /* any chip name */ |
| 81 |
expected_matched_names, 6); |
| 82 |
} |
| 83 |
|
| 84 |
void dummy_probe_v2_no_matches_found(void **state) |
| 85 |
{ |
| 86 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 87 |
.noc = 0, |
| 88 |
.paths = { NULL }, |
| 89 |
}; |
| 90 |
const struct io_mock dummy_io = { |
| 91 |
.fallback_open_state = &dummy_fallback_open_state, |
| 92 |
}; |
| 93 |
|
| 94 |
run_probe_v2_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=MX25L6436", |
| 95 |
"NONEXISTENT", NULL /* no matched names */, 0); |
| 96 |
} |
| 97 |
|
| 98 |
void dummy_probe_variable_size_test_success(void **state) |
| 99 |
{ |
| 100 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 101 |
.noc = 0, |
| 102 |
.paths = { NULL }, |
| 103 |
}; |
| 104 |
const struct io_mock dummy_io = { |
| 105 |
.fallback_open_state = &dummy_fallback_open_state, |
| 106 |
}; |
| 107 |
|
| 108 |
const char *expected_matched_names[1] = {"Opaque flash chip"}; |
| 109 |
run_probe_v2_lifecycle(state, &dummy_io, &programmer_dummy, "size=8388608,emulate=VARIABLE_SIZE", "Opaque flash chip", |
| 110 |
expected_matched_names, 1); |
| 111 |
} |
| 112 |
|
| 113 |
void dummy_init_fails_unhandled_param_test_success(void **state) |
| 114 |
{ |
| 115 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 116 |
.noc = 0, |
| 117 |
.paths = { NULL }, |
| 118 |
}; |
| 119 |
const struct io_mock dummy_io = { |
| 120 |
.fallback_open_state = &dummy_fallback_open_state, |
| 121 |
}; |
| 122 |
|
| 123 |
/* |
| 124 |
* Programmer init should fail due to `dummy_init` failure caused by |
| 125 |
* invalid value of `emulate` param. There is unhandled param left |
| 126 |
* at the end of param string. |
| 127 |
*/ |
| 128 |
run_init_error_path(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=INVALID,unhandled=value", 1); |
| 129 |
} |
| 130 |
|
| 131 |
void dummy_init_success_invalid_param_test_success(void **state) |
| 132 |
{ |
| 133 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 134 |
.noc = 0, |
| 135 |
.paths = { NULL }, |
| 136 |
}; |
| 137 |
const struct io_mock dummy_io = { |
| 138 |
.fallback_open_state = &dummy_fallback_open_state, |
| 139 |
}; |
| 140 |
|
| 141 |
/* |
| 142 |
* Programmer init should fail despite of the fact that `dummy_init` |
| 143 |
* is successful, due to invalid param at the end of param string. |
| 144 |
*/ |
| 145 |
run_init_error_path(state, &dummy_io, &programmer_dummy, |
| 146 |
"bus=spi,emulate=W25Q128FV,invalid=value", ERROR_FLASHROM_FATAL); |
| 147 |
} |
| 148 |
|
| 149 |
void dummy_init_success_unhandled_param_test_success(void **state) |
| 150 |
{ |
| 151 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 152 |
.noc = 0, |
| 153 |
.paths = { NULL }, |
| 154 |
}; |
| 155 |
const struct io_mock dummy_io = { |
| 156 |
.fallback_open_state = &dummy_fallback_open_state, |
| 157 |
}; |
| 158 |
|
| 159 |
/* |
| 160 |
* Programmer init should fail despite of the fact that `dummy_init` |
| 161 |
* is successful, due to unhandled param at the end of param string. |
| 162 |
* Unhandled param `voltage` is not used for dummyflasher. |
| 163 |
*/ |
| 164 |
run_init_error_path(state, &dummy_io, &programmer_dummy, |
| 165 |
"bus=spi,emulate=W25Q128FV,voltage=3.5V", ERROR_FLASHROM_FATAL); |
| 166 |
} |
| 167 |
|
| 168 |
void dummy_null_prog_param_test_success(void **state) |
| 169 |
{ |
| 170 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 171 |
.noc = 0, |
| 172 |
.paths = { NULL }, |
| 173 |
}; |
| 174 |
const struct io_mock dummy_io = { |
| 175 |
.fallback_open_state = &dummy_fallback_open_state, |
| 176 |
}; |
| 177 |
|
| 178 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, NULL); |
| 179 |
} |
| 180 |
|
| 181 |
void dummy_all_buses_test_success(void **state) |
| 182 |
{ |
| 183 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 184 |
.noc = 0, |
| 185 |
.paths = { NULL }, |
| 186 |
}; |
| 187 |
const struct io_mock dummy_io = { |
| 188 |
.fallback_open_state = &dummy_fallback_open_state, |
| 189 |
}; |
| 190 |
|
| 191 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=lpc+fwh"); |
| 192 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi"); |
| 193 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=prog"); |
| 194 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=parallel+fwh+prog"); |
| 195 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi+prog"); |
| 196 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=parallel+lpc+spi"); |
| 197 |
} |
| 198 |
|
| 199 |
void dummy_freq_param_init(void **state) |
| 200 |
{ |
| 201 |
struct io_mock_fallback_open_state dummy_fallback_open_state = { |
| 202 |
.noc = 0, |
| 203 |
.paths = { NULL }, |
| 204 |
}; |
| 205 |
const struct io_mock dummy_io = { |
| 206 |
.fallback_open_state = &dummy_fallback_open_state, |
| 207 |
}; |
| 208 |
|
| 209 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,freq=12Hz"); |
| 210 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,freq=123KHz"); |
| 211 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,freq=345MHz"); |
| 212 |
run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,freq=8000MHz"); |
| 213 |
/* Valid values for freq param are within the range [1Hz, 8000Mhz] */ |
| 214 |
run_init_error_path(state, &dummy_io, &programmer_dummy, "bus=spi,freq=0Hz", 0x1); |
| 215 |
run_init_error_path(state, &dummy_io, &programmer_dummy, "bus=spi,freq=8001Mhz", 0x1); |
| 216 |
} |
| 217 |
|
| 218 |
#else |
| 219 |
SKIP_TEST(dummy_basic_lifecycle_test_success) |
| 220 |
SKIP_TEST(dummy_probe_lifecycle_test_success) |
| 221 |
SKIP_TEST(dummy_probe_v2_one_match_for_W25Q128FV) |
| 222 |
SKIP_TEST(dummy_probe_v2_six_matches_for_MX25L6436) |
| 223 |
SKIP_TEST(dummy_probe_v2_no_matches_found) |
| 224 |
SKIP_TEST(dummy_probe_variable_size_test_success) |
| 225 |
SKIP_TEST(dummy_init_fails_unhandled_param_test_success) |
| 226 |
SKIP_TEST(dummy_init_success_invalid_param_test_success) |
| 227 |
SKIP_TEST(dummy_init_success_unhandled_param_test_success) |
| 228 |
SKIP_TEST(dummy_null_prog_param_test_success) |
| 229 |
SKIP_TEST(dummy_all_buses_test_success) |
| 230 |
SKIP_TEST(dummy_freq_param_init) |
| 231 |
#endif /* CONFIG_DUMMY */ |