summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2015-03-12 03:33:36 -0400
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-03-23 08:58:46 +0000
commit15b04fe8225887274573dcbc5f3ee3cd82b22bab (patch)
tree02d643cc93f7045d2aec422f852fc808c560fe7f
parent3ffcec1636fd596073abfebcb10a9f949085714e (diff)
downloadvboot-15b04fe8225887274573dcbc5f3ee3cd82b22bab.tar.gz
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> Reviewed-on: https://chromium-review.googlesource.com/261752 Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r--Makefile4
-rw-r--r--tests/test_common.h7
-rw-r--r--tests/vb21_host_key_tests.c38
-rw-r--r--tests/vb21_host_misc_tests.c15
4 files changed, 45 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 5645a8cd..14fd69cd 100644
--- a/Makefile
+++ b/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
diff --git a/tests/test_common.h b/tests/test_common.h
index 34e39ed7..9d6e8eaf 100644
--- a/tests/test_common.h
+++ b/tests/test_common.h
@@ -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_ */
diff --git a/tests/vb21_host_key_tests.c b/tests/vb21_host_key_tests.c
index e6730133..08efd9c5 100644
--- a/tests/vb21_host_key_tests.c
+++ b/tests/vb21_host_key_tests.c
@@ -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, temp_dir);
+ public_key_tests(combo, keybfile, temp_dir);
- private_key_tests(combo, pemfile);
- public_key_tests(combo, keybfile);
+ 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;
}
diff --git a/tests/vb21_host_misc_tests.c b/tests/vb21_host_misc_tests.c
index 638977e2..125d0c36 100644
--- a/tests/vb21_host_misc_tests.c
+++ b/tests/vb21_host_misc_tests.c
@@ -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;
}