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

51 Commits

Author SHA1 Message Date
Edward O'Callaghan
5d63d3f884 tree: Fix drivers to pass programmer_cfg to pcidev_init()
Allow for programmer_cfg plumbing in pcidev.c
The pci drivers impacted are plumbed here as well.

Change-Id: Ie0c9d1c0866d44f64d037c596f2e30547fcfd58f
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66671
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-09-07 02:45:15 +00:00
Anastasia Klimchuk
33af2e695d 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>
2022-09-04 22:48:10 +00:00
Anastasia Klimchuk
e18a528c6b tests: Test allow_brick is required for i2c programmers init
Add tests for i2c programmers that assert that initialisation fails
when allow_brick parameter is not provided.

Example of logs from test run:

[ RUN      ] parade_lspcon_no_allow_brick_test_success
Testing init error path for programmer=parade_lspcon with params: bus=254 ...
... init failed with error code -1 as expected
[       OK ] parade_lspcon_no_allow_brick_test_success

BUG=b:181803212
TEST=ninja test

Change-Id: I382f563016502f3342131d5f9c0de41dc665b03a
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66508
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:11 +00:00
Anastasia Klimchuk
5c5b0a8fab tests: Add basic lifecycle test for mediatek_i2c_spi
This unit test does not require any additional mocks because init
and shutdown of i2c infra was covered in realtek programmer lifecycle.
Default mocking of i2c is sufficient to run a basic lifecycle.

To run the test, config option for the programmer needs to be
enabled explicitly, since by default this programmer is disabled.

BUG=b:238816884
TEST=meson configure -Dconfig_mediatek_i2c_spi=true
ninja test

Change-Id: I98a12067d165c90013d33ffc45d20dab5c364c83
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66261
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Alexander Goncharov <chat@joursoir.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2022-08-08 03:15:22 +00:00
Anastasia Klimchuk
47541722c1 tests: Add basic lifecycle test for parade_lspcon
This unit test does not require any additional mocks because init
and shutdown of i2c infra was covered in realtek programmer lifecycle.
Default mocking of i2c is sufficient to run a basic lifecycle.

To run the test, config option for the programmer needs to be
enabled explicitly, since by default this programmer is disabled.

BUG=b:238816889
TEST=meson configure -Dconfig_parade_lspcon=true
ninja test

Change-Id: I0dcfae4a58c64b2e8d56ec51b4b050534cbb4cd2
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66003
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-08-08 03:14:58 +00:00
Evan Benn
dfbcf63302 tests/test.c: Allow filtering of tests using cmocka API
Tests can be filtered by providing patterns on the command line. The
pattern is the first argument provided to the test binary, if present.
Only tests matching the string provided are run, wildcards * and ?
match any characters, or one character respectively.

`meson test` or `ninja test` will continue to run all tests, as they do
not provide an argument to the test binary.

https://api.cmocka.org/group__cmocka.html

TEST=tests/flashrom_unit_tests 'layout_*'

Change-Id: I45f4ac5ef0cfb74156408022a19769d6598ad2ea
Signed-off-by: Evan Benn <evanbenn@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/65998
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-08-02 02:38:23 +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
Anastasia Klimchuk
fac9fc28f5 tests: Use regular cmocka wraps for hwaccess functions
hwaccess functions used to be static inline functions and needed
a special treatment so that they could be mocked for unit tests.

This has changed, see include/hwaccess_x86_io.h now the functions
are not static inline anymore, and it is possible to use regular
cmocka wraps.

Fixes https://ticket.coreboot.org/issues/385

BUG=b:181803212
TEST=ninja test

Change-Id: Iafce071ea7ad5bcfdebbba968699d5743705f8e0
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/64881
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Joursoir <chat@joursoir.net>
Reviewed-by: Thomas Heijligen <src@posteo.de>
2022-06-21 00:31:52 +00:00
Richard Hughes
40892b0c08 libflashrom: Return progress state to the library user
Projects using libflashrom like fwupd expect the user to wait for the
operation to complete. To avoid the user thinking the process has
"hung" or "got stuck" report back the progress complete of the erase,
write and read operations.

Add a new --progress flag to the CLI to report progress of operations.

