diff options
author | Bill Richardson <wfrichar@chromium.org> | 2015-03-05 16:51:39 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-03-12 19:27:28 +0000 |
commit | 89901f00ef04b38cd2ef6f59e7e26630d75ab5e6 (patch) | |
tree | 9471c62a2524ca854d4fd35dbc3671f11b28225f | |
parent | c8054eae600ec51f91027ff82647f1cfade047a3 (diff) | |
download | vboot-89901f00ef04b38cd2ef6f59e7e26630d75ab5e6.tar.gz |
futility: add tests for futil_file_type(), correctly this time
This adds a test to be sure we can identify the types of input
files that futility can handle.
This fixes commit d7e1e4f0befdda52ad48e5a8eb5fc49dbee40247, which
was reverted in commit 1ab2c10e8cc51a66272458117e35619d87f53db0
because the Makefile dependencies were wrong.
BUG=chromium:466433
BRANCH=none
TEST=make runtests
Also try this:
\rm -rf build
make $(pwd)/build/tests/futility/test_file_types -j16
Before, that failed every time. Now it works.
Change-Id: I7702e1b99f4f593ef0121686a8616a2cb132e64a
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/259651
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | Makefile | 19 | ||||
-rw-r--r-- | tests/futility/data/fw_gbb.bin | bin | 0 -> 978944 bytes | |||
-rw-r--r-- | tests/futility/data/fw_vblock.bin | bin | 0 -> 65536 bytes | |||
-rw-r--r-- | tests/futility/data/kern_preamble.bin | bin | 0 -> 139264 bytes | |||
-rw-r--r-- | tests/futility/data/random_noise.bin | bin | 0 -> 4096 bytes | |||
-rw-r--r-- | tests/futility/data/sample.vbprik2 | bin | 0 -> 4724 bytes | |||
-rw-r--r-- | tests/futility/data/sample.vbpubk2 | bin | 0 -> 2132 bytes | |||
-rw-r--r-- | tests/futility/test_file_types.c | 95 | ||||
-rw-r--r-- | tests/test_common.h | 1 |
9 files changed, 112 insertions, 3 deletions
@@ -681,14 +681,19 @@ TEST_NAMES = \ tests/vboot_firmware_tests \ tests/vboot_kernel_tests \ tests/vboot_nvstorage_test \ - tests/verify_kernel \ - tests/futility/binary_editor \ - tests/futility/test_not_really + tests/verify_kernel ifdef REGION_READ TEST_NAMES += tests/vboot_region_tests endif +TEST_FUTIL_NAMES = \ + tests/futility/binary_editor \ + tests/futility/test_file_types \ + tests/futility/test_not_really + +TEST_NAMES += ${TEST_FUTIL_NAMES} + TEST2X_NAMES = \ tests/vb2_api_tests \ tests/vb2_common_tests \ @@ -741,6 +746,7 @@ TEST_NAMES += ${TLCL_TEST_NAMES} TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES}) TEST_OBJS += $(addsuffix .o,${TEST_BINS}) +TEST_FUTIL_BINS = $(addprefix ${BUILD}/,${TEST_FUTIL_NAMES}) TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES}) TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES}) TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES}) @@ -1071,6 +1077,12 @@ ${TEST_BINS}: ${UTILLIB} ${TESTLIB} ${TEST_BINS}: INCLUDES += -Itests ${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB} +# Futility tests need almost everything that futility needs. +${TEST_FUTIL_BINS}: ${FUTIL_OBJS} ${UTILLIB} ${UTILLIB21} +${TEST_FUTIL_BINS}: INCLUDES += -Ifutility +${TEST_FUTIL_BINS}: OBJS += ${FUTIL_OBJS} ${UTILLIB} ${UTILLIB21} +${TEST_FUTIL_BINS}: LDLIBS += ${CRYPTO_LIBS} + ${TEST2X_BINS}: ${FWLIB2X} ${TEST2X_BINS}: LIBS += ${FWLIB2X} @@ -1348,6 +1360,7 @@ run2tests: test_setup .PHONY: runfutiltests runfutiltests: test_setup tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin + ${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really # Run long tests, including all permutations of encryption keys (instead of diff --git a/tests/futility/data/fw_gbb.bin b/tests/futility/data/fw_gbb.bin Binary files differnew file mode 100644 index 00000000..e717a00c --- /dev/null +++ b/tests/futility/data/fw_gbb.bin diff --git a/tests/futility/data/fw_vblock.bin b/tests/futility/data/fw_vblock.bin Binary files differnew file mode 100644 index 00000000..ec2769dd --- /dev/null +++ b/tests/futility/data/fw_vblock.bin diff --git a/tests/futility/data/kern_preamble.bin b/tests/futility/data/kern_preamble.bin Binary files differnew file mode 100644 index 00000000..6d34ee56 --- /dev/null +++ b/tests/futility/data/kern_preamble.bin diff --git a/tests/futility/data/random_noise.bin b/tests/futility/data/random_noise.bin Binary files differnew file mode 100644 index 00000000..1e2d76ee --- /dev/null +++ b/tests/futility/data/random_noise.bin diff --git a/tests/futility/data/sample.vbprik2 b/tests/futility/data/sample.vbprik2 Binary files differnew file mode 100644 index 00000000..34f12e41 --- /dev/null +++ b/tests/futility/data/sample.vbprik2 diff --git a/tests/futility/data/sample.vbpubk2 b/tests/futility/data/sample.vbpubk2 Binary files differnew file mode 100644 index 00000000..aac42f38 --- /dev/null +++ b/tests/futility/data/sample.vbpubk2 diff --git a/tests/futility/test_file_types.c b/tests/futility/test_file_types.c new file mode 100644 index 00000000..25beb479 --- /dev/null +++ b/tests/futility/test_file_types.c @@ -0,0 +1,95 @@ +/* + * Copyright 2015 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. + */ +#include <limits.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#include "file_type.h" +#include "futility.h" +#include "test_common.h" + +/* + * Files that exemplify each type. + * Paths are relative to the source directory. + * A missing path means we don't (yet?) know how to identify it reliably. + */ +static struct { + enum futil_file_type type; + const char * const file; +} test_case[] = { + {FILE_TYPE_UNKNOWN, "tests/futility/data/random_noise.bin"}, + {FILE_TYPE_PUBKEY, "tests/devkeys/root_key.vbpubk"}, + {FILE_TYPE_KEYBLOCK, "tests/devkeys/kernel.keyblock"}, + {FILE_TYPE_FW_PREAMBLE, "tests/futility/data/fw_vblock.bin"}, + {FILE_TYPE_GBB, "tests/futility/data/fw_gbb.bin"}, + {FILE_TYPE_BIOS_IMAGE, "tests/futility/data/bios_zgb_mp.bin"}, + {FILE_TYPE_OLD_BIOS_IMAGE, "tests/futility/data/bios_mario_mp.bin"}, + {FILE_TYPE_KERN_PREAMBLE, "tests/futility/data/kern_preamble.bin"}, + {FILE_TYPE_RAW_FIRMWARE, }, + {FILE_TYPE_RAW_KERNEL, }, + {FILE_TYPE_CHROMIUMOS_DISK, }, + {FILE_TYPE_PRIVKEY, "tests/devkeys/root_key.vbprivk"}, + {FILE_TYPE_VB2_PUBKEY, "tests/futility/data/sample.vbpubk2"}, + {FILE_TYPE_VB2_PRIVKEY, "tests/futility/data/sample.vbprik2"}, + {FILE_TYPE_PEM, "tests/testkeys/key_rsa2048.pem"}, +}; +BUILD_ASSERT(ARRAY_SIZE(test_case) == NUM_FILE_TYPES); + +int main(int argc, char *argv[]) +{ + char filename[PATH_MAX]; + char status[80]; + char *srcdir; + enum futil_file_type type; + int i; + + /* Where's the source directory? */ + srcdir = getenv("SRCDIR"); + if (argc > 1) + srcdir = argv[1]; + if (!srcdir) + srcdir = "."; + + /* Complain about some files we can't handle */ + TEST_EQ(futil_file_type("/Sir/Not/Appearing/In/This/Film", &type), + FILE_ERR_OPEN, "Identify missing file"); + TEST_EQ(futil_file_type("/", &type), + FILE_ERR_DIR, "Identify directory"); + TEST_EQ(futil_file_type("/dev/zero", &type), + FILE_ERR_CHR, "Identify char device"); + + /* Now test things we can handle */ + for (i = 0; i < NUM_FILE_TYPES; i++) { + + if (!test_case[i].file) { + printf("%sWarning: No test for file type %d (%s)%s\n", + COL_YELLOW, test_case[i].type, + futil_file_type_str(test_case[i].type), + COL_STOP); + continue; + } + + snprintf(filename, sizeof(filename), "%s/%s", + srcdir, test_case[i].file); + + type = NUM_FILE_TYPES; + snprintf(status, sizeof(status), + "File type %d (%s): examined", + test_case[i].type, + futil_file_type_str(test_case[i].type)); + TEST_EQ(FILE_ERR_NONE, futil_file_type(filename, &type), + status); + + snprintf(status, sizeof(status), + "File type %d (%s) identified", + test_case[i].type, + futil_file_type_str(test_case[i].type)); + TEST_EQ(type, test_case[i].type, status); + } + + return !gTestSuccess; +} diff --git a/tests/test_common.h b/tests/test_common.h index 9a84f505..34e39ed7 100644 --- a/tests/test_common.h +++ b/tests/test_common.h @@ -51,6 +51,7 @@ int TEST_SUCC(int result, const char* testname); * Don't use \e as MSC does not recognize it as a valid escape sequence. */ #define COL_GREEN "\x1b[1;32m" +#define COL_YELLOW "\x1b[1;33m" #define COL_RED "\x1b[0;31m" #define COL_STOP "\x1b[m" |