blob: 7b2c903551fba497f14a8513085a94f61b4bcbe9 [file] [log] [blame]
#!/system/bin/sh
# Copyright (c) 2012 Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
#
# Top-level executable for android-lava-wrapper project.
#
# Wrapper to run all kinds of tests included in Android image in an automated way
# The results are normalized to LAVA interchange format, the Dashboard Bundle.
# Define common functions
# =======================
# Function for failing, like in perl
function die() {
echo "lava-wrapper: error: $*"
exit 1
}
# Logging function with common prefix
function warn() {
echo "lava-wrapper: warn: $*"
}
# Logging function with common prefix
function info() {
echo "lava-wrapper: info: $*"
}
# Set the defaults
# ================
# Directory where all of our results are going to be saved
LAVA_SPOOL=/sdcard/LAVA
# Shows a help message when nonempty
show_help=yes
# Runs all of the tests when nonempty
run_tests=
# Parse the arguments
# ===================
while test -n "$1"; do
case "$1" in
--help|-h)
show_help=yes
run_tests=
shift
;;
--run-all-tests)
run_tests=yes
show_help=
shift
;;
*)
die "Unrecognized argument $1, try --help"
;;
esac
done
# Show help, if requested
# =======================
if [ "$show_help" = yes ]; then
echo "Usage: lava-wrapper [--run-all-tests]"
echo
echo "Run with --run-all-tests to actually start execution"
exit 0
fi
# Run the tests, if requested
# ===========================
if [ "$run_tests" = yes ]; then
# Ensure that the spool directory exists
if [ ! -d "$LAVA_SPOOL" ]; then
info "Creating directory $LAVA_SPOOL"
mkdir -p "$LAVA_SPOOL" || die "Unable to create $LAVA_SPOOL"
fi
# Generate a new unique directory where we will store each result
test_run_dir=$(mktemp -d -p $LAVA_SPOOL run.XXXXX)
info "Test results will be saved to $test_run_dir"
# Find all executables that look like _test and run them
for test_exe in $(find / -type f -name "*_test" 2>/dev/null); do
info "Considering test executable: $test_exe"
# Find a wrapper for that executable
wrapper=
# Wrappers are executables that can run a test and parse the output
# Each wrapper must accept, apart from the executable command, two
# additional arguments: -o to specify the output and -r to make the
# output human-readable. By default, if an executable has no wrapper it
# is _NOT_ executed.
for wrapper_finder in $(find /etc/lava/wrapper-finders/ -type f 2>/dev/null); do
# Skip finders that are not executable
test -x "$wrapper_finder" || continue
# Ask the wrapper if it supports the test we are currently
# considering. The wrapper must respond with a command to execute
# if it is supported or with no output otherwise.
wrapper=$("$wrapper_finder" "$test_exe")
if [ -n "$wrapper" ]; then
info "Accepted by: $wrapper_finder"
info "Analysis by: $wrapper"
break
fi
done
# If we have a wrapper then lets use it to run the test executable
if [ -n "$wrapper" ]; then
# Make the test executable if necessary
if [ ! -x $test_exe ]; then
chmod 0755 $test_exe || die "Unable to make $test_exe executable"
fi
# Find out where to write the results"
output_json="$test_run_dir/$(basename $test_exe).json"
touch $output_json || die "Unable to write to $output_json"
info "Bundle saved as: $output_json"
info "Starting test..."
"$wrapper" -o "$output_json" -r "$test_exe 2>&1"
info "Test finished!"
else
warn "Skipping! (no wrapper finder matched)"
fi
done
# Say that we are done
info "Done"
fi