diff --git a/.gitignore b/.gitignore index 4fdd43957b..165f505746 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ bin/ .classpath **/dependency-reduced-pom.xml +# Created by the jenkins test script +test-reports # Added by the users of vagrant jdk-7u45-linux-arm-vfp-sflt.gz diff --git a/cmake/run-cpp-tests.sh b/cmake/run-cpp-tests.sh deleted file mode 100755 index 2032b9a1dc..0000000000 --- a/cmake/run-cpp-tests.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -# Temporary method to deploy C++ integration tests to the RoboRIO - -if [ $(which sshpass) ] -then - # Send stderr to /dev/null - the only thing printed to it is the login prompt - sshpass -p "" ssh admin@10.1.90.2 killall FRCUserProgram java 2> /dev/null - sshpass -p "" scp target/cmake/wpilibc/wpilibC++IntegrationTests/FRCUserProgram admin@10.1.90.2:/home/admin 2> /dev/null - sshpass -p "" ssh admin@10.1.90.2 ./FRCUserProgram --gtest_color=yes $* 2> /dev/null -else - ssh admin@10.1.90.2 killall FRCUserProgram - scp target/cmake/wpilibc/wpilibC++IntegrationTests/FRCUserProgram admin@10.1.90.2:/home/admin - ssh admin@10.1.90.2 ./FRCUserProgram --gtest_color=yes $* -fi - - - diff --git a/test-scripts/README.html b/test-scripts/README.html new file mode 100644 index 0000000000..a8d91d40cf --- /dev/null +++ b/test-scripts/README.html @@ -0,0 +1,381 @@ +README

WPILIB TEST SCRIPTS

+

Overview

+

These test scripts are designed to allow the user of the WPILib test framework to quickly and easily deploy and run their tests on the WPI roboRIO.

+

In order for the automated test system to work there is a driver station onboard the roboRIO that handles a queue of users waiting to use the driver station. All of the interaction with this queue is handled internally by test scripts contained within this file.

+

Running Tests

+

See screen steps live: [TODO: Add link to screen steps live]

