2014-08-26 11:20:02 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#*----------------------------------------------------------------------------*#
|
2019-12-06 17:46:29 -05:00
|
|
|
#* Copyright (c) 2014-2019 FIRST. All Rights Reserved. *#
|
2014-08-26 11:20:02 -04:00
|
|
|
#* Open Source Software - may be modified and shared by FRC teams. The code *#
|
|
|
|
|
#* must be accompanied by the FIRST BSD license file in the root directory of *#
|
2019-12-06 17:46:29 -05:00
|
|
|
#* the project. *#
|
2014-08-26 11:20:02 -04:00
|
|
|
#*----------------------------------------------------------------------------*#
|
|
|
|
|
|
|
|
|
|
# This file is intended to be run in the DEFAULT_TEST_DIR on the roboRIO.
|
|
|
|
|
# Do not attempt to run this file on your local system.
|
|
|
|
|
# There is one file (delploy-and-run-test-on-robot.sh) that is designed to
|
2023-02-26 15:06:37 -08:00
|
|
|
# deploy this file along with the compiled tests for you.
|
2014-08-26 11:20:02 -04:00
|
|
|
|
2023-12-01 20:53:57 -08:00
|
|
|
set -e
|
|
|
|
|
|
2014-08-26 11:20:02 -04:00
|
|
|
# Configurable variables
|
|
|
|
|
source config.sh
|
|
|
|
|
|
|
|
|
|
DEFAULT_TEST_DIR=${DEFAULT_DESTINATION_DIR}
|
|
|
|
|
DEFAULT_PATH_TO_JRE=/usr/local/frc/JRE/bin/java
|
|
|
|
|
|
2019-12-06 17:46:29 -05:00
|
|
|
usage="$(basename "$0") [-h] (java|cpp) [-d test_dir] [-A] [arg] [arg]...
|
2014-08-26 11:20:02 -04:00
|
|
|
A script designed to run the integration tests.
|
|
|
|
|
This script should only be run on the roborio.
|
|
|
|
|
Where:
|
|
|
|
|
-h Show this help text
|
|
|
|
|
-d The directory where the tests have been placed.
|
2017-11-28 19:12:05 -08:00
|
|
|
This is done to prevent overwriting an already running program.
|
2023-02-26 15:06:37 -08:00
|
|
|
This script will automatically move the test into the ${DEFAULT_TEST_DIR}
|
2017-11-28 19:12:05 -08:00
|
|
|
directory.
|
2023-02-26 15:06:37 -08:00
|
|
|
Default: Assumes the test is in the same directory as this script.
|
2014-08-26 11:20:02 -04:00
|
|
|
-A Do not use the default arguments for the given language.
|
|
|
|
|
arg The arguments to be passed to test."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Are you trying to run this program on a platform other than the roboRIO?
|
|
|
|
|
if [[ ! -e "${DEFAULT_TEST_DIR}" ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
printf "Failed to find %s\nAre you trying to run this file on your local computer?\n" "${DEFAULT_TEST_DIR}"
|
|
|
|
|
printf "This script should only be run on the roboRIO.\n\n"
|
|
|
|
|
echo "$usage"
|
|
|
|
|
exit 1
|
2014-08-26 11:20:02 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
LANGUAGE=none
|
|
|
|
|
TEST_FILE=none
|
|
|
|
|
TEST_DIR="$DEFAULT_TEST_DIR"
|
2023-02-26 15:06:37 -08:00
|
|
|
# Begin searching for options from the second parameter on
|
2019-12-06 17:46:29 -05:00
|
|
|
PARAM_ARGS=${@:2}
|
2014-08-26 11:20:02 -04:00
|
|
|
# Where the test arguments start
|
2019-12-06 17:46:29 -05:00
|
|
|
TEST_RUN_ARGS=${@:2}
|
2014-08-26 11:20:02 -04:00
|
|
|
RUN_WITH_DEFAULT_ARGS=true
|
|
|
|
|
DEFAULT_ARGS=""
|
|
|
|
|
|
|
|
|
|
# Determine the language that we are attempting to run
|
|
|
|
|
if [[ "$1" = java ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
LANGUAGE=$1
|
|
|
|
|
TEST_FILE=$DEFAULT_JAVA_TEST_NAME
|
|
|
|
|
DEFAULT_ARGS=$DEFAULT_JAVA_TEST_ARGS
|
2014-08-26 11:20:02 -04:00
|
|
|
elif [[ "$1" = cpp ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
LANGUAGE=$1
|
|
|
|
|
TEST_FILE=$DEFAULT_CPP_TEST_NAME
|
|
|
|
|
DEFAULT_ARGS=$DEFAULT_CPP_TEST_ARGS
|
2014-08-26 11:20:02 -04:00
|
|
|
elif [[ "$1" = "-h" ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
#If the first argument is the help option
|
|
|
|
|
#Allow it to be searhced for in getopts
|
|
|
|
|
PARAM_ARGS=${@}
|
2014-08-26 11:20:02 -04:00
|
|
|
else
|
2018-05-16 22:47:35 -04:00
|
|
|
printf "Invalid language selection: %s\n\n" "$1" >&2
|
|
|
|
|
echo "$usage" >&2
|
|
|
|
|
exit 1
|
2014-08-26 11:20:02 -04:00
|
|
|
fi
|
|
|
|
|
|
2019-12-06 17:46:29 -05:00
|
|
|
PARAM_COUNTER=1
|
2014-08-26 11:20:02 -04:00
|
|
|
printf "Param Args ${PARAM_ARGS}\n"
|
|
|
|
|
|
2020-08-31 00:33:11 -07:00
|
|
|
# Check for optional parameters
|
2014-10-22 16:23:26 -04:00
|
|
|
while getopts ':hmd:A' option $PARAM_ARGS ; do
|
2018-05-16 22:47:35 -04:00
|
|
|
case "$option" in
|
|
|
|
|
h)
|
|
|
|
|
# Print the help message
|
|
|
|
|
printf "Usage:\n"
|
|
|
|
|
echo "$usage"
|
|
|
|
|
exit
|
|
|
|
|
;;
|
|
|
|
|
A)
|
|
|
|
|
# Remove the default arguments
|
|
|
|
|
RUN_WITH_DEFAULT_ARGS=false
|
|
|
|
|
PARAM_COUNTER=$[$PARAM_COUNTER +1]
|
|
|
|
|
;;
|
|
|
|
|
d)
|
|
|
|
|
TEST_DIR=$OPTARG
|
|
|
|
|
# Since we are selecting the directory the run args start from the 5th argument
|
|
|
|
|
PARAM_COUNTER=$[$PARAM_COUNTER +2]
|
|
|
|
|
;;
|
|
|
|
|
?)
|
|
|
|
|
# When an unknown param is found then we are done so break
|
|
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2014-08-26 11:20:02 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
TEST_RUN_ARGS=${@:$[$PARAM_COUNTER +1]}
|
|
|
|
|
|
|
|
|
|
if [[ "$RUN_WITH_DEFAULT_ARGS" == true ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
TEST_RUN_ARGS="${DEFAULT_ARGS} ${TEST_RUN_ARGS}"
|
2014-08-26 11:20:02 -04:00
|
|
|
fi
|
|
|
|
|
|
2020-08-31 00:33:11 -07:00
|
|
|
# Make sure at least two parameters are passed or four if running with -d option
|
2014-08-26 11:20:02 -04:00
|
|
|
if [[ $# -lt $PARAM_COUNTER ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
printf "Invalid arg count. Should be %s, was %s.\n" "${PARAM_COUNTER}" "$#"
|
|
|
|
|
echo "$usage"
|
|
|
|
|
exit 1
|
2014-08-26 11:20:02 -04:00
|
|
|
fi
|
|
|
|
|
|
2018-11-09 23:36:35 -05:00
|
|
|
# Make sure the webserver is disabled to save memory
|
|
|
|
|
/usr/local/natinst/etc/init.d/systemWebServer stop
|
|
|
|
|
|
2014-08-26 11:20:02 -04:00
|
|
|
# Kill all running robot programs
|
2023-12-01 20:53:57 -08:00
|
|
|
killall java FRCUserProgram || true
|
2014-08-26 11:20:02 -04:00
|
|
|
|
|
|
|
|
# If we are running with the -d argument move the test to the DEFAULT_TEST_DIR
|
|
|
|
|
if [[ ! -e "${TEST_DIR}/${TEST_FILE}" ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
printf "Failed to find %s.\nDid you copy the test file correctly?\n" "${TEST_DIR}/${TEST_FILE}"
|
|
|
|
|
echo "$usage"
|
|
|
|
|
exit 1
|
2014-08-26 11:20:02 -04:00
|
|
|
elif [[ $TEST_DIR != "$DEFAULT_TEST_DIR" ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
mv "${TEST_DIR}/${TEST_FILE}" "${DEFAULT_TEST_DIR}"
|
2014-08-26 11:20:02 -04:00
|
|
|
fi
|
|
|
|
|
|
2023-02-26 15:06:37 -08:00
|
|
|
# Make sure the executable file has permission to run
|
2014-08-26 11:20:02 -04:00
|
|
|
|
2016-10-19 22:30:29 -07:00
|
|
|
# Get the serial number and FPGADeviceCode for this rio
|
|
|
|
|
export serialnum=`/sbin/fw_printenv -n serial#`
|
|
|
|
|
export eval `/sbin/fw_printenv DeviceCode FPGADeviceCode DeviceDesc TargetClass`
|
|
|
|
|
|
2014-08-26 11:20:02 -04:00
|
|
|
# Store the run command for the language
|
|
|
|
|
RUN_COMMAND=none
|
|
|
|
|
if [[ ${LANGUAGE} = java ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
chmod a+x ${DEFAULT_JAVA_TEST_NAME}
|
|
|
|
|
RUN_COMMAND="env LD_LIBRARY_PATH=/opt/GenICam_v3_0_NI/bin/Linux32_ARM/:/usr/local/frc/lib ${DEFAULT_PATH_TO_JRE} -ea -jar ${DEFAULT_JAVA_TEST_NAME} ${TEST_RUN_ARGS}"
|
2014-08-26 11:20:02 -04:00
|
|
|
elif [[ ${LANGUAGE} = cpp ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
chmod a+x ${DEFAULT_CPP_TEST_NAME}
|
|
|
|
|
RUN_COMMAND="./${DEFAULT_CPP_TEST_NAME} ${TEST_RUN_ARGS}"
|
2014-08-26 11:20:02 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
printf "Running: %s\n\n" "${RUN_COMMAND}"
|
2016-08-12 19:18:48 -07:00
|
|
|
COREDUMP_DIR=${DEFAULT_DESTINATION_TEST_RESULTS_DIR}/coredump
|
|
|
|
|
mkdir -p ${COREDUMP_DIR}
|
|
|
|
|
CORE_LOCATION=${COREDUMP_DIR}/core
|
|
|
|
|
echo ${CORE_LOCATION} > /proc/sys/kernel/core_pattern
|
|
|
|
|
ulimit -c unlimited
|
2014-08-26 11:20:02 -04:00
|
|
|
eval ${RUN_COMMAND}
|
2016-08-12 19:18:48 -07:00
|
|
|
if [[ $? -gt 127 && -e ${CORE_LOCATION} ]]; then
|
2018-05-16 22:47:35 -04:00
|
|
|
mv ${CORE_LOCATION} ${COREDUMP_DIR}/core.${LANGUAGE}
|
|
|
|
|
if [[ ${LANGUAGE} = java ]]; then
|
|
|
|
|
cp -p ${DEFAULT_JAVA_TEST_NAME} ${COREDUMP_DIR}/
|
|
|
|
|
elif [[ ${LANGUAGE} = cpp ]]; then
|
|
|
|
|
cp -p ${DEFAULT_CPP_TEST_NAME} ${COREDUMP_DIR}/
|
|
|
|
|
fi
|
2016-08-12 19:18:48 -07:00
|
|
|
fi
|