summaryrefslogtreecommitdiff
path: root/common/cmd_vbexport_test.c
diff options
context:
space:
mode:
authorTom Wai-Hong Tam <waihong@chromium.org>2011-06-15 09:07:25 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:39:36 -0700
commit48e15702fe3a3d32abfc38f839af21db7a0b7a5f (patch)
treef541813e799e355173eb625f544de26d82af9cd5 /common/cmd_vbexport_test.c
parentdf2eeffdf8446bc8ceb8ae0bb3f476a0299180a6 (diff)
CHROMIUM: Implement utility APIs provided by u-boot and exported to vboot_reference.
We put the new vboot wrapper export API to /lib/vbexport directory to separate the original APIs which in /lib/chromeos directory. A u-boot prompt testing tool, vbexport_test, is added for the API unit tests. This CL is dependent on http://gerrit.chromium.org/gerrit/#change,2195 BUG=chromium-os:16543 TEST=build chromeos_seaboard_vboot_config, flash it to seaboard, and run: Tegra2 # vbexport_test debug Preforming the debug output tests... Expect: K 75 Hello! It's "Chrome OS". Actual: K 75 Hello! It's "Chrome OS". Expect: -22222 0xa932 Actual: -22222 0xa932 Expect: 44444 0xad9c Actual: 44444 0xad9c Expect: -1111111111 0xbdc5ca39 Actual: -1111111111 0xbdc5ca39 Expect: 2222222222 0x84746b8e Actual: 2222222222 0x84746b8e Expect: -8888888888888888888 0x84a452a6a1dc71c8 Actual: -8888888888888888888 0x84a452a6a1dc71c8 Expect: 11111111111111111111 0x9a3298afb5ac71c7 Actual: 11111111111111111111 0x9a3298afb5ac71c7 Tegra2 # vbexport_test malloc Preforming the malloc/free tests... Trying to malloc a memory block for 1 bytes... - SUCCESS Trying to malloc a memory block for 2 bytes... - SUCCESS Trying to malloc a memory block for 4 bytes... - SUCCESS Trying to malloc a memory block for 8 bytes... - SUCCESS Trying to malloc a memory block for 32 bytes... - SUCCESS Trying to malloc a memory block for 1024 bytes... - SUCCESS Trying to malloc a memory block for 4096 bytes... - SUCCESS Trying to malloc a memory block for 32768 bytes... - SUCCESS Trying to malloc a memory block for 1048576 bytes... - SUCCESS Trying to malloc a memory block for 12345 bytes... - SUCCESS Trying to malloc a memory block for 13579 bytes... - SUCCESS Tegra2 # vbexport_test sleep Preforming the sleep tests... System is going to sleep for 10 ms... From tick 20158963 to 20168065 (delta: 9102) - SUCCESS System is going to sleep for 50 ms... From tick 20345437 to 20395038 (delta: 49601) - SUCCESS System is going to sleep for 100 ms... From tick 20572586 to 20672087 (delta: 99501) - SUCCESS System is going to sleep for 500 ms... From tick 20849623 to 21349024 (delta: 499401) - SUCCESS System is going to sleep for 1000 ms... From tick 21526751 to 22526052 (delta: 999301) - SUCCESS Tegra2 # vbexport_test longsleep Preforming the long sleep tests... System is going to sleep for 5000 ms... From tick 71318054 to 76318055 (delta: 5000001) - SUCCESS System is going to sleep for 10000 ms... From tick 76495950 to 86495051 (delta: 9999101) - SUCCESS System is going to sleep for 50000 ms... From tick 86672951 to 136672052 (delta: 49999101) - SUCCESS Tegra2 # vbexport_test beep Preforming the beep tests... System is going to sleep for 500 ms... Beep! From tick 11288504 to 11788451 (delta: 499947) - SUCCESS Change-Id: Ia192c1f152fa75f7d587d8a87eb22a1cf0a505c3 Reviewed-on: http://gerrit.chromium.org/gerrit/2656 Tested-by: Tom Wai-Hong Tam <waihong@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/cmd_vbexport_test.c')
-rw-r--r--common/cmd_vbexport_test.c213
1 files changed, 213 insertions, 0 deletions
diff --git a/common/cmd_vbexport_test.c b/common/cmd_vbexport_test.c
new file mode 100644
index 0000000000..22b08aac65
--- /dev/null
+++ b/common/cmd_vbexport_test.c
@@ -0,0 +1,213 @@
+/*
+ * Copyright (c) 2011 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.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+/*
+ * Debug commands for testing Verify Boot Export APIs that are implemented by
+ * firmware and exported to vboot_reference. Some of the tests are automatic
+ * but some of them are manual.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <vboot_api.h>
+
+static int do_vbexport_test_debug(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ const char c = 'K';
+ const char s[] = "Hello! It's \"Chrome OS\".";
+ const int16_t hd = -22222;
+ const uint16_t hu = 44444;
+ const int32_t ld = -1111111111L;
+ const uint32_t lu = 2222222222UL;
+ const int64_t lld = -8888888888888888888LL;
+ const uint64_t llu = 11111111111111111111ULL;
+ VbExDebug("The \"Expect\" and \"Actual\" should be the same...\n");
+ VbExDebug("Expect: K 75 Hello! It's \"Chrome OS\".\n");
+ VbExDebug("Actual: %c %d %s\n", c, c, s);
+ VbExDebug("Expect: -22222 0xa932\n");
+ VbExDebug("Actual: %hd 0x%hx\n", hd, hd);
+ VbExDebug("Expect: 44444 0xad9c\n");
+ VbExDebug("Actual: %hu 0x%hx\n", hu, hu);
+ VbExDebug("Expect: -1111111111 0xbdc5ca39\n");
+ VbExDebug("Actual: %ld 0x%lx\n", ld, ld);
+ VbExDebug("Expect: 2222222222 0x84746b8e\n");
+ VbExDebug("Actual: %lu 0x%lx\n", lu, lu);
+ VbExDebug("Expect: -8888888888888888888 0x84a452a6a1dc71c8\n");
+ VbExDebug("Actual: %lld 0x%llx\n", lld, lld);
+ VbExDebug("Expect: 11111111111111111111 0x9a3298afb5ac71c7\n");
+ VbExDebug("Actual: %llu 0x%llx\n", llu, llu);
+ return 0;
+}
+
+static int do_vbexport_test_malloc_size(uint32_t size)
+{
+ char *mem = VbExMalloc(size);
+ int i;
+ VbExDebug("Trying to malloc a memory block for %lu bytes...", size);
+ if ((uint32_t)mem % CACHE_LINE_SIZE != 0) {
+ VbExDebug("\nMemory not algined with a cache line!\n");
+ VbExFree(mem);
+ return 1;
+ }
+ for (i = 0; i < size; i++) {
+ mem[i] = i % 0x100;
+ }
+ for (i = 0; i < size; i++) {
+ if (mem[i] != i % 0x100) {
+ VbExDebug("\nMemory verification failed!\n");
+ VbExFree(mem);
+ return 1;
+ }
+ }
+ VbExFree(mem);
+ VbExDebug(" - SUCCESS\n");
+ return 0;
+}
+
+static int do_vbexport_test_malloc(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ int ret = 0;
+ VbExDebug("Preforming the malloc/free tests...\n");
+ ret |= do_vbexport_test_malloc_size(1);
+ ret |= do_vbexport_test_malloc_size(2);
+ ret |= do_vbexport_test_malloc_size(4);
+ ret |= do_vbexport_test_malloc_size(8);
+ ret |= do_vbexport_test_malloc_size(32);
+ ret |= do_vbexport_test_malloc_size(1024);
+ ret |= do_vbexport_test_malloc_size(4 * 1024);
+ ret |= do_vbexport_test_malloc_size(32 * 1024);
+ ret |= do_vbexport_test_malloc_size(1 * 1024 * 1024);
+ ret |= do_vbexport_test_malloc_size(12345);
+ ret |= do_vbexport_test_malloc_size(13579);
+ return ret;
+}
+
+typedef void (*sleep_handler_t)(uint32_t);
+
+static void sleep_ms_handler(uint32_t msec)
+{
+ VbExSleepMs(msec);
+}
+
+static void beep_handler(uint32_t msec)
+{
+ VbExBeep(msec, 4000);
+}
+
+static int do_vbexport_test_sleep_time(sleep_handler_t handler, uint32_t msec)
+{
+ uint32_t start, end, delta, expected;
+ VbExDebug("System is going to sleep for %lu ms...\n", msec);
+ start = VbExGetTimer();
+ (*handler)(msec);
+ end = VbExGetTimer();
+ delta = end - start;
+ VbExDebug("From tick %lu to %lu (delta: %lu)", start, end, delta);
+
+ expected = msec * CONFIG_SYS_HZ;
+ /* The sleeping time should be accurate to within 10%. */
+ if (delta > expected + expected / 10) {
+ VbExDebug("\nSleep too long: expected %lu but actaully %lu!\n",
+ expected, delta);
+ return 1;
+ } else if (delta < expected - expected / 10) {
+ VbExDebug("\nSleep too short: expected %lu but actaully %lu!\n",
+ expected, delta);
+ return 1;
+ }
+ VbExDebug(" - SUCCESS\n");
+ return 0;
+}
+
+static int do_vbexport_test_sleep(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ int ret = 0;
+ VbExDebug("Preforming the sleep tests...\n");
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 10);
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 50);
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 100);
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 500);
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 1000);
+ return ret;
+}
+
+static int do_vbexport_test_longsleep(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ int ret = 0;
+ VbExDebug("Preforming the long sleep tests...\n");
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 5000);
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 10000);
+ ret |= do_vbexport_test_sleep_time(&sleep_ms_handler, 50000);
+ return ret;
+}
+
+static int do_vbexport_test_beep(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ int ret = 0;
+ VbExDebug("Preforming the beep tests...\n");
+ ret |= do_vbexport_test_sleep_time(&beep_handler, 500);
+ return ret;
+}
+
+static int do_vbexport_test_all(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ int ret = 0;
+ ret |= do_vbexport_test_debug(cmdtp, flag, argc, argv);
+ ret |= do_vbexport_test_malloc(cmdtp, flag, argc, argv);
+ ret |= do_vbexport_test_sleep(cmdtp, flag, argc, argv);
+ ret |= do_vbexport_test_beep(cmdtp, flag, argc, argv);
+ if (!ret)
+ VbExDebug("All tests passed!\n");
+ return ret;
+}
+
+static cmd_tbl_t cmd_vbexport_test_sub[] = {
+ U_BOOT_CMD_MKENT(all, 0, 1, do_vbexport_test_all, "", ""),
+ U_BOOT_CMD_MKENT(debug, 0, 1, do_vbexport_test_debug, "", ""),
+ U_BOOT_CMD_MKENT(malloc, 0, 1, do_vbexport_test_malloc, "", ""),
+ U_BOOT_CMD_MKENT(sleep, 0, 1, do_vbexport_test_sleep, "", ""),
+ U_BOOT_CMD_MKENT(longsleep, 0, 1, do_vbexport_test_longsleep, "", ""),
+ U_BOOT_CMD_MKENT(beep, 0, 1, do_vbexport_test_beep, "", ""),
+};
+
+static int do_vbexport_test(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ cmd_tbl_t *c;
+
+ if (argc < 2)
+ return cmd_usage(cmdtp);
+ argc--;
+ argv++;
+
+ c = find_cmd_tbl(argv[0], &cmd_vbexport_test_sub[0],
+ ARRAY_SIZE(cmd_vbexport_test_sub));
+ if (c)
+ return c->cmd(c, flag, argc, argv);
+ else
+ return cmd_usage(cmdtp);
+}
+
+U_BOOT_CMD(vbexport_test, CONFIG_SYS_MAXARGS, 1, do_vbexport_test,
+ "Perform tests for vboot_wrapper",
+ "all - perform all tests\n"
+ "vbexport_test debug - test the debug function\n"
+ "vbexport_test malloc - test the malloc and free functions\n"
+ "vbexport_test sleep - test the sleep and timer functions\n"
+ "vbexport_test longsleep - test the sleep functions for long delays\n"
+ "vbexport_test beep - test the beep functions"
+);
+