Files
OpenCellular/tests/vb21_host_misc_tests.c
Randall Spangler ca72512866 vboot: Disambiguate vb2.1 structs and functions
Futility needs to link against both vboot1/vboot2.0 and vboot2.1
functions.  This was easy in the past because it did (vboot1 +
vboot2.1) and there's no overlap.

In replacing vboot1 function calls and structs with vboot2.0, now there
are symbol collisions between vboot2.0 and vboot2.1.  For example, both
of them use a struct called vb2_signature, but the structs are defined
differently.  Functions which operate on those structs also overload.

Rename the vb2.1 structs to start with vb21_ instead of vb2_.  Do the
same for vb2.1 functions which operate on vb2.1 data.

BUG=chromium:611535
BRANCH=none
TEST=make runtests

Change-Id: I24defd87cbd9ef64239faf1a8e98ab2372d27539
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/347458
Reviewed-by: Daisuke Nojiri <dnojiri@google.com>
2016-07-26 17:31:54 -07:00

87 lines
2.5 KiB
C

/* Copyright (c) 2014 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 host misc library vboot2 functions
*/
#include <stdio.h>
#include <unistd.h>
#include "2sysincludes.h"
#include "2common.h"
#include "vb21_common.h"
#include "host_common.h"
#include "host_misc.h"
#include "test_common.h"
static void misc_tests(void)
{
TEST_EQ(roundup32(0), 0, "roundup32(0)");
TEST_EQ(roundup32(15), 16, "roundup32(15)");
TEST_EQ(roundup32(16), 16, "roundup32(16)");
TEST_EQ(vb2_desc_size(NULL), 0, "desc size null");
TEST_EQ(vb2_desc_size(""), 0, "desc size empty");
TEST_EQ(vb2_desc_size("foo"), 4, "desc size 'foo'");
TEST_EQ(vb2_desc_size("foob"), 8, "desc size 'foob'");
}
static void file_tests(const char *temp_dir)
{
char *testfile;
const uint8_t test_data[] = "Some test data";
uint8_t *read_data;
uint32_t read_size;
uint8_t cbuf[sizeof(struct vb21_struct_common) + 12];
struct vb21_struct_common *c = (struct vb21_struct_common *)cbuf;
xasprintf(&testfile, "%s/file_tests.dat", temp_dir);
unlink(testfile);
TEST_EQ(vb2_read_file(testfile, &read_data, &read_size),
VB2_ERROR_READ_FILE_OPEN, "vb2_read_file() missing");
TEST_EQ(vb2_write_file("no/such/dir", test_data, sizeof(test_data)),
VB2_ERROR_WRITE_FILE_OPEN, "vb2_write_file() open");
TEST_SUCC(vb2_write_file(testfile, test_data, sizeof(test_data)),
"vb2_write_file() good");
TEST_SUCC(vb2_read_file(testfile, &read_data, &read_size),
"vb2_read_file() good");
TEST_EQ(read_size, sizeof(test_data), " data size");
TEST_EQ(memcmp(read_data, test_data, read_size), 0, " data");
free(read_data);
unlink(testfile);
memset(cbuf, 0, sizeof(cbuf));
c->fixed_size = sizeof(*c);
c->total_size = sizeof(cbuf);
c->magic = 0x1234;
cbuf[sizeof(cbuf) - 1] = 0xed; /* Some non-zero data at the end */
TEST_SUCC(vb21_write_object(testfile, c), "vb2_write_object() good");
TEST_SUCC(vb2_read_file(testfile, &read_data, &read_size),
"vb2_read_file() object");
TEST_EQ(read_size, c->total_size, " data size");
/* Compare the entire buffer, including the non-zero data at the end */
TEST_EQ(memcmp(read_data, c, read_size), 0, " data");
free(read_data);
unlink(testfile);
}
int main(int argc, char* argv[])
{
if (argc != 2) {
fprintf(stderr, "Usage: %s <temp_dir>\n", argv[0]);
return -1;
}
const char *temp_dir = argv[1];
misc_tests();
file_tests(temp_dir);
return gTestSuccess ? 0 : 255;
}