[common/client] platform: abstract runtime services

This commit is contained in:
Geoffrey McRae
2026-09-12 12:51:17 +10:00
parent a7d2e4592f
commit eabc56a6de
49 changed files with 4064 additions and 940 deletions

View File

@@ -1,5 +1,12 @@
cmake_minimum_required(VERSION 3.10)
if(LG_CLIENT_PLATFORM_WINDOWS)
link_libraries(
$<TARGET_OBJECTS:client_test_version>
lg_egl_provider
)
endif()
add_executable(common-platform-tests
common_platform_test.c
)
@@ -17,6 +24,38 @@ set_tests_properties(common-platform-tests PROPERTIES
TIMEOUT 10
)
add_executable(event-source-tests
event_source_test.c
../src/event_source.c
)
target_include_directories(event-source-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
target_link_libraries(event-source-tests
${EXE_FLAGS}
lg_common
)
add_test(NAME event-source-tests
COMMAND event-source-tests
)
set_tests_properties(event-source-tests PROPERTIES
TIMEOUT 10
)
add_executable(windows-clipboard-files-tests
clipboard_files_windows_test.c
../platform/Windows/clipboard_files.c
)
target_link_libraries(windows-clipboard-files-tests
${EXE_FLAGS}
)
add_test(NAME windows-clipboard-files-tests
COMMAND windows-clipboard-files-tests
)
set_tests_properties(windows-clipboard-files-tests PROPERTIES
TIMEOUT 10
)
if(LG_CLIENT_PLATFORM_LINUX)
add_executable(config-platform-tests
config_platform_test.c
@@ -59,6 +98,20 @@ if(LG_CLIENT_PLATFORM_LINUX)
set_tests_properties(keycode-tests PROPERTIES
TIMEOUT 10
)
add_executable(process-tests
process_test.c
../platform/Linux/process.c
)
target_link_libraries(process-tests
${EXE_FLAGS}
)
add_test(NAME process-tests
COMMAND process-tests
)
set_tests_properties(process-tests PROPERTIES
TIMEOUT 10
)
endif()
if(LG_CLIENT_PLATFORM_WINDOWS)
@@ -76,6 +129,7 @@ endif()
add_executable(font-tests
font_test.c
font_platform_stub.c
../src/font.c
)
@@ -93,10 +147,17 @@ target_link_libraries(sw-surface-tests
add_test(NAME sw-surface-tests COMMAND sw-surface-tests)
set_tests_properties(sw-surface-tests PROPERTIES TIMEOUT 10)
target_compile_definitions(font-tests PRIVATE
CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1
FONT_TEST_FILE="${PROJECT_TOP}/repos/gui/cimgui/imgui/misc/fonts/DroidSans.ttf"
)
target_include_directories(font-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../include"
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
target_link_libraries(font-tests
${EXE_FLAGS}
lg_common
lg_gui
)
add_test(NAME font-tests
COMMAND font-tests
@@ -105,160 +166,164 @@ set_tests_properties(font-tests PROPERTIES
TIMEOUT 10
)
add_executable(lgmp-transport-tests
lgmp_transport_test.c
../src/kb_hid.c
)
target_link_libraries(lgmp-transport-tests
${EXE_FLAGS}
transport_LGMP
lg_common
lgmp
)
if(ENABLE_AUDIO)
target_compile_definitions(lgmp-transport-tests PRIVATE
ENABLE_AUDIO
)
endif()
add_test(NAME lgmp-transport-tests
COMMAND lgmp-transport-tests
)
set_tests_properties(lgmp-transport-tests PROPERTIES
TIMEOUT 10
)
add_executable(lgmp-frame-tests
lgmp_frame_test.c
../src/kb_hid.c
)
target_link_libraries(lgmp-frame-tests
${EXE_FLAGS}
transport_LGMP
lg_common
lgmp
)
set(LGMP_FRAME_CASES
malformed
serial-damage
lanes
leases
dma
)
foreach(name IN LISTS LGMP_FRAME_CASES)
add_test(NAME lgmp-frame-${name}
COMMAND lgmp-frame-tests ${name}
)
set_tests_properties(lgmp-frame-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
add_executable(lgmp-input-tests
lgmp_input_test.c
../transports/LGMP/input.c
../src/kb_hid.c
)
target_include_directories(lgmp-input-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
target_link_libraries(lgmp-input-tests
${EXE_FLAGS}
lg_common
lgmp
)
set(LGMP_INPUT_CASES
claim
blocked
restart
pressure
idle
)
foreach(name IN LISTS LGMP_INPUT_CASES)
add_test(NAME lgmp-input-${name}
COMMAND lgmp-input-tests ${name}
)
set_tests_properties(lgmp-input-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
add_executable(lgmp-clipboard-tests
lgmp_clipboard_test.c
../transports/LGMP/clipboard.c
)
target_include_directories(lgmp-clipboard-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../transports/LGMP"
)
target_link_libraries(lgmp-clipboard-tests
${EXE_FLAGS}
lg_common
lgmp
)
set(LGMP_CLIPBOARD_CASES
claim
offer-request
inbound-stream
outbound-stream
blocked
cancel
restart
process-restart
file-stream
file-limits
file-owner-loss
file-malformed
disconnect
malformed
file-format
)
foreach(name IN LISTS LGMP_CLIPBOARD_CASES)
add_test(NAME lgmp-clipboard-${name}
COMMAND lgmp-clipboard-tests ${name}
)
set_tests_properties(lgmp-clipboard-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
if(ENABLE_AUDIO)
add_executable(lgmp-audio-tests
lgmp_audio_test.c
if(LG_CLIENT_PLATFORM_LINUX)
add_executable(lgmp-transport-tests
lgmp_transport_test.c
../src/kb_hid.c
)
target_compile_definitions(lgmp-audio-tests PRIVATE
ENABLE_AUDIO
)
target_include_directories(lgmp-audio-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../transports/LGMP"
)
target_link_libraries(lgmp-audio-tests
target_link_libraries(lgmp-transport-tests
${EXE_FLAGS}
transport_LGMP
lg_common
lgmp
)
add_test(NAME lgmp-audio
COMMAND lgmp-audio-tests
if(ENABLE_AUDIO)
target_compile_definitions(lgmp-transport-tests PRIVATE
ENABLE_AUDIO
)
endif()
add_test(NAME lgmp-transport-tests
COMMAND lgmp-transport-tests
)
set_tests_properties(lgmp-audio PROPERTIES
TIMEOUT 20
set_tests_properties(lgmp-transport-tests PROPERTIES
TIMEOUT 10
)
add_executable(lgmp-frame-tests
lgmp_frame_test.c
../src/kb_hid.c
)
target_link_libraries(lgmp-frame-tests
${EXE_FLAGS}
transport_LGMP
lg_common
lgmp
)
set(LGMP_FRAME_CASES
malformed
serial-damage
lanes
leases
dma
)
foreach(name IN LISTS LGMP_FRAME_CASES)
add_test(NAME lgmp-frame-${name}
COMMAND lgmp-frame-tests ${name}
)
set_tests_properties(lgmp-frame-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
add_executable(lgmp-input-tests
lgmp_input_test.c
../transports/LGMP/input.c
../src/kb_hid.c
)
target_include_directories(lgmp-input-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
target_link_libraries(lgmp-input-tests
${EXE_FLAGS}
lg_common
lgmp
)
set(LGMP_INPUT_CASES
claim
blocked
restart
pressure
idle
)
foreach(name IN LISTS LGMP_INPUT_CASES)
add_test(NAME lgmp-input-${name}
COMMAND lgmp-input-tests ${name}
)
set_tests_properties(lgmp-input-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
add_executable(lgmp-clipboard-tests
lgmp_clipboard_test.c
../transports/LGMP/clipboard.c
)
target_include_directories(lgmp-clipboard-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../transports/LGMP"
)
target_link_libraries(lgmp-clipboard-tests
${EXE_FLAGS}
lg_common
lgmp
)
set(LGMP_CLIPBOARD_CASES
claim
offer-request
inbound-stream
outbound-stream
blocked
cancel
restart
process-restart
file-stream
file-limits
file-owner-loss
file-malformed
disconnect
malformed
file-format
)
foreach(name IN LISTS LGMP_CLIPBOARD_CASES)
add_test(NAME lgmp-clipboard-${name}
COMMAND lgmp-clipboard-tests ${name}
)
set_tests_properties(lgmp-clipboard-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
if(ENABLE_AUDIO)
add_executable(lgmp-audio-tests
lgmp_audio_test.c
../src/kb_hid.c
)
target_compile_definitions(lgmp-audio-tests PRIVATE
ENABLE_AUDIO
)
target_include_directories(lgmp-audio-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../transports/LGMP"
)
target_link_libraries(lgmp-audio-tests
${EXE_FLAGS}
transport_LGMP
lg_common
lgmp
)
add_test(NAME lgmp-audio
COMMAND lgmp-audio-tests
)
set_tests_properties(lgmp-audio PROPERTIES
TIMEOUT 20
)
endif()
endif()
if(LG_CLIENT_PLATFORM_LINUX)
add_executable(wayland-motion-tests
motion_test.c
)
target_include_directories(wayland-motion-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../displayservers/Wayland"
)
add_test(NAME wayland-motion-tests
COMMAND wayland-motion-tests
)
set_tests_properties(wayland-motion-tests PROPERTIES
TIMEOUT 10
)
endif()
add_executable(wayland-motion-tests
motion_test.c
)
target_include_directories(wayland-motion-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../displayservers/Wayland"
)
add_test(NAME wayland-motion-tests
COMMAND wayland-motion-tests
)
set_tests_properties(wayland-motion-tests PROPERTIES
TIMEOUT 10
)
if(ENABLE_WAYLAND)
if(LG_CLIENT_PLATFORM_LINUX AND ENABLE_WAYLAND)
add_executable(wayland-presentation-tests
wayland_presentation_test.c
../displayservers/Wayland/presentation.c
@@ -339,7 +404,7 @@ if(ENABLE_WAYLAND)
endforeach()
endif()
if(ENABLE_X11)
if(LG_CLIENT_PLATFORM_LINUX AND ENABLE_X11)
add_executable(x11-clipboard-tests
x11_clipboard_test.c
../displayservers/X11/clipboard.c
@@ -380,54 +445,56 @@ if(ENABLE_X11)
endforeach()
endif()
add_executable(displayserver-input-tests
displayserver_input_test.c
../displayservers/Wayland/input_event.c
../displayservers/X11/input_event.c
)
target_include_directories(displayserver-input-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../displayservers"
)
if(LG_CLIENT_PLATFORM_LINUX)
add_executable(displayserver-input-tests
displayserver_input_test.c
../displayservers/Wayland/input_event.c
../displayservers/X11/input_event.c
)
target_include_directories(displayserver-input-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../displayservers"
)
set(DISPLAYSERVER_INPUT_CASES
pointer-events
pointer-buttons
pointer-release
wheel-steps
relative-motion
keyboard-focus
keyboard-keys
keyboard-state
)
set(DISPLAYSERVER_INPUT_CASES
pointer-events
pointer-buttons
pointer-release
wheel-steps
relative-motion
keyboard-focus
keyboard-keys
keyboard-state
)
foreach(backend IN ITEMS wayland x11)
foreach(name IN LISTS DISPLAYSERVER_INPUT_CASES)
add_test(NAME display-input-${backend}-${name}
COMMAND displayserver-input-tests ${backend} ${name}
foreach(backend IN ITEMS wayland x11)
foreach(name IN LISTS DISPLAYSERVER_INPUT_CASES)
add_test(NAME display-input-${backend}-${name}
COMMAND displayserver-input-tests ${backend} ${name}
)
set_tests_properties(display-input-${backend}-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
endforeach()
foreach(name IN ITEMS wheel-residual wheel-multiple)
add_test(NAME display-input-wayland-${name}
COMMAND displayserver-input-tests wayland ${name}
)
set_tests_properties(display-input-${backend}-${name} PROPERTIES
set_tests_properties(display-input-wayland-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
endforeach()
foreach(name IN ITEMS wheel-residual wheel-multiple)
add_test(NAME display-input-wayland-${name}
COMMAND displayserver-input-tests wayland ${name}
)
set_tests_properties(display-input-wayland-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
foreach(name IN ITEMS pointer-routing keyboard-routing held-keys)
add_test(NAME display-input-x11-${name}
COMMAND displayserver-input-tests x11 ${name}
)
set_tests_properties(display-input-x11-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
foreach(name IN ITEMS pointer-routing keyboard-routing held-keys)
add_test(NAME display-input-x11-${name}
COMMAND displayserver-input-tests x11 ${name}
)
set_tests_properties(display-input-x11-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
endif()
add_executable(windows-input-tests
windows_input_test.c
@@ -575,6 +642,7 @@ target_include_directories(app-keybind-tests PRIVATE
target_link_libraries(app-keybind-tests
${EXE_FLAGS}
lg_common
lg_gui
)
set(APP_KEYBIND_CASES
invalid
@@ -641,37 +709,39 @@ foreach(name IN LISTS CLIPBOARD_CASES)
)
endforeach()
add_executable(clipboard-files-tests
clipboard_files_test.c
../src/clipboard_files.c
)
target_include_directories(clipboard-files-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
target_link_libraries(clipboard-files-tests
${EXE_FLAGS}
lg_common
PkgConfig::FUSE3
)
add_test(NAME clipboard-files-lifecycle
COMMAND clipboard-files-tests
)
set_tests_properties(clipboard-files-lifecycle PROPERTIES
TIMEOUT 10
)
add_test(NAME clipboard-files-failures
COMMAND clipboard-files-tests failures
)
set_tests_properties(clipboard-files-failures PROPERTIES
TIMEOUT 10
)
add_test(NAME clipboard-files-mount
COMMAND clipboard-files-tests mount
)
set_tests_properties(clipboard-files-mount PROPERTIES
TIMEOUT 10
SKIP_RETURN_CODE 77
)
if(LG_CLIENT_PLATFORM_LINUX)
add_executable(clipboard-files-tests
clipboard_files_test.c
../src/clipboard_files.c
)
target_include_directories(clipboard-files-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
target_link_libraries(clipboard-files-tests
${EXE_FLAGS}
lg_common
PkgConfig::FUSE3
)
add_test(NAME clipboard-files-lifecycle
COMMAND clipboard-files-tests
)
set_tests_properties(clipboard-files-lifecycle PROPERTIES
TIMEOUT 10
)
add_test(NAME clipboard-files-failures
COMMAND clipboard-files-tests failures
)
set_tests_properties(clipboard-files-failures PROPERTIES
TIMEOUT 10
)
add_test(NAME clipboard-files-mount
COMMAND clipboard-files-tests mount
)
set_tests_properties(clipboard-files-mount PROPERTIES
TIMEOUT 10
SKIP_RETURN_CODE 77
)
endif()
if(ENABLE_SPICE)
add_executable(spice-clipboard-tests
@@ -817,6 +887,7 @@ add_executable(frame-scheduler-tests
)
target_compile_definitions(frame-scheduler-tests PRIVATE
CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1
nanotime=testNanotime
)
target_include_directories(frame-scheduler-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
@@ -890,12 +961,12 @@ endforeach()
add_executable(config-message-tests
config_message_test.c
../src/message.c
../src/core.c
../src/config.c
../platform/${LG_CLIENT_PLATFORM}/config.c
)
target_compile_definitions(config-message-tests PRIVATE
CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1
microtime=testMicrotime
)
target_include_directories(config-message-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
@@ -927,8 +998,6 @@ foreach(name IN LISTS CONFIG_MESSAGE_CASES)
endforeach()
if(ENABLE_AUDIO)
pkg_check_modules(AUDIO_TEST_SAMPLERATE REQUIRED IMPORTED_TARGET
samplerate)
add_executable(audio-tests
audio_test.c
)
@@ -944,7 +1013,7 @@ if(ENABLE_AUDIO)
target_link_libraries(audio-tests
${EXE_FLAGS}
lg_common
PkgConfig::AUDIO_TEST_SAMPLERATE
${SAMPLERATE_TARGET}
)
set(AUDIO_CASES
format
@@ -1078,109 +1147,114 @@ if(ENABLE_EGL)
TIMEOUT 10
)
add_executable(texture-upload-tests
texture_upload_test.c
../renderers/EGL/texture_buffer.c
)
target_include_directories(texture-upload-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../renderers/EGL"
"${PROJECT_TOP}/common/include"
)
target_link_libraries(texture-upload-tests
${EXE_FLAGS}
LGProtocol::LGProtocol
lg_egl_provider
)
set(TEXTURE_UPLOAD_CASES
direct
direct-full
direct-rect
persistent
persistent-full
persistent-rect
fallback
)
foreach(name IN LISTS TEXTURE_UPLOAD_CASES)
add_test(NAME texture-upload-${name}
COMMAND texture-upload-tests ${name}
if(LG_CLIENT_PLATFORM_LINUX)
add_executable(texture-upload-tests
texture_upload_test.c
../renderers/EGL/texture_buffer.c
)
set_tests_properties(texture-upload-${name} PROPERTIES
TIMEOUT 10
target_include_directories(texture-upload-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../renderers/EGL"
"${PROJECT_TOP}/common/include"
)
endforeach()
endif()
find_package(GTest REQUIRED)
find_program(WESTON_EXECUTABLE NAMES weston)
if(NOT WESTON_EXECUTABLE)
message(FATAL_ERROR "weston is required to run framebuffer rendering tests")
endif()
if(ENABLE_X11)
find_program(XVFB_RUN_EXECUTABLE NAMES xvfb-run)
if(NOT XVFB_RUN_EXECUTABLE)
message(FATAL_ERROR "xvfb-run is required to run X11 rendering tests")
target_link_libraries(texture-upload-tests
${EXE_FLAGS}
LGProtocol::LGProtocol
lg_egl_provider
)
set(TEXTURE_UPLOAD_CASES
direct
direct-full
direct-rect
persistent
persistent-full
persistent-rect
fallback
)
foreach(name IN LISTS TEXTURE_UPLOAD_CASES)
add_test(NAME texture-upload-${name}
COMMAND texture-upload-tests ${name}
)
set_tests_properties(texture-upload-${name} PROPERTIES
TIMEOUT 10
)
endforeach()
endif()
endif()
add_executable(render-tests
render_test.cpp
)
add_dependencies(render-tests looking-glass-client)
if(LG_CLIENT_PLATFORM_LINUX)
find_package(GTest REQUIRED)
find_program(WESTON_EXECUTABLE NAMES weston)
if(NOT WESTON_EXECUTABLE)
message(FATAL_ERROR
"weston is required to run framebuffer rendering tests")
endif()
if(ENABLE_X11)
find_program(XVFB_RUN_EXECUTABLE NAMES xvfb-run)
if(NOT XVFB_RUN_EXECUTABLE)
message(FATAL_ERROR "xvfb-run is required to run X11 rendering tests")
endif()
endif()
set_target_properties(render-tests PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
add_executable(render-tests
render_test.cpp
)
add_dependencies(render-tests looking-glass-client)
target_compile_options(render-tests PRIVATE
-fno-fast-math
)
target_compile_definitions(render-tests PRIVATE
LG_CLIENT_PATH="$<TARGET_FILE:looking-glass-client>"
)
target_include_directories(render-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../include"
"${PROJECT_TOP}/common/include"
)
target_link_libraries(render-tests
LGProtocol::LGProtocol
)
if(TARGET GTest::gtest_main)
target_link_libraries(render-tests GTest::gtest_main)
else()
target_link_libraries(render-tests GTest::Main)
endif()
add_test(NAME render-tests
COMMAND /bin/bash
"${CMAKE_CURRENT_SOURCE_DIR}/run-with-weston.sh"
"${WESTON_EXECUTABLE}"
"$<TARGET_FILE:render-tests>"
"--gtest_filter=-X11*"
)
set_tests_properties(render-tests PROPERTIES
TIMEOUT 120
)
if(ENABLE_X11)
add_test(NAME render-x11-tests
COMMAND "${CMAKE_COMMAND}" -E env
--unset=WAYLAND_DISPLAY
LIBGL_ALWAYS_SOFTWARE=1
"${XVFB_RUN_EXECUTABLE}"
-a
-e /dev/stderr
-s "-screen 0 1024x768x24 +extension GLX"
"$<TARGET_FILE:render-tests>"
"--gtest_filter=X11*"
set_target_properties(render-tests PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
set_tests_properties(render-x11-tests PROPERTIES
target_compile_options(render-tests PRIVATE
-fno-fast-math
)
target_compile_definitions(render-tests PRIVATE
LG_CLIENT_PATH="$<TARGET_FILE:looking-glass-client>"
)
target_include_directories(render-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../include"
"${PROJECT_TOP}/common/include"
)
target_link_libraries(render-tests
LGProtocol::LGProtocol
)
if(TARGET GTest::gtest_main)
target_link_libraries(render-tests GTest::gtest_main)
else()
target_link_libraries(render-tests GTest::Main)
endif()
add_test(NAME render-tests
COMMAND /bin/bash
"${CMAKE_CURRENT_SOURCE_DIR}/run-with-weston.sh"
"${WESTON_EXECUTABLE}"
"$<TARGET_FILE:render-tests>"
"--gtest_filter=-X11*"
)
set_tests_properties(render-tests PROPERTIES
TIMEOUT 120
)
if(ENABLE_X11)
add_test(NAME render-x11-tests
COMMAND "${CMAKE_COMMAND}" -E env
--unset=WAYLAND_DISPLAY
LIBGL_ALWAYS_SOFTWARE=1
"${XVFB_RUN_EXECUTABLE}"
-a
-e /dev/stderr
-s "-screen 0 1024x768x24 +extension GLX"
"$<TARGET_FILE:render-tests>"
"--gtest_filter=X11*"
)
set_tests_properties(render-x11-tests PROPERTIES
TIMEOUT 120
)
endif()
endif()

View File

@@ -20,8 +20,16 @@
#include "app.h"
#include "app_internal.h"
#include "core.h"
#include "input.h"
#include "main.h"
#include "overlay/msg.h"
#include "overlays.h"
#include "render_queue.h"
#include "sw_surface.h"
#include "test.h"
#include "transport_fallback.h"
#include "util.h"
#include "common/array.h"
#include "common/ll.h"
@@ -194,11 +202,16 @@ void core_updateOverlayState(void)
{
}
bool evdev_isExclusive(void)
bool inputPlatformIsKeyboardExclusive(void)
{
return t.exclusive;
}
bool inputPlatformIsPointerExclusive(void)
{
return false;
}
bool lgInput_available(void)
{
return t.available;
@@ -219,8 +232,235 @@ void lgInput_releaseKeys(void)
++t.releaseN;
}
void ImGuiIO_AddKeyEvent(ImGuiIO * self, ImGuiKey key, bool down)
void core_handleMousePosition(double x, double y)
{
(void)x;
(void)y;
}
void core_handleMouseAbsolute(void)
{
}
void core_handleMouseGrabbed(double x, double y)
{
(void)x;
(void)y;
}
void core_handleMouseNormal(double x, double y)
{
(void)x;
(void)y;
}
void core_handleGrabEvent(bool active)
{
(void)active;
}
void core_handleCaptureLost(void)
{
}
void core_updatePositionInfo(void)
{
}
void core_alignToGuest(void)
{
}
bool core_startVideoThreads(void)
{
return true;
}
void core_stopVideoThreads(void)
{
}
bool lgInput_mousePress(unsigned int button)
{
(void)button;
return true;
}
bool lgInput_mouseRelease(unsigned int button)
{
(void)button;
return true;
}
void lgInput_releaseAll(void)
{
}
void lgInput_releaseButtons(void)
{
}
bool lgInput_keyboardLEDs(bool numLock, bool capsLock, bool scrollLock)
{
(void)numLock;
(void)capsLock;
(void)scrollLock;
return true;
}
void main_framePresented(uint64_t frameToken, uint64_t presentTime,
bool valid)
{
(void)frameToken;
(void)presentTime;
(void)valid;
}
void main_videoStreamEnabled(void)
{
}
struct LG_OverlayOps LGOverlayMsg;
void overlayAlert_show(LG_MsgAlert type, const char * format, va_list args)
{
(void)type;
(void)format;
(void)args;
}
MsgBoxHandle overlayMsg_show(const char * caption,
MsgBoxConfirmCallback confirm, void * confirmOpaque,
MsgBoxCloseCallback close, void * closeOpaque,
const char * format, va_list args)
{
(void)caption;
(void)confirm;
(void)confirmOpaque;
(void)close;
(void)closeOpaque;
(void)format;
(void)args;
return NULL;
}
void overlayMsg_close(MsgBoxHandle handle)
{
(void)handle;
}
bool overlayMsg_modal(void)
{
return false;
}
void overlayStatus_set(LGUserStatus status, bool value)
{
(void)status;
(void)value;
}
GraphHandle overlayGraph_register(const char * name, RingBuffer buffer,
float min, float max, GraphFormatFn formatFn)
{
(void)name;
(void)buffer;
(void)min;
(void)max;
(void)formatFn;
return NULL;
}
void overlayGraph_unregister(GraphHandle handle)
{
(void)handle;
}
void overlayGraph_invalidate(GraphHandle handle)
{
(void)handle;
}
void overlayGraph_setCompact(GraphHandle handle, bool compact)
{
(void)handle;
(void)compact;
}
void overlayConfig_register(const char * title,
void (*callback)(void * udata, int * id), void * udata)
{
(void)title;
(void)callback;
(void)udata;
}
void overlayConfig_registerTab(const char * title,
void (*callback)(void * udata, int * id), void * udata)
{
(void)title;
(void)callback;
(void)udata;
}
bool util_uiFontAddText(const char * text)
{
(void)text;
return true;
}
void lgTransportFallback_requestVideoActive(
LG_TransportFallback * fallback, bool active)
{
(void)fallback;
(void)active;
}
bool lgSwSurface_setActive(const LG_SwSurfaceOps * ops,
LG_Transport * transport, bool active,
LG_TransportCancelledFn cancelled, void * opaque)
{
(void)ops;
(void)transport;
(void)active;
(void)cancelled;
(void)opaque;
return true;
}
uint64_t renderQueue_sourceTransition(RenderQueueSource source,
uint64_t generation, bool swSurface,
atomic_uint_least64_t * publishedSerial)
{
(void)source;
(void)generation;
(void)swSurface;
(void)publishedSerial;
return 0;
}
uint64_t renderQueue_sourceSwSurfaceConfigureTransition(
RenderQueueSource source, uint64_t generation, int width, int height,
atomic_uint_least64_t * publishedSerial)
{
(void)source;
(void)generation;
(void)width;
(void)height;
(void)publishedSerial;
return 0;
}
void renderQueue_sourceCursorState(RenderQueueSource source,
uint64_t generation, bool visible, int x, int y, int hx, int hy)
{
(void)source;
(void)generation;
(void)visible;
(void)x;
(void)y;
(void)hx;
(void)hy;
}
static void count(int key, void * opaque)

View File

@@ -0,0 +1,103 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "core/clipboard_files.h"
#include "test.h"
static struct
{
uint64_t dataset;
uint64_t transfer;
LG_ClipboardFileError error;
unsigned int acquired;
unsigned int cancelled;
}
trace;
bool clipboard_fileAcquired(uint64_t dataset, uint64_t acquisition,
LG_ClipboardFileError error)
{
trace.dataset = dataset;
trace.transfer = acquisition;
trace.error = error;
++trace.acquired;
return true;
}
bool clipboard_fileCancel(uint64_t dataset, uint64_t request,
LG_ClipboardFileError reason)
{
trace.dataset = dataset;
trace.transfer = request;
trace.error = reason;
++trace.cancelled;
return true;
}
int main(void)
{
const LG_ClipboardFileRequest request =
{
.dataset = UINT64_C(0x1234),
.request = UINT64_C(0x5678),
.node = 1,
.operation = LG_CLIPBOARD_FILE_READ,
};
CHECK(clipboardFiles_init());
CHECK(!clipboardFiles_remoteOffer(request.dataset));
CHECK(!clipboardFiles_remoteReady(request.dataset));
char * data = (char *)(uintptr_t)1;
size_t size = 1;
CHECK(!clipboardFiles_getRemote("text/uri-list", &data, &size));
CHECK(!data);
CHECK(size == 0);
data = (char *)(uintptr_t)1;
size = 1;
CHECK(!clipboardFiles_getRemotePresentation(
1, "text/uri-list", &data, &size));
CHECK(!data);
CHECK(size == 0);
clipboardFiles_localAcquire(request.dataset, request.request);
CHECK(trace.acquired == 1);
CHECK(trace.dataset == request.dataset);
CHECK(trace.transfer == request.request);
CHECK(trace.error == LG_CLIPBOARD_FILE_ERROR_NOT_SUPPORTED);
clipboardFiles_localRequest(&request);
CHECK(trace.cancelled == 1);
CHECK(trace.dataset == request.dataset);
CHECK(trace.transfer == request.request);
CHECK(trace.error == LG_CLIPBOARD_FILE_ERROR_NOT_SUPPORTED);
clipboardFiles_localRequest(NULL);
CHECK(trace.cancelled == 1);
CHECK(clipboardFiles_remoteDataBegin(&request, 0) ==
LG_CLIPBOARD_RESULT_FAILED);
CHECK(clipboardFiles_remoteDataChunk(&request, 0, NULL, 0) ==
LG_CLIPBOARD_RESULT_FAILED);
CHECK(clipboardFiles_remoteDataEnd(&request, 0) ==
LG_CLIPBOARD_RESULT_FAILED);
clipboardFiles_free();
return 0;
}

View File

@@ -34,7 +34,6 @@
#define MAX_CALL 16U
#define MAX_DATA 32U
#define TEST_ALARM_S 5U
struct Provider
{
@@ -1412,7 +1411,6 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
alarm(TEST_ALARM_S);
debug_init();
for (unsigned int i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
if (strcmp(argv[1], tests[i].name) == 0)

View File

@@ -36,7 +36,6 @@
#define MAX_CTL 16U
#define DEBOUNCE_US UINT64_C(500000)
#define TEST_ALARM_S 5U
struct LG_Transport
{
@@ -98,12 +97,27 @@ bool lgTransport_isValid(const char * name)
(strcmp(name, "lgmp") == 0 || strcmp(name, "spice") == 0);
}
int clock_gettime(clockid_t id, struct timespec * ts)
uint64_t testMicrotime(void)
{
const uint64_t ns = t.now * UINT64_C(1000);
ts->tv_sec = ns / UINT64_C(1000000000);
ts->tv_nsec = ns % UINT64_C(1000000000);
return 0;
return t.now;
}
void core_onWindowSizeChanged(unsigned int width, unsigned int height)
{
if (!g_state.transport.handle ||
!(g_state.transportFeatures & LG_TRANSPORT_FEATURE_WINDOW_SIZE) ||
(g_state.srcSize.x == width && g_state.srcSize.y == height))
return;
const LG_TransportControl control =
{
.type = LG_TRANSPORT_CONTROL_WINDOW_SIZE,
.windowSize = { .width = width, .height = height },
};
LG_TransportControlToken token;
g_state.transport.ops->sendControl(
g_state.transport.handle, &control, &token);
}
static LG_TransportStatus sendCtl(LG_Transport * transport,
@@ -459,7 +473,6 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
alarm(TEST_ALARM_S);
debug_init();
for (unsigned int i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
if (strcmp(argv[1], tests[i].name) == 0)

View File

@@ -0,0 +1,129 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "event_source.h"
#include "test.h"
struct Trace
{
unsigned int notifications;
unsigned int wakeAttempts;
unsigned int wakeFailures;
unsigned int dispatches;
bool notifyDuringDispatch;
LGEventSourceState * state;
};
static bool notify(void * opaque)
{
struct Trace * trace = (struct Trace *)opaque;
++trace->wakeAttempts;
if (trace->wakeFailures)
{
--trace->wakeFailures;
return false;
}
++trace->notifications;
return true;
}
static void dispatch(void * opaque)
{
struct Trace * trace = (struct Trace *)opaque;
++trace->dispatches;
if (trace->notifyDuringDispatch)
{
trace->notifyDuringDispatch = false;
lgEventSourceNotify(trace->state);
}
}
int main(void)
{
struct Trace trace = { 0 };
LGEventSourceState state;
LG_DSEventSource source;
CHECK(!lgEventSourceInit(NULL, dispatch, &trace));
CHECK(!lgEventSourceInit(&state, NULL, &trace));
source = lgEventSourceGet(NULL);
CHECK(!lgEventSourceValid(&source));
CHECK(lgEventSourceInit(&state, dispatch, &trace));
trace.state = &state;
source = lgEventSourceGet(&state);
CHECK(lgEventSourceValid(&source));
lgEventSourceNotify(&state);
CHECK(trace.notifications == 0);
CHECK(trace.wakeAttempts == 0);
CHECK(source.subscribe(source.opaque, notify, &trace));
CHECK(trace.notifications == 1);
CHECK(trace.wakeAttempts == 1);
CHECK(!source.subscribe(source.opaque, notify, &trace));
lgEventSourceNotify(&state);
CHECK(trace.notifications == 1);
CHECK(trace.wakeAttempts == 1);
source.dispatch(source.opaque);
CHECK(trace.dispatches == 1);
lgEventSourceNotify(&state);
lgEventSourceNotify(&state);
CHECK(trace.notifications == 2);
CHECK(trace.wakeAttempts == 2);
source.dispatch(source.opaque);
CHECK(trace.dispatches == 2);
trace.wakeFailures = 1;
lgEventSourceNotify(&state);
CHECK(trace.notifications == 2);
CHECK(trace.wakeAttempts == 3);
lgEventSourceNotify(&state);
CHECK(trace.notifications == 3);
CHECK(trace.wakeAttempts == 4);
trace.notifyDuringDispatch = true;
source.dispatch(source.opaque);
CHECK(trace.dispatches == 3);
CHECK(trace.notifications == 4);
CHECK(trace.wakeAttempts == 5);
source.dispatch(source.opaque);
CHECK(trace.dispatches == 4);
source.unsubscribe(source.opaque);
lgEventSourceNotify(&state);
CHECK(trace.notifications == 4);
CHECK(trace.wakeAttempts == 5);
trace.wakeFailures = 1;
CHECK(!source.subscribe(source.opaque, notify, &trace));
CHECK(trace.notifications == 4);
CHECK(trace.wakeAttempts == 6);
CHECK(source.subscribe(source.opaque, notify, &trace));
CHECK(trace.notifications == 5);
CHECK(trace.wakeAttempts == 7);
source.dispatch(source.opaque);
CHECK(trace.dispatches == 5);
source.unsubscribe(source.opaque);
lgEventSourceFree(&state);
return 0;
}

View File

@@ -0,0 +1,140 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "font_platform.h"
#include "font_platform_stub.h"
#include <stdlib.h>
#include <string.h>
struct FontPlatform
{
unsigned int unused;
};
static FontPlatformStubStats stats;
const FontPlatformStubStats * font_platformStubStats(void)
{
return &stats;
}
bool font_platformInit(FontPlatform ** platform)
{
if (!platform)
return false;
*platform = calloc(1, sizeof(**platform));
if (!*platform)
return false;
++stats.initCount;
return true;
}
void font_platformFree(FontPlatform * platform)
{
if (!platform)
return;
++stats.freeCount;
free(platform);
}
char * font_platformSelect(FontPlatform * platform, const char * fontName)
{
if (!platform || !fontName)
return NULL;
++stats.selectCount;
const size_t length = strlen(FONT_TEST_FILE) + 1;
char * path = malloc(length);
if (path)
memcpy(path, FONT_TEST_FILE, length);
return path;
}
bool font_platformResolve(FontPlatform * platform,
const uint32_t * glyphs, size_t glyphCount,
FontPlatformAddFaceFn addFace, void * opaque, size_t * unresolved)
{
if (!platform || (!glyphs && glyphCount) || !addFace || !unresolved ||
glyphCount > SIZE_MAX / sizeof(*glyphs))
return false;
++stats.resolveCount;
uint32_t * primary = malloc(glyphCount * sizeof(*primary));
uint32_t * fallback = malloc(glyphCount * sizeof(*fallback));
if ((!primary || !fallback) && glyphCount)
{
free(primary);
free(fallback);
return false;
}
size_t primaryCount = 0;
size_t fallbackCount = 0;
for (size_t i = 0; i < glyphCount; ++i)
if (glyphs[i] <= 0xff)
primary[primaryCount++] = glyphs[i];
else
fallback[fallbackCount++] = glyphs[i];
FontPlatformFaceResult result = FONT_PLATFORM_FACE_ACCEPT;
if (primaryCount)
result = addFace(
opaque, FONT_TEST_FILE, 0, primary, primaryCount);
if (result == FONT_PLATFORM_FACE_ERROR)
goto fail;
size_t missing = result == FONT_PLATFORM_FACE_ACCEPT ? 0 : primaryCount;
if (fallbackCount)
{
result = addFace(opaque, FONT_TEST_FILE, 1,
fallback, fallbackCount);
if (result == FONT_PLATFORM_FACE_ERROR)
goto fail;
if (result == FONT_PLATFORM_FACE_SKIP)
++stats.incompatibleSkipCount;
else
goto fail;
result = addFace(opaque, FONT_TEST_FILE, 0,
fallback, fallbackCount);
if (result == FONT_PLATFORM_FACE_ERROR)
goto fail;
if (result == FONT_PLATFORM_FACE_ACCEPT)
{
++stats.fallbackAcceptCount;
}
else
missing += fallbackCount;
}
*unresolved = missing;
free(primary);
free(fallback);
return true;
fail:
free(primary);
free(fallback);
return false;
}

View File

@@ -0,0 +1,37 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_FONT_PLATFORM_STUB_
#define _H_LG_FONT_PLATFORM_STUB_
typedef struct FontPlatformStubStats
{
unsigned int initCount;
unsigned int freeCount;
unsigned int selectCount;
unsigned int resolveCount;
unsigned int incompatibleSkipCount;
unsigned int fallbackAcceptCount;
}
FontPlatformStubStats;
const FontPlatformStubStats * font_platformStubStats(void);
#endif

View File

@@ -19,10 +19,16 @@
*/
#include "font.h"
#include "font_platform_stub.h"
#include "test.h"
#include "common/debug.h"
#include "cimgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void testInvalidFontData(void)
{
@@ -59,9 +65,59 @@ static void testValidFontData(void)
free(data);
}
static void testFontLifecycle(void)
{
const FontPlatformStubStats * stats = font_platformStubStats();
CHECK(!font_addText("before init"));
CHECK(font_init());
CHECK(font_init());
CHECK(stats->initCount == 1);
char * path = font_get("test font");
CHECK(path);
CHECK(strcmp(path, FONT_TEST_FILE) == 0);
free(path);
CHECK(stats->selectCount == 1);
const char text[] = "fallback \xE4\xB8\xAD";
CHECK(font_addText(text));
CHECK(!font_addText(text));
ImFontAtlas * atlas = ImFontAtlas_ImFontAtlas();
CHECK(atlas);
ImFont * large = NULL;
CHECK(font_buildAtlas(atlas, 14.0f, &large));
CHECK(large);
CHECK(stats->resolveCount == 1);
CHECK(stats->incompatibleSkipCount == 1);
CHECK(stats->fallbackAcceptCount == 1);
large = NULL;
CHECK(font_buildAtlas(atlas, 18.0f, &large));
CHECK(large);
CHECK(stats->resolveCount == 2);
CHECK(stats->incompatibleSkipCount == 2);
CHECK(stats->fallbackAcceptCount == 2);
ImFontAtlas_destroy(atlas);
font_free();
font_free();
CHECK(stats->freeCount == 1);
CHECK(!font_addText("after free"));
CHECK(font_init());
CHECK(stats->initCount == 2);
font_free();
CHECK(stats->freeCount == 2);
}
int main(void)
{
debug_init();
testInvalidFontData();
testValidFontData();
testFontLifecycle();
return 0;
}

View File

@@ -66,11 +66,9 @@ static struct LG_Transport tr;
struct AppState g_state;
int clock_gettime(clockid_t id, struct timespec * ts)
uint64_t testNanotime(void)
{
ts->tv_sec = t.now / UINT64_C(1000000000);
ts->tv_nsec = t.now % UINT64_C(1000000000);
return 0;
return t.now;
}
static bool getPeriod(uint64_t * period)

View File

@@ -26,8 +26,8 @@
#include <math.h>
#include <pthread.h>
#include <unistd.h>
#define TEST_ALARM_S 5U
struct Feedback
{
@@ -307,7 +307,7 @@ static OverlayFrameTiming take(void)
return out;
}
static bool near(float value, float expected)
static bool isNear(float value, float expected)
{
return fabsf(value - expected) < 0.000001f;
}
@@ -360,13 +360,13 @@ static void testOrder(void)
CHECK(ringbuffer_getCount(g_state.frameLatency) == 1);
const OverlayFrameTiming out = take();
CHECK(out.validMask == OVERLAY_FRAME_TIMING_VALID_ALL);
CHECK(near(out.capture, 0.000011f));
CHECK(near(out.transport, 0.000010f));
CHECK(near(out.receive, 0.000002f));
CHECK(near(out.providerPrepare, 0.000003f));
CHECK(near(out.dispatch, 0.000035f));
CHECK(near(out.queue, 0.000050f));
CHECK(near(out.present, 0.000500f));
CHECK(isNear(out.capture, 0.000011f));
CHECK(isNear(out.transport, 0.000010f));
CHECK(isNear(out.receive, 0.000002f));
CHECK(isNear(out.providerPrepare, 0.000003f));
CHECK(isNear(out.dispatch, 0.000035f));
CHECK(isNear(out.queue, 0.000050f));
CHECK(isNear(out.present, 0.000500f));
frameTimingFinishFrame(token, &timing);
main_framePresented(token, 600, true);
@@ -394,8 +394,8 @@ static void testUntracked(void)
CHECK((out.validMask & OVERLAY_FRAME_TIMING_VALID_PROVIDER) ==
OVERLAY_FRAME_TIMING_VALID_PROVIDER);
CHECK(!(out.validMask & OVERLAY_FRAME_TIMING_VALID_PRESENT));
CHECK(near(out.receive, 0.000002f));
CHECK(near(out.providerPrepare, 0.000003f));
CHECK(isNear(out.receive, 0.000002f));
CHECK(isNear(out.providerPrepare, 0.000003f));
CHECK(out.present == 0.0f);
finish();
}
@@ -440,7 +440,7 @@ static void testProviderUnavailable(void)
CHECK(out.validMask & OVERLAY_FRAME_TIMING_VALID_PRODUCER);
CHECK(out.validMask & OVERLAY_FRAME_TIMING_VALID_TRANSPORT);
CHECK(!(out.validMask & OVERLAY_FRAME_TIMING_VALID_PROVIDER));
CHECK(near(out.transport, 0.000015f));
CHECK(isNear(out.transport, 0.000015f));
finish();
}
@@ -491,8 +491,8 @@ static void testFifo(void)
CHECK(ringbuffer_getCount(g_state.frameLatency) == 2);
const OverlayFrameTiming out1 = take();
const OverlayFrameTiming out2 = take();
CHECK(near(out1.capture, 0.000081f));
CHECK(near(out2.capture, 0.000082f));
CHECK(isNear(out1.capture, 0.000081f));
CHECK(isNear(out2.capture, 0.000082f));
finish();
}
@@ -786,7 +786,6 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
alarm(TEST_ALARM_S);
debug_init();
for (size_t i = 0; i < ARRAY_LENGTH(tests); ++i)
if (strcmp(argv[1], tests[i].name) == 0)

View File

@@ -20,8 +20,11 @@
#include "app.h"
#include "core.h"
#include "font.h"
#include "input.h"
#include "kb.h"
#include "main.h"
#include "message.h"
#include "test.h"
#include "util.h"
@@ -80,6 +83,81 @@ struct AppState g_state;
struct CursorState g_cursor;
struct AppParams g_params;
const int lg_keycode_to_imgui[LG_KEY_MAX] = { 0 };
void app_alert(LG_MsgAlert type, const char * format, ...)
{
(void)type;
(void)format;
}
void app_handleMouseRelative(double normx, double normy,
double rawx, double rawy)
{
(void)normx;
(void)normy;
(void)rawx;
(void)rawy;
}
void app_updateMouseState(void)
{
}
void lgMessage_post(const LGMsg * msg)
{
(void)msg;
}
void ImGuiIO_AddKeyEvent(ImGuiIO * self, ImGuiKey key, bool down)
{
(void)self;
(void)key;
(void)down;
}
int main_cursorThread(void * unused)
{
(void)unused;
return 0;
}
int main_frameThread(void * unused)
{
(void)unused;
return 0;
}
bool font_init(void)
{
return true;
}
void font_free(void)
{
}
char * font_get(const char * fontName)
{
(void)fontName;
return NULL;
}
bool font_addText(const char * text)
{
(void)text;
return true;
}
bool font_buildAtlas(struct ImFontAtlas * atlas, float size,
struct ImFont ** large)
{
(void)atlas;
(void)size;
(void)large;
return true;
}
static void push(enum EvType type, double x, double y, bool leaving)
{
CHECK(m.count < sizeof(m.ev) / sizeof(m.ev[0]));
@@ -282,13 +360,13 @@ void app_mouseTrace(const char * file, unsigned int line,
(void)format;
}
void evdev_setGrab(bool keyboard, bool pointer)
void inputPlatformSetGrab(bool keyboard, bool pointer)
{
(void)keyboard;
(void)pointer;
}
bool evdev_isExclusive(void)
bool inputPlatformIsKeyboardExclusive(void)
{
return false;
}
@@ -390,7 +468,7 @@ static void setLocal(double x, double y)
g_cursor.guest.y = lround(guest.y);
}
static bool near(double a, double b)
static bool isNear(double a, double b)
{
return fabs(a - b) < 0.000001;
}
@@ -405,8 +483,8 @@ static void testInsetExit(void)
CHECK(count(EV_UNGRAB) == 0);
CHECK(count(EV_WARP) == 0);
CHECK(near(g_cursor.exitPos.x, 9.75));
CHECK(near(g_cursor.exitPos.y, 19.75));
CHECK(isNear(g_cursor.exitPos.x, 9.75));
CHECK(isNear(g_cursor.exitPos.y, 19.75));
CHECK(g_cursor.exit);
CHECK(!g_cursor.inView);
CHECK(!g_cursor.viewReq);
@@ -511,8 +589,8 @@ static void testExitImmediate(void)
startExit();
CHECK(count(EV_UNGRAB) == 0);
CHECK(count(EV_WARP) == 0);
CHECK(near(g_cursor.exitPos.x, 111));
CHECK(near(g_cursor.exitPos.y, 50));
CHECK(isNear(g_cursor.exitPos.x, 111));
CHECK(isNear(g_cursor.exitPos.y, 50));
CHECK(!g_cursor.inView);
CHECK(!g_cursor.viewReq);
CHECK(g_cursor.exit);
@@ -903,8 +981,8 @@ static void testRotateScale(void)
struct DoublePoint guest;
util_localCurToGuest(&guest);
CHECK(near(guest.x, 40));
CHECK(near(guest.y, 20));
CHECK(isNear(guest.x, 40));
CHECK(isNear(guest.y, 20));
}
}
@@ -941,13 +1019,13 @@ static void testGeometry(void)
struct DoublePoint local;
CHECK(util_guestCurToLocal(&local));
CHECK(near(local.x, expected[rot].x));
CHECK(near(local.y, expected[rot].y));
CHECK(isNear(local.x, expected[rot].x));
CHECK(isNear(local.y, expected[rot].y));
struct DoublePoint delta = { 1, 2 };
util_rotatePoint(&delta);
CHECK(near(delta.x, rotated[rot].x));
CHECK(near(delta.y, rotated[rot].y));
CHECK(isNear(delta.x, rotated[rot].x));
CHECK(isNear(delta.y, rotated[rot].y));
}
static const double scales[] = { 0.5, 1.0, 2.0 };
@@ -966,15 +1044,15 @@ static void testGeometry(void)
struct DoublePoint round;
util_localCurToGuest(&round);
CHECK(near(round.x, 40));
CHECK(near(round.y, 20));
CHECK(isNear(round.x, 40));
CHECK(isNear(round.y, 20));
}
g_cursor.guest.valid = false;
struct DoublePoint local = { -1, -2 };
CHECK(!util_guestCurToLocal(&local));
CHECK(near(local.x, -1));
CHECK(near(local.y, -2));
CHECK(isNear(local.x, -1));
CHECK(isNear(local.y, -2));
}
static struct DoublePoint inputFor(int rot, double x, double y)
@@ -1030,8 +1108,8 @@ static void testEdges(void)
CHECK(g_cursor.exit);
CHECK(!g_cursor.inView);
CHECK(!g_cursor.viewReq);
CHECK(near(g_cursor.exitPos.x, cases[i].target.x));
CHECK(near(g_cursor.exitPos.y, cases[i].target.y));
CHECK(isNear(g_cursor.exitPos.x, cases[i].target.x));
CHECK(isNear(g_cursor.exitPos.y, cases[i].target.y));
}
}
@@ -1065,8 +1143,8 @@ static void testScales(void)
CHECK(g_cursor.exit);
CHECK(!g_cursor.inView);
CHECK(!g_cursor.viewReq);
CHECK(near(g_cursor.exitPos.x, cases[i].target));
CHECK(near(g_cursor.exitPos.y, 50));
CHECK(isNear(g_cursor.exitPos.x, cases[i].target));
CHECK(isNear(g_cursor.exitPos.y, 50));
}
}
@@ -1101,8 +1179,8 @@ static void testBorderExit(void)
CHECK(g_cursor.exit);
CHECK(!g_cursor.inView);
CHECK(!g_cursor.viewReq);
CHECK(near(g_cursor.exitPos.x, 111));
CHECK(near(g_cursor.exitPos.y, 50));
CHECK(isNear(g_cursor.exitPos.x, 111));
CHECK(isNear(g_cursor.exitPos.y, 50));
}
}

146
client/tests/process_test.c Normal file
View File

@@ -0,0 +1,146 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "platform/process.h"
#include "test.h"
#include <signal.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
static volatile sig_atomic_t stopCount;
static volatile sig_atomic_t restoredCount;
static bool acceptStop(void * opaque)
{
const int expected = 42;
if (!opaque || *(const int *)opaque != expected)
return false;
++stopCount;
return true;
}
static bool rejectStop(void * opaque)
{
(void)opaque;
return false;
}
static void restoredHandler(int signal)
{
(void)signal;
++restoredCount;
}
static void testPrivilege(void)
{
enum LG_ProcessPrivilege expected = LG_PROCESS_PRIVILEGE_NORMAL;
if (getuid() == 0)
expected = LG_PROCESS_PRIVILEGE_ROOT;
else if (getuid() != geteuid())
expected = LG_PROCESS_PRIVILEGE_SETUID;
CHECK(lgProcessGetPrivilege() == expected);
}
static void testExecutablePath(void)
{
char * path = lgProcessGetExecutablePath(NULL);
CHECK(path);
CHECK(path[0] == '/');
struct stat actual;
struct stat expected;
CHECK(stat(path, &actual) == 0);
CHECK(stat("/proc/self/exe", &expected) == 0);
CHECK(actual.st_dev == expected.st_dev);
CHECK(actual.st_ino == expected.st_ino);
free(path);
}
static void testHandledStop(void)
{
const int opaque = 42;
CHECK(!lgProcessInstallStopHandler(NULL, NULL));
CHECK(lgProcessInstallStopHandler(acceptStop, (void *)&opaque));
CHECK(!lgProcessInstallStopHandler(acceptStop, (void *)&opaque));
struct sigaction action;
CHECK(sigaction(SIGINT, NULL, &action) == 0);
CHECK(action.sa_flags & SA_RESTART);
raise(SIGINT);
CHECK(stopCount == 1);
raise(SIGTERM);
CHECK(stopCount == 2);
lgProcessRemoveStopHandler();
lgProcessRemoveStopHandler();
}
static void testPreviousHandlerRestored(void)
{
struct sigaction previous;
struct sigaction action = { 0 };
action.sa_handler = restoredHandler;
sigemptyset(&action.sa_mask);
CHECK(sigaction(SIGINT, &action, &previous) == 0);
CHECK(lgProcessInstallStopHandler(acceptStop, NULL));
lgProcessRemoveStopHandler();
raise(SIGINT);
CHECK(restoredCount == 1);
CHECK(sigaction(SIGINT, &previous, NULL) == 0);
}
static void testRejectedStopTerminates(void)
{
const pid_t child = fork();
CHECK(child >= 0);
if (child == 0)
{
if (!lgProcessInstallStopHandler(rejectStop, NULL))
_exit(EXIT_FAILURE);
raise(SIGTERM);
_exit(EXIT_FAILURE);
}
int status = 0;
CHECK(waitpid(child, &status, 0) == child);
CHECK(WIFSIGNALED(status));
CHECK(WTERMSIG(status) == SIGTERM);
}
int main(void)
{
testPrivilege();
testExecutablePath();
testHandledStop();
testPreviousHandlerRestored();
testRejectedStopTerminates();
return 0;
}

View File

@@ -31,7 +31,6 @@
#include <unistd.h>
#define TEST_WAIT_MS 3000U
#define TEST_ALARM_S 5U
struct LG_Transport
{
@@ -874,7 +873,6 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
alarm(TEST_ALARM_S);
debug_init();
for (unsigned int i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
if (strcmp(argv[1], tests[i].name) == 0)