aboutsummaryrefslogtreecommitdiff
path: root/cmake/RunTest.cmake
diff options
context:
space:
mode:
authorHarish Mahendrakar <harish.mahendrakar@ittiam.com>2022-08-08 17:32:14 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-08-08 17:32:14 +0000
commit8e70d764467652b3ab43e65d30d50df72532ea45 (patch)
treec78adfd6bffe3bf8b0f2edb165f4687a16f9dad5 /cmake/RunTest.cmake
parent3eb6b26bc34ace509cd8d5842d276f2934cfa07a (diff)
parent0a0c005652f9b1c0f737643845591a2196b26538 (diff)
downloadlibopus-8e70d764467652b3ab43e65d30d50df72532ea45.tar.gz
Merge commit 'c9d5bea13e3cb7381bfa897a45d8bab4e7b767a7' into HEAD am: 170fd0b529 am: 0a0c005652
Original change: https://android-review.googlesource.com/c/platform/external/libopus/+/2164282 Change-Id: Icc343d34ed21be34d5f6f72c97fb69c8f1b123ca Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'cmake/RunTest.cmake')
-rw-r--r--cmake/RunTest.cmake61
1 files changed, 61 insertions, 0 deletions
diff --git a/cmake/RunTest.cmake b/cmake/RunTest.cmake
new file mode 100644
index 00000000..f6f8b4a2
--- /dev/null
+++ b/cmake/RunTest.cmake
@@ -0,0 +1,61 @@
+if(NOT EXISTS ${TEST_EXECUTABLE})
+ message(FATAL_ERROR "Error could not find ${TEST_EXECUTABLE}, ensure that you built the test binary")
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Android")
+
+ # support to run plain old binary on android devices
+ # requires android debug bridge to be installed
+
+ find_program(adb_executable adb)
+ if(NOT adb_executable)
+ message(FATAL_ERROR "Error could not find adb")
+ endif()
+
+ # check if any device emulator is attached
+ execute_process(COMMAND ${adb_executable} shell echo RESULT_VARIABLE CMD_RESULT)
+ if(CMD_RESULT)
+ message(FATAL_ERROR "Error adb: no devices/emulators found")
+ endif()
+
+ # push binary
+ set(android_path /data/local/tmp)
+ execute_process(COMMAND ${adb_executable} push ${TEST_EXECUTABLE} ${android_path} RESULT_VARIABLE CMD_RESULT)
+ if(CMD_RESULT)
+ message(FATAL_ERROR "Error running ${adb_executable} push ${TEST_EXECUTABLE} ${android_path} failed with result ${CMD_RESULT}")
+ endif()
+
+ # set permissions
+ get_filename_component(test_executable ${TEST_EXECUTABLE} NAME)
+ set(test_executable_on_android /data/local/tmp/${test_executable})
+ execute_process(COMMAND ${adb_executable} shell chmod 555 ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
+ if(CMD_RESULT)
+ message(FATAL_ERROR "Error running ${adb_executable} shell chmod 555 ${test_executable_on_android} failed with result ${CMD_RESULT}")
+ endif()
+
+ # run executable
+ execute_process(COMMAND ${adb_executable} shell ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
+ if(CMD_RESULT)
+ message(FATAL_ERROR "Error running ${adb_executable} shell ${test_executable_on_android} failed with result ${CMD_RESULT}")
+ endif()
+
+ # clean up binary
+ execute_process(COMMAND ${adb_executable} shell rm ${test_executable_on_android} RESULT_VARIABLE CMD_RESULT)
+ if(CMD_RESULT)
+ message(FATAL_ERROR "Error running ${adb_executable} shell rm ${test_executable_on_android} failed with result ${CMD_RESULT}")
+ endif()
+
+elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
+ # CTest doesn't support iOS
+
+ message(FATAL_ERROR "Error CTest is not supported on iOS")
+
+else()
+ # for other platforms just execute test binary on host
+
+ execute_process(COMMAND ${TEST_EXECUTABLE} RESULT_VARIABLE CMD_RESULT)
+ if(CMD_RESULT)
+ message(FATAL_ERROR "Error running ${TEST_EXECUTABLE} failed with result ${CMD_RESULT}")
+ endif()
+
+endif() \ No newline at end of file