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