summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2013-01-14 18:28:22 -0800
committerChromeBot <chrome-bot@google.com>2013-01-14 18:37:52 -0800
commit97b2a66ecd6a2905e4811def58acb32dbb63cd97 (patch)
treef364c8ae7e9c3f4ef27713006e8012b032635055
parentc14428a66c0c39005a30eea49d33fc677ba08a70 (diff)
downloadvboot-97b2a66ecd6a2905e4811def58acb32dbb63cd97.tar.gz
futility now knows where it lives...
BUG=none BRANCH=none TEST=none Change-Id: I29752f07520d8ca7d17ba68ff6c7ab6b4f362933 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/41262
-rw-r--r--Makefile34
-rw-r--r--futility/futility.c87
-rwxr-xr-xfutility/tests/common.sh46
-rwxr-xr-xfutility/tests/run_futility_tests.sh (renamed from tests/run_futility_tests.sh)33
4 files changed, 154 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index 04d11b20..2416bdce 100644
--- a/Makefile
+++ b/Makefile
@@ -128,7 +128,7 @@ LDLIBS = $(CRYPTO_LIBS)
# Create output directories if necessary. Do this via explicit shell commands
# so it happens before trying to generate/include dependencies.
-SUBDIRS := firmware host utility cgpt tests tests/tpm_lite
+SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
_dir_create := $(foreach d, \
$(shell find $(SUBDIRS) -name '*.c' -exec dirname {} \; | sort -u), \
$(shell [ -d $(BUILD)/$(d) ] || mkdir -p $(BUILD)/$(d)))
@@ -139,14 +139,14 @@ all: fwlib $(if $(FIRMWARE_ARCH),,host_stuff)
# Host targets
.PHONY: host_stuff
-host_stuff: fwlib hostlib cgpt utils tests
+host_stuff: fwlib hostlib cgpt utils futil tests
.PHONY: clean
clean:
$(Q)/bin/rm -rf ${BUILD}
.PHONY: install
-install: cgpt_install utils_install
+install: cgpt_install utils_install futil_install
# Coverage
COV_INFO = $(BUILD)/coverage.info
@@ -378,7 +378,7 @@ $(CGPT): $(CGPT_OBJS) $$(LIBS)
@printf " LDcgpt $(subst $(BUILD)/,,$(@))\n"
$(Q)$(LD) -o $(CGPT) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) $(LDLIBS)
-C_DESTDIR = $(DESTDIR)
+C_DESTDIR = $(DESTDIR)/old_bins
.PHONY: cgpt_install
cgpt_install: $(CGPT)
@@ -447,7 +447,7 @@ utils: $(UTIL_BINS) $(UTIL_SCRIPTS)
$(Q)cp -f $(UTIL_SCRIPTS) $(BUILD)/utility
$(Q)chmod a+rx $(patsubst %,$(BUILD)/%,$(UTIL_SCRIPTS))
-U_DESTDIR = $(DESTDIR)
+U_DESTDIR = $(DESTDIR)/old_bins
.PHONY: utils_install
utils_install: $(UTIL_BINS) $(UTIL_SCRIPTS)
@@ -455,6 +455,24 @@ utils_install: $(UTIL_BINS) $(UTIL_SCRIPTS)
${Q}mkdir -p $(U_DESTDIR)
${Q}$(INSTALL) -t $(U_DESTDIR) $^
+# -----------------------------------------------------------------------------
+# new Firmware Utility
+
+FUTIL_BIN = ${BUILD}/futility/futility
+
+.PHONY: futil
+futil : $(FUTIL_BIN)
+
+F_DESTDIR = $(DESTDIR)
+
+.PHONY: futil_install
+futil_install: ${FUTIL_BIN}
+ @printf " INSTALL futility\n"
+ ${Q}mkdir -p $(F_DESTDIR)
+ ${Q}$(INSTALL) -t $(F_DESTDIR) $^
+
+# -----------------------------------------------------------------------------
+
${BUILD}/utility/dump_kernel_config: LIBS += $(DUMPKERNELCONFIGLIB)
# GBB utility needs C++ linker
@@ -647,7 +665,7 @@ ${BUILD}/tests/tpm_lite/tpmtest_%: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
# Frequently-run tests
.PHONY: runtests
-runtests: runbmptests runcgpttests runfuzztests runmisctests
+runtests : runbmptests runcgpttests runfuzztests runmisctests runfutiltests
# Generate test keys
.PHONY: genkeys
@@ -696,6 +714,10 @@ runmisctests: tests utils
tests/run_vboot_common_tests.sh
tests/run_vbutil_tests.sh
+runfutiltests: DESTDIR := $(BUILD)/installerooney
+runfutiltests: install
+ futility/tests/run_futility_tests.sh $(DESTDIR)
+
# Run long tests, including all permutations of encryption keys (instead of
# just the ones we use) and tests of currently-unused code (e.g. vboot_ec).
# Not run by automated build.
diff --git a/futility/futility.c b/futility/futility.c
index 9dece2a2..12997489 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -6,51 +6,82 @@
#define _GNU_SOURCE
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#define DEBUG 1
+#ifdef DEBUG
+#define debug(args...) printf(args)
+#else
+#define debug(args...)
+#endif
+
#define MYNAME "futility"
-/* Just point, don't modify, unlike basename(3) */
-static const char *base(const char *fullpath)
-{
- const char *p;
- p = strrchr(fullpath, '/');
- if (p)
- p++;
- else
- p = fullpath;
- return p;
-}
int main(int argc, char *argv[], char *envp[])
{
+ char *progname;
+ char truename[PATH_MAX];
+ char oldname[PATH_MAX];
+ char buf[80];
+ pid_t myproc;
+ ssize_t r;
+ char *s;
int i;
- const char *progname;
-
- for(i = 0; i < argc; i++)
- printf("[%d] = (%s)\n", i, argv[i]);
- progname = base(argv[0]);
+ /* What program are we wrapping? */
+ progname = strrchr(argv[0], '/');
+ if (progname)
+ progname++;
+ else
+ progname = argv[0];
+ debug("progname is %s\n", progname);
- /* Invoked directly and told what to launch */
+ /* Invoked directly by name */
if (0 == strcmp(progname, MYNAME)) {
if (argc < 2) {
- fprintf(stderr, "%s needs some arguments\n", progname);
- return 1;
+ fprintf(stderr, "Usage: %s PROGRAM|COMMAND [args...]\n", MYNAME);
+ exit(1);
}
- printf("KHAAAAAN!!\n");
- /* execvpe() will search PATH for the program */
- execvpe(argv[1], argv+1, envp);
- fprintf(stderr, "%s failed to exec %s: %s\n", MYNAME,
- argv[1], strerror(errno));
- return 1;
+ /* FIXME: Implement some functions of our own... */
+
+ /* Going to just wrap existing utilities */
+ argc--;
+ argv++;
+
+ /* FIXME: diddle argv[0] so it has the right name? */
+ }
+
+ /* The old binaries live under the true executable. Find out where that is. */
+ myproc = getpid();
+ snprintf(buf, 80, "/proc/%d/exe", myproc);
+ r = readlink(buf, truename, PATH_MAX-1);
+ if (r < 0) {
+ fprintf(stderr, "%s => %s: %s\n", argv[0], buf, strerror(errno));
+ exit(1);
+ }
+ debug("truename is %s\n", truename);
+ s = strrchr(truename, '/'); /* Find the true directory */
+ if (s) {
+ *s = '\0';
+ } else { /* I don't think this can happen */
+ fprintf(stderr, "%s doesn't make sense\n", truename);
+ exit(1);
}
+ /* We've allocated PATH_MAX. If the old binary path doesn't fit, it can't be
+ * in the filesystem. */
+ snprintf(oldname, PATH_MAX, "%s/old_bins/%s", truename, progname);
+ debug("oldname is %s\n", oldname);
+
+ for (i = 0; i < argc; i++)
+ debug("argv[%d] = %s\n", i, argv[i]);
- /* Invoked by another name */
- fprintf(stderr, "%s doesn't know how to pretend to be %s yet\n",
- MYNAME, progname);
+ execv(oldname, argv);
+ fprintf(stderr, "%s failed to exec: %s\n", oldname, strerror(errno));
return 1;
}
diff --git a/futility/tests/common.sh b/futility/tests/common.sh
new file mode 100755
index 00000000..0105b0cd
--- /dev/null
+++ b/futility/tests/common.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+# Copyright (c) 2013 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.
+
+# Color output encodings.
+COL_RED='\E[31;1m'
+COL_GREEN='\E[32;1m'
+COL_YELLOW='\E[33;1m'
+COL_BLUE='\E[34;1m'
+COL_STOP='\E[0;m'
+
+# args: [message]
+function green {
+ echo -e "${COL_GREEN}$*${COL_STOP}"
+}
+
+# args: [message]
+function yellow {
+ echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}"
+}
+
+function red {
+ echo -e "${COL_RED}$*${COL_STOP}"
+}
+
+# args: [nested level [message]]
+function error {
+ local lev=${1:-}
+ case "${1:-}" in
+ [0-9]*)
+ lev=$1
+ shift
+ ;;
+ *) lev=0
+ ;;
+ esac
+ local x=$(caller $lev)
+ local cline=${x%% *}
+ local cfunc=${x#* }
+ cfunc=${cfunc##*/}
+ local args="$*"
+ local spacer=${args:+: }
+ red "at ${cfunc}, line ${cline}${spacer}${args}" 1>&2
+ exit 1
+}
diff --git a/tests/run_futility_tests.sh b/futility/tests/run_futility_tests.sh
index f52fbd87..c3920c96 100755
--- a/tests/run_futility_tests.sh
+++ b/futility/tests/run_futility_tests.sh
@@ -7,12 +7,14 @@
. "$(dirname "$0")/common.sh"
# Where are the programs I'm testing against?
-BPATH=$(readlink -f $(dirname "$0")/../build)
-PATH="${BPATH}/futility:${BPATH}/utility:${BPATH}/cgpt:${PATH}"
+[ -z "${1:-}" ] && error "Directory argument is required"
+BINDIR="$1"
+shift
-echo "PWD is $(pwd)"
-# This is the new wrapper program
-FUTILITY=futility
+FUTILITY="$BINDIR/futility"
+OLDDIR="$BINDIR/old_bins"
+
+BUILD=$(dirname "${BINDIR}")
# Here are the old programs to be wrapped
# FIXME(chromium-os:37062): There are others besides these.
@@ -24,7 +26,8 @@ PROGS=${*:-cgpt crossystem dev_debug_vboot dev_sign_file dumpRSAPublicKey
# Get ready
pass=0
progs=0
-OUTDIR="${TEST_DIR}/futility_test_dir"
+pwd
+OUTDIR="${BUILD}/tests/futility_test_dir"
[ -d "$OUTDIR" ] || mkdir -p "$OUTDIR"
# For now just compare results of invoking each program with no args.
@@ -34,11 +37,12 @@ for i in $PROGS; do
# Try the real thing first
echo -n "$i ... "
- rc=$("$i" 1>"${OUTDIR}/$i.stdout.0" 2>"${OUTDIR}/$i.stderr.0" || echo "$?")
+ rc=$("${OLDDIR}/$i" 1>"${OUTDIR}/$i.stdout.0" 2>"${OUTDIR}/$i.stderr.0" \
+ || echo "$?")
echo "${rc:-0}" > "${OUTDIR}/$i.return.0"
# Now try the wrapper version
- rc=$("$FUTILITY" -C "$i" 1>"${OUTDIR}/$i.stdout.1" \
+ rc=$("$FUTILITY" "$i" 1>"${OUTDIR}/$i.stdout.1" \
2>"${OUTDIR}/$i.stderr.1" || echo "$?")
echo "${rc:-0}" > "${OUTDIR}/$i.return.1"
@@ -46,14 +50,19 @@ for i in $PROGS; do
if cmp -s "${OUTDIR}/$i.return.0" "${OUTDIR}/$i.return.1" &&
cmp -s "${OUTDIR}/$i.stdout.0" "${OUTDIR}/$i.stdout.1" &&
cmp -s "${OUTDIR}/$i.stderr.0" "${OUTDIR}/$i.stderr.1" ; then
- echo -e "${COL_GREEN}passed${COL_STOP}"
+ green "passed"
: $(( pass++ ))
rm -f "${OUTDIR}/$i.*.[01]"
else
- echo -e "${COL_RED}failed${COL_STOP}"
+ red "failed"
fi
done
# done
-echo "$pass / $progs passed"
-[ "$pass" -eq "$progs" ]
+if [ "$pass" -eq "$progs" ]; then
+ green "Success: $pass / $progs passed"
+ exit 0
+fi
+
+red "FAIL: $pass / $progs passed"
+exit 1