Edward O'Callaghan has submitted this change. ( https://review.coreboot.org/c/flashrom/+/67642 )
(
2 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: tests: Add unit test for initialisation with NULL programmer param ......................................................................
tests: Add unit test for initialisation with NULL programmer param
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 --- M tests/dummyflasher.c M tests/lifecycle.c M tests/tests.c M tests/tests.h 4 files changed, 39 insertions(+), 1 deletion(-)
Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Thomas Heijligen: Looks good to me, but someone else must approve Edward O'Callaghan: Looks good to me, approved
diff --git a/tests/dummyflasher.c b/tests/dummyflasher.c index b52a542..1148217 100644 --- a/tests/dummyflasher.c +++ b/tests/dummyflasher.c @@ -110,6 +110,19 @@ "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) @@ -117,4 +130,5 @@ 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 */ diff --git a/tests/lifecycle.c b/tests/lifecycle.c index 568b179..0c79699 100644 --- a/tests/lifecycle.c +++ b/tests/lifecycle.c @@ -39,7 +39,8 @@ io_mock_register(io);
struct flashrom_programmer *flashprog; - char *param_dup = strdup(param); + + char *param_dup = param ? strdup(param) : NULL;
printf("Testing flashrom_programmer_init for programmer=%s ...\n", prog->name); assert_int_equal(0, flashrom_programmer_init(&flashprog, prog->name, param_dup)); diff --git a/tests/tests.c b/tests/tests.c index 7f20069..53bad65 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -424,6 +424,7 @@ 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(dummy_null_prog_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 cdbf01c..7d84101 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -48,6 +48,7 @@ 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 dummy_null_prog_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);