summaryrefslogtreecommitdiffstats
path: root/tests/lifecycle.c
Commit message (Collapse)AuthorAgeFilesLines
* tests/lifecycle.c: Avoid unnecessary heap allocationsEdward O'Callaghan2023-01-221-10/+3
| | | | | | | | | | Just use a static string on the stack. Change-Id: I0414ab9a63867fc58b04ad62ed3ec4f221448a58 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/71918 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: Add unit test for initialisation with NULL programmer paramAnastasia Klimchuk2022-09-201-1/+2
| | | | | | | | | | | | | | | | 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>
* tests/lifecycle: Run shutdown for init error pathsAnastasia Klimchuk2022-09-041-0/+11
| | | | | | | | | | | | | | | | | | | | | `run_init_error_path` tests the scenario when init function of a programmer fails. Init can fail at different phases and depending on a specific test scenario it could be before or after shutdown function has been registered. If shutdown function has already been registered, it needs to run because it cleans up the resources allocated during init. This patch prevents memory leaks. BUG=b:181803212 TEST=ninja test Change-Id: I604edff18e35b7c044b73d3a8adfa8c800eddfd2 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67198 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Add function to test programmer init error pathsAnastasia Klimchuk2022-08-101-0/+19
| | | | | | | | | | | | | | | New function tests an error path for programmer initialisation, and expects programmer init to fail with given error code. BUG=b:181803212 TEST=ninja test Change-Id: Icc59396e604d74442852b4bbd575440df3347c3f Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66507 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Split lifecycle test file into per-programmer filesAnastasia Klimchuk2022-07-101-383/+0
| | | | | | | | | | | | | | | | | | | This patch creates individual files for each programmer's lifecycle tests. Common functions that are reusable for all tests are gathered in lifecycle.c. Each individual file needs to include lifecycle.h BUG=b:237606255 TEST=ninja test Change-Id: If2307699dcbb3a085b91a2dcd41156e6fd07f812 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/65543 Reviewed-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Create lifecycle.h and gather includes and macro thereAnastasia Klimchuk2022-07-101-12/+1
| | | | | | | | | | | | | | | | | | New header file lifecycle.h need to gather all things shared among lifecycle tests. This is one step to the goal of splitting lifecycle tests into separate per-programmer file. BUG=b:237606255 TEST=ninja test Change-Id: I93d0db943d9c96e2c36e9f7dce5c885c959745a0 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/65541 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Remove unnecessary static keyword from lifecycle testsAnastasia Klimchuk2022-06-281-9/+9
| | | | | | | | | | | | | | | | | | Lifecycle tests had local struct declared with static keyword, but static was not necessary for them. So, removing. BUG=b:233816068 TEST=ninja test Change-Id: If844d07ec42b878bd0da8460655be45e865f089f Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/65323 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Evan Benn <evanbenn@google.com> Reviewed-by: Joursoir <chat@joursoir.net> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Add dummyflasher unit tests for opaque programmerAnastasia Klimchuk2022-06-281-1/+15
| | | | | | | | | | | | | | | | | | In commit a721181a08 dummyflasher became an opaque master too, and now registers prog bus by default. This patch upgrades a dummy unit test which uses all buses as programmer param, and adds a unit test which covers specific use case for opaque programmer. BUG=b:233816068 TEST=ninja test Change-Id: I61a5333b61ea84fb91c7f8310d52b64213c62f83 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/65236 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Joursoir <chat@joursoir.net> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Rearange CPP guardsThomas Heijligen2022-05-121-33/+34
| | | | | | | | | | | | | | | This fixes -Werror=unused-function when not all programmer tests are build. `run_basic_lifecycle` and `run_probe_lifecycle` need to have a prototype to not throw a -Werror=unused-function if no programmer needs them. Change-Id: I02880e73996b30df618738e86b8a52126fbe5b3b Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/64224 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: Add and include headers with function prototypesAnastasia Klimchuk2022-04-291-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Part 2 of fixing -Wmissing-prototypes warnings. This patch adds headers with function prototypes and includes the headers into source files. This fixes the warnings like this: warning: no previous prototype for ‘function_name’ [-Wmissing-prototypes] This patch is needed to sync compiler warning options between meson and makefile. TEST=running the following produces no warnings: meson setup --wipe (to clean build directory) ninja test Change-Id: Ia1ff22deb2354569f277649c6575ef2d5ffbb6e0 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/63489 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
* tests: Mark all static functions as staticAnastasia Klimchuk2022-04-291-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Part 1 of fixing -Wmissing-prototypes warnings. This patch is adding static to all functions which are actually static. This fixes the warnings like this: warning: no previous prototype for ‘function_name’ [-Wmissing-prototypes] This patch is needed to sync compiler warning options between meson and makefile. TEST=running the following produces no warnings: meson setup --wipe (to clean build directory) ninja test Change-Id: Ic54da5ac1b2a46f55e3e3bee4ed952bdf59e8444 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/63571 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
* tests/: Add file path and flags validation to open() callsEdward O'Callaghan2022-04-181-3/+42
| | | | | | | | | | | | | | | | | With this change we add path and flag validation to many tests that do not call open. Expected path is set to NULL, if the code indead calls open then the assertion for non-NULL will make the test fail. BUG=b:217629892,b:215255210 TEST=`ninja test`. Change-Id: I892fa1ecee26ebce9640893edbb228fa9aa7b0b6 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Co-Author: Daniel Campello <campello@chromium.org> Signed-off-by: Daniel Campello <campello@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/62320 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests/lifecycle.c: Deduce out io-setup-teardown do-patternEdward O'Callaghan2022-04-121-33/+19
| | | | | | | | | | | | | | | | | | | | | | | The following do-block is quite error prone to do manually, ``` io_mock_register(&XXX_io); run_probe_lifecycle(state, &XXX, "", ".."); io_mock_register(NULL); ```. Hence, deduce out the common pattern and fold up into the common worker function to handle state machine setup and teardown in a consistent way. BUG=b:227521116 TEST=`ninja test`. Change-Id: Icc00acd980a027337acb079f5afc3cccdfe4c765 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/63231 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Daniel Campello <campello@chromium.org>
* tests/linux_spi: Validate params file path and flagsEdward O'Callaghan2022-04-101-0/+6
| | | | | | | | | | | | | | | Add path and flags validation for '/dev/null' to open operation. BUG=b:217629892,b:215255210 TEST=`ninja test`. Signed-off-by: Edward O'Callaghan <quasisec@google.com> Co-Author: Daniel Campello <campello@chromium.org> Signed-off-by: Daniel Campello <campello@chromium.org> Change-Id: If5d24c65f291c53a35509fea5d2f5b3fdb51c306 Reviewed-on: https://review.coreboot.org/c/flashrom/+/62319 Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: assert pathname and flags when calling open()Daniel Campello2022-04-061-8/+6
| | | | | | | | | | | | | | | | | | | With this change the wrappers for mock and friends are able to take an optional io_mock_fallback_open_state struct to assert expected pathnames and flags whenever an open operation is called. Based partially on https://review.coreboot.org/c/flashrom/+/62319/5 BUG=b:227404721,b:217629892,b:215255210 TEST=./test_build.sh; FEATURES=test emerge-amd64-generic flashrom BRANCH=none Signed-off-by: Daniel Campello <campello@chromium.org> Co-Author: Edward O'Callaghan <quasisec@google.com> Change-Id: Ib46ca5b854c8453ec02ae09f3151cd4d25f988eb Reviewed-on: https://review.coreboot.org/c/flashrom/+/63227 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: use MOCK_FD instead of NON_ZERODaniel Campello2022-04-061-6/+4
| | | | | | | | | | | | | | | | | | With this change the mocks are able to return a non-negative value for the file descriptor expected from open operations. This avoid issues with subsequent error checks of the form `if (fd < 0)` BUG=b:227404721 TEST=./test_build.sh; FEATURES=test emerge-amd64-generic flashrom BRANCH=none Signed-off-by: Daniel Campello <campello@chromium.org> Change-Id: Ib6bac051852aea2465665a6fd669b7f5e3772985 Reviewed-on: https://review.coreboot.org/c/flashrom/+/63193 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: Upgrade linux_spi test to run probe lifecycleAnastasia Klimchuk2022-03-201-2/+28
| | | | | | | | | | | | | | | | This test adds a mock for linux_spi ioctl and mocks it for read request. Read buffer is populated with chip manufacture id and chip model id to emulate successful probing. BUG=b:181803212 TEST=ninja test Change-Id: I32d8e972d99b52c2b18f688aa6aeae75dd170f72 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/59742 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Nico Huber <nico.h@gmx.de>
* tests: Upgrade linux_mtd test to run probe lifecycleAnastasia Klimchuk2022-03-201-2/+2
| | | | | | | | | | | | | | | No additional mocks are needed, because linux_mtd is doing most of the job in init function. BUG=b:181803212 TEST=ninja test Change-Id: I74436f36f628680c22c7225b1584f06464307775 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/59743 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Add run_probe_lifecycle and add dummyflasher probe testAnastasia Klimchuk2022-03-201-7/+54
| | | | | | | | | | | | | | | | | | | | | | | | This patch implements run_probe_lifecycle and adds dummyflasher test to run probing lifecycle. A lifecycle consists of 3 steps: 1) init programmer 2) do some action 3) shutdown programmer. Step 2 can be "do nothing", and this is named "basic lifecycle", i.e. the simplest. This patch implements "probe lifecycle" which probes a chip as Step 2. Internally there is one run_lifecycle function which performs steps 1, 2, 3. run_lifecycle is operating via libflashrom API. Long term goal for cli_classic is to operate via libflashrom API, so the test aligns with this approach. BUG=b:181803212 TEST=ninja test Change-Id: I9eb7fe3a436fbba5e70db957139fd26e00efec36 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/59741 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Rename run_lifecycle into run_basic_lifecycleAnastasia Klimchuk2022-03-101-15/+15
| | | | | | | | | | | | | | | | | | | | | | Lifecycle tests are getting an upgrade in this chain, with new type of tests: lifecycle with probing. Existing lifecycle, being the simplest possible one becomes "basic lifecycle". With time, most of existing tests will be upgraded to probing lifecycle, however not necessarily all of them. Basic lifecycle will likely to stay as an option. This can be convenient, for a developer who wishes to add a test for a programmer, to have a choice of basic and extended option. BUG=b:181803212 TEST=ninja test Change-Id: I2771921ae2bd37f4b3f49342e03d9abb5ee36ea0 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/59740 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
* tests: Rename init_shutdown.c into lifecycle.cAnastasia Klimchuk2022-03-101-0/+352
Lifecycle tests are getting an upgrade later in this chain, which means lifecycle becomes more than just init and shutdown. Rename into lifecycle.c to reflect the upgrade. BUG=b:181803212 TEST=ninja test Change-Id: I8d734c43cc15c7ec1055d3fb5bdcdca8c90d0987 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/59739 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>