\ No newline at end of file diff --git a/test-scripts/README.md b/test-scripts/README.md new file mode 100644 index 0000000000..12c0199388 --- /dev/null +++ b/test-scripts/README.md @@ -0,0 +1,9 @@ +# WPILIB TEST SCRIPTS +## Overview +These test scripts are designed to allow the user of the WPILib test framework to quickly and easily deploy and run their tests on the WPI roboRIO. + +In order for the automated test system to work there is a driver station onboard the roboRIO that handles a queue of users waiting to use the driver station. All of the interaction with this queue is handled internally by test scripts contained within this file. + +## Running Tests + +See screen steps live: [TODO: Add link to screen steps live] diff --git a/test-scripts/config.sh b/test-scripts/config.sh new file mode 100644 index 0000000000..522870dd4f --- /dev/null +++ b/test-scripts/config.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#*----------------------------------------------------------------------------*# +#* Copyright (c) FIRST 2014. All Rights Reserved. *# +#* 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 *# +#* the project. *# +#*----------------------------------------------------------------------------*# + +# If this is changed, update the .gitignore +# so that test results are not commited to the repo +DEFAULT_LOCAL_TEST_RESULTS_DIR=../test-reports + + +ROBOT_ADDRESS=admin@roboRIO-190.local +DEFAULT_LOCAL_RUN_TEST_SCRIPT="run-tests-on-robot.sh" + +DEFAULT_DESTINATION_DIR=/home/admin +DEFAULT_TEST_SCP_DIR=${DEFAULT_DESTINATION_DIR}/deployedTests +DEFAULT_DESTINATION_TEST_RESULTS_DIR=${DEFAULT_DESTINATION_DIR}/testResults + +# C++ test variables +DEFAULT_CPP_TEST_NAME=FRCUserProgram +DEFAULT_CPP_TEST_ARGS="--gtest_color=yes" +DEFAULT_LOCAL_CPP_TEST_FILE=../cmake/target/cmake/wpilibc/wpilibC++IntegrationTests/FRCUserProgram +CPP_REPORT=cppreport.xml +DEFAULT_LOCAL_CPP_TEST_RESULT=${DEFAULT_LOCAL_TEST_RESULTS_DIR}/${CPP_REPORT} +DEFAULT_DESTINATION_CPP_TEST_RESULTS=${DEFAULT_DESTINATION_TEST_RESULTS_DIR}/${CPP_REPORT} + +# Java test variables +DEFAULT_JAVA_TEST_NAME=FRCUserProgram.jar +DEFAULT_JAVA_TEST_ARGS="" +DEFAULT_LOCAL_JAVA_TEST_FILE=../wpilibj/wpilibJavaIntegrationTests/target/wpilibJavaIntegrationTests-0.1.0-SNAPSHOT.jar +JAVA_REPORT=javareport.xml +DEFAULT_LOCAL_JAVA_TEST_RESULT=${DEFAULT_LOCAL_TEST_RESULTS_DIR}/${JAVA_REPORT} +DEFAULT_DESTINATION_JAVA_TEST_RESULTS=${DEFAULT_DESTINATION_TEST_RESULTS_DIR}/AntReports/TEST-edu.wpi.first.wpilibj.test.TestSuite.xml + + + diff --git a/test-scripts/deploy-and-run-test-on-robot.sh b/test-scripts/deploy-and-run-test-on-robot.sh new file mode 100644 index 0000000000..bbedb0ec7e --- /dev/null +++ b/test-scripts/deploy-and-run-test-on-robot.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +#*----------------------------------------------------------------------------*# +#* Copyright (c) FIRST 2014. All Rights Reserved. *# +#* 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 *# +#* the project. *# +#*----------------------------------------------------------------------------*# + +# Configurable variables +source config.sh + +# Java variables +DEFAULT_DESTINATION_JAVA_TEST_FILE=${DEFAULT_TEST_SCP_DIR}/${DEFAULT_JAVA_TEST_NAME} + +# C++ Variables +DEFAULT_DESTINATION_CPP_TEST_FILE=${DEFAULT_TEST_SCP_DIR}/${DEFAULT_CPP_TEST_NAME} + +DEFAULT_DESTINATION_RUN_TEST_SCRIPT=${DEFAULT_DESTINATION_DIR}/${DEFAULT_LOCAL_RUN_TEST_SCRIPT} + +usage="$(basename "$0") [-h] (java|cpp) [-A] [arg] [arg]... +A script designed to run the integration tests. +This script should only be run on the roborio. +Where: + -h Show this help text. + -A Disable language recomended arguments. + arg Additional arguments to be passed to test." + + +# These variables are set when the language is selected +LANGUAGE=none +LOCAL_TEST_FILE=none +DESTINATION_TEST_FILE=none +TEST_RUN_ARGS="" + +# Begin searching for options from the third paramater on +PARAM_ARGS=${@:2} + +if [[ "$1" = java ]]; then + LANGUAGE=$1 + LOCAL_TEST_FILE=$DEFAULT_LOCAL_JAVA_TEST_FILE + DESTINATION_TEST_FILE=$DEFAULT_DESTINATION_JAVA_TEST_FILE +elif [[ "$1" = cpp ]]; then + LANGUAGE=$1 + LOCAL_TEST_FILE=$DEFAULT_LOCAL_CPP_TEST_FILE + DESTINATION_TEST_FILE=$DEFAULT_DESTINATION_CPP_TEST_FILE +elif [[ "$1" = "-h" ]]; then + printf "Usage:\n" + echo "$usage" + exit +else + printf "Invalid language selection: %s\n\n" "$1" >&2 + echo "$usage" >&2 + exit 1 +fi + +# Check if the test file to upload exists +if [[ ! -e ${LOCAL_TEST_FILE} ]]; then + printf "The test file does not exist: %s\nAre you sure that you compiled the tests??\n\n" "${LOCAL_TEST_FILE}" >&2 + echo "$usage" >&2 + exit 1 +fi + +TEST_RUN_ARGS="${@:2}" + +shopt -s huponexit + +SCP_TEST_SCRIPT="scp config.sh ${DEFAULT_LOCAL_RUN_TEST_SCRIPT} ${ROBOT_ADDRESS}:/${DEFAULT_DESTINATION_DIR}" +SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR="ssh -t ${ROBOT_ADDRESS} 'chmod a+x ${DEFAULT_DESTINATION_RUN_TEST_SCRIPT}; mkdir ${DEFAULT_TEST_SCP_DIR} 2>/dev/null'" +SCP_TEST_PROGRAM="scp ${LOCAL_TEST_FILE} ${ROBOT_ADDRESS}:/${DESTINATION_TEST_FILE}" +SSH_RUN_TESTS="ssh -t ${ROBOT_ADDRESS} '${DEFAULT_DESTINATION_RUN_TEST_SCRIPT} ${LANGUAGE} $(whoami) -d ${DEFAULT_TEST_SCP_DIR} ${TEST_RUN_ARGS}'" + +if [ $(which sshpass) ]; then + sshpass -p "" ${SCP_TEST_SCRIPT} + sshpass -p "" ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} + sshpass -p "" ${SCP_TEST_PROGRAM} + sshpass -p "" ${SSH_RUN_TESTS} +else + eval ${SCP_TEST_SCRIPT} + eval ${SSH_CHMOD_AND_MAKE_TEMP_TEST_DIR} + eval ${SCP_TEST_PROGRAM} + eval ${SSH_RUN_TESTS} +fi + diff --git a/test-scripts/jenkins-run-tests-get-results.sh b/test-scripts/jenkins-run-tests-get-results.sh new file mode 100644 index 0000000000..931c756345 --- /dev/null +++ b/test-scripts/jenkins-run-tests-get-results.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +#*----------------------------------------------------------------------------*# +#* Copyright (c) FIRST 2014. All Rights Reserved. *# +#* 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 *# +#* the project. *# +#*----------------------------------------------------------------------------*# + +# Configurable variables +source config.sh + +# If there are already test results in the repository then remove them +if [[ -e ${DEFAULT_LOCAL_TEST_RESULTS_DIR} ]]; then + rm -R ${DEFAULT_LOCAL_TEST_RESULTS_DIR} +fi + +# Make the directory where the tests should live +mkdir ${DEFAULT_LOCAL_TEST_RESULTS_DIR} 2>/dev/null + +# Remove the preivous test results from the the robot +SSH_REMOVE_OLD_TEST_RESULTS="ssh -t ${ROBOT_ADDRESS} 'rm -R ${DEFAULT_DESTINATION_TEST_RESULTS_DIR}; mkdir ${DEFAULT_DESTINATION_TEST_RESULTS_DIR}'" +if [ $(which sshpass) ]; then + sshpass -p "" ${SSH_REMOVE_OLD_TEST_RESULTS} +else + eval ${SSH_REMOVE_OLD_TEST_RESULTS} +fi + +printf "Running cpp test\n" + +# Run the C++ Tests +deploy-and-run-test-on-robot.sh cpp "--gtest_output=xml:${DEFAULT_DESTINATION_CPP_TEST_RESULTS}" + +# Retrive the C++ Test Results +SCP_GET_CPP_TEST_RESULT="scp ${ROBOT_ADDRESS}:${DEFAULT_DESTINATION_CPP_TEST_RESULTS} ${DEFAULT_LOCAL_CPP_TEST_RESULT}" +if [ $(which sshpass) ]; then + sshpass -p "" ${SCP_GET_CPP_TEST_RESULT} +else + eval ${SCP_GET_CPP_TEST_RESULT} +fi + +# Run the Java Tests +deploy-and-run-test-on-robot.sh java + +# Retrive the Java Test Results +SCP_GET_JAVA_TEST_RESULT="scp ${ROBOT_ADDRESS}:${DEFAULT_DESTINATION_JAVA_TEST_RESULTS} ${DEFAULT_LOCAL_JAVA_TEST_RESULT}" +if [ $(which sshpass) ]; then + sshpass -p "" ${SCP_GET_JAVA_TEST_RESULT} +else + eval ${SCP_GET_JAVA_TEST_RESULT} +fi diff --git a/test-scripts/run-tests-on-robot.sh b/test-scripts/run-tests-on-robot.sh new file mode 100644 index 0000000000..107474bae5 --- /dev/null +++ b/test-scripts/run-tests-on-robot.sh @@ -0,0 +1,166 @@ +#!/usr/bin/env bash +#*----------------------------------------------------------------------------*# +#* Copyright (c) FIRST 2014. All Rights Reserved. *# +#* 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 *# +#* the project. *# +#*----------------------------------------------------------------------------*# + +# 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 +# deploy this file allong with the compiled tests for you. + +# Configurable variables +source config.sh + +DEFAULT_TEST_DIR=${DEFAULT_DESTINATION_DIR} +DEFAULT_PATH_TO_JRE=/usr/local/frc/JRE/bin/java + +usage="$(basename "$0") [-h] (java|cpp) name [-d test_dir] [-A] [arg] [arg]... +A script designed to run the integration tests. +This script should only be run on the roborio. +Where: + -h Show this help text + name The name of the user trying to run the tests (used for driver station) + -d The directory where the tests have been placed. + This is done to prevent overwriting an already running program + in the case where another user already has the driver station mutex. + This scrip will automatically move the test into the ${DEFAULT_TEST_DIR} + directory when the driver station mutex is released. + Default: Assumes the test is in the same directory as this scrip. + -A Do not use the default arguments for the given language. + arg The arguments to be passed to test." + +mutexTaken=false +# This function should run even if the script exits abnormally +function finish { + if [ "$mutexTaken" == true ]; then + /usr/local/frc/bin/teststand ds --name="${NAME}" disable + /usr/local/frc/bin/teststand give --name="${NAME}" + mutexTaken=false + fi +} +trap finish EXIT SIGINT + +# This function should be run asynchronysly to enable the tests 10 +# seconds after they have been run. +function enableIn10Seconds { + sleep 10 + /usr/local/frc/bin/teststand ds --name="${NAME}" enable +} + +# Are you trying to run this program on a platform other than the roboRIO? +if [[ ! -e "${DEFAULT_TEST_DIR}" ]]; then + 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 +fi + +LANGUAGE=none +TEST_FILE=none +NAME=$2 +TEST_DIR="$DEFAULT_TEST_DIR" +# Begin searching for options from the third paramater on +PARAM_ARGS=${@:3} +# Where the test arguments start +TEST_RUN_ARGS=${@:3} +RUN_WITH_DEFAULT_ARGS=true +DEFAULT_ARGS="" + +# Determine the language that we are attempting to run +if [[ "$1" = java ]]; then + LANGUAGE=$1 + TEST_FILE=$DEFAULT_JAVA_TEST_NAME + DEFAULT_ARGS=$DEFAULT_JAVA_TEST_ARGS +elif [[ "$1" = cpp ]]; then + LANGUAGE=$1 + TEST_FILE=$DEFAULT_CPP_TEST_NAME + DEFAULT_ARGS=$DEFAULT_CPP_TEST_ARGS +elif [[ "$1" = "-h" ]]; then + #If the first argument is the help option + #Allow it to be searhced for in getopts + PARAM_ARGS=${@} +else + printf "Invalid language selection: %s\n\n" "$1" >&2 + echo "$usage" >&2 + exit 1 +fi + +PARAM_COUNTER=2 +printf "Param Args ${PARAM_ARGS}\n" + +# Check for optional paramaters +while getopts ':hd:A' option $PARAM_ARGS ; do + 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 +done + +TEST_RUN_ARGS=${@:$[$PARAM_COUNTER +1]} + +if [[ "$RUN_WITH_DEFAULT_ARGS" == true ]]; then + TEST_RUN_ARGS="${DEFAULT_ARGS} ${TEST_RUN_ARGS}" +fi + +# Make sure at least two paramaters are passed or four if running with -d option +if [[ $# -lt $PARAM_COUNTER ]]; then + printf "Invalid arg count. Should be %s, was %s.\n" "${PARAM_COUNTER}" "$#" + echo "$usage" + exit 1 +fi + +# Attempt to take the mutex for the driver station +mutexTaken=true +/usr/local/frc/bin/teststand take --name="${NAME}" + +# Kill all running robot programs +killall java FRCUserProgram + +# Once we have the mutex no other tests are running +# If we are running with the -d argument move the test to the DEFAULT_TEST_DIR +if [[ ! -e "${TEST_DIR}/${TEST_FILE}" ]]; then + printf "Failed to find %s.\nDid you copy the test file correctly?\n" "${TEST_DIR}/${TEST_FILE}" + echo "$usage" + exit 1 +elif [[ $TEST_DIR != "$DEFAULT_TEST_DIR" ]]; then + mv "${TEST_DIR}/${TEST_FILE}" "${DEFAULT_TEST_DIR}" +fi + +# Make sure the excecutable file has permission to run + +# Setup the driver station to enable automatically in 10 seconds without waiting for the function to excecute. +enableIn10Seconds& + +# Store the run command for the language +RUN_COMMAND=none +if [[ ${LANGUAGE} = java ]]; then + chmod a+x ${DEFAULT_JAVA_TEST_NAME} + RUN_COMMAND="${DEFAULT_PATH_TO_JRE} -ea -jar ${DEFAULT_JAVA_TEST_NAME} ${TEST_RUN_ARGS}" +elif [[ ${LANGUAGE} = cpp ]]; then + chmod a+x ${DEFAULT_CPP_TEST_NAME} + RUN_COMMAND="./${DEFAULT_CPP_TEST_NAME} ${TEST_RUN_ARGS}" +fi + +printf "Running: %s\n\n" "${RUN_COMMAND}" +eval ${RUN_COMMAND} diff --git a/test-scripts/spawn_driver_station.sh b/test-scripts/spawn_driver_station.sh new file mode 100644 index 0000000000..23e15ab67f --- /dev/null +++ b/test-scripts/spawn_driver_station.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +#*----------------------------------------------------------------------------*# +#* Copyright (c) FIRST 2014. All Rights Reserved. *# +#* 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 *# +#* the project. *# +#*----------------------------------------------------------------------------*# + +source config.sh + +TESTSTAND_SERVE_COMMAND=".scratch/teststand serve" + +#Checks to see if the mutex driver station is running. If it isn't then start it. + +SSH_CHECK_FOR_TESTSTAND="ssh -qn ${ROBOT_ADDRESS} 'pidof ${TESTSTAND_SERVE_COMMAND}' &>/dev/null" + +if [ $(which sshpass) ]; then + SSH_CHECK_FOR_TESTSTAND="sshpass -p '' ${SSH_CHECK_FOR_TESTSTAND}" +fi + +echo $SSH_CHECK_FOR_TESTSTAND + +if $(eval $SSH_CHECK_FOR_TESTSTAND); then + echo "Driver STation is already running"; + exit 0; +fi + +echo "Starting Driver Station"; + +SSH_START_TESTSTAND_DRIVER_STATION="ssh ${ROBOT_ADDRESS} '${TESTSTAND_SERVE_COMMAND}'" + +if [ $(which sshpass) ]; then + sshpass -p "" ${SSH_START_TESTSTAND_DRIVER_STATION} & +else + eval ${SSH_START_TESTSTAND_DRIVER_STATION} & +fi \ No newline at end of file diff --git a/wpilibj/wpilibJavaIntegrationTests/README.html b/wpilibj/wpilibJavaIntegrationTests/README.html new file mode 100644 index 0000000000..9c26b77411 --- /dev/null +++ b/wpilibj/wpilibJavaIntegrationTests/README.html @@ -0,0 +1,377 @@ +README

