mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-25 10:45:02 +00:00
Rather than write to temp files in the cwd, use the existing build dir as our scratch space. This lets us build out of tree properly even if the source repo is read only. BUG=chromium:466499 TEST=precq still passes TEST=out-of-tree ebuild passes BRANCH=None Change-Id: I5dd69dcb8289cc557143e115e409b9c0924263b3 Reviewed-on: https://chromium-review.googlesource.com/259530 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org>
87 lines
2.5 KiB
C
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 "vb2_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 vb2_struct_common) + 12];
|
|
struct vb2_struct_common *c = (struct vb2_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(vb2_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;
|
|
}
|