1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

21 Commits

Author SHA1 Message Date
Edward O'Callaghan
46856234b3 tests/lifecycle.c: Avoid unnecessary heap allocations
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>
2023-01-22 05:54:50 +00:00
Anastasia Klimchuk
5363f35fa0 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>
2022-09-20 23:45:08 +00:00
Anastasia Klimchuk
5fbe87ce50 tests/lifecycle: Run shutdown for init error paths
`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>
2022-09-04 22:47:52 +00:00
Anastasia Klimchuk
4adfd99d78 tests: Add function to test programmer init error paths
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>
2022-08-10 23:53:00 +00:00
Anastasia Klimchuk
94efa44542 tests: Split lifecycle test file into per-programmer files
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>
2022-07-10 22:28:45 +00:00
Anastasia Klimchuk
f41465d440 tests: Create lifecycle.h and gather includes and macro there
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>
2022-07-10 22:27:59 +00:00
Anastasia Klimchuk
71488a8c13 tests: Remove unnecessary static keyword from lifecycle tests
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>
2022-06-28 22:05:36 +00:00
Anastasia Klimchuk
eb63685e19 tests: Add dummyflasher unit tests for opaque programmer
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>
2022-06-28 22:05:08 +00:00
Thomas Heijligen
f3d09b5997 tests: Rearange CPP guards
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>
2022-05-12 08:54:39 +00:00
Anastasia Klimchuk
c4784f1a9a tests: Add and include headers with function prototypes
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>
2022-04-29 04:30:38 +00:00
Anastasia Klimchuk
402e5d697c tests: Mark all static functions as static
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>
2022-04-29 04:24:33 +00:00
Edward O'Callaghan
8abe12e86e tests/: Add file path and flags validation to open() calls
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>
2022-04-18 23:16:37 +00:00
Edward O'Callaghan
999bbb32ae tests/lifecycle.c: Deduce out io-setup-teardown do-pattern
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>
2022-04-12 23:59:49 +00:00
Edward O'Callaghan
950037a724 tests/linux_spi: Validate params file path and flags
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>
2022-04-10 11:17:38 +00:00
Daniel Campello
885fb2e82b tests: assert pathname and flags when calling open()
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>
2022-04-06 07:43:55 +00:00
Daniel Campello
9454336970 tests: use MOCK_FD instead of NON_ZERO
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>
2022-04-06 03:05:19 +00:00
Anastasia Klimchuk
78221212fa tests: Upgrade linux_spi test to run probe lifecycle
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>
2022-03-20 22:41:53 +00:00
Anastasia Klimchuk
e2f31ca02b tests: Upgrade linux_mtd test to run probe lifecycle
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>
2022-03-20 22:27:37 +00:00
Anastasia Klimchuk
e539d112cd tests: Add run_probe_lifecycle and add dummyflasher probe test
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>
2022-03-20 22:18:40 +00:00
Anastasia Klimchuk
79e2bd045c tests: Rename run_lifecycle into run_basic_lifecycle
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>
2022-03-10 09:34:14 +00:00
Anastasia Klimchuk
fd36978f1a tests: Rename init_shutdown.c into lifecycle.c
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>
2022-03-10 08:52:09 +00:00