1#!/bin/bash -eux 2# Copyright 2015 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6me=${0##*/} 7TMP="$me.tmp" 8 9# Work in scratch directory 10cd "$OUTDIR" 11 12 13# The first part of this is a script version of the compiled test by the same 14# name, to ensure we have working results. 15 16# Args are <expected_type>, <file_to_probe> 17test_case() { 18 local result 19 result=$("${FUTILITY}" show -t "${SRCDIR}/$2" | awk '{print $NF}') 20 [ "$1" = "$result" ] 21} 22 23# Arg is <file_to_probe> 24fail_case() { 25 if "${FUTILITY}" show -t "$1" ; then false; else true; fi 26} 27 28# Known types 29test_case "unknown" "tests/futility/data/short_junk.bin" 30test_case "unknown" "tests/futility/data/random_noise.bin" 31test_case "pubkey" "tests/devkeys/root_key.vbpubk" 32test_case "keyblock" "tests/devkeys/kernel.keyblock" 33test_case "fw_pre" "tests/futility/data/fw_vblock.bin" 34test_case "gbb" "tests/futility/data/fw_gbb.bin" 35test_case "bios" "tests/futility/data/bios_peppy_mp.bin" 36test_case "kernel" "tests/futility/data/kernel_part.bin" 37# We don't have a way to identify these (yet?) 38# test_case "RAW_FIRMWARE" 39# test_case "RAW_KERNEL" 40# test_case "CHROMIUMOS_DISK" 41test_case "prikey" "tests/devkeys/root_key.vbprivk" 42test_case "pubkey21" "tests/futility/data/sample.vbpubk2" 43test_case "prikey21" "tests/futility/data/sample.vbprik2" 44test_case "pem" "tests/testkeys/key_rsa2048.pem" 45test_case "pem" "tests/testkeys/key_rsa8192.pub.pem" 46 47# Expect failure here. 48fail_case "/Sir/Not/Appearing/In/This/Film" 49fail_case "${SRCDIR}" 50fail_case "/dev/zero" 51 52 53# Now test the show command when the file type is intentionally wrong. It 54# often won't work, but it certainly shouldn't core dump. 55 56# We'll ask futility to tell us what types it supports 57TYPES=$("${FUTILITY}" show --type help | awk '/^ +/ {print $1}') 58 59# And we'll just reuse the same files above. 60FILES=$(awk '/^test_case / {print $NF}' "$0" | tr -d '"') 61 62# futility should normally exit with either 0 or 1. Make sure that happens. 63# NOTE: /bin/bash returns values > 125 for special problems like signals. 64# I welcome patches to do this more portably. 65for type in $TYPES; do 66 for file in $FILES; do 67 "${FUTILITY}" show --type "${type}" "${SRCDIR}/${file}" && \ 68 rc=$? || rc=$? 69 [ "$rc" -le 2 ] 70 done 71done 72 73 74# cleanup 75rm -rf "${TMP}"* 76exit 0 77