mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-25 10:45:02 +00:00
vb21 tests: use the build dir for temp files
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>
This commit is contained in:
committed by
ChromeOS Commit Bot
parent
47c2aa0b71
commit
cdf7dc9498
4
Makefile
4
Makefile
@@ -1353,9 +1353,9 @@ run2tests: test_setup
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS}
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD}
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD}
|
||||
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
|
||||
|
||||
.PHONY: runfutiltests
|
||||
|
||||
@@ -58,4 +58,11 @@ int TEST_SUCC(int result, const char* testname);
|
||||
/* Check that all memory allocations were freed */
|
||||
int vboot_api_stub_check_memory(void);
|
||||
|
||||
/* Abort if asprintf fails. */
|
||||
#define xasprintf(...) \
|
||||
do { \
|
||||
if (asprintf(__VA_ARGS__) < 0) \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
#endif /* VBOOT_REFERENCE_TEST_COMMON_H_ */
|
||||
|
||||
@@ -31,18 +31,20 @@ static const struct alg_combo test_algs[] = {
|
||||
};
|
||||
|
||||
static void private_key_tests(const struct alg_combo *combo,
|
||||
const char *pemfile)
|
||||
const char *pemfile, const char *temp_dir)
|
||||
{
|
||||
struct vb2_private_key *key, *k2;
|
||||
const struct vb2_private_key *ckey;
|
||||
struct vb2_packed_private_key *pkey;
|
||||
const char *testfile = "test.vbprik2";
|
||||
char *testfile;
|
||||
const char *notapem = "not_a_pem";
|
||||
const char *testdesc = "test desc";
|
||||
const struct vb2_id test_id = {.raw = {0xaa}};
|
||||
uint8_t *buf, *buf2;
|
||||
uint32_t bufsize;
|
||||
|
||||
xasprintf(&testfile, "%s/test.vbprik2", temp_dir);
|
||||
|
||||
TEST_SUCC(vb2_private_key_read_pem(&key, pemfile), "Read pem - good");
|
||||
TEST_PTR_NEQ(key, NULL, " key_ptr");
|
||||
TEST_PTR_NEQ(key->rsa_private_key, NULL, " rsa_private_key");
|
||||
@@ -166,17 +168,19 @@ static void private_key_tests(const struct alg_combo *combo,
|
||||
}
|
||||
|
||||
static void public_key_tests(const struct alg_combo *combo,
|
||||
const char *keybfile)
|
||||
const char *keybfile, const char *temp_dir)
|
||||
{
|
||||
struct vb2_public_key *key, k2;
|
||||
struct vb2_packed_key *pkey;
|
||||
const char *testfile = "test.vbpubk2";
|
||||
char *testfile;
|
||||
const char *testdesc = "test desc";
|
||||
const struct vb2_id test_id = {.raw = {0xbb}};
|
||||
const uint32_t test_version = 0xcc01;
|
||||
uint8_t *buf;
|
||||
uint32_t bufsize;
|
||||
|
||||
xasprintf(&testfile, "%s/test.vbprik2", temp_dir);
|
||||
|
||||
TEST_EQ(vb2_public_key_read_keyb(&key, "no_such_key"),
|
||||
VB2_ERROR_READ_KEYB_DATA, "Read keyb - no file");
|
||||
TEST_PTR_EQ(key, NULL, " key_ptr");
|
||||
@@ -276,34 +280,40 @@ static void public_key_tests(const struct alg_combo *combo,
|
||||
free(pkey);
|
||||
}
|
||||
|
||||
static int test_algorithm(const struct alg_combo *combo, const char *keys_dir)
|
||||
static int test_algorithm(const struct alg_combo *combo, const char *keys_dir,
|
||||
const char *temp_dir)
|
||||
{
|
||||
int rsa_bits = vb2_rsa_sig_size(combo->sig_alg) * 8;
|
||||
char pemfile[1024];
|
||||
char keybfile[1024];
|
||||
char *pemfile;
|
||||
char *keybfile;
|
||||
|
||||
printf("***Testing algorithm: %s\n", combo->name);
|
||||
|
||||
sprintf(pemfile, "%s/key_rsa%d.pem", keys_dir, rsa_bits);
|
||||
sprintf(keybfile, "%s/key_rsa%d.keyb", keys_dir, rsa_bits);
|
||||
xasprintf(&pemfile, "%s/key_rsa%d.pem", keys_dir, rsa_bits);
|
||||
xasprintf(&keybfile, "%s/key_rsa%d.keyb", keys_dir, rsa_bits);
|
||||
|
||||
private_key_tests(combo, pemfile);
|
||||
public_key_tests(combo, keybfile);
|
||||
private_key_tests(combo, pemfile, temp_dir);
|
||||
public_key_tests(combo, keybfile, temp_dir);
|
||||
|
||||
free(pemfile);
|
||||
free(keybfile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc == 2) {
|
||||
if (argc == 3) {
|
||||
const char *keys_dir = argv[1];
|
||||
const char *temp_dir = argv[2];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(test_algs); i++) {
|
||||
if (test_algorithm(test_algs + i, argv[1]))
|
||||
if (test_algorithm(test_algs + i, keys_dir, temp_dir))
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Usage: %s <keys_dir>", argv[0]);
|
||||
fprintf(stderr, "Usage: %s <keys_dir> <temp_dir>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Tests for host misc library vboot2 functions
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "2sysincludes.h"
|
||||
@@ -27,9 +28,9 @@ static void misc_tests(void)
|
||||
TEST_EQ(vb2_desc_size("foob"), 8, "desc size 'foob'");
|
||||
}
|
||||
|
||||
static void file_tests(void)
|
||||
static void file_tests(const char *temp_dir)
|
||||
{
|
||||
const char *testfile = "file_tests.dat";
|
||||
char *testfile;
|
||||
const uint8_t test_data[] = "Some test data";
|
||||
uint8_t *read_data;
|
||||
uint32_t read_size;
|
||||
@@ -37,6 +38,8 @@ static void file_tests(void)
|
||||
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),
|
||||
@@ -70,8 +73,14 @@ static void file_tests(void)
|
||||
|
||||
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();
|
||||
file_tests(temp_dir);
|
||||
|
||||
return gTestSuccess ? 0 : 255;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user