Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/67199 )
(
1 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: tests: Add tests to cover unhandled programmer params paths ......................................................................
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 --- M tests/dummyflasher.c M tests/tests.c M tests/tests.h 3 files changed, 84 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Edward O'Callaghan: Looks good to me, approved
diff --git a/tests/dummyflasher.c b/tests/dummyflasher.c index ddaf0cc..b52a542 100644 --- a/tests/dummyflasher.c +++ b/tests/dummyflasher.c @@ -55,8 +55,66 @@ 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 2994c02..11348b5 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -410,6 +410,9 @@ 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 4808b58..cdbf01c 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -45,6 +45,9 @@ 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);