Include a test for the dummy spi25 device.

TEST=./test_build.sh; ./flashrom -p lspcon_i2c_spi:bus=7 -r /dev/null --progress

Change-Id: I7197572bb7f19e3bdb2bde855d70a0f50fd3854c
Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: Daniel Campello <campello@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/49643
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
2022-05-25 08:08:13 +00:00
Sergii Dmytruk
b728f4b948 tests: test write protection
Tests both WP implementation and its emulation in dummy programmer.

Change-Id: I49af7f6d173eb4c56c22d80b01a473b8c499c0f8
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/59075
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-05-12 03:05:37 +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
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
Daniel Campello
f31650b23b tests: add more mock wrappers
This change allows for tests to run when the compiler is inlining some
other interfaces.  This happens when compiling on the chromium chroot
environment.

* __fgets_chk() is being used instead of fgets() in
  get_max_kernel_buf_size() on linux_spi.c
* __vfprintf_chk() is being used instead of fprintf() in
  disable_power_management() on power.c
* __open64_2() is being used instead of open() in i2c_open_path() on
  i2c_helper_linux.c

BUG=b:224828279
TEST=./test_build.sh; FEATURES=test emerge-volteer flashrom

Signed-off-by: Daniel Campello <campello@chromium.org>
Change-Id: I9776104d655c37891093da08789d37e5e27700de
Reviewed-on: https://review.coreboot.org/c/flashrom/+/62844
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2022-03-21 02:10:20 +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
Anastasia Klimchuk
9a52d20b34 tests: Add tests for verify operation
This patch adds two tests which cover verify operation, and
adds io_mock for fread.

BUG=b:181803212
TEST=ninja test

Change-Id: I1cc6f73f9b1e385eb963adccf20759c13a40ed3b
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/59239
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
2022-02-18 03:39:40 +00:00
Nikolai Artemiev
94f91ef864 tests: add fprintf() mock with redirection to io_mock
We've seen somewhat obscure test failures where the real fprintf()
function was passed a fake file returned by the fopen() mock.

Although the code that caused the specific failure was cros-specific,
adding an fprintf() mock should help avoid future debugging.

TEST=ninja test
BRANCH=none
BUG=b:217661133

Change-Id: I3f8594ea24d17436a7932732d9d05416b804dc93
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61708
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2022-02-14 02:32:04 +00:00
Anastasia Klimchuk
f47ff316ec tests: Add init-shutdown test for raiden_debug_spi
This patch adds a test for raiden_debug_spi and lots of libusb wraps.

libusb.h becomes required for tests to build and run, since new tests
are using libusb structs in depth and opaque symbols not sufficient
anymore.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I880a8637ab02de179df9169c1898230bce4dc1c7
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57918
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-11-29 01:38:39 +00:00
Anastasia Klimchuk
421d9133bb tests: Add wraps for __xstat/__fxstat variants of stat/fstat
__xstat and __fxstat variants of stat/fstat are invoked under
chromium chroot. For all existing tests it is sufficient for
stat/fstat to "do nothing, return 0", so new wraps do just that.

Test which needs __xstat: linux_mtd lifecycle.

Tests which need __fxstat:
read_chip_test_success
read_chip_with_dummyflasher_test_success
write_chip_test_success
write_chip_with_dummyflasher_test_success

Without this patch tests above fail under chromium chroot.

BUG=b:181803212
TEST=running tests on three different environments,
1) stat64/fstat64 (ninja tests in upstream tree)
2) stat64/fstat64 (ninja tests in chromium tree)
2) __xstat64/__fxstat64 (emerge with tests in chromium tree)

Change-Id: I4c5c243acde09dc5bb6b2a14042fcd23a49707db
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58103
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-11-17 15:02:57 +00:00
Anastasia Klimchuk
8aaee03333 tests: Add tests to write on chip
This patch adds two tests and initialises page_size in mock chip
chip_W25Q128_V. page_size was not needed for previous tests
(erase and read). page_size only needed to execute writing on chip
with dummyflasher, so it is added here.

BUG=b:181803212
TEST=ninja test

