From 7a0e0ed80cf65aa4f5142b1ee197c1f0c0a44955 Mon Sep 17 00:00:00 2001 From: Nimrod Gileadi Date: Fri, 5 Aug 2022 04:24:49 -0700 Subject: [PATCH] Use testspeed to test all sample models and all models in mujoco/test. PiperOrigin-RevId: 465534183 Change-Id: Ic0c398d45ce3a4da5d0a2b7310439f17f0ec4162 --- test/sample/testspeed_test.sh | 38 ++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/test/sample/testspeed_test.sh b/test/sample/testspeed_test.sh index 78c506ae..bb0e8e10 100755 --- a/test/sample/testspeed_test.sh +++ b/test/sample/testspeed_test.sh @@ -13,10 +13,29 @@ # See the License for the specific language governing permissions and # limitations under the License. -MODEL="${CMAKE_SOURCE_DIR}/model/humanoid100/humanoid100.xml" +MODEL_DIRS=( + "${CMAKE_SOURCE_DIR}/model" + "${CMAKE_SOURCE_DIR}/test" +) die() { echo "$*" 1>&2 ; exit 1; } +test_model() { + local EXPECTED_STR='Simulation time' + local model="$1" + echo "Testing $model" >&2 + + # run testspeed, writing its output to stderr. + # die if testspeed returns a failure code, or if it doesn't have the string + # "Simulation time" in the output. + ("$TARGET_BINARY" "$model" 10 || die "testspeed failed") \ + | tee >(cat 1>&2) | grep -q "$EXPECTED_STR" + + if [ "$?" != 0 ]; then + die "Expected string not found in output ($EXPECTED_STR)." + fi +} + if [ -z "$TARGET_BINARY" ]; then die "Expecting environment variable TARGET_BINARY." fi @@ -27,12 +46,17 @@ if [ -z "$MUJOCO_DLL_DIR" ]; then PATH=$PATH:$MUJOCO_DLL_DIR fi -readonly EXPECTED_STR='Simulation time' -("$TARGET_BINARY" "$MODEL" 10 || die "testspeed failed") | grep "$EXPECTED_STR" - -if [ "$?" != 0 ]; then -die "Expected string not found in output ($EXPECTED_STR)." -fi +shopt -s globstar +for model_dir in ${MODEL_DIRS[@]}; do + echo "Looking in $model_dir" + for model in $model_dir/**/*.xml; do + if [[ $(basename $model) == malformed* ]]; then + echo "Skipping $model" >&2 + continue + fi + test_model "$model" + done +done cd $CURRENT_DIR echo "PASS"