aboutsummaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* tests: Add llvm-cov option and run target for code coverageEvan Benn2022-12-111-1/+5
| | | | | | | | | | | | | | | | | Code coverage can be requested with -Dllvm_cov and run with ninja llvm-cov-tests or llvm-cov-cli. BUG=b:187647884 BRANCH=None TEST=meson test; ninja llvm-cov-tests TEST=ran test_build.sh with coverage enabled TEST=jenkins ran test_build.sh with coverage disabled Change-Id: Id6c73bff46e7b88d425956a80def97082b201f56 Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69268 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: Detect llvm coverage run and redirect to real I/O functionsEvan Benn2022-12-093-1/+20
| | | | | | | | | | | | | | | | | Code coverage writes data to disk, we need to use real io functions at this point so that the data is really written. BUG=b:187647884 BRANCH=None TEST=llvm-profdata merge -sparse default.profraw -o default.profdata TEST=llvm-cov show ./flashrom_unit_tests -instr-profile=default.profdata --format=html --output-dir=. Change-Id: I21cc1d631e92fa19006b967e85676f108e80b307 Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69267 Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Detect gcov run and redirect to real I/O functionsEvan Benn2022-12-091-0/+2
| | | | | | | | | | | | | | | | Code coverage writes data to disk, we need to use real io functions at this point so that the data is really written. BUG=b:187647884 BRANCH=None TEST=meson test TEST=ninja coverage Change-Id: If06053ecd78e886c8f7fc55813f4b5635be78c6b Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69266 Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Redirect to real I/O to support coverage runEvan Benn2022-12-094-0/+91
| | | | | | | | | | | | | | | | Implement a check that redirects mock io functions to the real implementations. Real I/O functions are needed for the coverage tool to be able to create and write files. BUG=None BRANCH=None TEST=None Change-Id: I0817fce6ea0f53a4c127794a0d8246504675f805 Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69539 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: Add fwrite and fdopen to io_mockEvan Benn2022-12-092-0/+6
| | | | | | | | | | | | | BUG=None BRANCH=None TEST=None Change-Id: I4dff96c264b3ada354538b434b2808fb66c7ef59 Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69538 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Mock the mode_t variant of openEvan Benn2022-12-094-17/+35
| | | | | | | | | | | | | | | | | open has a second form with a mode_t argument. When mocking without this argument a caller trying to O_CREAT would have their mode_t argument discarded and a random stack variable would be used instead. BUG=b:187647884 BRANCH=None TEST=meson test Change-Id: I8c134e6d36a248d0f51985e389085a9e585fb83d Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69263 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Move test.h includeEvan Benn2022-12-082-1/+2
| | | | | | | | | | | | | BUG=None BRANCH=None TEST=None Change-Id: I8e0611c415c921f5b04b20270fb26e147fefd1b8 Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69537 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: Add selfcheck to unit testsEvan Benn2022-12-054-0/+172
| | | | | | | | | | | | | | | | | Add unit tests for programmer_table, flashchips, and board_matches structs. The tests are derived from the selfcheck function, checking that the required fields have been filled in. BUG=b:140595239 BRANCH=None TEST=meson test Change-Id: I41cd014d9bf909296b6c28e3e00548e6883ff41a Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69620 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: add probe lifecycle test for ch341a_spiAlexander Goncharov2022-11-293-3/+47
| | | | | | | | | | | | | | This test upgrades mocks to simulate a read request. Read buffer is populated with chip manufacture id and chip model id to emulate successful probing. TEST=ninja test Change-Id: I0a2d5591d097435fc69719e1d9bd153433425821 Signed-off-by: Alexander Goncharov <chat@joursoir.net> Reviewed-on: https://review.coreboot.org/c/flashrom/+/68755 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: add basic lifecycle test for ch341a_spiAlexander Goncharov2022-11-294-1/+97
| | | | | | | | | | | | | | | | | | | | TEST=the following scenarios run tests successfully 1) ch341a_spi is enabled result: all tests run and pass, including ch341a 2) ch341a_spi is disabled result: ch341a_spi test is skipped, the rest of tests run and pass 3) libusb isn't presented in the system result: tests for usb programmers are skipped, the rest of tests run normally Change-Id: If28fbe09ad685082152aa3a7e8d5a150169aee9e Signed-off-by: Alexander Goncharov <chat@joursoir.net> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67664 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: add mocks for libusb's asynchronous APIAlexander Goncharov2022-11-292-0/+12
| | | | | | | | | | | This patch adds mocks for several libusb functions are introduced in one of the previous commits. Signed-off-by: Alexander Goncharov <chat@joursoir.net> Change-Id: I5a316687ab39a112d968eeaedb71f7b4b659d8d5 Reviewed-on: https://review.coreboot.org/c/flashrom/+/69873 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: add more wrappers for libusb funcsAlexander Goncharov2022-11-294-0/+66
| | | | | | | | | | | The patch adds wrappers for libusb functions that are used in the ch341a programmer and have not yet been introduced. Change-Id: Ic11efb9fd746cb91911dbe87e1c0028759f5bb0b Signed-off-by: Alexander Goncharov <chat@joursoir.net> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69872 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* tests: Move SKIP_TEST macro to common headerEvan Benn2022-11-282-3/+3
| | | | | | | | | | | | | BUG=None BRANCH=None TEST=None Change-Id: I6cca635212867dad5a8e391a46b1d943530c539a Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69621 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: ensure chip erase operation is executedNikolai Artemiev2022-11-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | The `full_chip_erase_with_wp_dummyflasher_test_success` test case checks that erasing a write-protected region of a dummyflasher chip fails. However erase optimization may cause the erase operation to be skipped if the flash contents are already erased, so the erase operation appears to succeed and the test case fails. Writing a non-erased value to the chip ensures that an erase operation will be executed and write protection will be properly tested. BUG=b:237620197 BRANCH=none TEST=ninja test Change-Id: Ia00444dcd2ad96c64832a13201efbd064cd7302d Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69130 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
* meson: Move programmer test sources into programmer definitionFelix Singer2022-11-111-9/+4
| | | | | | | | | | | | | | | | | Move the definition of the programmer test source files into the dictionary defining the programmers itself. This way there is a better overview about which of the available programmers have tests and which don't. Also, to keep the tests working, iterate over all programmers and add their test source files to the list of sources that should be built. Signed-off-by: Felix Singer <felixsinger@posteo.net> Change-Id: I307faaf8a9f7ae3c54bd96e7d871a3abb8aadea3 Reviewed-on: https://review.coreboot.org/c/flashrom/+/68162 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tree/: Convert flashchip erase_block func ptr to enumerateEdward O'Callaghan2022-11-111-1/+6
| | | | | | | | | | | | | | This forges the way for flashchips.c to be pure declarative data and lookup functions for dispatch to be pure. This means that the flashchips data could be extracted out to be agnostic data of the flashrom code and algorithms. Change-Id: I02ae7e4c67c5bf34ec2fd7ffe4af8a2aba6fd5e5 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69133 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tree/: Convert flashchips db to use indirection for erase_blockEdward O'Callaghan2022-11-112-10/+10
| | | | | | | | | | | | | | This paves the way to allow for the conversion of flashchip erase_block func ptr to enumerate values. This change should be a NOP. TEST=`diff -u <(objdump -D flashchips.o_bk) <(objdump -D flashchips.o)`. Change-Id: I122295ec9add0fe0efd27273c9725e5d64f6dbe2 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/69131 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tree/: Rename ERROR_FATAL to ERROR_FLASHROM_FATALEdward O'Callaghan2022-11-091-2/+2
| | | | | | | | Change-Id: I51ee789f9a1443bfff1e3c85c9b40b5023db6062 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/68776 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net>
* tests: Add prefix to io_mock functions not to clash with macrosAnastasia Klimchuk2022-11-088-43/+43
| | | | | | | | | | | | | | | | | | | | Flashrom I/O mock functions need to be renamed so that they do not have name clash with standard I/O, because the latter are allowed to be macros. Adding a prefix to flashrom mock functions avoids them being accidentally expanded. Standard I/O functions are expanded and flashrom mocks stay as they are. BUG=b:237606255 TEST=ninja test 1) gcc 12.2.0 on Debian 2) clang 15.0 on Chromium OS Ticket: https://ticket.coreboot.org/issues/411 Change-Id: I7998a8fb1b9e65621e12adbfab5460a245d5606b Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/68433 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net>
* tests: Undefine _FORTIFY_SOURCE for unit tests to avoid _chk variantsAnastasia Klimchuk2022-11-072-18/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The option _FORTIFY_SOURCE, when enabled, can result in some functions being expanded into _chk variants. For example, `fprintf` can get expanded into `__fprintf_chk`. This makes sense for building a real binary, but is not needed for unit tests. In unit test environment all those functions are wrapped. In the example above, both `fprintf` and `__fprintf_chk` needed to be mocked. Disabling _FORTIFY_SOURCE avoids expanding functions into _chk variants, without any loss of testing coverage because that would be wrapped/mocked anyway. This patch also removes two existing _chk wraps because they are not needed anymore. BUG=b:237606255 TEST=ninja test on 1) gcc 12.2.0 on Debian 2) clang 15.0 on Chromium OS Ticket: https://ticket.coreboot.org/issues/411 Change-Id: I70cb1cd90d1f377ff4606acad3c1b514120ae4f7 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/68432 Reviewed-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests/meson.build: Rename list of source files to `test_srcs`Felix Singer2022-11-011-3/+3
| | | | | | | | | | | | Rename the list of source files to `test_srcs` so that there is less confusion with the variable `srcs` from the top-level meson.build file containing the flashrom source files. Signed-off-by: Felix Singer <felixsinger@posteo.net> Change-Id: Ica0fc3923070bff63323204bd58edb5276dc9493 Reviewed-on: https://review.coreboot.org/c/flashrom/+/68228 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
* tree/: Convert flashchip read func ptr to enumerateEdward O'Callaghan2022-11-012-3/+8
| | | | | | | | | | | | | | | | This forges the way for flashchips.c to be pure declarative data and lookup functions for dispatch to be pure. This means that the flashchips data could be extracted out to be agnostic data of the flashrom code and algorithms. TEST='R|W|E && --flash-name' on ARM, AMD & Intel DUT's. Change-Id: I612d46fefedf2b69e7e2064aa857fa0756efb4e7 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66788 Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-by: Felix Singer <felixsinger@posteo.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tree/: Convert flashchip write func ptr to enumerateEdward O'Callaghan2022-11-013-4/+10
| | | | | | | | | | | | | | | | This forges the way for flashchips.c to be pure declarative data and lookup functions for dispatch to be pure. This means that the flashchips data could be extracted out to be agnostic data of the flashrom code and algorithms. TEST='R|W|E && --flash-name' on ARM, AMD & Intel DUT's. Change-Id: I80149de169464b204fb09f1424a86fc645b740fd Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66782 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-by: Felix Singer <felixsinger@posteo.net>
* tree/: Convert flashchip probe func ptr to enumerateEdward O'Callaghan2022-11-011-1/+1
| | | | | | | | | | | | | | | | This forges the way for flashchips.c to be pure declarative data and lookup functions for dispatch to be pure. This means that the flashchips data could be extracted out to be agnostic data of the flashrom code and algorithms. TEST='R|W|E && --flash-name' on ARM, AMD & Intel DUT's. Change-Id: I00aaab9c83f305cd47e78c36d9c2867f2b73c396 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66781 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-by: Felix Singer <felixsinger@posteo.net>
* tree/: Convert flashchip decode range func ptr to enumNikolai Artemiev2022-10-281-1/+1
| | | | | | | | | | | | | | | | | | | | Replace the `decode_range` function pointer in `struct flashchip` to an enum value. The enum value can be used to find the corresponding function pointer by passing it to `lookup_decode_range_func_ptr()`. Removing function pointers like `decode_range` makes it possible to represent chip data in a declarative format that does not have to be stored as C source code. BUG=b:242479049 BRANCH=none TEST=ninja && ninja test Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Change-Id: If6d08d414d3d1ddadc95ca1d407fc87c23ab543d Reviewed-on: https://review.coreboot.org/c/flashrom/+/67195 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/meson.build: Turn file list into list of file objectsFelix Singer2022-10-151-2/+2
| | | | | | | | | | | | | | | | | When a file object is created, Meson also checks if the file actually exists and an error points to the specific line of meson.build if not. If just a list of filenames is used, then the error occurs at the line where the list is used. Thus, use file objects in tests/meson.build for more useful error messages. Signed-off-by: Felix Singer <felixsinger@posteo.net> Change-Id: I0b9144a6b76c1772833817b4e6873818dcf36b05 Reviewed-on: https://review.coreboot.org/c/flashrom/+/68197 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Add unit test for initialisation with NULL programmer paramAnastasia Klimchuk2022-09-204-1/+18
| | | | | | | | | | | | | | | | 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/parade_lspcon.c: Replace spaces with tabsAnastasia Klimchuk2022-09-201-10/+10
| | | | | | | | | | | | Spaces were accidentally introduced in previous commit, replace with tabs as it should be. Change-Id: Ic3a7d3004b8358953917a6666bcf8f1cdade02fd Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67643 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
* tests: Add workaround to allow tests mock fileno on FreeBSDAnastasia Klimchuk2022-09-161-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | fileno can be a function and a macro in FreeBSD, depending on whether the environment in multi-threaded or single-threaded. For single thread, macro is used. Macro is expanded into a inline code which accesses private field of file descriptor. This is impossible to mock in tests. Pretending that environment is multi-threaded makes fileno function to be called instead of a macro. Function can be mocked for tests. BUG=b:237606255 TEST=ninja test tests pass on two environments: 1) FreeBSD 13.1-RELEASE-p2 GENERIC amd64 2) Debian 5.17.11 x86_64 GNU/Linux Change-Id: I3789ea9107a4cf8033cf59bb96d3c82aa58de026 TICKET: https://ticket.coreboot.org/issues/411 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67312 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Peter Marheine <pmarheine@chromium.org>
* tests: Guard Linux-specific linux/spidev.h header fileAnastasia Klimchuk2022-09-121-0/+2
| | | | | | | | | | | | | | | | | | This allows unit tests to build on non-Linux platforms. BUG=b:237606255 TEST=unit tests compile on two environments: 1) FreeBSD 13.1-RELEASE-p2 GENERIC amd64 2) Debian 5.17.11 x86_64 GNU/Linux Change-Id: Icdb1b0cb29c5d62187153788ad5e0e631e8d0b62 TICKET: https://ticket.coreboot.org/issues/411 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67311 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Thomas Heijligen <src@posteo.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Use MOCK_FD instead of NON_ZERO for file operationsAnastasia Klimchuk2022-09-121-2/+2
| | | | | | | | | | | | | | | | | | NON_ZERO can be a negative number, so MOCK_FD is safer option to use as a mock file descriptor. Also it is more readable. BUG=b:237606255 TEST=ninja test (on linux) Change-Id: I097dd59f69c3fb532ac136796fcf5cae8839af7b TICKET: https://ticket.coreboot.org/issues/411 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67310 Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Alexander Goncharov <chat@joursoir.net> Reviewed-by: Thomas Heijligen <src@posteo.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* meson: Refactor the programmer selectionThomas Heijligen2022-09-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements a positive selection choice of which programmers should be built. - Each programmer is represented through an entry in the programmer dictionary - The entry contains: - A list of systems and CPU families where the programmer can run on - A list of required dependencies - A list of sources needed to build the programmer - A list of compiler flags - A flag to determin if the programmer should be build on 'auto' - If an entry is not given it is set to the default value - If a programmer gets selected, an 'active' flag is added to the entry on runtime - All programmers with an 'active' flag will be included in the build - One or more programmers can be selected through '-Dprogrammer=<>' - 'auto' enables all programmers which are available, deps are found and have the 'default' flag - 'all' enables all programmers which are available and deps are found - 'group_***' enables all programmers which are available, deps are found and the programmer belongs to the selected group - '_programmer_name_' forces the programmer to be built or the build will fail. Change-Id: Ib44b26e3748fc71f116184082b4aed0bb208b4c1 Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/63724 Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* Revert "cmocka: Drop as meson subproject"Nico Huber2022-09-081-1/+1
| | | | | | | | | | | | | | | | | | This reverts commit 99eca0899b931b21b7c44ed1753c5f01b35798af. The environment provided by our Jenkins builder doesn't have cmocka. It's not exactly known why it worked as a subproject. However, if it allows us to enforce tests in the CI, we should revert now and drop the subproject again once the environment is updated. Change-Id: Iafdab92eb8ab96d02fb2c29524d785bdc7a54034 Signed-off-by: Nico Huber <nico.huber@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67345 Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Add wrappers for libusb_(attach|detach)_kernel_driverThomas Heijligen2022-09-073-0/+16
| | | | | | | | | Change-Id: Ia463824a209db65e82ccfbf320368b2ce82eb36f Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67079 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tree: Fix drivers to pass programmer_cfg to pcidev_init()Edward O'Callaghan2022-09-072-2/+4
| | | | | | | | | | | | 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>
* tests: Add tests to cover unhandled programmer params pathsAnastasia Klimchuk2022-09-043-0/+64
| | | | | | | | | | | | | | | 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>
* 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/parade_lspcon.c: Add emulation for ioctl, read, write operationsAnastasia Klimchuk2022-09-041-0/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, parade lspcon unit test had no custom emulation and was running basic lifecycle with default mocks (default mocks do nothing and return success). I have discovered that it does not work in all environments. Specifically, in functions `parade_lspcon_wait_command_done` and `parade_lspcon_wait_rom_free` there is a local variable `uint8_t val` which is declared and not explicitly initialised. It can get different initial values depending on the environment/toolchain (for example gcc vs clang). Later during the code execution, this variable is used as a holder for writing/reading data from register(s). For unit test, reading and writing data from registers is emulated. With default mocks, initial value of variable was propagated further as if it was "read" from a register. So the unit test could pass or fail depending on the initial value of local variable, which in turn depends on environment and toolchain. If initial value was 0 the test reliably passed (this is the case with upstream build environment, locally I have gcc 11.3.0 on x86_64). If it was 1 the test reliably failed (this is the case of chromium flashrom tree, this is clang 15.0 under chroot, tested on x86_64 and arm boards). If it was any other value then it could be anything. This patch adds custom mocks for ioctl/read/write operations and emulates a successful scenario of running a lifecycle. Local variable is initialised by reading from the register, same as it happens in the real (non-test) run for this programmer. BUG=b:242816982 TEST=ninja test Change-Id: I98f52507a0ddbbfbeb390038d14192cacc2be683 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67161 Reviewed-by: Peter Marheine <pmarheine@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net>
* cmocka: Drop as meson subprojectThomas Heijligen2022-08-171-1/+1
| | | | | | | | | | | | | | | | | Depend exclusive on the cmocka package provided by the build environment. Cmocka is widely available in Linux distributions and BSD systems. Besides that, it is suboptimal to fetch own dependencies in the build process. Most packaging systems even forbid fetching additional assets at build time. Change-Id: I751c85d5f72e47356113cf55dfbaec73cbd8028c Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66696 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Felix Singer <felixsinger@posteo.net>
* tests/realtek_mst_i2c_spi.c: Fix macro closing commentFelix Singer2022-08-101-1/+1
| | | | | | | | | Signed-off-by: Felix Singer <felixsinger@posteo.net> Change-Id: I7b130c58305f4a8b2afbfdb7dcead9d6535d98af Reviewed-on: https://review.coreboot.org/c/flashrom/+/66509 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Thomas Heijligen <src@posteo.de>
* tests: Test allow_brick is required for i2c programmers initAnastasia Klimchuk2022-08-105-0/+54
| | | | | | | | | | | | | | | | | | | | | | 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>
* tests: Add function to test programmer init error pathsAnastasia Klimchuk2022-08-102-0/+21
| | | | | | | | | | | | | | | 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: Add basic lifecycle test for mediatek_i2c_spiAnastasia Klimchuk2022-08-084-0/+39
| | | | | | | | | | | | | | | | | | | | | | 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>
* tests: Add basic lifecycle test for parade_lspconAnastasia Klimchuk2022-08-084-0/+39
| | | | | | | | | | | | | | | | | | | | | 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>
* tests/test.c: Allow filtering of tests using cmocka APIEvan Benn2022-08-021-1/+4
| | | | | | | | | | | | | | | | | | | | | | 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>
* meson: fix various meson build warnings and formattingNikolai Artemiev2022-07-281-3/+0
| | | | | | | | | | | | | | | | | | | | | | - Make run_command() calls check for failures to fix warnings about ignoring errors, see https://github.com/mesonbuild/meson/issues/9300. - Remove `include_directories('../subprojects')` from tests/meson.build. It isn't necessary and caused build warnings due to referencing files outside the tests/ directory. - Fix indent level and formatting in a few places. BUG=none BRANCH=none TEST=meson; ninja; ninja test Change-Id: I17ae0c51d68ed004772a237641f08345f4893200 Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/66060 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
* realtek_mst_i2c_spi: Use underscores for parameters instead hyphensFelix Singer2022-07-221-1/+1
| | | | | | | | | | | | | | | | realtek_mst_i2c_spi is the only programmer which uses hyphens instead of underscores in its parameter names. Thus, for consistency, rename the parameters so that they use underscores. Signed-off-by: Felix Singer <felixsinger@posteo.net> Change-Id: I5ff6d8d432d875670fcaa2088e9cf9d9f1b83dc2 Reviewed-on: https://review.coreboot.org/c/flashrom/+/65935 Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Thomas Heijligen <src@posteo.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
* realtek_mst_i2c_spi.c: Add allow-brick=yes programmer paramEdward O'Callaghan2022-07-171-1/+1
| | | | | | | | | | | | | | | | | | Currently i2c programmers do not have a safe allow listing mechanism via board_enable to facilitate fully qualified chip detection. Since i2c addresses alone can overlap a user may make the mistake of using the wrong programmer. Although unlikely, it is within the realm of possibility that a user could accidently somehow program another chip on their board. Change-Id: Ifb303989fdb67f7267002bd0425f3d050450ec93 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/65545 Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
* tests: Make libusb conditional dependency for unit testsAnastasia Klimchuk2022-07-103-6/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unit tests had an unconditional dependency on libusb and this was a) strictly speaking not needed, b) blocking one build system effort. This patch is a temporary solution to unblock one build system effort, specifically CB:63724. It creates a condition so that libusb is only included when it is required, not always. This workaround is based on the fact that at the moment only 2 lifecycle unit tests are using libusb symbols: dediprog and raiden_debug. BUG=b:237606255 TEST=the following scenarios run tests successfully 1) dediprog and raiden_debug programmers enabled, libusb.h present result: all test run and pass 2) dediprog disabled, libusb.h present result: dediprog test skipped, all other tests run and pass 3) dediprog and raiden_debug both disabled, libusb.h changed to libusbabcd.h result: dediprog and raiden_debug tests are skipped, all other tests run and pass Change-Id: Iec8a1826951fd6ae586e90fde1a55170e7de41a8 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/65627 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-109-383/+502
| | | | | | | | | | | | | | | | | | | 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>