Change-Id: I6f0336613ab16a7e59857006496e3590ddb14d00
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58357
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-11-08 03:52:36 +00:00
Anastasia Klimchuk
99330d67b0 tests: Fix fread wrap to return success by default
Successful return value for fread is the number of items read, and
default behaviour for all wraps is to return success.

This worked previously because all existing tests have custom mocks
for fread, so default behaviour hasn't been used. However next patch
in this chain adds new test which needs default fread wrap.

BUG=b:181803212
TEST=ninja test

Change-Id: I17d82d281a87129843f547b87c18f52aca23314d
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58356
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-10-19 08:10:03 +00:00
Anastasia Klimchuk
a7a59cf0bb tests: Extract libusb wraps into separate file
In preparation for adding more tests with lots of libusb wraps,
existing wraps are extracted into separate file.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I17c1cc0189fcb742a99ad1b0fd615ab95504a74a
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57916
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-10-18 12:22:47 +00:00
Anastasia Klimchuk
97acc374e4 tests: Move current_io to io_mock.c be visible across tests
tests.c is growing and needs to be split, specifically all
libusb wraps need to be extracted into their own file. See later
in the chain a lot more wraps are added for libusb functions. To
be able to split it, current_io needs to be moved one level up,
to be visible across tests. This allows having multiple files with
wraps, and all the wraps can use current_io.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I5327b5de430afe13a8cc931c8b4b188dcb8c8cf6
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57915
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-10-18 12:22:30 +00:00
Anastasia Klimchuk
83b5191399 tests: Move LOG_ME to include/tests.h to be available everywhere
LOG_ME macro is very generic and can be useful anywhere in tests.
Previously was only used in scope of tests.c. With time more tests
are added, and more files, LOG_ME needs to be visible everywhere.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: If7f3d256161bc8b81e996328e445cccab9a82174
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57914
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-10-18 12:22:23 +00:00
Anastasia Klimchuk
d23613cf66 tests: Add NON_ZERO macro and not_null function instead of MOCK_HANDLE
This patch adds NON_ZERO macro and not_null function into io_mock.h,
so that they can be used anywhere in tests. Common usage for not_null
is to indicate a valid pointer, where it doesn't matter what the
pointer is, only matters it is not null. Common usage of NON_ZERO is
to indicate a valid file descriptor, where it only matters the
descriptor is non-zero integer.

New features replace all usages of previous MOCK_HANDLE.

This patch corrects return value from __wrap_ioctl to be successful
by default. It used to be MOCK_HANDLE, but should be 0. Included in
this patch because this is also a replacement of MOCK_HANDLE.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I5ad6ee4aa9091447c6c9108c92bf7f6e755fca48
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57269
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-10-18 12:22:12 +00:00
Anastasia Klimchuk
1f62b8346e tests: Add tests to read from chip
Two tests cover the code which performs do_read operation.

First one works with fake chip and dummy programmer. Fake chip has all
operations defined, and a buffer to emulate chip memory.

Second one uses the chip which is closer to the real one, because
read/write/unlock/erase operations are real. The tests takes the
advantage of dummyflasher's capability of emulating a W25Q128.V chip.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: Ia57781ebc670c7bd6197e56fe8a20651a425c756
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57326
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-10-01 11:28:57 +00:00
Victor Ding
cce29a4855 mec1308: remove MEC1308 EC programmer
Best efforts were made to upstream older Chromebook support for good
intentions for folks interested. However, we no longer have the hardware
available to test and maintain the code as the hardware is now end of
life. Therefore the code state has sadly fallen into a unknown state.

BUG=none
BRANCH=none
TEST=builds and ninja test passes

Signed-off-by: Victor Ding <victording@google.com>
Change-Id: I535b6380846734c999474519e9e60a73eb6a2ec4
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56476
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-09-22 13:22:42 +00:00
Victor Ding
e3f55a13ba ene_lpc: remove ENE LPC programmer
Best efforts were made to upstream older Chromebook support for good
intentions for folks interested. However, we no longer have the hardware
available to test and maintain the code as the hardware is now end of
life. Therefore the code state has sadly fallen into a unknown state.

BUG=none
BRANCH=none
TEST=builds and ninja test passes

