Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/52497 )
Change subject: Add unit test to run init/shutdown for dummyflasher.c ......................................................................
Add unit test to run init/shutdown for dummyflasher.c
I plan to do this for all drivers in programmer table, one at a time. Dummy is the first and the easiest.
After this was rebased on the top of memory checks https://review.coreboot.org/c/flashrom/+/51243 , dummy has been discovered to leak memory on shutdown, so I fix it here.
TEST=builds and ninja test BUG=b:181803212
Change-Id: I3c0ef73397f00c1db7aabb5f9f00cb43525af29c Signed-off-by: Anastasia Klimchuk aklm@chromium.org --- M dummyflasher.c A tests/init_shutdown.c M tests/meson.build M tests/tests.c M tests/tests.h 5 files changed, 47 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/97/52497/1
diff --git a/dummyflasher.c b/dummyflasher.c index 5190282..ec5060d 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -650,6 +650,7 @@ free(flashchip_contents); } #endif + free(data); return 0; }
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c new file mode 100644 index 0000000..5226860 --- /dev/null +++ b/tests/init_shutdown.c @@ -0,0 +1,37 @@ +/* + * This file is part of the flashrom project. + * + * Copyright 2021 Google LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <include/test.h> +#include <string.h> + +#include "programmer.h" + +static void run_lifecycle(void **state, enum programmer prog, const char *param) +{ + (void) state; /* unused */ + + printf("Testing programmer_init for programmer=%u ...\n", prog); + assert_int_equal(0, programmer_init(prog, strdup(param))); + printf("... programmer_init for programmer=%u successful\n", prog); + + printf("Testing programmer_shutdown for programmer=%u ...\n", prog); + assert_int_equal(0, programmer_shutdown()); + printf("... programmer_shutdown for programmer=%u successful\n", prog); +} + +void dummy_init_and_shutdown_test_success(void **state) +{ + run_lifecycle(state, PROGRAMMER_DUMMY, "bus=parallel+lpc+fwh+spi"); +} diff --git a/tests/meson.build b/tests/meson.build index f0cb76d..815ea76 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -18,6 +18,7 @@ 'helpers.c', 'flashrom.c', 'spi25.c', + 'init_shutdown.c', ]
mocks = [ diff --git a/tests/tests.c b/tests/tests.c index 5be4216..1dc819e 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -68,5 +68,10 @@ }; ret |= cmocka_run_group_tests_name("spi25.c tests", spi25_tests, NULL, NULL);
+ const struct CMUnitTest init_shutdown_tests[] = { + cmocka_unit_test(dummy_init_and_shutdown_test_success), + }; + ret |= cmocka_run_group_tests_name("init_shutdown.c tests", init_shutdown_tests, NULL, NULL); + return ret; } diff --git a/tests/tests.h b/tests/tests.h index cb905fd..32fed0a 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -40,4 +40,7 @@ void probe_spi_at25f_test_success(void **state); void probe_spi_st95_test_success(void **state); /* spi95.c */
+/* init_shutdown.c */ +void dummy_init_and_shutdown_test_success(void **state); + #endif /* TESTS_H */