From 7bb97a85b15d78aff8aa47471bc6fb9bc5af85ac Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Thu, 11 Apr 2024 17:38:14 -0600 Subject: [PATCH] Compile unit tests for iOS and Android While you can't easily run these unit tests, it's easy enough to still compile them so we don't need to go out of way to prohibit this. CMake has some support for running tests on the target OS so perhaps in the future we find a compelling way to run the test suite on a mobile OS. --- .github/workflows/ci.yml | 14 +++++++------- CMakeLists.txt | 4 +--- cmake/Macros.cmake | 5 +++++ test/TestUtilities/SystemUtil.cpp | 3 ++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c0be68d8..b4a77d1e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,16 +65,16 @@ jobs: - platform: { name: macOS, os: macos-12 } config: { name: Frameworks, flags: -GNinja -DSFML_BUILD_FRAMEWORKS=TRUE -DBUILD_SHARED_LIBS=TRUE } - platform: { name: Android, os: ubuntu-22.04 } - config: { name: x86 (API 21), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: x86, api: 21 } + config: { name: x86 (API 21), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: x86, api: 21 } type: { name: Release } - platform: { name: Android, os: ubuntu-22.04 } - config: { name: x86_64 (API 24), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=24 -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: x86_64, api: 24 } + config: { name: x86_64 (API 24), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=24 -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: x86_64, api: 24 } type: { name: Release } - platform: { name: Android, os: ubuntu-22.04 } - config: { name: armeabi-v7a (API 29), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=29 -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: armeabi-v7a, api: 29 } + config: { name: armeabi-v7a (API 29), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=29 -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: armeabi-v7a, api: 29 } type: { name: Debug, flags: -DCMAKE_BUILD_TYPE=Debug } - platform: { name: Android, os: ubuntu-22.04 } - config: { name: arm64-v8a (API 33), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=33 -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: arm64-v8a, api: 33 } + config: { name: arm64-v8a (API 33), flags: -GNinja -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=33 -DCMAKE_ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/26.1.10909125 -DBUILD_SHARED_LIBS=TRUE -DCMAKE_ANDROID_STL_TYPE=c++_shared, arch: arm64-v8a, api: 33 } type: { name: Debug, flags: -DCMAKE_BUILD_TYPE=Debug } - platform: { name: macOS , os: macos-12 } config: { name: System Deps, flags: -GNinja -DBUILD_SHARED_LIBS=TRUE -DSFML_USE_SYSTEM_DEPS=TRUE } @@ -202,7 +202,7 @@ jobs: run: cmake --build build --target runtests --config ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }} - name: Test - if: runner.os != 'Windows' || contains(matrix.platform.name, 'MinGW') + if: (runner.os != 'Windows' || contains(matrix.platform.name, 'MinGW')) && !contains(matrix.platform.name, 'iOS') && !contains(matrix.platform.name, 'Android') run: | ctest --test-dir build --output-on-failure -C ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }} --repeat until-pass:3 # Run gcovr to extract coverage information from the test run @@ -211,7 +211,7 @@ jobs: fi - name: Upload Coverage Report to Coveralls - if: matrix.type.name == 'Debug' && github.repository == 'SFML/SFML' # Disable upload in forks + if: matrix.type.name == 'Debug' && github.repository == 'SFML/SFML' && !contains(matrix.platform.name, 'iOS') && !contains(matrix.platform.name, 'Android') # Disable upload in forks uses: coverallsapp/github-action@v2 with: file: ./build/coverage.out @@ -269,7 +269,7 @@ jobs: - { name: Linux OpenGL ES, os: ubuntu-22.04, flags: -DSFML_OPENGL_ES=ON } - { name: macOS, os: macos-12 } - { name: iOS, os: macos-12, flags: -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64 } - - { name: Android, os: ubuntu-22.04, flags: -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DSFML_BUILD_TEST_SUITE=FALSE -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DCMAKE_ANDROID_STL_TYPE=c++_shared } + - { name: Android, os: ubuntu-22.04, flags: -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_NDK=$ANDROID_NDK -DCMAKE_ANDROID_STL_TYPE=c++_shared } steps: - name: Checkout Code diff --git a/CMakeLists.txt b/CMakeLists.txt index bc0dbab30..73188cbb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -517,9 +517,7 @@ sfml_set_option(SFML_BUILD_TEST_SUITE FALSE BOOL "TRUE to build the SFML test su sfml_set_option(SFML_ENABLE_COVERAGE FALSE BOOL "TRUE to enable coverage reporting, FALSE to ignore it") if(SFML_BUILD_TEST_SUITE) - if(SFML_OS_IOS) - message(WARNING "Unit testing not supported on iOS") - elseif(SFML_BUILD_WINDOW AND SFML_BUILD_GRAPHICS AND SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO) + if(SFML_BUILD_WINDOW AND SFML_BUILD_GRAPHICS AND SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO) enable_testing() add_subdirectory(test) else() diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 27c06019e..38e97098a 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -365,6 +365,11 @@ function(sfml_add_test target SOURCES DEPENDS) add_dependencies(${target} "install-mesa3d") endif() + # Delay test registration when cross compiling to avoid running crosscompiled app on host OS + if(CMAKE_CROSSCOMPILING) + set(CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE PRE_TEST) + endif() + # Add the test catch_discover_tests(${target} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) endfunction() diff --git a/test/TestUtilities/SystemUtil.cpp b/test/TestUtilities/SystemUtil.cpp index 6720de8b8..95f5a78c8 100644 --- a/test/TestUtilities/SystemUtil.cpp +++ b/test/TestUtilities/SystemUtil.cpp @@ -87,7 +87,8 @@ std::vector loadIntoMemory(const std::filesystem::path& path) const auto size = file.tellg(); file.seekg(0, std::ios::beg); std::vector buffer(static_cast(size)); - [[maybe_unused]] const auto& result = file.read(reinterpret_cast(buffer.data()), size); + [[maybe_unused]] const auto& result = file.read(reinterpret_cast(buffer.data()), + static_cast(size)); assert(result); return buffer; }