Signed-off-by: Victor Ding <victording@google.com>
Change-Id: I3f40db22c42c04ce029c4defd837e05ebb550c9b
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56475
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-09-22 13:22:21 +00:00
Anastasia Klimchuk
05b59d2ca3 tests: Mock file i/o for linux_mtd and linux_spi tests
This patch adds an init-shutdown test for linux_mtd. Since
linux_mtd is using file i/o operations, those are added to the
framework and mocked.

Another driver linux_spi which is also using file i/o, got an upgrade
in this patch, and it is now reading max buffer size from sysfs (using
mocked file i/o).

A good side-effect is that linux_mtd is the first test for opaque
masters, which is great to have in preparation for a change like
CB:56103 but for opaque masters.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I73f0d6ff2ad5074add7a721ed3416230d3647e3f
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56413
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-08-30 02:44:17 +00:00
Anastasia Klimchuk
ed43237cfa tests: Add tests to erase a chip
Two tests cover the code which performs do_erase operation.

First one works with fake chip and dummy programmer. Fake chip has all
operations defined, and a buffer to emulate chip memory.

Second one uses the chip which is closer to the real one, because
read/write/unlock/erase operations are real. The tests takes the
advantage of dummyflasher's capability of emulating a W25Q128.V chip.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I6f74bfe4e02244d24d6c837cc3d551251e7b4898
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56501
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-08-19 04:30:13 +00:00
Peter Marheine
47f4c18260 tests: add init_shutdown test for realtek_mst_i2c_spi
This can catch regressions like the earlier one in this programmer that
caused initialization to always fail. Requires support for mocking POSIX
file I/O functions because the programmer does ioctls on the opened
file.

TEST=ninja test

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: I5a5c617d1ec35d2a3bbe622e5add82a65eb396f0
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56911
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-08-19 03:53:41 +00:00
Anastasia Klimchuk
e0ece4a4bb tests: Add init-shutdown test for nicrealtek
This patch adds a test and mocks for two pci functions that
nicreltek is using.

Main reason for this is to have at least one test for par master
(currently there are none), in preparation for a change like
CB:56103 but for par masters.

BUG=b:181803212
TEST=ninja test

Change-Id: Iaed14fe1d83c8eb45ec185ebd3f1c97cb81941f4
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56470
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-08-09 07:05:17 +00:00
Anastasia Klimchuk
e2c8ecf6e0 tests: Add unit tests for layout sanity checks
Three more tests in this patch where layout does / does not pass
sanity checks.

BUG=b:193584590
TEST=ninja test

Change-Id: Ia21585d60443b2741f3868d7887476090e35f79b
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56440
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-07-22 02:03:52 +00:00
Anastasia Klimchuk
35e8bf64a7 tests: Add layout tests for overlapping regions
There are no tests for layout, it would be great to add some.

Also partially inspired by
commit 06a89d713951a2e08ef8fb698a7688357baa83d1
and commit c9039fc27916c03e21ba91365d01e6bc49503053

BUG=b:193584590
TEST=ninja test

