summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-02-05 09:44:31 -0800
committerChromeBot <chrome-bot@google.com>2013-02-06 17:38:04 -0800
commit7c55708979036bff83370036034d8d2cea3053ed (patch)
treee3b70cb9d4b095801084f7e91c8bd106fe558582
parent5ca4ea087a3d67c2a639e8b9254f51f076bf85fa (diff)
downloadvboot-7c55708979036bff83370036034d8d2cea3053ed.tar.gz
Reformat to kernel style
No code changes, just reformatting. BUG=none BRANCH=none TEST=make runtests Change-Id: Ibffadf6c8a5911b79a29f8f554ca00c595f6b27b Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/42624
-rw-r--r--firmware/stub/vboot_api_stub.c245
-rw-r--r--tests/vboot_api_kernel_tests.c503
2 files changed, 389 insertions, 359 deletions
diff --git a/firmware/stub/vboot_api_stub.c b/firmware/stub/vboot_api_stub.c
index dd0d5d4b..c71c38ac 100644
--- a/firmware/stub/vboot_api_stub.c
+++ b/firmware/stub/vboot_api_stub.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 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.
*
@@ -22,187 +22,198 @@ __pragma(warning (disable: 4100))
/* U-Boot's printf uses '%L' for uint64_t. gcc uses '%l'. */
#define MAX_FMT 255
static char fmtbuf[MAX_FMT+1];
-static const char *fixfmt(const char *format) {
- int i;
- for(i=0; i<MAX_FMT && format[i]; i++) {
- fmtbuf[i] = format[i];
- if(format[i] == '%' && format[i+1] == 'L') {
- fmtbuf[i+1] = 'l';
- i++;
- }
- }
- fmtbuf[i] = '\0';
- return fmtbuf;
-}
-void VbExError(const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- fprintf(stderr, "ERROR: ");
- vfprintf(stderr, fixfmt(format), ap);
- va_end(ap);
- exit(1);
+static const char *fixfmt(const char *format)
+{
+ int i;
+ for(i=0; i<MAX_FMT && format[i]; i++) {
+ fmtbuf[i] = format[i];
+ if(format[i] == '%' && format[i+1] == 'L') {
+ fmtbuf[i+1] = 'l';
+ i++;
+ }
+ }
+ fmtbuf[i] = '\0';
+ return fmtbuf;
+}
+
+void VbExError(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ fprintf(stderr, "ERROR: ");
+ vfprintf(stderr, fixfmt(format), ap);
+ va_end(ap);
+ exit(1);
}
-
-void VbExDebug(const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- fprintf(stderr, "DEBUG: ");
- vfprintf(stderr, fixfmt(format), ap);
- va_end(ap);
+void VbExDebug(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ fprintf(stderr, "DEBUG: ");
+ vfprintf(stderr, fixfmt(format), ap);
+ va_end(ap);
}
-
-void* VbExMalloc(size_t size) {
- void* p = malloc(size);
- if (!p) {
- /* Fatal Error. We must abort. */
- abort();
- }
- return p;
+void *VbExMalloc(size_t size)
+{
+ void *p = malloc(size);
+ if (!p) {
+ /* Fatal Error. We must abort. */
+ abort();
+ }
+ return p;
}
-
-void VbExFree(void* ptr) {
- free(ptr);
+void VbExFree(void *ptr)
+{
+ free(ptr);
}
-
-uint64_t VbExGetTimer(void) {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
+uint64_t VbExGetTimer(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
}
-
-void VbExSleepMs(uint32_t msec) {
+void VbExSleepMs(uint32_t msec)
+{
}
-
-VbError_t VbExBeep(uint32_t msec, uint32_t frequency) {
- return VBERROR_SUCCESS;
+VbError_t VbExBeep(uint32_t msec, uint32_t frequency)
+{
+ return VBERROR_SUCCESS;
}
-
-VbError_t VbExNvStorageRead(uint8_t* buf) {
- return VBERROR_SUCCESS;
+VbError_t VbExNvStorageRead(uint8_t *buf)
+{
+ return VBERROR_SUCCESS;
}
-
-VbError_t VbExNvStorageWrite(const uint8_t* buf) {
- return VBERROR_SUCCESS;
+VbError_t VbExNvStorageWrite(const uint8_t *buf)
+{
+ return VBERROR_SUCCESS;
}
-
-VbError_t VbExHashFirmwareBody(VbCommonParams* cparams,
- uint32_t firmware_index) {
- return VBERROR_SUCCESS;
+VbError_t VbExHashFirmwareBody(VbCommonParams *cparams,
+ uint32_t firmware_index)
+{
+ return VBERROR_SUCCESS;
}
-
-VbError_t VbExDisplayInit(uint32_t* width, uint32_t* height) {
- return VBERROR_SUCCESS;
+VbError_t VbExDisplayInit(uint32_t *width, uint32_t *height)
+{
+ return VBERROR_SUCCESS;
}
-
-VbError_t VbExDisplayBacklight(uint8_t enable) {
- return VBERROR_SUCCESS;
+VbError_t VbExDisplayBacklight(uint8_t enable)
+{
+ return VBERROR_SUCCESS;
}
-
-VbError_t VbExDisplayScreen(uint32_t screen_type) {
- return VBERROR_SUCCESS;
+VbError_t VbExDisplayScreen(uint32_t screen_type)
+{
+ return VBERROR_SUCCESS;
}
-
VbError_t VbExDisplayImage(uint32_t x, uint32_t y,
- void* buffer, uint32_t buffersize) {
- return VBERROR_SUCCESS;
+ void *buffer, uint32_t buffersize)
+{
+ return VBERROR_SUCCESS;
}
-
-VbError_t VbExDisplayDebugInfo(const char* info_str) {
- return VBERROR_SUCCESS;
+VbError_t VbExDisplayDebugInfo(const char *info_str)
+{
+ return VBERROR_SUCCESS;
}
-
-uint32_t VbExKeyboardRead(void) {
- return 0;
+uint32_t VbExKeyboardRead(void)
+{
+ return 0;
}
-
-uint32_t VbExIsShutdownRequested(void) {
- return 0;
+uint32_t VbExIsShutdownRequested(void)
+{
+ return 0;
}
VbError_t VbExDecompress(void *inbuf, uint32_t in_size,
uint32_t compression_type,
- void *outbuf, uint32_t *out_size) {
- return VBERROR_SUCCESS;
+ void *outbuf, uint32_t *out_size)
+{
+ return VBERROR_SUCCESS;
}
-int VbExTrustEC(void) {
- return 1;
+int VbExTrustEC(void)
+{
+ return 1;
}
-VbError_t VbExEcRunningRW(int *in_rw) {
- *in_rw = 0;
- return VBERROR_SUCCESS;
+VbError_t VbExEcRunningRW(int *in_rw)
+{
+ *in_rw = 0;
+ return VBERROR_SUCCESS;
}
-VbError_t VbExEcJumpToRW(void) {
- return VBERROR_SUCCESS;
+VbError_t VbExEcJumpToRW(void)
+{
+ return VBERROR_SUCCESS;
}
-VbError_t VbExEcRebootToRO(void) {
- /* Nothing to reboot, so all we can do is return failure. */
- return VBERROR_UNKNOWN;
+VbError_t VbExEcRebootToRO(void)
+{
+ /* Nothing to reboot, so all we can do is return failure. */
+ return VBERROR_UNKNOWN;
}
-VbError_t VbExEcStayInRO(void) {
- return VBERROR_SUCCESS;
+VbError_t VbExEcStayInRO(void)
+{
+ return VBERROR_SUCCESS;
}
#define SHA256_HASH_SIZE 32
-VbError_t VbExEcHashRW(const uint8_t **hash, int *hash_size) {
- static const uint8_t fake_hash[32] = {1, 2, 3, 4};
- *hash = fake_hash;
- *hash_size = sizeof(fake_hash);
- return VBERROR_SUCCESS;
+VbError_t VbExEcHashRW(const uint8_t **hash, int *hash_size)
+{
+ static const uint8_t fake_hash[32] = {1, 2, 3, 4};
+
+ *hash = fake_hash;
+ *hash_size = sizeof(fake_hash);
+ return VBERROR_SUCCESS;
}
VbError_t VbExEcGetExpectedRW(enum VbSelectFirmware_t select,
- const uint8_t **image, int *image_size) {
- static uint8_t fake_image[64] = {5, 6, 7, 8};
- *image = fake_image;
- *image_size = sizeof(fake_image);
- return VBERROR_SUCCESS;
+ const uint8_t **image, int *image_size)
+{
+ static uint8_t fake_image[64] = {5, 6, 7, 8};
+ *image = fake_image;
+ *image_size = sizeof(fake_image);
+ return VBERROR_SUCCESS;
}
-/**
- * Read the SHA-256 hash of the expected contents of the EC image associated
- * with the main firmware specified by the "select" argument.
- */
VbError_t VbExEcGetExpectedRWHash(enum VbSelectFirmware_t select,
- const uint8_t **hash, int *hash_size) {
- static const uint8_t fake_hash[32] = {1, 2, 3, 4};
+ const uint8_t **hash, int *hash_size)
+{
+ static const uint8_t fake_hash[32] = {1, 2, 3, 4};
- *hash = fake_hash;
- *hash_size = sizeof(fake_hash);
- return VBERROR_SUCCESS;
+ *hash = fake_hash;
+ *hash_size = sizeof(fake_hash);
+ return VBERROR_SUCCESS;
}
-VbError_t VbExEcUpdateRW(const uint8_t *image, int image_size) {
- return VBERROR_SUCCESS;
+VbError_t VbExEcUpdateRW(const uint8_t *image, int image_size)
+{
+ return VBERROR_SUCCESS;
}
-VbError_t VbExEcProtectRW(void) {
- return VBERROR_SUCCESS;
+VbError_t VbExEcProtectRW(void)
+{
+ return VBERROR_SUCCESS;
}
int VbExLegacy(void)
{
- return 1;
+ return 1;
}
diff --git a/tests/vboot_api_kernel_tests.c b/tests/vboot_api_kernel_tests.c
index 444cff7c..be9ad389 100644
--- a/tests/vboot_api_kernel_tests.c
+++ b/tests/vboot_api_kernel_tests.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012 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.
*
@@ -21,27 +21,27 @@
#define DEFAULT_COUNT -1
typedef struct {
- uint64_t bytes_per_lba;
- uint64_t lba_count;
- uint32_t flags;
- const char *diskname;
+ uint64_t bytes_per_lba;
+ uint64_t lba_count;
+ uint32_t flags;
+ const char *diskname;
} disk_desc_t;
typedef struct {
- char *name;
+ char *name;
- /* inputs for test case */
- uint32_t want_flags;
- VbError_t diskgetinfo_return_val;
- disk_desc_t disks_to_provide[MAX_TEST_DISKS];
- int disk_count_to_return;
- VbError_t loadkernel_return_val[MAX_TEST_DISKS];
+ /* inputs for test case */
+ uint32_t want_flags;
+ VbError_t diskgetinfo_return_val;
+ disk_desc_t disks_to_provide[MAX_TEST_DISKS];
+ int disk_count_to_return;
+ VbError_t loadkernel_return_val[MAX_TEST_DISKS];
- /* outputs from test */
- uint32_t expected_recovery_request_val;
- const char *expected_to_find_disk;
- const char *expected_to_load_disk;
- uint32_t expected_return_val;
+ /* outputs from test */
+ uint32_t expected_recovery_request_val;
+ const char *expected_to_find_disk;
+ const char *expected_to_load_disk;
+ uint32_t expected_return_val;
} test_case_t;
@@ -52,110 +52,124 @@ static const char pickme[] = "correct choice";
#define DONT_CARE ((const char *)42)
test_case_t test[] = {
-
- {
- .name = "first removable drive",
- .want_flags = VB_DISK_FLAG_REMOVABLE,
- .disks_to_provide = {
- {512, 10, VB_DISK_FLAG_REMOVABLE, 0 }, /* too small */
- {2048, 100, VB_DISK_FLAG_REMOVABLE, 0 }, /* wrong LBA */
- {512, 100, VB_DISK_FLAG_FIXED, 0 }, /* wrong type */
- {512, 100, 0, 0 }, /* wrong flags */
- {512, 100, -1, 0 }, /* still wrong flags */
- {512, 100, VB_DISK_FLAG_REMOVABLE, pickme},
- {512, 100, VB_DISK_FLAG_REMOVABLE, "holygrail"}, /* already got one */
- },
- .disk_count_to_return = DEFAULT_COUNT,
- .diskgetinfo_return_val = VBERROR_SUCCESS,
- .loadkernel_return_val = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
-
- .expected_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED,
- .expected_to_find_disk = pickme,
- .expected_to_load_disk = pickme,
- .expected_return_val = VBERROR_SUCCESS
- },
-
- {
- .name = "second removable drive",
- .want_flags = VB_DISK_FLAG_REMOVABLE,
- .disks_to_provide = {
- {512, 100, 0, 0 }, /* wrong flags */
- {512, 100, VB_DISK_FLAG_REMOVABLE, "not yet"},
- {512, 100, VB_DISK_FLAG_REMOVABLE, pickme},
- },
- .disk_count_to_return = DEFAULT_COUNT,
- .diskgetinfo_return_val = VBERROR_SUCCESS,
- .loadkernel_return_val = { 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, },
-
- .expected_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED,
- .expected_to_find_disk = pickme,
- .expected_to_load_disk = pickme,
- .expected_return_val = VBERROR_SUCCESS
- },
-
- {
- .name = "first fixed drive",
- .want_flags = VB_DISK_FLAG_FIXED,
- .disks_to_provide = {
- {512, 10, VB_DISK_FLAG_FIXED, 0 }, /* too small */
- {2048, 100, VB_DISK_FLAG_FIXED, 0 }, /* wrong LBA */
- {512, 100, VB_DISK_FLAG_REMOVABLE, 0 }, /* wrong type */
- {512, 100, 0, 0 }, /* wrong flags */
- {512, 100, -1, 0 }, /* still wrong flags */
- {512, 100, VB_DISK_FLAG_REMOVABLE|VB_DISK_FLAG_FIXED, 0 }, /* flags */
- {512, 100, VB_DISK_FLAG_FIXED, pickme},
- {512, 100, VB_DISK_FLAG_FIXED, "holygrail"}, /* already got one */
- },
- .disk_count_to_return = DEFAULT_COUNT,
- .diskgetinfo_return_val = VBERROR_SUCCESS,
- .loadkernel_return_val = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
-
- .expected_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED,
- .expected_to_find_disk = pickme,
- .expected_to_load_disk = pickme,
- .expected_return_val = VBERROR_SUCCESS
- },
-
- {
- .name = "no drives at all",
- .want_flags = VB_DISK_FLAG_FIXED,
- .disks_to_provide = {
- },
- .disk_count_to_return = DEFAULT_COUNT,
- .diskgetinfo_return_val = VBERROR_SUCCESS,
- .loadkernel_return_val = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
-
- .expected_recovery_request_val = VBNV_RECOVERY_RW_NO_DISK,
- .expected_to_find_disk = 0,
- .expected_to_load_disk = 0,
- .expected_return_val = VBERROR_NO_DISK_FOUND
- },
-
- {
- .name = "no valid drives",
- .want_flags = VB_DISK_FLAG_FIXED,
- .disks_to_provide = {
- {512, 10, VB_DISK_FLAG_FIXED, 0 }, /* too small */
- {2048, 100, VB_DISK_FLAG_FIXED, 0 }, /* wrong LBA */
- {512, 100, VB_DISK_FLAG_REMOVABLE, 0 }, /* wrong type */
- {512, 100, 0, 0 }, /* wrong flags */
- {512, 100, -1, 0 }, /* still wrong flags */
- {512, 100, VB_DISK_FLAG_FIXED, "bad1"}, /* doesn't load */
- {512, 100, VB_DISK_FLAG_FIXED, "bad2"}, /* doesn't load */
- },
- .disk_count_to_return = DEFAULT_COUNT,
- .diskgetinfo_return_val = VBERROR_SUCCESS,
- .loadkernel_return_val = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
-
- .expected_recovery_request_val = VBNV_RECOVERY_RW_NO_DISK,
- .expected_to_find_disk = DONT_CARE,
- .expected_to_load_disk = 0,
- .expected_return_val = 1
- },
-
+ {
+ .name = "first removable drive",
+ .want_flags = VB_DISK_FLAG_REMOVABLE,
+ .disks_to_provide = {
+ /* too small */
+ {512, 10, VB_DISK_FLAG_REMOVABLE, 0},
+ /* wrong LBA */
+ {2048, 100, VB_DISK_FLAG_REMOVABLE, 0},
+ /* wrong type */
+ {512, 100, VB_DISK_FLAG_FIXED, 0},
+ /* wrong flags */
+ {512, 100, 0, 0},
+ /* still wrong flags */
+ {512, 100, -1, 0},
+ {512, 100, VB_DISK_FLAG_REMOVABLE, pickme},
+ /* already got one */
+ {512, 100, VB_DISK_FLAG_REMOVABLE, "holygrail"},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VBERROR_SUCCESS,
+ .loadkernel_return_val = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+
+ .expected_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED,
+ .expected_to_find_disk = pickme,
+ .expected_to_load_disk = pickme,
+ .expected_return_val = VBERROR_SUCCESS
+ },
+ {
+ .name = "second removable drive",
+ .want_flags = VB_DISK_FLAG_REMOVABLE,
+ .disks_to_provide = {
+ /* wrong flags */
+ {512, 100, 0, 0},
+ {512, 100, VB_DISK_FLAG_REMOVABLE, "not yet"},
+ {512, 100, VB_DISK_FLAG_REMOVABLE, pickme},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VBERROR_SUCCESS,
+ .loadkernel_return_val = {1, 0, 1, 1, 1, 1, 1, 1, 1, 1,},
+
+ .expected_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED,
+ .expected_to_find_disk = pickme,
+ .expected_to_load_disk = pickme,
+ .expected_return_val = VBERROR_SUCCESS
+ },
+ {
+ .name = "first fixed drive",
+ .want_flags = VB_DISK_FLAG_FIXED,
+ .disks_to_provide = {
+ /* too small */
+ {512, 10, VB_DISK_FLAG_FIXED, 0},
+ /* wrong LBA */
+ {2048, 100, VB_DISK_FLAG_FIXED, 0},
+ /* wrong type */
+ {512, 100, VB_DISK_FLAG_REMOVABLE, 0},
+ /* wrong flags */
+ {512, 100, 0, 0},
+ /* still wrong flags */
+ {512, 100, -1, 0},
+ /* flags */
+ {512, 100, VB_DISK_FLAG_REMOVABLE|VB_DISK_FLAG_FIXED,
+ 0},
+ {512, 100, VB_DISK_FLAG_FIXED, pickme},
+ /* already got one */
+ {512, 100, VB_DISK_FLAG_FIXED, "holygrail"},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VBERROR_SUCCESS,
+ .loadkernel_return_val = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+
+ .expected_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED,
+ .expected_to_find_disk = pickme,
+ .expected_to_load_disk = pickme,
+ .expected_return_val = VBERROR_SUCCESS
+ },
+ {
+ .name = "no drives at all",
+ .want_flags = VB_DISK_FLAG_FIXED,
+ .disks_to_provide = {},
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VBERROR_SUCCESS,
+ .loadkernel_return_val = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+
+ .expected_recovery_request_val = VBNV_RECOVERY_RW_NO_DISK,
+ .expected_to_find_disk = 0,
+ .expected_to_load_disk = 0,
+ .expected_return_val = VBERROR_NO_DISK_FOUND
+ },
+ {
+ .name = "no valid drives",
+ .want_flags = VB_DISK_FLAG_FIXED,
+ .disks_to_provide = {
+ /* too small */
+ {512, 10, VB_DISK_FLAG_FIXED, 0},
+ /* wrong LBA */
+ {2048, 100, VB_DISK_FLAG_FIXED, 0},
+ /* wrong type */
+ {512, 100, VB_DISK_FLAG_REMOVABLE, 0},
+ /* wrong flags */
+ {512, 100, 0, 0},
+ /* still wrong flags */
+ {512, 100, -1, 0},
+ /* doesn't load */
+ {512, 100, VB_DISK_FLAG_FIXED, "bad1"},
+ /* doesn't load */
+ {512, 100, VB_DISK_FLAG_FIXED, "bad2"},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VBERROR_SUCCESS,
+ .loadkernel_return_val = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+
+ .expected_recovery_request_val = VBNV_RECOVERY_RW_NO_DISK,
+ .expected_to_find_disk = DONT_CARE,
+ .expected_to_load_disk = 0,
+ .expected_return_val = 1
+ },
};
-
/****************************************************************************/
/* Mock data */
@@ -168,153 +182,158 @@ static const char *got_find_disk;
static const char *got_load_disk;
static uint32_t got_return_val;
-/* Reset mock data (for use before each test) */
-static void ResetMocks(int i) {
- Memset(&lkparams, 0, sizeof(lkparams));
- Memset(&mock_disks, 0, sizeof(mock_disks));
- load_kernel_calls = 0;
-
- got_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED;
- got_find_disk = 0;
- got_load_disk = 0;
- got_return_val = 0xdeadbeef;
-
- t = test+i;
+/**
+ * Reset mock data (for use before each test)
+ */
+static void ResetMocks(int i)
+{
+ Memset(&lkparams, 0, sizeof(lkparams));
+ Memset(&mock_disks, 0, sizeof(mock_disks));
+ load_kernel_calls = 0;
+
+ got_recovery_request_val = VBNV_RECOVERY_NOT_REQUESTED;
+ got_find_disk = 0;
+ got_load_disk = 0;
+ got_return_val = 0xdeadbeef;
+
+ t = test + i;
}
-int is_nonzero(const void *vptr, size_t count) {
- const char *p = (const char *)vptr;
- while (count--)
- if (*p++)
- return 1;
+int is_nonzero(const void *vptr, size_t count)
+{
+ const char *p = (const char *)vptr;
+ while (count--)
+ if (*p++)
+ return 1;
- return 0;
+ return 0;
}
-int CheckResults(void) {
- VBDEBUG(("%s()\n", __FUNCTION__));
- VBDEBUG((" recovery_request: %x %x\n",
- t->expected_recovery_request_val, got_recovery_request_val));
- VBDEBUG((" find_disk: (%s) (%s)\n",
- (t->expected_to_find_disk == DONT_CARE
- ? "DONT CARE"
- : t->expected_to_find_disk),
- got_find_disk));
- VBDEBUG((" load_disk: (%s) (%s)\n",
- (t->expected_to_load_disk == DONT_CARE
- ? "DONT CARE"
- : t->expected_to_load_disk),
- got_load_disk));
- VBDEBUG((" return_val: %x %x\n",
- t->expected_return_val, got_return_val));
- return (t->expected_recovery_request_val == got_recovery_request_val &&
- (t->expected_to_find_disk == DONT_CARE ||
- t->expected_to_find_disk == got_find_disk) &&
- (t->expected_to_load_disk == DONT_CARE ||
- t->expected_to_load_disk == got_load_disk) &&
- t->expected_return_val == got_return_val);
+int CheckResults(void)
+{
+ VBDEBUG(("%s()\n", __FUNCTION__));
+ VBDEBUG((" recovery_request: %x %x\n",
+ t->expected_recovery_request_val, got_recovery_request_val));
+ VBDEBUG((" find_disk: (%s) (%s)\n",
+ (t->expected_to_find_disk == DONT_CARE
+ ? "DONT CARE"
+ : t->expected_to_find_disk),
+ got_find_disk));
+ VBDEBUG((" load_disk: (%s) (%s)\n",
+ (t->expected_to_load_disk == DONT_CARE
+ ? "DONT CARE"
+ : t->expected_to_load_disk),
+ got_load_disk));
+ VBDEBUG((" return_val: %x %x\n",
+ t->expected_return_val, got_return_val));
+ return (t->expected_recovery_request_val == got_recovery_request_val &&
+ (t->expected_to_find_disk == DONT_CARE ||
+ t->expected_to_find_disk == got_find_disk) &&
+ (t->expected_to_load_disk == DONT_CARE ||
+ t->expected_to_load_disk == got_load_disk) &&
+ t->expected_return_val == got_return_val);
}
/****************************************************************************/
/* Mocked verification functions */
-VbError_t VbExDiskGetInfo(VbDiskInfo** infos_ptr, uint32_t* count,
- uint32_t disk_flags) {
- int i;
- int num_disks = 0;
-
- VBDEBUG(("My %s\n", __FUNCTION__));
-
- *infos_ptr = mock_disks;
-
- for(i=0; i<MAX_TEST_DISKS; i++) {
- if (is_nonzero(&t->disks_to_provide[i], sizeof(t->disks_to_provide[i]))) {
- mock_disks[num_disks].bytes_per_lba =
- t->disks_to_provide[i].bytes_per_lba;
- mock_disks[num_disks].lba_count = t->disks_to_provide[i].lba_count;
- mock_disks[num_disks].flags = t->disks_to_provide[i].flags;
- mock_disks[num_disks].handle =
- (VbExDiskHandle_t)t->disks_to_provide[i].diskname;
- VBDEBUG((" mock_disk[%d] %lld %lld 0x%x %s\n", i,
- mock_disks[num_disks].bytes_per_lba,
- mock_disks[num_disks].lba_count,
- mock_disks[num_disks].flags,
- (mock_disks[num_disks].handle
- ? (char *)mock_disks[num_disks].handle
- : "0")));
- num_disks++;
- } else {
- mock_disks[num_disks].handle = (VbExDiskHandle_t)"INVALID";
- }
- }
-
- if (t->disk_count_to_return >= 0)
- *count = t->disk_count_to_return;
- else
- *count = num_disks;
-
- VBDEBUG((" *count=%lld\n", *count));
- VBDEBUG((" return 0x%x\n", t->diskgetinfo_return_val));
-
- return t->diskgetinfo_return_val;
+VbError_t VbExDiskGetInfo(VbDiskInfo **infos_ptr, uint32_t *count,
+ uint32_t disk_flags)
+{
+ int i;
+ int num_disks = 0;
+
+ VBDEBUG(("My %s\n", __FUNCTION__));
+
+ *infos_ptr = mock_disks;
+
+ for(i=0; i<MAX_TEST_DISKS; i++) {
+ if (is_nonzero(&t->disks_to_provide[i],
+ sizeof(t->disks_to_provide[i]))) {
+ mock_disks[num_disks].bytes_per_lba =
+ t->disks_to_provide[i].bytes_per_lba;
+ mock_disks[num_disks].lba_count =
+ t->disks_to_provide[i].lba_count;
+ mock_disks[num_disks].flags =
+ t->disks_to_provide[i].flags;
+ mock_disks[num_disks].handle = (VbExDiskHandle_t)
+ t->disks_to_provide[i].diskname;
+ VBDEBUG((" mock_disk[%d] %lld %lld 0x%x %s\n", i,
+ mock_disks[num_disks].bytes_per_lba,
+ mock_disks[num_disks].lba_count,
+ mock_disks[num_disks].flags,
+ (mock_disks[num_disks].handle
+ ? (char *)mock_disks[num_disks].handle
+ : "0")));
+ num_disks++;
+ } else {
+ mock_disks[num_disks].handle =
+ (VbExDiskHandle_t)"INVALID";
+ }
+ }
+
+ if (t->disk_count_to_return >= 0)
+ *count = t->disk_count_to_return;
+ else
+ *count = num_disks;
+
+ VBDEBUG((" *count=%lld\n", *count));
+ VBDEBUG((" return 0x%x\n", t->diskgetinfo_return_val));
+
+ return t->diskgetinfo_return_val;
}
-VbError_t VbExDiskFreeInfo(VbDiskInfo* infos,
- VbExDiskHandle_t preserve_handle) {
- got_load_disk = (const char *)preserve_handle;
- VBDEBUG(("%s(): got_load_disk = %s\n", __FUNCTION__,
- got_load_disk ? got_load_disk : "0"));
- return VBERROR_SUCCESS;
+VbError_t VbExDiskFreeInfo(VbDiskInfo *infos,
+ VbExDiskHandle_t preserve_handle)
+{
+ got_load_disk = (const char *)preserve_handle;
+ VBDEBUG(("%s(): got_load_disk = %s\n", __FUNCTION__,
+ got_load_disk ? got_load_disk : "0"));
+ return VBERROR_SUCCESS;
}
-VbError_t LoadKernel(LoadKernelParams* params) {
- got_find_disk = (const char *)params->disk_handle;
- VBDEBUG(("%s(%d): got_find_disk = %s\n", __FUNCTION__,
- load_kernel_calls,
- got_find_disk ? got_find_disk : "0"));
- return t->loadkernel_return_val[load_kernel_calls++];
+VbError_t LoadKernel(LoadKernelParams *params)
+{
+ got_find_disk = (const char *)params->disk_handle;
+ VBDEBUG(("%s(%d): got_find_disk = %s\n", __FUNCTION__,
+ load_kernel_calls,
+ got_find_disk ? got_find_disk : "0"));
+ return t->loadkernel_return_val[load_kernel_calls++];
}
-int VbNvSet(VbNvContext* context, VbNvParam param, uint32_t value) {
- VBDEBUG(("%s(): got_recovery_request_val = %d (0x%x)\n", __FUNCTION__,
- value, value));
- got_recovery_request_val = value;
- return 0;
+int VbNvSet(VbNvContext *context, VbNvParam param, uint32_t value)
+{
+ VBDEBUG(("%s(): got_recovery_request_val = %d (0x%x)\n", __FUNCTION__,
+ value, value));
+ got_recovery_request_val = value;
+ return 0;
}
/****************************************************************************/
-
-
/* This is not declared in any headers, so declare it here. */
-uint32_t VbTryLoadKernel(VbCommonParams* cparams, LoadKernelParams* p,
+uint32_t VbTryLoadKernel(VbCommonParams *cparams, LoadKernelParams *p,
uint32_t get_info_flags);
-
-static void VbTryLoadKernelTest(void) {
- int i;
- int num_tests = sizeof(test) / sizeof(test[0]);
-
- for (i=0; i<num_tests; i++) {
- VBDEBUG(("STARTING %s ...\n", test[i].name));
- ResetMocks(i);
- got_return_val = VbTryLoadKernel(0, &lkparams, test[i].want_flags);
- VBDEBUG(("VbTryLoadKernel(): got_return_val = 0x%x\n", got_return_val));
- TEST_TRUE(CheckResults(), test[i].name);
- }
+static void VbTryLoadKernelTest(void)
+{
+ int i;
+ int num_tests = sizeof(test) / sizeof(test[0]);
+
+ for (i=0; i<num_tests; i++) {
+ VBDEBUG(("STARTING %s ...\n", test[i].name));
+ ResetMocks(i);
+ got_return_val = VbTryLoadKernel(0, &lkparams,
+ test[i].want_flags);
+ VBDEBUG(("VbTryLoadKernel(): got_return_val = 0x%x\n",
+ got_return_val));
+ TEST_TRUE(CheckResults(), test[i].name);
+ }
}
+int main(void)
+{
+ VbTryLoadKernelTest();
-/* disable MSVC warnings on unused arguments */
-__pragma(warning (disable: 4100))
-
-int main(int argc, char* argv[]) {
- int error_code = 0;
-
- VbTryLoadKernelTest();
-
- if (!gTestSuccess)
- error_code = 255;
-
- return error_code;
+ return gTestSuccess ? 0 : 255;
}