Skip to content

Commit

Permalink
ci(tests): add test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Sep 6, 2023
1 parent 533321f commit 6e00c37
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 116 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@
path = third-party/ffmpeg-linux-powerpc64le
url = https://github.com/LizardByte/build-deps
branch = ffmpeg-linux-powerpc64le
[submodule "third-party/googletest"]
path = third-party/googletest
url = https://github.com/google/googletest/
branch = main
111 changes: 58 additions & 53 deletions cmake/compile_definitions/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,70 @@ elseif(UNIX)
endif()
endif()

include_directories(SYSTEM third-party/nv-codec-headers/include)
# tests
if(BUILD_TESTS)
add_subdirectory(tests)
endif()

include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third-party/nv-codec-headers/include)
file(GLOB NVENC_SOURCES CONFIGURE_DEPENDS "src/nvenc/*.cpp" "src/nvenc/*.h")
list(APPEND PLATFORM_TARGET_FILES ${NVENC_SOURCES})

configure_file(src/version.h.in version.h @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/src/version.h.in version.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(SUNSHINE_TARGET_FILES
third-party/nanors/rs.c
third-party/nanors/rs.h
third-party/moonlight-common-c/src/Input.h
third-party/moonlight-common-c/src/Rtsp.h
third-party/moonlight-common-c/src/RtspParser.c
third-party/moonlight-common-c/src/Video.h
third-party/tray/tray.h
src/upnp.cpp
src/upnp.h
src/cbs.cpp
src/utility.h
src/uuid.h
src/config.h
src/config.cpp
src/main.cpp
src/main.h
src/crypto.cpp
src/crypto.h
src/nvhttp.cpp
src/nvhttp.h
src/httpcommon.cpp
src/httpcommon.h
src/confighttp.cpp
src/confighttp.h
src/rtsp.cpp
src/rtsp.h
src/stream.cpp
src/stream.h
src/video.cpp
src/video.h
src/video_colorspace.cpp
src/video_colorspace.h
src/input.cpp
src/input.h
src/audio.cpp
src/audio.h
src/platform/common.h
src/process.cpp
src/process.h
src/network.cpp
src/network.h
src/move_by_copy.h
src/system_tray.cpp
src/system_tray.h
src/task_pool.h
src/thread_pool.h
src/thread_safe.h
src/sync.h
src/round_robin.h
src/stat_trackers.h
src/stat_trackers.cpp
${CMAKE_SOURCE_DIR}/third-party/nanors/rs.c
${CMAKE_SOURCE_DIR}/third-party/nanors/rs.h
${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/Input.h
${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/Rtsp.h
${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/RtspParser.c
${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/Video.h
${CMAKE_SOURCE_DIR}/third-party/tray/tray.h
${CMAKE_SOURCE_DIR}/src/upnp.cpp
${CMAKE_SOURCE_DIR}/src/upnp.h
${CMAKE_SOURCE_DIR}/src/cbs.cpp
${CMAKE_SOURCE_DIR}/src/utility.h
${CMAKE_SOURCE_DIR}/src/uuid.h
${CMAKE_SOURCE_DIR}/src/config.h
${CMAKE_SOURCE_DIR}/src/config.cpp
${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/main.h
${CMAKE_SOURCE_DIR}/src/crypto.cpp
${CMAKE_SOURCE_DIR}/src/crypto.h
${CMAKE_SOURCE_DIR}/src/nvhttp.cpp
${CMAKE_SOURCE_DIR}/src/nvhttp.h
${CMAKE_SOURCE_DIR}/src/httpcommon.cpp
${CMAKE_SOURCE_DIR}/src/httpcommon.h
${CMAKE_SOURCE_DIR}/src/confighttp.cpp
${CMAKE_SOURCE_DIR}/src/confighttp.h
${CMAKE_SOURCE_DIR}/src/rtsp.cpp
${CMAKE_SOURCE_DIR}/src/rtsp.h
${CMAKE_SOURCE_DIR}/src/stream.cpp
${CMAKE_SOURCE_DIR}/src/stream.h
${CMAKE_SOURCE_DIR}/src/video.cpp
${CMAKE_SOURCE_DIR}/src/video.h
${CMAKE_SOURCE_DIR}/src/video_colorspace.cpp
${CMAKE_SOURCE_DIR}/src/video_colorspace.h
${CMAKE_SOURCE_DIR}/src/input.cpp
${CMAKE_SOURCE_DIR}/src/input.h
${CMAKE_SOURCE_DIR}/src/audio.cpp
${CMAKE_SOURCE_DIR}/src/audio.h
${CMAKE_SOURCE_DIR}/src/platform/common.h
${CMAKE_SOURCE_DIR}/src/process.cpp
${CMAKE_SOURCE_DIR}/src/process.h
${CMAKE_SOURCE_DIR}/src/network.cpp
${CMAKE_SOURCE_DIR}/src/network.h
${CMAKE_SOURCE_DIR}/src/move_by_copy.h
${CMAKE_SOURCE_DIR}/src/system_tray.cpp
${CMAKE_SOURCE_DIR}/src/system_tray.h
${CMAKE_SOURCE_DIR}/src/task_pool.h
${CMAKE_SOURCE_DIR}/src/thread_pool.h
${CMAKE_SOURCE_DIR}/src/thread_safe.h
${CMAKE_SOURCE_DIR}/src/sync.h
${CMAKE_SOURCE_DIR}/src/round_robin.h
${CMAKE_SOURCE_DIR}/src/stat_trackers.h
${CMAKE_SOURCE_DIR}/src/stat_trackers.cpp
${PLATFORM_TARGET_FILES})

set_source_files_properties(src/upnp.cpp PROPERTIES COMPILE_FLAGS -Wno-pedantic)
Expand Down
50 changes: 25 additions & 25 deletions cmake/compile_definitions/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ endif()
if(CUDA_FOUND)
include_directories(SYSTEM third-party/nvfbc)
list(APPEND PLATFORM_TARGET_FILES
src/platform/linux/cuda.cu
src/platform/linux/cuda.cpp
third-party/nvfbc/NvFBC.h)
${CMAKE_SOURCE_DIR}/src/platform/linux/cuda.cu
${CMAKE_SOURCE_DIR}/src/platform/linux/cuda.cpp
${CMAKE_SOURCE_DIR}/third-party/nvfbc/NvFBC.h)

add_compile_definitions(SUNSHINE_BUILD_CUDA)
endif()
Expand All @@ -104,7 +104,7 @@ if(LIBDRM_FOUND AND LIBCAP_FOUND)
add_compile_definitions(SUNSHINE_BUILD_DRM)
include_directories(SYSTEM ${LIBDRM_INCLUDE_DIRS} ${LIBCAP_INCLUDE_DIRS})
list(APPEND PLATFORM_LIBRARIES ${LIBDRM_LIBRARIES} ${LIBCAP_LIBRARIES})
list(APPEND PLATFORM_TARGET_FILES src/platform/linux/kmsgrab.cpp)
list(APPEND PLATFORM_TARGET_FILES ${CMAKE_SOURCE_DIR}/src/platform/linux/kmsgrab.cpp)
list(APPEND SUNSHINE_DEFINITIONS EGL_NO_X11=1)
elseif(NOT LIBDRM_FOUND)
message(WARNING "Missing libdrm")
Expand Down Expand Up @@ -132,8 +132,8 @@ if(WAYLAND_FOUND)

list(APPEND PLATFORM_LIBRARIES ${WAYLAND_LIBRARIES})
list(APPEND PLATFORM_TARGET_FILES
src/platform/linux/wlgrab.cpp
src/platform/linux/wayland.cpp)
${CMAKE_SOURCE_DIR}/src/platform/linux/wlgrab.cpp
${CMAKE_SOURCE_DIR}/src/platform/linux/wayland.cpp)
endif()

# x11
Expand All @@ -146,7 +146,7 @@ if(X11_FOUND)
add_compile_definitions(SUNSHINE_BUILD_X11)
include_directories(SYSTEM ${X11_INCLUDE_DIR})
list(APPEND PLATFORM_LIBRARIES ${X11_LIBRARIES})
list(APPEND PLATFORM_TARGET_FILES src/platform/linux/x11grab.cpp)
list(APPEND PLATFORM_TARGET_FILES ${CMAKE_SOURCE_DIR}/src/platform/linux/x11grab.cpp)
endif()

if(NOT ${CUDA_FOUND} AND NOT ${WAYLAND_FOUND} AND NOT ${X11_FOUND} AND NOT (${LIBDRM_FOUND} AND ${LIBCAP_FOUND}))
Expand All @@ -171,24 +171,24 @@ else()
endif()

list(APPEND PLATFORM_TARGET_FILES
src/platform/linux/publish.cpp
src/platform/linux/vaapi.h
src/platform/linux/vaapi.cpp
src/platform/linux/cuda.h
src/platform/linux/graphics.h
src/platform/linux/graphics.cpp
src/platform/linux/misc.h
src/platform/linux/misc.cpp
src/platform/linux/audio.cpp
src/platform/linux/input.cpp
src/platform/linux/x11grab.h
src/platform/linux/wayland.h
third-party/glad/src/egl.c
third-party/glad/src/gl.c
third-party/glad/include/EGL/eglplatform.h
third-party/glad/include/KHR/khrplatform.h
third-party/glad/include/glad/gl.h
third-party/glad/include/glad/egl.h)
${CMAKE_SOURCE_DIR}/src/platform/linux/publish.cpp
${CMAKE_SOURCE_DIR}/src/platform/linux/vaapi.h
${CMAKE_SOURCE_DIR}/src/platform/linux/vaapi.cpp
${CMAKE_SOURCE_DIR}/src/platform/linux/cuda.h
${CMAKE_SOURCE_DIR}/src/platform/linux/graphics.h
${CMAKE_SOURCE_DIR}/src/platform/linux/graphics.cpp
${CMAKE_SOURCE_DIR}/src/platform/linux/misc.h
${CMAKE_SOURCE_DIR}/src/platform/linux/misc.cpp
${CMAKE_SOURCE_DIR}/src/platform/linux/audio.cpp
${CMAKE_SOURCE_DIR}/src/platform/linux/input.cpp
${CMAKE_SOURCE_DIR}/src/platform/linux/x11grab.h
${CMAKE_SOURCE_DIR}/src/platform/linux/wayland.h
${CMAKE_SOURCE_DIR}/third-party/glad/src/egl.c
${CMAKE_SOURCE_DIR}/third-party/glad/src/gl.c
${CMAKE_SOURCE_DIR}/third-party/glad/include/EGL/eglplatform.h
${CMAKE_SOURCE_DIR}/third-party/glad/include/KHR/khrplatform.h
${CMAKE_SOURCE_DIR}/third-party/glad/include/glad/gl.h
${CMAKE_SOURCE_DIR}/third-party/glad/include/glad/egl.h)

list(APPEND PLATFORM_LIBRARIES
Boost::dynamic_linking
Expand Down
30 changes: 15 additions & 15 deletions cmake/compile_definitions/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ set(APPLE_PLIST_FILE ${SUNSHINE_SOURCE_ASSETS_DIR}/macos/assets/Info.plist)
set(SUNSHINE_TRAY 0)

set(PLATFORM_TARGET_FILES
src/platform/macos/av_audio.h
src/platform/macos/av_audio.m
src/platform/macos/av_img_t.h
src/platform/macos/av_video.h
src/platform/macos/av_video.m
src/platform/macos/display.mm
src/platform/macos/input.cpp
src/platform/macos/microphone.mm
src/platform/macos/misc.mm
src/platform/macos/misc.h
src/platform/macos/nv12_zero_device.cpp
src/platform/macos/nv12_zero_device.h
src/platform/macos/publish.cpp
third-party/TPCircularBuffer/TPCircularBuffer.c
third-party/TPCircularBuffer/TPCircularBuffer.h
${CMAKE_SOURCE_DIR}/src/platform/macos/av_audio.h
${CMAKE_SOURCE_DIR}/src/platform/macos/av_audio.m
${CMAKE_SOURCE_DIR}/src/platform/macos/av_img_t.h
${CMAKE_SOURCE_DIR}/src/platform/macos/av_video.h
${CMAKE_SOURCE_DIR}/src/platform/macos/av_video.m
${CMAKE_SOURCE_DIR}/src/platform/macos/display.mm
${CMAKE_SOURCE_DIR}/src/platform/macos/input.cpp
${CMAKE_SOURCE_DIR}/src/platform/macos/microphone.mm
${CMAKE_SOURCE_DIR}/src/platform/macos/misc.mm
${CMAKE_SOURCE_DIR}/src/platform/macos/misc.h
${CMAKE_SOURCE_DIR}/src/platform/macos/nv12_zero_device.cpp
${CMAKE_SOURCE_DIR}/src/platform/macos/nv12_zero_device.h
${CMAKE_SOURCE_DIR}/src/platform/macos/publish.cpp
${CMAKE_SOURCE_DIR}/third-party/TPCircularBuffer/TPCircularBuffer.c
${CMAKE_SOURCE_DIR}/third-party/TPCircularBuffer/TPCircularBuffer.h
${APPLE_PLIST_FILE})

if(SUNSHINE_ENABLE_TRAY)
Expand Down
36 changes: 18 additions & 18 deletions cmake/compile_definitions/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@ file(GLOB NVPREFS_FILES CONFIGURE_DEPENDS
"src/platform/windows/nvprefs/*.h")

# vigem
include_directories(SYSTEM third-party/ViGEmClient/include)
set_source_files_properties(third-party/ViGEmClient/src/ViGEmClient.cpp
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include)
set_source_files_properties(${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/src/ViGEmClient.cpp
PROPERTIES COMPILE_DEFINITIONS "UNICODE=1;ERROR_INVALID_DEVICE_OBJECT_PARAMETER=650")
set_source_files_properties(third-party/ViGEmClient/src/ViGEmClient.cpp
set_source_files_properties(${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/src/ViGEmClient.cpp
PROPERTIES COMPILE_FLAGS "-Wno-unknown-pragmas -Wno-misleading-indentation -Wno-class-memaccess")

# sunshine icon
if(NOT DEFINED SUNSHINE_ICON_PATH)
set(SUNSHINE_ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/sunshine.ico")
endif()

configure_file(src/platform/windows/windows.rs.in windows.rc @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/src/platform/windows/windows.rs.in windows.rc @ONLY)

set(PLATFORM_TARGET_FILES
"${CMAKE_CURRENT_BINARY_DIR}/windows.rc"
src/platform/windows/publish.cpp
src/platform/windows/misc.h
src/platform/windows/misc.cpp
src/platform/windows/input.cpp
src/platform/windows/display.h
src/platform/windows/display_base.cpp
src/platform/windows/display_vram.cpp
src/platform/windows/display_ram.cpp
src/platform/windows/audio.cpp
third-party/ViGEmClient/src/ViGEmClient.cpp
third-party/ViGEmClient/include/ViGEm/Client.h
third-party/ViGEmClient/include/ViGEm/Common.h
third-party/ViGEmClient/include/ViGEm/Util.h
third-party/ViGEmClient/include/ViGEm/km/BusShared.h
${CMAKE_SOURCE_DIR}/src/platform/windows/publish.cpp
${CMAKE_SOURCE_DIR}/src/platform/windows/misc.h
${CMAKE_SOURCE_DIR}/src/platform/windows/misc.cpp
${CMAKE_SOURCE_DIR}/src/platform/windows/input.cpp
${CMAKE_SOURCE_DIR}/src/platform/windows/display.h
${CMAKE_SOURCE_DIR}/src/platform/windows/display_base.cpp
${CMAKE_SOURCE_DIR}/src/platform/windows/display_vram.cpp
${CMAKE_SOURCE_DIR}/src/platform/windows/display_ram.cpp
${CMAKE_SOURCE_DIR}/src/platform/windows/audio.cpp
${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/src/ViGEmClient.cpp
${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/Client.h
${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/Common.h
${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/Util.h
${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/km/BusShared.h
${NVPREFS_FILES})

set(OPENSSL_LIBRARIES
Expand Down
14 changes: 10 additions & 4 deletions cmake/dependencies/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
# this file will also load platform specific dependencies

# submodules
# testing
if(BUILD_TESTS)
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/googletest)
include_directories(${CMAKE_SOURCE_DIR}/third-party/googletest/include)
endif()

# moonlight common library
add_subdirectory(third-party/moonlight-common-c/enet)
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/enet)

# web server
add_subdirectory(third-party/Simple-Web-Server)
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/Simple-Web-Server)

# miniupnp
set(UPNPC_BUILD_SHARED OFF CACHE BOOL "No shared libraries")
set(UPNPC_BUILD_TESTS OFF CACHE BOOL "Don't build tests for miniupnpc")
set(UPNPC_BUILD_SAMPLE OFF CACHE BOOL "Don't build samples for miniupnpc")
set(UPNPC_NO_INSTALL ON CACHE BOOL "Don't install any libraries build for miniupnpc")
add_subdirectory(third-party/miniupnp/miniupnpc)
include_directories(SYSTEM third-party/miniupnp/miniupnpc/include)
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/miniupnp/miniupnpc)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third-party/miniupnp/miniupnpc/include)

# ffmpeg pre-compiled binaries
if(WIN32)
Expand Down
2 changes: 2 additions & 0 deletions cmake/prep/options.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
option(BUILD_TESTS "Build tests" ON)

# if this option is set, the build will exit after configuring special package configuration files
option(SUNSHINE_CONFIGURE_ONLY "Configure special files only, then exit." OFF)

Expand Down
24 changes: 24 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include_directories(SYSTEM ${CMAKE_SOURCE_DIR})

enable_testing()

set(INSTALL_GTEST OFF)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # cmake-lint: disable=C0103

set(TEST_SOURCES
${CMAKE_SOURCE_DIR}/tests/main.cpp
${CMAKE_SOURCE_DIR}/tests/test_main.cpp
)

add_executable(sunshine_test ${TEST_SOURCES})
target_link_libraries(sunshine_test
${SUNSHINE_TARGET_FILES}
${SUNSHINE_EXTERNAL_LIBRARIES}
${EXTRA_LIBS}
gtest
)
set_target_properties(sunshine_test PROPERTIES CXX_STANDARD 17)
target_compile_options(sunshine_test PRIVATE ${SUNSHINE_COMPILE_OPTIONS})
add_test(NAME sunshine_test COMMAND sunshine_test)
7 changes: 7 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "gtest/gtest.h"

int
main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
19 changes: 19 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file tests/test_main.cpp
* @brief Test src/main.*.
*/

#include <gtest/gtest.h>
#include <src/main.h>

TEST(MainTestSuite, WriteFileTest) {
EXPECT_EQ(write_file("write_file_test.txt", "test"), 0);
}

TEST(MainTestSuite, ReadFileTest) {
// read file from WriteFileTest
EXPECT_EQ(read_file("write_file_test.txt"), "test");

// read missing file
EXPECT_EQ(read_file("non-existing-file.txt"), "");
}
1 change: 1 addition & 0 deletions third-party/googletest
Submodule googletest added at f8d7d7
Loading

0 comments on commit 6e00c37

Please sign in to comment.