RunTest.cmake 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. if(NOT EXISTS ${TEST_EXECUTABLE})
  2. message(FATAL_ERROR "Error could not find ${TEST_EXECUTABLE}, ensure that you built the test binary")
  3. endif()
  4. if(CMAKE_SYSTEM_NAME STREQUAL "Android")
  5. # support to run plain old binary on android devices
  6. # requires android debug bridge to be installed
  7. find_program(adb_executable adb)
  8. if(NOT adb_executable)
  9. message(FATAL_ERROR "Error could not find adb")
  10. endif()
  11. # check if any device emulator is attached
  12. execute_process(COMMAND ${adb_executable} shell echo RESULT_VARIABLE CMD_RESULT)
  13. if(CMD_RESULT)
  14. message(FATAL_ERROR "Error adb: no devices/emulators found")
  15. endif()
  16. # push binary
  17. set(android_path /data/local/tmp)
  18. execute_process(COMMAND ${adb_executable} push ${TEST_EXECUTABLE} ${android_path} RESULT_VARIABLE CMD_RESULT)
  19. if(CMD_RESULT)
  20. message(FATAL_ERROR "Error running ${adb_executable} push ${TEST_EXECUTABLE} ${android_path} failed with result ${CMD_RESULT}")
  21. endif()
  22. # set permissions
  23. get_filename_component(test_executable ${TEST_EXECUTABLE} NAME)
  24. set(test_executable_on_android /data/local/tmp/${test_executable})
  25. execute_process(COMMAND ${adb_executable} shell chmod 555 ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
  26. if(CMD_RESULT)
  27. message(FATAL_ERROR "Error running ${adb_executable} shell chmod 555 ${test_executable_on_android} failed with result ${CMD_RESULT}")
  28. endif()
  29. # run executable
  30. execute_process(COMMAND ${adb_executable} shell ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
  31. if(CMD_RESULT)
  32. message(FATAL_ERROR "Error running ${adb_executable} shell ${test_executable_on_android} failed with result ${CMD_RESULT}")
  33. endif()
  34. # clean up binary
  35. execute_process(COMMAND ${adb_executable} shell rm ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
  36. if(CMD_RESULT)
  37. message(FATAL_ERROR "Error running ${adb_executable} shell rm ${test_executable_on_android} failed with result ${CMD_RESULT}")
  38. endif()
  39. elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
  40. # CTest doesn't support iOS
  41. message(FATAL_ERROR "Error CTest is not supported on iOS")
  42. else()
  43. # for other platforms just execute test binary on host
  44. execute_process(COMMAND ${TEST_EXECUTABLE} RESULT_VARIABLE CMD_RESULT)
  45. if(CMD_RESULT)
  46. message(FATAL_ERROR "Error running ${TEST_EXECUTABLE} failed with result ${CMD_RESULT}")
  47. endif()
  48. endif()