1d4afb5ceSopenharmony_ciproject(lws-minimal-ws-client-spam C)
2d4afb5ceSopenharmony_cicmake_minimum_required(VERSION 2.8.12)
3d4afb5ceSopenharmony_cifind_package(libwebsockets CONFIG REQUIRED)
4d4afb5ceSopenharmony_cilist(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR})
5d4afb5ceSopenharmony_ciinclude(CheckIncludeFile)
6d4afb5ceSopenharmony_ciinclude(CheckCSourceCompiles)
7d4afb5ceSopenharmony_ciinclude(LwsCheckRequirements)
8d4afb5ceSopenharmony_ci
9d4afb5ceSopenharmony_ciset(SAMP lws-minimal-ws-client-spam)
10d4afb5ceSopenharmony_ciset(SRCS minimal-ws-client-spam.c)
11d4afb5ceSopenharmony_ci
12d4afb5ceSopenharmony_ciset(requirements 1)
13d4afb5ceSopenharmony_cirequire_pthreads(requirements)
14d4afb5ceSopenharmony_cirequire_lws_config(LWS_ROLE_WS 1 requirements)
15d4afb5ceSopenharmony_cirequire_lws_config(LWS_WITH_CLIENT 1 requirements)
16d4afb5ceSopenharmony_cirequire_lws_config(LWS_WITH_TLS 1 requirements)
17d4afb5ceSopenharmony_ci
18d4afb5ceSopenharmony_ciif (requirements)
19d4afb5ceSopenharmony_ci	add_executable(${SAMP} ${SRCS})
20d4afb5ceSopenharmony_ci	find_program(VALGRIND "valgrind")
21d4afb5ceSopenharmony_ci       #
22d4afb5ceSopenharmony_ci       # instantiate the server per sai builder instance, they are running in the same
23d4afb5ceSopenharmony_ci       # machine context in parallel so they can tread on each other otherwise
24d4afb5ceSopenharmony_ci       #
25d4afb5ceSopenharmony_ci       set(PORT_WCS_SRV "7620")
26d4afb5ceSopenharmony_ci       if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "0")
27d4afb5ceSopenharmony_ci	       set(PORT_WCS_SRV 7621)
28d4afb5ceSopenharmony_ci       endif()
29d4afb5ceSopenharmony_ci       if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "1")
30d4afb5ceSopenharmony_ci	       set(PORT_WCS_SRV 7622)
31d4afb5ceSopenharmony_ci       endif()
32d4afb5ceSopenharmony_ci       if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "2")
33d4afb5ceSopenharmony_ci	       set(PORT_WCS_SRV 7623)
34d4afb5ceSopenharmony_ci       endif()
35d4afb5ceSopenharmony_ci       if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "3")
36d4afb5ceSopenharmony_ci	       set(PORT_WCS_SRV 7624)
37d4afb5ceSopenharmony_ci       endif()
38d4afb5ceSopenharmony_ci
39d4afb5ceSopenharmony_ci# hack
40d4afb5ceSopenharmony_ciif (WIN32)
41d4afb5ceSopenharmony_cielse()
42d4afb5ceSopenharmony_ci
43d4afb5ceSopenharmony_ciif (LWS_WITH_SERVER)
44d4afb5ceSopenharmony_ciif (WIN32)
45d4afb5ceSopenharmony_ci	add_test(NAME st_wcs_srv COMMAND cmd.exe /c start /b $<TARGET_FILE:test-server> -s --port ${PORT_WCS_SRV})
46d4afb5ceSopenharmony_ci	add_test(NAME ki_wcs_srv COMMAND taskkill /F /IM $<TARGET_FILE_NAME:test-server> /T)
47d4afb5ceSopenharmony_cielse()
48d4afb5ceSopenharmony_ci	if (VALGRIND)
49d4afb5ceSopenharmony_ci		add_test(NAME st_wcs_srv COMMAND
50d4afb5ceSopenharmony_ci			${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh
51d4afb5ceSopenharmony_ci			wcs_srv ${VALGRIND} --tool=memcheck $<TARGET_FILE:test-server>
52d4afb5ceSopenharmony_ci				-r ${CMAKE_SOURCE_DIR}/destdir/usr/local/share/libwebsockets-test-server/
53d4afb5ceSopenharmony_ci				-s --port ${PORT_WCS_SRV} )
54d4afb5ceSopenharmony_ci		add_test(NAME ki_wcs_srv COMMAND
55d4afb5ceSopenharmony_ci			${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh
56d4afb5ceSopenharmony_ci			wcs_srv ${VALGRIND} $<TARGET_FILE_NAME:test-server> --port ${PORT_WCS_SRV})
57d4afb5ceSopenharmony_ci	else()
58d4afb5ceSopenharmony_ci		add_test(NAME st_wcs_srv COMMAND
59d4afb5ceSopenharmony_ci			${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh
60d4afb5ceSopenharmony_ci			wcs_srv $<TARGET_FILE:test-server>
61d4afb5ceSopenharmony_ci				-r ${CMAKE_SOURCE_DIR}/destdir/usr/local/share/libwebsockets-test-server/
62d4afb5ceSopenharmony_ci				-s --port ${PORT_WCS_SRV} )
63d4afb5ceSopenharmony_ci		add_test(NAME ki_wcs_srv COMMAND
64d4afb5ceSopenharmony_ci			${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh
65d4afb5ceSopenharmony_ci			wcs_srv $<TARGET_FILE_NAME:test-server> --port ${PORT_WCS_SRV})
66d4afb5ceSopenharmony_ci	endif()
67d4afb5ceSopenharmony_ciendif()
68d4afb5ceSopenharmony_ci
69d4afb5ceSopenharmony_ci	set_tests_properties(st_wcs_srv PROPERTIES WORKING_DIRECTORY . FIXTURES_SETUP wcs_srv TIMEOUT 800)
70d4afb5ceSopenharmony_ci	set_tests_properties(ki_wcs_srv PROPERTIES FIXTURES_CLEANUP wcs_srv)
71d4afb5ceSopenharmony_ci
72d4afb5ceSopenharmony_ci	add_test(NAME ws-client-spam COMMAND lws-minimal-ws-client-spam --server localhost --port ${PORT_WCS_SRV} -l 32 -c 3)
73d4afb5ceSopenharmony_ci	set_tests_properties(ws-client-spam PROPERTIES
74d4afb5ceSopenharmony_ci			     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/ws-client/minimal-ws-client-spam
75d4afb5ceSopenharmony_ci			     FIXTURES_REQUIRED "wcs_srv"
76d4afb5ceSopenharmony_ci			     TIMEOUT 40)
77d4afb5ceSopenharmony_ciendif()
78d4afb5ceSopenharmony_ciendif()
79d4afb5ceSopenharmony_ci
80d4afb5ceSopenharmony_ci	if (websockets_shared)
81d4afb5ceSopenharmony_ci		target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS})
82d4afb5ceSopenharmony_ci		add_dependencies(${SAMP} websockets_shared)
83d4afb5ceSopenharmony_ci	else()
84d4afb5ceSopenharmony_ci		target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS})
85d4afb5ceSopenharmony_ci	endif()
86d4afb5ceSopenharmony_ciendif()
87