Change-Id: I7aa8dc0c9bc5a22fe5deea757eea1a151b969cea
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56324
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2021-07-19 04:42:01 +00:00
Anastasia Klimchuk
80c3296499 tests: Wrap strdup to help cmocka recognise memory allocation
This is a known issue in cmocka (see
https://github.com/clibs/cmocka/issues/17) where cmocka does not
recognise memory allocation happening inside strdup, and then later
throws an error when the memory is freed. If the issue is fixed at
some point, this workaround can be removed.

Given that cmocka already overrides malloc, calloc, realloc, free,
adding strdup there seems fine.

Existing tests now can (and have to) free the memory they allocated
by strdup, and this is in the same patch.

BUG=b:193584590
TEST=ninja test

Change-Id: I56aef6b342752d80995c36ab075b12198fc101d9
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56323
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2021-07-19 04:41:32 +00:00
Anastasia Klimchuk
02bc0b2c53 dediprog: Init-shutdown test for dediprog
This patch adds mocks for libusb functions. To avoid dependency on
libusb.h, libusb symbols for context and device handle are redefined.
Real libusb functions are never called in tests anyway, cmocka wraps
work with this without complaints.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I38508dfb6d7c24d42522f22fcae0c5e410c5f7ea
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55934
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
2021-07-19 03:23:04 +00:00
Anastasia Klimchuk
514e7ddc10 tests.c: Move opening brace on new line for function body
BUG=b:181803212
TEST=builds and ninja test

Change-Id: Ia1b00bb68ec2426161bfc183d93d2c0719a949ec
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55974
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2021-07-08 06:08:54 +00:00
Anastasia Klimchuk
21e22ba8a7 tests: Add unit test to run init/shutdown for mec1308.c, ene_lpc.c
This patch includes mocks for io operations in hwaccess_x86_io.h
because those are needed to test lifecycle of mec1308.c and
ene_lpc.c

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I3af612defe1af3850dfc1626a208d873e3a3eddc
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/51487
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2021-06-05 08:50:37 +00:00
Anastasia Klimchuk
98534e717b tests: Add unit test to run init/shutdown for linux_spi.c
The current implementation tests a particular path of the init
procedure. There are two ways for it to succeed: reading the buffer
size from sysfs and the fallback to getpagesize(). This test does
the latter (fallback to getpagesize).

Extract from meson-logs/testlog.txt for new test:

[ RUN      ] linux_spi_init_and_shutdown_test_success
Testing programmer_init for programmer=25 ...
__wrap_open64 is called
__wrap_ioctl is called
__wrap_ioctl is called
__wrap_ioctl is called
__wrap_fopen64 is called
... programmer_init for programmer=25 successful
Testing programmer_shutdown for programmer=25 ...
... programmer_shutdown for programmer=25 successful
[       OK ] linux_spi_init_and_shutdown_test_success

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I4911fbb6f04371283f0e62d2196bdd691a227584
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52498
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2021-04-27 12:47:48 +00:00
Anastasia Klimchuk
cffaac1e0f tests: Add unit test to run init/shutdown for dummyflasher.c
Introduce test to exercise that init and shutdown of drivers
correctly manage the drivers life-time state. We constrain
ourselves to dummyflasher in particular here as it does not need
any mocking.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I3c0ef73397f00c1db7aabb5f9f00cb43525af29c
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52497
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-04-27 12:46:45 +00:00
Anastasia Klimchuk
ab9d1460ba tests: Add logging to STDOUT when __wrap function is called
Calls to __wrap functions are now logged to stdout, makes
it easier to understand what’s happening, really helps
when writing tests (and can be useful when debugging tests).

TEST=builds and ninja test
BUG=b:181803212

Change-Id: Ifcef55c9cdb7756c38dcc44fdc57cd88c3d65e70
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52496
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2021-04-27 12:44:08 +00:00
Nikolai Artemiev
702c58a321 tests: Update licence headers
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Change-Id: Ia964279ace569b4b93f4e2919c1c228a9b621745
Reviewed-on: https://review.coreboot.org/c/flashrom/+/45438
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2020-09-17 00:48:04 +00:00
Edward O'Callaghan
76d2445d39 tests/spi25.c: Add unit-test coverage of spi95.c
Add spi95.c unit-tests to spi25.c to avoid some clutter.

BUG=b:157280555
BRANCH=none
TEST=builds

Change-Id: I6de59451b82131b58114b268ff6dd0b18cd5952b
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/41656
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2020-06-17 11:08:30 +00:00
Edward O'Callaghan
3cc70c25f9 tests/: Add helper.c unit tests
BUG=b:157280555
BRANCH=none
TEST=builds

Change-Id: If4a1fe7c499f51bb9d7cd48ef26caf9dfae3c1fa
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/41655
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2020-06-17 11:08:06 +00:00
Edward O'Callaghan
629b8f06ec tests/: Add flashrom.c unit tests
BUG=b:157280555
BRANCH=none
TEST=builds

Change-Id: I2d9213f98c6c9639f2417466ba4895117e8d600a
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/41646
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
2020-06-17 11:07:35 +00:00
Edward O'Callaghan
41f48c75a2 tests/: Add spi25.c unit tests
BUG=b:157280555
BRANCH=none
TEST=builds

Change-Id: I47112952835ce2c4c773a9d90379ff8ceefaaf9a
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/41645
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2020-06-16 02:25:17 +00:00