blob: 936fe80684c763656687e7e607c5651a5b8f8733 [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
spool_dir=/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
--spool|-s)
spool_dir="$2"
shift 2
;;
--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 [--spool|-s DIR] [--run-all-tests]"
echo
echo "Available switches and options:"
echo
echo " --run-all-tests: starts execution of tests"
echo " -s DIR, or"
echo " --spool DIR: selects alternate output directory"
echo
echo "Test results will be saved to the spool directory, by default"
echo "that is /sdcard/LAVA/. A new unique directory will be created"
echo "relative to the spool directory each time you run the program."
echo "It is advised that the spool directory is purged after collecting"
echo "the results to simplify correct discovery."
exit 0
fi
# Run the tests, if requested
# ===========================
if [ "$run_tests" = yes ]; then
# Ensure that the spool directory exists
if [ ! -d "$spool_dir" ]; then
info "Creating directory $spool_dir"
mkdir -p "$spool_dir" || die "Unable to create $spool_dir"
fi
# Generate a new unique directory where we will store each result
test_run_dir=$(mktemp -d -p $spool_dir 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 /system/bin -type f -name 'lava-wrapper-finder-*' 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