TO LOAD & RUN INTEGRATION TESTS

+

See: allwpilib/test-scripts

\ No newline at end of file diff --git a/wpilibj/wpilibJavaIntegrationTests/README.md b/wpilibj/wpilibJavaIntegrationTests/README.md index 0df86c7f5e..5aa567aa99 100644 --- a/wpilibj/wpilibJavaIntegrationTests/README.md +++ b/wpilibj/wpilibJavaIntegrationTests/README.md @@ -1,7 +1,3 @@ -TO LOAD & RUN INTEGRATION TESTS +## TO LOAD & RUN INTEGRATION TESTS -1. Run `mvn clean package` from this directory -2. Run `scp target/wpilibJavaIntegrationTests-0.1.0-SNAPSHOT.jar admin@10.1.90.2:/home/admin` and enter the password on the RoboRio -3. ssh into the RoboRio using `ssh admin@10.1.90.2` -4. Run the integration tests on the roborio using `./runintegrationjavaprogram` -5. Enable the robot using a driver station (this will be automatic eventually) +See: allwpilib/test-scripts diff --git a/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLanucher.java b/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLanucher.java index 31f4f3ada2..9e129bbe87 100644 --- a/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLanucher.java +++ b/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AntJunitLanucher.java @@ -24,20 +24,6 @@ import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest; */ public class AntJunitLanucher { - /** - * Deletes the given file recursively - * - * @param f - * the file to delete - */ - static void deleteFile(File f) { - if (f.isDirectory()) { - for (File c : f.listFiles()) - deleteFile(c); - } - f.delete(); - } - public static void main(String... args) { if (args.length == 0) { String path = String.format("%s/%s", @@ -46,9 +32,6 @@ public class AntJunitLanucher { Project project = new Project(); try { - // Delete the the old test directory if it exists - deleteFile(new File(pathToReports)); - // Create the file to store the test output new File(pathToReports).mkdirs(); JUnitTask task = new JUnitTask();