diff options
author | Anastasia Klimchuk <aklm@chromium.org> | 2022-08-30 12:52:50 +1000 |
---|---|---|
committer | Anastasia Klimchuk <aklm@chromium.org> | 2022-09-04 22:48:10 +0000 |
commit | 33af2e695d28a89e0eaf9b058310bc5bf0e6e80f (patch) | |
tree | 9bd6a18174aa4593c80b067f884474c6539ef4eb /tests | |
parent | 5fbe87ce504be99a12c196415e3da5e04605d56a (diff) | |
download | flashrom-33af2e695d28a89e0eaf9b058310bc5bf0e6e80f.tar.gz flashrom-33af2e695d28a89e0eaf9b058310bc5bf0e6e80f.tar.bz2 flashrom-33af2e695d28a89e0eaf9b058310bc5bf0e6e80f.zip |
tests: Add tests to cover unhandled programmer params paths
Unhandled programmer params are considered as an error for
initialisation procedure, adding tests to run those scenarios.
BUG=b:181803212
TEST=ninja test
Change-Id: Ia64f6362f46a029e168bfdb3bdb903328fd1f9c7
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/67199
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/dummyflasher.c | 58 | ||||
-rw-r--r-- | tests/tests.c | 3 | ||||
-rw-r--r-- | tests/tests.h | 3 |
3 files changed, 64 insertions, 0 deletions
diff --git a/tests/dummyflasher.c b/tests/dummyflasher.c index ddaf0cc9..b52a5427 100644 --- a/tests/dummyflasher.c +++ b/tests/dummyflasher.c @@ -55,8 +55,66 @@ void dummy_probe_variable_size_test_success(void **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); +} + #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) #endif /* CONFIG_DUMMY */ diff --git a/tests/tests.c b/tests/tests.c index 2994c022..11348b5a 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -410,6 +410,9 @@ int main(int argc, char *argv[]) cmocka_unit_test(dummy_basic_lifecycle_test_success), cmocka_unit_test(dummy_probe_lifecycle_test_success), cmocka_unit_test(dummy_probe_variable_size_test_success), + cmocka_unit_test(dummy_init_fails_unhandled_param_test_success), + cmocka_unit_test(dummy_init_success_invalid_param_test_success), + cmocka_unit_test(dummy_init_success_unhandled_param_test_success), cmocka_unit_test(nicrealtek_basic_lifecycle_test_success), cmocka_unit_test(raiden_debug_basic_lifecycle_test_success), cmocka_unit_test(dediprog_basic_lifecycle_test_success), diff --git a/tests/tests.h b/tests/tests.h index 4808b58b..cdbf01cf 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -45,6 +45,9 @@ void probe_spi_st95_test_success(void **state); /* spi95.c */ void dummy_basic_lifecycle_test_success(void **state); void dummy_probe_lifecycle_test_success(void **state); void dummy_probe_variable_size_test_success(void **state); +void dummy_init_fails_unhandled_param_test_success(void **state); +void dummy_init_success_invalid_param_test_success(void **state); +void dummy_init_success_unhandled_param_test_success(void **state); void nicrealtek_basic_lifecycle_test_success(void **state); void raiden_debug_basic_lifecycle_test_success(void **state); void dediprog_basic_lifecycle_test_success(void **state); |