summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-01-24 14:19:56 -0800
committerChromeBot <chrome-bot@google.com>2013-01-25 13:58:44 -0800
commit786a5dca74387de5ffdc51ca5a099a4e90f406da (patch)
tree1ae8402d022c6ac2d3141ac64026ea1ffcef80a6
parent45cc0f2c0a48b377520842597769a5813cf55902 (diff)
downloadvboot-786a5dca74387de5ffdc51ca5a099a4e90f406da.tar.gz
Start adding display tests
BUG=chromium-os:38139 BRANCH=none TEST=make runtests Change-Id: Idd1c275077a9a00cd2f7eab684238eb5b2d235dd Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/42015 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--Makefile4
-rw-r--r--firmware/lib/include/vboot_display.h5
-rw-r--r--firmware/lib/vboot_display.c3
-rw-r--r--tests/vboot_display_tests.c83
4 files changed, 91 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index b37a21f2..b14e8ef3 100644
--- a/Makefile
+++ b/Makefile
@@ -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;
+}