summaryrefslogtreecommitdiff
path: root/tests/futility/test_main.sh
blob: 83fc53db98fedaaa477a7f6321427e4db1f41dd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash -eux
# Copyright 2014 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"

# No args returns nonzero exit code
${FUTILITY} && false

# It's weird but okay if the command is a full path.
${FUTILITY} /fake/path/to/help  > "$TMP"
grep Usage "$TMP"

# Make sure logging does something.
LOG="/tmp/futility.log"
[ -f ${LOG} ] && mv ${LOG} ${LOG}.backup
touch ${LOG}
${FUTILITY} help
grep ${FUTILITY} ${LOG}
rm -f ${LOG}
[ -f ${LOG}.backup ] && mv ${LOG}.backup ${LOG}

# Make sure deprecated functions fail via symlink
DEPRECATED="dev_sign_file"

for i in $DEPRECATED; do
  ln -sf ${FUTILITY} $i
  if ./$i 2>${TMP}.outmsg ; then false; fi
  grep deprecated ${TMP}.outmsg
  # They may still fail when invoked through futility
  # but with a different error message.
  ${FUTILITY} $i 1>${TMP}.outmsg2 2>&1 || true
  if grep deprecated ${TMP}.outmsg2; then false; fi
  rm -f $i
done

# Use some known digests to verify that things work...
DEVKEYS=${SRCDIR}/tests/devkeys
SHA=e78ce746a037837155388a1096212ded04fb86eb

# all progs in the pipelines should work
set -o pipefail

# If it's invoked as the name of a command we know, it should do that command
ln -sf ${FUTILITY} vbutil_key
./vbutil_key --unpack ${DEVKEYS}/installer_kernel_data_key.vbpubk | grep ${SHA}
ln -sf ${FUTILITY} vbutil_keyblock
./vbutil_keyblock --unpack ${DEVKEYS}/installer_kernel.keyblock | grep ${SHA}
cp ${FUTILITY} show
./show ${SCRIPTDIR}/data/rec_kernel_part.bin | grep ${SHA}

# If it's invoked by any other name, expect the command to be the first arg.
ln -sf ${FUTILITY} muggle
./muggle vbutil_key --unpack ${DEVKEYS}/installer_kernel_data_key.vbpubk \
  | grep ${SHA}
ln -sf ${FUTILITY} buggle
./buggle vbutil_keyblock --unpack ${DEVKEYS}/installer_kernel.keyblock \
  | grep ${SHA}
cp ${FUTILITY} boo
./boo show ${SCRIPTDIR}/data/rec_kernel_part.bin | grep ${SHA}


# we expect the first command fail, but the output to match anyway
set +o pipefail

# If it can't figure out the command at all, it should complain.
${FUTILITY} muggle | grep Usage:
./buggle futility | grep Usage:
./boo | grep Usage:

# cleanup
rm -f ${TMP}* vbutil_key vbutil_keyblock show muggle buggle boo
exit 0