diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 55618d5c1..253aa0ccd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,8 +2,6 @@ name: 'CI Multiplatform Build' on: push: - branches: - - master pull_request: paths-ignore: - '**.md' @@ -121,11 +119,15 @@ jobs: run: | mkdir ./build cd ./build - cmake -DENABLE_SPARKLE_UPDATER=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DQTDIR="/usr/local/Cellar/qt/${{ env.QT_VERSION }}" -DDepsPath="/tmp/obsdeps" -DVLCPath="${{ github.workspace }}/cmbuild/vlc-${{ env.VLC_VERSION }}" -DENABLE_VLC=ON -DBUILD_BROWSER=ON -DBROWSER_DEPLOY=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64" .. + cmake -DENABLE_UNIT_TESTS=YES -DENABLE_SPARKLE_UPDATER=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DQTDIR="/usr/local/Cellar/qt/${{ env.QT_VERSION }}" -DDepsPath="/tmp/obsdeps" -DVLCPath="${{ github.workspace }}/cmbuild/vlc-${{ env.VLC_VERSION }}" -DENABLE_VLC=ON -DBUILD_BROWSER=ON -DBROWSER_DEPLOY=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64" .. - name: 'Build' shell: bash working-directory: ${{ github.workspace }}/build run: make -j4 + - name: 'Test' + shell: bash + working-directory: ${{ github.workspace }}/build + run: make CTEST_OUTPUT_ON_FAILURE=1 test - name: 'Install prerequisite: Packages app' if: success() && (github.event_name != 'pull_request' || contains( github.event.pull_request.labels.*.name, 'Seeking Testers')) shell: bash @@ -289,7 +291,8 @@ jobs: python3-dev \ qtbase5-dev \ libqt5svg5-dev \ - swig + swig \ + libcmocka-dev - name: 'Restore Chromium Embedded Framework from cache' id: cef-cache uses: actions/cache@v1 @@ -310,11 +313,15 @@ jobs: run: | mkdir ./build cd ./build - cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/obs-studio-portable" -DENABLE_VLC=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_linux64" .. + cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/obs-studio-portable" -DENABLE_UNIT_TESTS=ON -DENABLE_VLC=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_linux64" .. - name: 'Build' shell: bash working-directory: ${{ github.workspace }}/build run: make -j4 + - name: 'Test' + shell: bash + working-directory: ${{ github.workspace }}/build + run: make CTEST_OUTPUT_ON_FAILURE=1 test - name: 'Package' if: success() && (github.event_name != 'pull_request' || contains( github.event.pull_request.labels.*.name, 'Seeking Testers')) shell: bash diff --git a/CI/install-dependencies-osx.sh b/CI/install-dependencies-osx.sh index 036c62159..35e4fb19f 100755 --- a/CI/install-dependencies-osx.sh +++ b/CI/install-dependencies-osx.sh @@ -28,7 +28,7 @@ sudo installer -pkg ./Packages.pkg -target / brew update #Base OBS Deps and ccache -for DEPENDENCY in jack speexdsp ccache mbedtls freetype fdk-aac; do +for DEPENDENCY in jack speexdsp ccache mbedtls freetype fdk-aac cmocka; do if [ ! -d "$(brew --cellar)/${DEPENDENCY}" ]; then brew install $DEPENDENCY else diff --git a/CI/scripts/macos/Brewfile b/CI/scripts/macos/Brewfile index 1b0e4b008..2401ad9e0 100644 --- a/CI/scripts/macos/Brewfile +++ b/CI/scripts/macos/Brewfile @@ -4,6 +4,7 @@ brew "speexdsp" brew "cmake" brew "freetype" brew "fdk-aac" +brew "cmocka" brew "https://gist.githubusercontent.com/DDRBoxman/9c7a2b08933166f4b61ed9a44b242609/raw/ef4de6c587c6bd7f50210eccd5bd51ff08e6de13/qt.rb", link: true brew "https://gist.githubusercontent.com/DDRBoxman/4cada55c51803a2f963fa40ce55c9d3e/raw/572c67e908bfbc1bcb8c476ea77ea3935133f5b5/swig.rb", link: true brew "akeru-inc/tap/xcnotary" diff --git a/CMakeLists.txt b/CMakeLists.txt index e41068f57..56bb1a3da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,12 @@ if(NOT INSTALLER_RUN) add_subdirectory(libobs) add_subdirectory(plugins) add_subdirectory(UI) - if (BUILD_TESTS) + + if (ENABLE_UNIT_TESTS) + enable_testing() + endif() + + if (BUILD_TESTS OR ENABLE_UNIT_TESTS) add_subdirectory(test) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index afcbf5ec0..45a5543b9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,10 +1,16 @@ -add_subdirectory(test-input) +if(BUILD_TESTS) + add_subdirectory(test-input) -if(WIN32) - add_subdirectory(win) + if(WIN32) + add_subdirectory(win) + endif() + + if(APPLE AND UNIX) + add_subdirectory(osx) + endif() endif() -if(APPLE AND UNIX) - add_subdirectory(osx) +if (ENABLE_UNIT_TESTS) + add_subdirectory(cmocka) endif() diff --git a/test/cmocka/CMakeLists.txt b/test/cmocka/CMakeLists.txt new file mode 100644 index 000000000..747d4321b --- /dev/null +++ b/test/cmocka/CMakeLists.txt @@ -0,0 +1,39 @@ +project(obs-cmocka) + +# Fix libobs path +macro(fixLink target_arg) + if(APPLE AND UNIX) + add_custom_command (TARGET ${target_arg} + POST_BUILD COMMAND "${CMAKE_INSTALL_NAME_TOOL}" + "-change" "@rpath/libobs.0.dylib" "@executable_path/../../libobs/libobs.0.dylib" + "$" VERBATIM) + endif() +endmacro() + +set(CMAKE_MACOSX_RPATH TRUE) +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +list(APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/") + +find_package(CMocka CONFIG REQUIRED) +include_directories(${CMOCKA_INCLUDE_DIR}) +include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs") + +# fix rpath on linux +if (UNIX AND NOT APPLE) + set(CMAKE_INSTALL_RPATH "$ORIGIN";../../libobs) +endif() + +# Serializer test +add_executable(test_serializer test_serializer.c) +target_link_libraries(test_serializer ${CMOCKA_LIBRARIES} libobs) + +add_test(test_serializer ${CMAKE_CURRENT_BINARY_DIR}/test_serializer) +fixLink(test_serializer) + + +# darray test +add_executable(test_darray test_darray.c) +target_link_libraries(test_darray ${CMOCKA_LIBRARIES} libobs) + +add_test(test_darray ${CMAKE_CURRENT_BINARY_DIR}/test_darray) +fixLink(test_darray) diff --git a/test/cmocka/test_darray.c b/test/cmocka/test_darray.c new file mode 100644 index 000000000..7ac2bef7d --- /dev/null +++ b/test/cmocka/test_darray.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +#include + +static void array_basic_test(void **state) +{ + DARRAY(uint8_t) testarray; + da_init(testarray); + + uint8_t t = 1; + da_push_back_array(testarray, &t, sizeof(uint8_t)); + + assert_int_equal(testarray.num, 1); + assert_memory_equal(testarray.array, &t, 1); + + da_free(testarray); +} + +int main() +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(array_basic_test), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/test_serializer.c b/test/cmocka/test_serializer.c new file mode 100644 index 000000000..9c41d2ee9 --- /dev/null +++ b/test/cmocka/test_serializer.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +#include + +static void serialize_test(void **state) +{ + struct array_output_data output; + struct serializer s; + + array_output_serializer_init(&s, &output); + + s_w8(&s, 0x01); + s_w8(&s, 0xff); + s_w8(&s, 0xe1); + + assert_int_equal(output.bytes.num, 3); + uint8_t expected[3] = {0x01, 0xff, 0xe1}; + assert_memory_equal(output.bytes.array, expected, 3); +} + +int main() +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(serialize_test), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/osx/test.mm b/test/osx/test.mm index 353884ba4..9b1ff45b3 100644 --- a/test/osx/test.mm +++ b/test/osx/test.mm @@ -40,7 +40,7 @@ using DisplayContext = static void CreateOBS() { - if (!obs_startup("en", nullptr)) + if (!obs_startup("en", nullptr, nullptr)) throw "Couldn't create OBS"; struct obs_video_info ovi; @@ -67,7 +67,7 @@ static DisplayContext CreateDisplay(NSView *view) info.zsformat = GS_ZS_NONE; info.window.view = view; - return DisplayContext{obs_display_create(&info)}; + return DisplayContext{obs_display_create(&info, 0)}; } static SceneContext SetupScene()