ShellTests.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright 2021 DeepMind Technologies Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # https://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. function(add_mujoco_shell_test TEST_NAME TARGET_BINARY)
  15. find_program(BASH_PROGRAM bash)
  16. if(BASH_PROGRAM)
  17. # Set up the test directory
  18. set(TEST_TMPDIR "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}")
  19. add_test(NAME ${TEST_NAME}_setup
  20. COMMAND ${BASH_PROGRAM} "${PROJECT_SOURCE_DIR}/cmake/setup_test_dir.sh" ${TEST_TMPDIR}
  21. )
  22. set_tests_properties(${TEST_NAME}_setup PROPERTIES FIXTURES_SETUP ${TEST_NAME}_fixture)
  23. add_test(NAME ${TEST_NAME}_cleanup
  24. COMMAND ${BASH_PROGRAM} "${PROJECT_SOURCE_DIR}/cmake/cleanup_test_dir.sh"
  25. ${TEST_TMPDIR}
  26. )
  27. set_tests_properties(${TEST_NAME}_cleanup PROPERTIES FIXTURES_CLEANUP ${TEST_NAME}_fixture)
  28. add_test(
  29. NAME ${TEST_NAME}
  30. COMMAND ${BASH_PROGRAM} "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}.sh"
  31. WORKING_DIRECTORY $<TARGET_FILE_DIR:${TARGET_BINARY}>
  32. )
  33. set_tests_properties(${TEST_NAME} PROPERTIES FIXTURES_REQUIRED ${TEST_NAME}_fixture)
  34. set_property(
  35. TEST "${TEST_NAME}"
  36. PROPERTY ENVIRONMENT
  37. "CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}"
  38. "TARGET_BINARY=$<TARGET_FILE:${TARGET_BINARY}>"
  39. "TEST_TMPDIR=${TEST_TMPDIR}"
  40. )
  41. if(WIN32)
  42. # Define the directory containing the mujoco DLL library so that it can be added to the PATH.
  43. # We modify the PATH in the script as it is more reliable.
  44. set_property(
  45. TEST "${TEST_NAME}"
  46. APPEND
  47. PROPERTY ENVIRONMENT "MUJOCO_DLL_DIR=$<TARGET_FILE_DIR:mujoco>"
  48. )
  49. endif()
  50. endif()
  51. endfunction()