summaryrefslogtreecommitdiff
path: root/tests/test_common.h
Commit message (Collapse)AuthorAgeFilesLines
* vboot/secdata: rewrite rollback_index and centralize reads/writesJoel Kitching2019-11-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In current kernel verification code, secdata reads and writes are spread throughout the code. vboot2's design is to use vb2_context.secdata_* for storing the state of secdata spaces, and have the caller (depthcharge) read/save this field when necessary. Centralize secdata reads/writes into the functions of secdata_tpm.c, previously known as rollback_index.c. Functions which directly read/write to the TPM space are modified to use vb2_secdata_*_get and vb2_secdata_*_set. The secure spaces get read/flushed by functions in vboot_api_kernel.c. These calls and the underlying functions from secdata_tpm.c will eventually be relocated to depthcharge. Create a new external function vb2ex_commit_data, which commits any modified nvdata/secdata. Currently the depthcharge implementation of this function only writes nvdata, but once secdata TPM drivers have been migrated from vboot_reference to depthcharge, it will also commit these data spaces. This CL also removes the VbExNvStorageRead call from vb2_kernel_setup, and the data is instead read in depthcharge CL:1819379, right before calling VbSelectAndLoadKernel. As such, both the VbExNvStorageRead and VbExNvStorageWrite functions may be removed. Finally, create a vb2_secdata_kernel_lock function, which should be used right before attempting to leave vboot (by booting an OS or chainloading to another firmware). This should eventually be exposed as a vb2ex_ API function and relocated to depthcharge. BUG=b:124141368, chromium:972956, chromium:1006689 TEST=make clean && make runtests BRANCH=none Change-Id: Ifbfb21122af0bf85e22a6d3a0d48a1db7f7c25b7 Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:1819380, chromium:1939168 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1728298 Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
* vboot: add VB2_ASSERT and VB2_DIE macrosJoel Kitching2019-09-231-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | Sometimes vboot needs to make assertions to work sanely without always having to return VB2_ERROR_* values. Add VB2_ASSERT and VB2_DIE macros to deal with these cases. Convert existing VbAssert macro to use either VB2_ASSERT or TEST_* macros depending on the case. Implement testing infrastructure to check that aborts are being triggered correctly. The TEST_ASSERT macro should be used. BUG=b:124141368, chromium:1005700 TEST=make clean && make runtests BRANCH=none Change-Id: I298384ba50842a94a311df7f868f807bf2109cff Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:1813277 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1800112 Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
* vboot: fix up some headers, includes, comments, spacingJoel Kitching2019-08-281-1/+0
| | | | | | | | | | | | | BUG=b:124141368 TEST=make clean && make runtests BRANCH=none Change-Id: Id97f544da845f7070555e5e8cc6e782b2d45c300 Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1758151 Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
* vboot: use malloc and free directlyRandall Spangler2016-11-061-3/+0
| | | | | | | | | | | | | | | | Originally, vboot1 code used VbExMalloc() and VbExFree() since it needed to talk to EFI firmware that didn't have standard malloc() and free(). Now, coreboot and depthcharge implement them as wrappers around those standard calls. vboot2 code already calls them directly, so let vboot1 code do that too. BUG=chromium:611535 BRANCH=none TEST=make runtests; emerge-kevin coreboot depthcharge Change-Id: I49ad0e32e38d278dc3589bfaf494bcf0e4b0a4bd Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/400905
* test: Make TEST_* report test locationstabilize-8337.BDaisuke Nojiri2016-05-101-14/+81
| | | | | | | | | | | | | | | | | | | This patch converts TEST_* functions to macros, which print file name and line # of the check. This will allow us to locate a failed test quickly. New TEST_* macros also automatically generate a test name if testname == NULL. This will save us time to think of a name for every single check we write in a test. BUG=none BRANCH=tot TEST=make runtests Change-Id: Ibdeb99681985c3f348836d256fa3484f2f0c315f Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/343233 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* test: Add TEST_STR_NEQDaisuke Nojiri2016-05-081-0/+5
| | | | | | | | | | | | | | TEST_STR_NES can be used to check the returned string is not what it shouldn't be. BUG=none BRANCH=tot TEST=make runtests Change-Id: I09d5a63334e9b8365a44bb96ed31db8155d95e21 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/343120 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* vb21 tests: use the build dir for temp filesMike Frysinger2015-03-131-0/+7
| | | | | | | | | | | | | | | | | | Rather than write to temp files in the cwd, use the existing build dir as our scratch space. This lets us build out of tree properly even if the source repo is read only. BUG=chromium:466499 TEST=precq still passes TEST=out-of-tree ebuild passes BRANCH=None Change-Id: I5dd69dcb8289cc557143e115e409b9c0924263b3 Reviewed-on: https://chromium-review.googlesource.com/259530 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org>
* futility: add tests for futil_file_type(), correctly this timeBill Richardson2015-03-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This adds a test to be sure we can identify the types of input files that futility can handle. This fixes commit d7e1e4f0befdda52ad48e5a8eb5fc49dbee40247, which was reverted in commit 1ab2c10e8cc51a66272458117e35619d87f53db0 because the Makefile dependencies were wrong. BUG=chromium:466433 BRANCH=none TEST=make runtests Also try this: \rm -rf build make $(pwd)/build/tests/futility/test_file_types -j16 Before, that failed every time. Now it works. Change-Id: I7702e1b99f4f593ef0121686a8616a2cb132e64a Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/259651 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Revert "futility: add tests for futil_file_type()"Prathmesh Prabhu2015-03-121-1/+0
| | | | | | | | | | | | This reverts commit 271c071344beaacc45201c17406bcf3b4daece88. BUG=chromium:466433 TEST=None. Change-Id: Ic84d069d672a76b46201a0e3700801a1e6d47438 Reviewed-on: https://chromium-review.googlesource.com/259364 Reviewed-by: David James <davidjames@chromium.org> Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
* futility: add tests for futil_file_type()Bill Richardson2015-03-111-0/+1
| | | | | | | | | | | | | This adds a test to be sure we can identify the types of input files that futility can handle. BUG=none BRANCH=none TEST=make runtests Change-Id: Iff1dcc05530af2969a82d7c32599850bba59597a Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/258501
* vboot2: Use more specific error codesstabilize-5944.Bstabilize-5943.Bstabilize-5942.Bfactory-samus-5939.BRandall Spangler2014-06-071-0/+4
| | | | | | | | | | | | | | | | | | | | | Error codes reported by the crypto and storage APIs are now very specific, and tests verify the proper errors are reported. More specific error codes coming to other files next, but I don't want this CL to get too long. This also changes test_common.c so TEST_EQ() reports mismatched values in both decimal and hex, and adds TEST_SUCC() to test for a successful return value. BUG=chromium:370082 BRANCH=none TEST=make clean && VBOOT2=1 COV=1 make Change-Id: I255c8e5769284fbc286b9d94631b19677a71cdd0 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/202778 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* Add memory leak checkingSimon Glass2013-09-171-0/+3
| | | | | | | | | | | | | | | | | Add checks that the vboot library does not leak memory. This works by tracking VbExMalloc() calls and making sure that they have an associated VbExFree(). Adjust host_signature to use VbExFree() instead of free(), so that this scheme works correctly for existing code. BUG=chrome-os-partner:21115 BRANCH=pit TEST=FEATURES=test emerge-peach_pit vboot_reference Change-Id: I6ccccfbcc162fc43fb75862cd0eddad78ce8b18a Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/66175
* Enable (and test) custom dev-mode soundsBill Richardson2011-10-051-0/+8
| | | | | | | | | | | | | | BUG=none TEST=manual cd src/platform/vboot_reference make && make runtests Change-Id: I7f7d50d7c9c5541e0b99031245f882996a6b88ec Reviewed-on: http://gerrit.chromium.org/gerrit/8731 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Add tests for vboot_firmware.cRandall Spangler2011-09-011-5/+5
| | | | | | | | | | | | | | | Yaay, LoadFirmware() finally has unit tests! Fix minor memory leak in LoadFirmware(). BUG=chromium-os:17564 TEST=make && make runtests Change-Id: I7eabc14484271f488b77f286e846781ccc22b8f2 (cherry picked from commit 2b7c5635d7069c55a1d96d11b99d02291b7e308b) Reviewed-on: http://gerrit.chromium.org/gerrit/7052 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
* Add tests for rsa_utility.cRandall Spangler2011-09-011-0/+6
| | | | | | | | | | BUG=chromium-os:17564 TEST=make && make runtests Change-Id: Ia86241f5407ba53d93d3862b29c61b510e560e92 Reviewed-on: http://gerrit.chromium.org/gerrit/6959 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
* Partial unit tests for rollback_indexRandall Spangler2011-08-261-2/+8
| | | | | | | | | | | BUG=chromium-os:17564 TEST=make && make runtests Change-Id: I8ea6bcc15f277e10c5b8539f2ea19ad90be34889 Reviewed-on: http://gerrit.chromium.org/gerrit/6770 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
* Add tests for vboot_reference stateful_util.cRandall Spangler2011-08-241-1/+7
| | | | | | | | | | BUG=chromium-os:17564 TEST=make && make runtests Change-Id: I5d55be2dfead0c5d7af72841cbd6c65485685cd6 Reviewed-on: http://gerrit.chromium.org/gerrit/6596 Reviewed-by: Stefan Reinauer <reinauer@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
* Make vboot_reference build in MSVC command line environment.vbendeb2010-06-241-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is a mostly NOOP change which modifies the source code to compile cleanly in the MSVC command line build environment. A new makefile is introduced (msc/nmakefile) along with a README.txt in the same directory explaining how to build the code in the DOS window. As of this submission the build is running in a 32 bit environment, the intention is to use the same makefile for 64 bit builds in the future. Enabling high compilation warnings level allowed to identify a couple of bugs in the code which are being fixed. Not all sources are being compiled in the MSVC environment, only those in firmware/ and most of those in test/ subdirectories. The benchmark calculations require porting of the timer facilities and are being postponed. TEST Built in DOS and linux environments. Ran unit tests in linux environment. Review URL: http://codereview.chromium.org/2809037
* Remove unused files, and tidy the directory structure of the remaining ones.Randall Spangler2010-06-171-27/+0
| | | | Review URL: http://codereview.chromium.org/2815011
* Remove old firmware verification code, now that firmware build has switched ↵Randall Spangler2010-06-161-25/+0
| | | | | | to the new algorithms. Review URL: http://codereview.chromium.org/2835006
* Make kernel signature a part of the kernel preamble.Gaurav Shah2010-05-261-0/+4
| | | | | | | | | With this change, the kernel signature is a part of the preamble block (and therefore, used during preamble signature verification). BUG=670 TEST=image verification tests still pass. corrected splicing test expectations (and it passes). Review URL: http://codereview.chromium.org/2292001
* Change VerifyFirmware() to take separate pointers to firmware verification ↵Gaurav Shah2010-04-181-14/+13
| | | | | | | | | | | header and firmware data. The firmware verification code no longer assumes that verification data and firmware data are contiguous and follow each other. Needed for EFI where the actual firmware must be stored in its own firmware volume. BUG=1704 TEST=modified existing tests for the new API, and they still pass Review URL: http://codereview.chromium.org/1578035
* Propagate use of uint64_t to more functions that may need to deal with ↵Gaurav Shah2010-03-291-4/+4
| | | | | | | | | | | | | arbitrary length data. This CL fixes some functions to use uint64_t that I missed the first time around. It ended up requiring some minor changes to how some of the helper functions work (StatefulMemcpy*()). Also adds new tests to make sure that reference code can verify/process big firmware and kernel images. BUG=670 TEST=Adds some new, old ones still pass. Review URL: http://codereview.chromium.org/1519008
* VBoot Reference: Fix splicing bugs in Firmware and Kernel verification.Gaurav Shah2010-03-291-2/+5
| | | | | | | | | | | | | | | BUG=670 TESTS=Adds new tests which verify this doesn't occur anymore. Existing tests still pass. The existing code computes and verifies signatures on firmware/kernel data and firmware/kernel versions separately. This causes a image splicing bug where it is possible to combine together a version signature from a valid new firmware with firmware data and signature from an older version. The same problem exists with kernel verification. This CL fixes this by changing the firmware/kernel signatures to also include the version information. For the Firmware, there's a separate signature on the preamble (which contains the version) but the firmware signature now also includes this preamble in addition to the firmware data. For the Kernel, there's a separate signature on the kernel config/options (wich also contains the version), but the kernel signature now also includes these config/options in addition to the kernel data. Review URL: http://codereview.chromium.org/1430001
* VBoot Reference: Add kernel rollback prevention and choosing logic.Gaurav Shah2010-03-261-3/+10
| | | | | | Also adds tests for kernel rollback prevention. Review URL: http://codereview.chromium.org/1320010
* Move test utility functions to a common place.Gaurav Shah2010-03-251-1/+48
| | | | | | | | | | | | | Also removes the dev_mode flag from Firmware Image verification as key signature for the firmware should be checked whether or not dev mode is enabled. BUG=670 TEST=All tests still pass. Merge remote branch 'refs/remotes/origin/master' into fixtests Fix tests, remove dev mode. Move common code. Review URL: http://codereview.chromium.org/1280002
* VBoot Reference: Add version checking to for preventing rollbacks.Gaurav Shah2010-03-241-0/+13
This CL adds a new function VerifyFirmwareDriver_f() means to be a part of the RO firmware which determine which copy of the firmware to boot from. It is meant to ensure that a particular firmware is only booted if 1) it verifies successfully, 2) its version is newer or equal to current stored version. In addition, the driver function also updates the stored version if needed. Currently I am using the TLCL API with stub calls, (in fact, most of the TPM interaction is done in rollback_index.c which implements the actual version query/update API) used by the firmware. Review URL: http://codereview.chromium.org/1241002