summaryrefslogtreecommitdiff
path: root/tests/futility/test_file_types.sh
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2015-03-26 16:29:10 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-03-31 06:28:14 +0000
commit453ecd19560af8efe3e518ba745dc6e8bfecac90 (patch)
treeb9f9e2f3f59e9a90c69d989cd9c853ec60e1a8b3 /tests/futility/test_file_types.sh
parent6ea2f72d0356a73915b736a5ef3498ac06a50770 (diff)
downloadvboot-453ecd19560af8efe3e518ba745dc6e8bfecac90.tar.gz
futility: add --type arg to show and sign commands
This allows the user to manually specify the type of an input file, since not all file types can be reliably identified. This also adds a test to ensure that futility doesn't coredump if you give it the wrong type (although I'm sure it's not exhaustive). BUG=chromium:231574 BRANCH=none TEST=make runtests Signed-off-by: Bill Richardson <wfrichar@chromium.org> Change-Id: I9d909305d9989fe7299e744c585de380109cf8cd Reviewed-on: https://chromium-review.googlesource.com/262895 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'tests/futility/test_file_types.sh')
-rwxr-xr-xtests/futility/test_file_types.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/futility/test_file_types.sh b/tests/futility/test_file_types.sh
new file mode 100755
index 00000000..8acbcf72
--- /dev/null
+++ b/tests/futility/test_file_types.sh
@@ -0,0 +1,74 @@
+#!/bin/bash -eux
+# 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.
+
+me=${0##*/}
+TMP="$me.tmp"
+
+# Work in scratch directory
+cd "$OUTDIR"
+
+
+# The first part of this is a script version of the compiled test by the same
+# name, to ensure we have working results.
+
+# Args are <expected_type>, <file_to_probe>
+test_case() {
+ local result
+ result=$(${FUTILITY} show -t "${SRCDIR}/$2" | awk '{print $NF}')
+ [ "$1" = "$result" ]
+}
+
+# Arg is <file_to_probe>
+fail_case() {
+ if ${FUTILITY} show -t "$1" ; then false; else true; fi
+}
+
+# Known types
+test_case "unknown" "tests/futility/data/random_noise.bin"
+test_case "pubkey" "tests/devkeys/root_key.vbpubk"
+test_case "keyblock" "tests/devkeys/kernel.keyblock"
+test_case "fw_pre" "tests/futility/data/fw_vblock.bin"
+test_case "gbb" "tests/futility/data/fw_gbb.bin"
+test_case "bios" "tests/futility/data/bios_zgb_mp.bin"
+test_case "oldbios" "tests/futility/data/bios_mario_mp.bin"
+test_case "kernel" "tests/futility/data/kern_preamble.bin"
+# We don't have a way to identify these (yet?)
+# test_case "RAW_FIRMWARE"
+# test_case "RAW_KERNEL"
+# test_case "CHROMIUMOS_DISK"
+test_case "prikey" "tests/devkeys/root_key.vbprivk"
+test_case "pubkey21" "tests/futility/data/sample.vbpubk2"
+test_case "prikey21" "tests/futility/data/sample.vbprik2"
+test_case "pem" "tests/testkeys/key_rsa2048.pem"
+
+# Expect failure here.
+fail_case "/Sir/Not/Appearing/In/This/Film"
+fail_case "${SRCDIR}"
+fail_case "/dev/zero"
+
+
+# Now test the show command when the file type is intentionally wrong. It
+# often won't work, but it certainly shouldn't core dump.
+
+# We'll ask futility to tell us what types it supports
+TYPES=$(${FUTILITY} show --type help | awk '/^ +/ {print $1}')
+
+# And we'll just reuse the same files above.
+FILES=$(awk '/^test_case / {print $NF}' $0 | tr -d '"')
+
+# futility should normally exit with either 0 or 1. Make sure that happens.
+# NOTE: /bin/bash returns values > 125 for special problems like signals.
+# I welcome patches to do this more portably.
+for type in $TYPES; do
+ for file in $FILES; do
+ ${FUTILITY} show --type ${type} "${SRCDIR}/${file}" && rc=$? || rc=$?
+ [ "$rc" -le 2 ]
+ done
+done
+
+
+# cleanup
+rm -rf ${TMP}*
+exit 0