2018-07-04 17:59:59 +08:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Parse arguments -----------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
DOC_STRING="Run unit tests."
|
|
|
|
|
|
|
|
USAGE_STRING=$(cat <<- END
|
2020-09-02 21:19:07 +08:00
|
|
|
Usage: $0 [-h|--help] [--gdb] [--xml] [--gtest_args=ARGS] [--python-version=VERSION]
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
Then either ran all the tests
|
|
|
|
|
|
|
|
[--all]
|
|
|
|
|
|
|
|
Or choose one or more of the following
|
|
|
|
|
|
|
|
[--libcarla-release] [--libcarla-debug]
|
|
|
|
[--benchmark]
|
2018-10-21 21:12:43 +08:00
|
|
|
|
|
|
|
You can also set the command-line arguments passed to GTest on a ".gtest"
|
|
|
|
config file in the Carla project main folder. E.g.
|
|
|
|
|
|
|
|
# Contents of ${CARLA_ROOT_FOLDER}/.gtest
|
|
|
|
gtest_shuffle
|
|
|
|
gtest_filter=misc*
|
2018-07-04 17:59:59 +08:00
|
|
|
END
|
|
|
|
)
|
|
|
|
|
|
|
|
GDB=
|
2018-07-07 00:14:38 +08:00
|
|
|
XML_OUTPUT=false
|
2018-10-21 21:12:43 +08:00
|
|
|
GTEST_ARGS=`sed -e 's/#.*$//g' ${CARLA_ROOT_FOLDER}/.gtest | sed -e '/^[[:space:]]*$/!s/^/--/g' | sed -e ':a;N;$!ba;s/\n/ /g'`
|
2018-07-04 17:59:59 +08:00
|
|
|
LIBCARLA_RELEASE=false
|
|
|
|
LIBCARLA_DEBUG=false
|
2020-09-02 21:19:07 +08:00
|
|
|
SMOKE_TESTS=false
|
|
|
|
PYTHON_API=false
|
2019-01-27 01:08:54 +08:00
|
|
|
RUN_BENCHMARK=false
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2020-09-02 21:19:07 +08:00
|
|
|
OPTS=`getopt -o h --long help,gdb,xml,gtest_args:,all,libcarla-release,libcarla-debug,python-api,smoke,benchmark,python-version:, -n 'parse-options' -- "$@"`
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
2020-12-18 16:12:58 +08:00
|
|
|
source $(dirname "$0")/Environment.sh
|
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
PY_VERSION_LIST=3
|
2020-08-25 20:10:53 +08:00
|
|
|
|
2020-08-25 21:12:46 +08:00
|
|
|
while [[ $# -gt 0 ]]; do
|
2018-07-04 17:59:59 +08:00
|
|
|
case "$1" in
|
|
|
|
--gdb )
|
2018-11-01 02:53:34 +08:00
|
|
|
GDB="gdb --args";
|
2018-07-04 17:59:59 +08:00
|
|
|
shift ;;
|
2018-07-07 00:14:38 +08:00
|
|
|
--xml )
|
|
|
|
XML_OUTPUT=true;
|
2020-03-05 20:16:18 +08:00
|
|
|
# Create the folder for the test-results
|
|
|
|
mkdir -p "${CARLA_TEST_RESULTS_FOLDER}"
|
2018-07-07 00:14:38 +08:00
|
|
|
shift ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
--gtest_args )
|
|
|
|
GTEST_ARGS="$2";
|
2019-03-08 21:41:23 +08:00
|
|
|
shift 2 ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
--all )
|
|
|
|
LIBCARLA_RELEASE=true;
|
|
|
|
LIBCARLA_DEBUG=true;
|
2020-09-02 21:19:07 +08:00
|
|
|
PYTHON_API=true;
|
2018-07-04 17:59:59 +08:00
|
|
|
shift ;;
|
|
|
|
--libcarla-release )
|
|
|
|
LIBCARLA_RELEASE=true;
|
|
|
|
shift ;;
|
|
|
|
--libcarla-debug )
|
|
|
|
LIBCARLA_DEBUG=true;
|
|
|
|
shift ;;
|
2020-09-02 21:19:07 +08:00
|
|
|
--smoke )
|
|
|
|
SMOKE_TESTS=true;
|
2018-07-04 17:59:59 +08:00
|
|
|
shift ;;
|
2020-09-02 21:19:07 +08:00
|
|
|
--python-api )
|
|
|
|
PYTHON_API=true;
|
2019-03-08 21:41:23 +08:00
|
|
|
shift ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
--benchmark )
|
|
|
|
LIBCARLA_RELEASE=true;
|
2019-01-27 01:08:54 +08:00
|
|
|
RUN_BENCHMARK=true;
|
2018-07-04 17:59:59 +08:00
|
|
|
GTEST_ARGS="--gtest_filter=benchmark*";
|
|
|
|
shift ;;
|
2020-09-02 21:19:07 +08:00
|
|
|
--python-version )
|
2020-10-01 22:12:15 +08:00
|
|
|
PY_VERSION_LIST="$2"
|
2020-08-25 21:12:46 +08:00
|
|
|
shift 2 ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
-h | --help )
|
|
|
|
echo "$DOC_STRING"
|
|
|
|
echo -e "$USAGE_STRING"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
* )
|
2020-08-25 21:12:46 +08:00
|
|
|
shift ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-09-02 21:19:07 +08:00
|
|
|
if ! { ${LIBCARLA_RELEASE} || ${LIBCARLA_DEBUG} || ${PYTHON_API} || ${SMOKE_TESTS}; }; then
|
2018-07-04 17:59:59 +08:00
|
|
|
fatal_error "Nothing selected to be done."
|
|
|
|
fi
|
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
# Convert comma-separated string to array of unique elements.
|
|
|
|
IFS="," read -r -a PY_VERSION_LIST <<< "${PY_VERSION_LIST}"
|
|
|
|
|
2019-03-20 05:41:42 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- Download Content need it by the tests -------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
if { ${LIBCARLA_RELEASE} || ${LIBCARLA_DEBUG}; }; then
|
|
|
|
|
2019-06-19 20:34:26 +08:00
|
|
|
CONTENT_TAG=0.1.4
|
2019-03-20 05:41:42 +08:00
|
|
|
|
|
|
|
mkdir -p ${LIBCARLA_TEST_CONTENT_FOLDER}
|
|
|
|
pushd "${LIBCARLA_TEST_CONTENT_FOLDER}" >/dev/null
|
|
|
|
|
|
|
|
if [ "$(get_git_repository_version)" != "${CONTENT_TAG}" ]; then
|
|
|
|
pushd .. >/dev/null
|
|
|
|
rm -Rf ${LIBCARLA_TEST_CONTENT_FOLDER}
|
|
|
|
git clone -b ${CONTENT_TAG} https://github.com/carla-simulator/opendrive-test-files.git ${LIBCARLA_TEST_CONTENT_FOLDER}
|
|
|
|
popd >/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2018-07-04 17:59:59 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- Run LibCarla tests --------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
if ${LIBCARLA_DEBUG} ; then
|
|
|
|
|
2018-07-07 00:14:38 +08:00
|
|
|
if ${XML_OUTPUT} ; then
|
|
|
|
EXTRA_ARGS="--gtest_output=xml:${CARLA_TEST_RESULTS_FOLDER}/libcarla-debug.xml"
|
|
|
|
else
|
|
|
|
EXTRA_ARGS=
|
|
|
|
fi
|
|
|
|
|
2019-01-27 00:27:14 +08:00
|
|
|
log "Running LibCarla.server unit tests (debug)."
|
|
|
|
echo "Running: ${GDB} libcarla_test_server_debug ${GTEST_ARGS} ${EXTRA_ARGS}"
|
|
|
|
LD_LIBRARY_PATH=${LIBCARLA_INSTALL_SERVER_FOLDER}/lib ${GDB} ${LIBCARLA_INSTALL_SERVER_FOLDER}/test/libcarla_test_server_debug ${GTEST_ARGS} ${EXTRA_ARGS}
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-01-27 00:27:14 +08:00
|
|
|
log "Running LibCarla.client unit tests (debug)."
|
|
|
|
echo "Running: ${GDB} libcarla_test_client_debug ${GTEST_ARGS} ${EXTRA_ARGS}"
|
|
|
|
${GDB} ${LIBCARLA_INSTALL_CLIENT_FOLDER}/test/libcarla_test_client_debug ${GTEST_ARGS} ${EXTRA_ARGS}
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ${LIBCARLA_RELEASE} ; then
|
|
|
|
|
2018-07-07 00:14:38 +08:00
|
|
|
if ${XML_OUTPUT} ; then
|
|
|
|
EXTRA_ARGS="--gtest_output=xml:${CARLA_TEST_RESULTS_FOLDER}/libcarla-release.xml"
|
|
|
|
else
|
|
|
|
EXTRA_ARGS=
|
|
|
|
fi
|
|
|
|
|
2019-01-27 00:27:14 +08:00
|
|
|
log "Running LibCarla.server unit tests (release)."
|
|
|
|
echo "Running: ${GDB} libcarla_test_server_release ${GTEST_ARGS} ${EXTRA_ARGS}"
|
|
|
|
LD_LIBRARY_PATH=${LIBCARLA_INSTALL_SERVER_FOLDER}/lib ${GDB} ${LIBCARLA_INSTALL_SERVER_FOLDER}/test/libcarla_test_server_release ${GTEST_ARGS} ${EXTRA_ARGS}
|
2018-10-21 21:12:43 +08:00
|
|
|
|
2019-01-27 01:46:30 +08:00
|
|
|
if ! { ${RUN_BENCHMARK} ; }; then
|
2019-01-27 01:08:54 +08:00
|
|
|
|
|
|
|
log "Running LibCarla.client unit tests (release)."
|
|
|
|
echo "Running: ${GDB} libcarla_test_client_debug ${GTEST_ARGS} ${EXTRA_ARGS}"
|
|
|
|
${GDB} ${LIBCARLA_INSTALL_CLIENT_FOLDER}/test/libcarla_test_client_release ${GTEST_ARGS} ${EXTRA_ARGS}
|
|
|
|
|
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ==============================================================================
|
2019-03-08 21:41:23 +08:00
|
|
|
# -- Run Python API unit tests -------------------------------------------------
|
2018-07-04 17:59:59 +08:00
|
|
|
# ==============================================================================
|
|
|
|
|
2019-03-08 21:41:23 +08:00
|
|
|
pushd "${CARLA_PYTHONAPI_ROOT_FOLDER}/test/unit" >/dev/null
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2018-07-07 00:14:38 +08:00
|
|
|
if ${XML_OUTPUT} ; then
|
|
|
|
EXTRA_ARGS="-X"
|
|
|
|
else
|
|
|
|
EXTRA_ARGS=
|
|
|
|
fi
|
|
|
|
|
2020-09-02 21:19:07 +08:00
|
|
|
if ${PYTHON_API} ; then
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
for PY_VERSION in ${PY_VERSION_LIST[@]} ; do
|
|
|
|
|
|
|
|
log "Running Python API for Python ${PY_VERSION} unit tests."
|
|
|
|
|
|
|
|
/usr/bin/env python${PY_VERSION} -m nose2 ${EXTRA_ARGS}
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
done
|
2018-07-07 00:14:38 +08:00
|
|
|
|
|
|
|
if ${XML_OUTPUT} ; then
|
|
|
|
mv test-results.xml ${CARLA_TEST_RESULTS_FOLDER}/python-api-3.xml
|
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
popd >/dev/null
|
|
|
|
|
2019-03-08 21:41:23 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- Run smoke tests -----------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
2020-09-03 22:56:21 +08:00
|
|
|
if ${SMOKE_TESTS} ; then
|
2019-03-29 01:35:31 +08:00
|
|
|
pushd "${CARLA_PYTHONAPI_ROOT_FOLDER}/util" >/dev/null
|
2019-03-08 21:41:23 +08:00
|
|
|
log "Checking connection with the simulator."
|
2020-10-28 16:42:37 +08:00
|
|
|
for PY_VERSION in ${PY_VERSION_LIST[@]} ; do
|
|
|
|
/usr/bin/env python${PY_VERSION} test_connection.py -p 3654 --timeout=60.0
|
|
|
|
done
|
2019-03-08 21:41:23 +08:00
|
|
|
popd >/dev/null
|
|
|
|
fi
|
|
|
|
|
2021-03-02 18:34:30 +08:00
|
|
|
pushd "${CARLA_PYTHONAPI_ROOT_FOLDER}/test" >/dev/null
|
2019-03-08 21:41:23 +08:00
|
|
|
|
2021-03-03 23:04:57 +08:00
|
|
|
if ${XML_OUTPUT} ; then
|
|
|
|
EXTRA_ARGS="-c smoke/unittest.cfg -X"
|
|
|
|
else
|
|
|
|
EXTRA_ARGS=
|
|
|
|
fi
|
|
|
|
|
2020-09-02 21:19:07 +08:00
|
|
|
if ${SMOKE_TESTS} ; then
|
2021-03-02 18:34:30 +08:00
|
|
|
smoke_list=`cat smoke_test_list.txt`
|
2020-10-28 16:42:37 +08:00
|
|
|
for PY_VERSION in ${PY_VERSION_LIST[@]} ; do
|
|
|
|
log "Running smoke tests for Python ${PY_VERSION}."
|
2021-03-03 23:04:57 +08:00
|
|
|
/usr/bin/env python${PY_VERSION} -m nose2 -v ${EXTRA_ARGS} ${smoke_list}
|
2020-10-28 16:42:37 +08:00
|
|
|
done
|
2019-03-08 21:41:23 +08:00
|
|
|
|
|
|
|
if ${XML_OUTPUT} ; then
|
|
|
|
mv test-results.xml ${CARLA_TEST_RESULTS_FOLDER}/smoke-tests-3.xml
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
popd >/dev/null
|
|
|
|
|
2018-07-04 17:59:59 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- ...and we are done --------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
log "Success!"
|