diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | firmware/lib/include/vboot_display.h | 5 | ||||
-rw-r--r-- | firmware/lib/vboot_display.c | 3 | ||||
-rw-r--r-- | tests/vboot_display_tests.c | 83 |
4 files changed, 91 insertions, 4 deletions
@@ -422,6 +422,7 @@ TEST_NAMES = \ vboot_common_tests \ vboot_common2_tests \ vboot_common3_tests \ + vboot_display_tests \ vboot_firmware_tests \ vboot_nvstorage_test @@ -942,6 +943,7 @@ runmisctests: test_setup ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests ${RUNTEST} ${BUILD_RUN}/tests/vboot_common2_tests ${TEST_KEYS} ${RUNTEST} ${BUILD_RUN}/tests/vboot_common3_tests ${TEST_KEYS} + ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests ${RUNTEST} ${BUILD_RUN}/tests/vboot_firmware_tests ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test @@ -951,7 +953,7 @@ runfutiltests: test_setup install @echo "$@ passed" # Run long tests, including all permutations of encryption keys (instead of -# just the ones we use) and tests of currently-unused code (e.g. vboot_ec). +# just the ones we use) and tests of currently-unused code. # Not run by automated build. .PHONY: runlongtests runlongtests: test_setup genkeys genfuzztestcases diff --git a/firmware/lib/include/vboot_display.h b/firmware/lib/include/vboot_display.h index 57688aed..b9ec04c0 100644 --- a/firmware/lib/include/vboot_display.h +++ b/firmware/lib/include/vboot_display.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * @@ -19,5 +19,8 @@ VbError_t VbDisplayDebugInfo(VbCommonParams* cparams, VbNvContext *vncptr); VbError_t VbCheckDisplayKey(VbCommonParams* cparams, uint32_t key, VbNvContext *vncptr); +/* Internal functions, for unit testing */ +const char *RecoveryReasonString(uint8_t code); + #endif /* VBOOT_REFERENCE_VBOOT_DISPLAY_H_ */ diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c index d0250bf3..929cacc2 100644 --- a/firmware/lib/vboot_display.c +++ b/firmware/lib/vboot_display.c @@ -402,8 +402,7 @@ static void FillInSha1Sum(char *outbuf, VbPublicKey* key) { VbExFree(digest); } - -static const char *RecoveryReasonString(uint8_t code) { +const char *RecoveryReasonString(uint8_t code) { switch(code) { case VBNV_RECOVERY_NOT_REQUESTED: return "Recovery not requested"; diff --git a/tests/vboot_display_tests.c b/tests/vboot_display_tests.c new file mode 100644 index 00000000..5713667b --- /dev/null +++ b/tests/vboot_display_tests.c @@ -0,0 +1,83 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Tests for firmware display library. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "gbb_header.h" +#include "host_common.h" +#include "test_common.h" +#include "vboot_common.h" +#include "vboot_display.h" +#include "vboot_nvstorage.h" + +/* Mock data */ +static VbCommonParams cparams; +static VbNvContext vnc; +static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; +static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data; +static GoogleBinaryBlockHeader gbb; +static char debug_info[4096]; + +/* Reset mock data (for use before each test) */ +static void ResetMocks(void) +{ + Memset(&cparams, 0, sizeof(cparams)); + cparams.shared_data_size = sizeof(shared_data); + cparams.shared_data_blob = shared_data; + cparams.gbb_data = &gbb; + + Memset(&gbb, 0, sizeof(gbb)); + gbb.major_version = GBB_MAJOR_VER; + gbb.minor_version = GBB_MINOR_VER; + gbb.flags = 0; + + Memset(&vnc, 0, sizeof(vnc)); + VbNvSetup(&vnc); + VbNvTeardown(&vnc); /* So CRC gets generated */ + + Memset(&shared_data, 0, sizeof(shared_data)); + VbSharedDataInit(shared, sizeof(shared_data)); + + *debug_info = 0; +} + +/* Mocks */ + +VbError_t VbExDisplayDebugInfo(const char *info_str) +{ + strncpy(debug_info, info_str, sizeof(debug_info)); + debug_info[sizeof(debug_info) - 1] = '\0'; + return VBERROR_SUCCESS; +} + +/* Test displaying debug info */ +static void DebugInfoTest(void) +{ + int i; + + /* Recovery string should be non-null for any code */ + for (i = 0; i < 0x100; i++) + TEST_PTR_NEQ(RecoveryReasonString(i), NULL, "Non-null reason"); + + /* Display debug info */ + VbDisplayDebugInfo(&cparams, &vnc); + TEST_NEQ(*debug_info, '\0', "Some debug info was displayed"); +} + +/* disable MSVC warnings on unused arguments */ +__pragma(warning (disable: 4100)) + +int main(int argc, char* argv[]) +{ + ResetMocks(); // KLUDGE + + DebugInfoTest(); + + return gTestSuccess ? 0 : 255; +} |