blob: 96d10c007ece49b1836cf7e0cd0b2430fc7f40c4 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001#!/usr/bin/env bash
2#*----------------------------------------------------------------------------*#
3#* Copyright (c) 2014-2019 FIRST. All Rights Reserved. *#
4#* Open Source Software - may be modified and shared by FRC teams. The code *#
5#* must be accompanied by the FIRST BSD license file in the root directory of *#
6#* the project. *#
7#*----------------------------------------------------------------------------*#
8
9# This file is intended to be run in the DEFAULT_TEST_DIR on the roboRIO.
10# Do not attempt to run this file on your local system.
11# There is one file (delploy-and-run-test-on-robot.sh) that is designed to
12# deploy this file allong with the compiled tests for you.
13
14# Configurable variables
15source config.sh
16
17DEFAULT_TEST_DIR=${DEFAULT_DESTINATION_DIR}
18DEFAULT_PATH_TO_JRE=/usr/local/frc/JRE/bin/java
19
20usage="$(basename "$0") [-h] (java|cpp) [-d test_dir] [-A] [arg] [arg]...
21A script designed to run the integration tests.
22This script should only be run on the roborio.
23Where:
24 -h Show this help text
25 -d The directory where the tests have been placed.
26 This is done to prevent overwriting an already running program.
27 This scrip will automatically move the test into the ${DEFAULT_TEST_DIR}
28 directory.
29 Default: Assumes the test is in the same directory as this scrip.
30 -A Do not use the default arguments for the given language.
31 arg The arguments to be passed to test."
32
33
34# Are you trying to run this program on a platform other than the roboRIO?
35if [[ ! -e "${DEFAULT_TEST_DIR}" ]]; then
36 printf "Failed to find %s\nAre you trying to run this file on your local computer?\n" "${DEFAULT_TEST_DIR}"
37 printf "This script should only be run on the roboRIO.\n\n"
38 echo "$usage"
39 exit 1
40fi
41
42LANGUAGE=none
43TEST_FILE=none
44TEST_DIR="$DEFAULT_TEST_DIR"
45# Begin searching for options from the second paramater on
46PARAM_ARGS=${@:2}
47# Where the test arguments start
48TEST_RUN_ARGS=${@:2}
49RUN_WITH_DEFAULT_ARGS=true
50DEFAULT_ARGS=""
51
52# Determine the language that we are attempting to run
53if [[ "$1" = java ]]; then
54 LANGUAGE=$1
55 TEST_FILE=$DEFAULT_JAVA_TEST_NAME
56 DEFAULT_ARGS=$DEFAULT_JAVA_TEST_ARGS
57elif [[ "$1" = cpp ]]; then
58 LANGUAGE=$1
59 TEST_FILE=$DEFAULT_CPP_TEST_NAME
60 DEFAULT_ARGS=$DEFAULT_CPP_TEST_ARGS
61elif [[ "$1" = "-h" ]]; then
62 #If the first argument is the help option
63 #Allow it to be searhced for in getopts
64 PARAM_ARGS=${@}
65else
66 printf "Invalid language selection: %s\n\n" "$1" >&2
67 echo "$usage" >&2
68 exit 1
69fi
70
71PARAM_COUNTER=1
72printf "Param Args ${PARAM_ARGS}\n"
73
74# Check for optional paramaters
75while getopts ':hmd:A' option $PARAM_ARGS ; do
76 case "$option" in
77 h)
78 # Print the help message
79 printf "Usage:\n"
80 echo "$usage"
81 exit
82 ;;
83 A)
84 # Remove the default arguments
85 RUN_WITH_DEFAULT_ARGS=false
86 PARAM_COUNTER=$[$PARAM_COUNTER +1]
87 ;;
88 d)
89 TEST_DIR=$OPTARG
90 # Since we are selecting the directory the run args start from the 5th argument
91 PARAM_COUNTER=$[$PARAM_COUNTER +2]
92 ;;
93 ?)
94 # When an unknown param is found then we are done so break
95 break
96 ;;
97 esac
98done
99
100TEST_RUN_ARGS=${@:$[$PARAM_COUNTER +1]}
101
102if [[ "$RUN_WITH_DEFAULT_ARGS" == true ]]; then
103 TEST_RUN_ARGS="${DEFAULT_ARGS} ${TEST_RUN_ARGS}"
104fi
105
106# Make sure at least two paramaters are passed or four if running with -d option
107if [[ $# -lt $PARAM_COUNTER ]]; then
108 printf "Invalid arg count. Should be %s, was %s.\n" "${PARAM_COUNTER}" "$#"
109 echo "$usage"
110 exit 1
111fi
112
113# Make sure the webserver is disabled to save memory
114/usr/local/natinst/etc/init.d/systemWebServer stop
115
116# Kill all running robot programs
117killall java FRCUserProgram
118
119# If we are running with the -d argument move the test to the DEFAULT_TEST_DIR
120if [[ ! -e "${TEST_DIR}/${TEST_FILE}" ]]; then
121 printf "Failed to find %s.\nDid you copy the test file correctly?\n" "${TEST_DIR}/${TEST_FILE}"
122 echo "$usage"
123 exit 1
124elif [[ $TEST_DIR != "$DEFAULT_TEST_DIR" ]]; then
125 mv "${TEST_DIR}/${TEST_FILE}" "${DEFAULT_TEST_DIR}"
126fi
127
128# Make sure the excecutable file has permission to run
129
130# Get the serial number and FPGADeviceCode for this rio
131export serialnum=`/sbin/fw_printenv -n serial#`
132export eval `/sbin/fw_printenv DeviceCode FPGADeviceCode DeviceDesc TargetClass`
133
134# Store the run command for the language
135RUN_COMMAND=none
136if [[ ${LANGUAGE} = java ]]; then
137 chmod a+x ${DEFAULT_JAVA_TEST_NAME}
138 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}"
139elif [[ ${LANGUAGE} = cpp ]]; then
140 chmod a+x ${DEFAULT_CPP_TEST_NAME}
141 RUN_COMMAND="./${DEFAULT_CPP_TEST_NAME} ${TEST_RUN_ARGS}"
142fi
143
144printf "Running: %s\n\n" "${RUN_COMMAND}"
145COREDUMP_DIR=${DEFAULT_DESTINATION_TEST_RESULTS_DIR}/coredump
146mkdir -p ${COREDUMP_DIR}
147CORE_LOCATION=${COREDUMP_DIR}/core
148echo ${CORE_LOCATION} > /proc/sys/kernel/core_pattern
149ulimit -c unlimited
150eval ${RUN_COMMAND}
151if [[ $? -gt 127 && -e ${CORE_LOCATION} ]]; then
152 mv ${CORE_LOCATION} ${COREDUMP_DIR}/core.${LANGUAGE}
153 if [[ ${LANGUAGE} = java ]]; then
154 cp -p ${DEFAULT_JAVA_TEST_NAME} ${COREDUMP_DIR}/
155 elif [[ ${LANGUAGE} = cpp ]]; then
156 cp -p ${DEFAULT_CPP_TEST_NAME} ${COREDUMP_DIR}/
157 fi
158fi