• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1project(lws-minimal-secure-streams C)
2cmake_minimum_required(VERSION 2.8.12)
3find_package(libwebsockets CONFIG REQUIRED)
4list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR})
5include(CheckCSourceCompiles)
6include(LwsCheckRequirements)
7
8set(SAMP lws-minimal-secure-streams)
9
10set(requirements 1)
11require_lws_config(LWS_ROLE_H1 1 requirements)
12require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
13require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements)
14require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements)
15require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
16
17require_lws_config(LWS_WITH_SYS_FAULT_INJECTION 1 has_fault_injection)
18
19if (requirements)
20	add_executable(${SAMP} minimal-secure-streams.c)
21
22	find_program(VALGRIND "valgrind")
23
24	if (LWS_CTEST_INTERNET_AVAILABLE AND NOT WIN32)
25
26		#
27		# When running in CI, wait for a lease on the resources
28		# before starting this test, so the server does not get
29		# thousands of simultaneous tls connection attempts
30		#
31		# sai-resource holds the lease on the resources until
32		# the time given in seconds or the sai-resource instance
33		# exits, whichever happens first
34		#
35		# If running under Sai, creates a lock test called "res_sspcmin"
36		#
37
38		sai_resource(warmcat_conns 1 40 sspcmin)
39
40		#
41		# simple test not via proxy
42		#
43
44		if (VALGRIND)
45			message("testing via valgrind")
46			add_test(NAME ss-warmcat COMMAND
47				${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
48				$<TARGET_FILE:lws-minimal-secure-streams>)
49		else()
50			add_test(NAME ss-warmcat COMMAND lws-minimal-secure-streams)
51		endif()
52
53		set_tests_properties(ss-warmcat
54				     PROPERTIES
55				     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/secure-streams/minimal-secure-streams
56				     TIMEOUT 40)
57		if (DEFINED ENV{SAI_OVN})
58			set_tests_properties(ss-warmcat PROPERTIES FIXTURES_REQUIRED "res_sspcmin")
59		endif()
60
61		if (has_fault_injection)
62			if (VALGRIND)
63				add_test(NAME ss-warmcat-fi1 COMMAND
64					${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
65					$<TARGET_FILE:lws-minimal-secure-streams>
66					--fault-injection "ss/ss_create_destroy_me"
67					--expected-exit 1)
68				add_test(NAME ss-warmcat-fi2 COMMAND
69					${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
70					$<TARGET_FILE:lws-minimal-secure-streams>
71					--fault-injection "ss/ss_no_streamtype_policy"
72					--expected-exit 1)
73			else()
74				add_test(NAME ss-warmcat-fi1 COMMAND lws-minimal-secure-streams
75					 --fault-injection "ss/ss_create_destroy_me"
76					 --expected-exit 1)
77				add_test(NAME ss-warmcat-fi2 COMMAND lws-minimal-secure-streams
78					 --fault-injection "ss/ss_no_streamtype_policy"
79					 --expected-exit 1)
80 			 endif()
81
82			set_tests_properties(ss-warmcat-fi1
83					     ss-warmcat-fi2
84				     PROPERTIES
85				     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/secure-streams/minimal-secure-streams
86				     TIMEOUT 5)
87
88		endif()
89
90
91		if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API)
92
93			#
94			# Define test dep to bring up and take down the test
95			# proxy
96			#
97
98			if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
99				# uds abstract namespace for linux
100				set(CTEST_SOCKET_PATH "@ctest-ssp-$ENV{SAI_PROJECT}-$ENV{SAI_OVN}")
101			else()
102				# filesystem socket for others
103				set(CTEST_SOCKET_PATH "/tmp/ctest-ssp-$ENV{SAI_PROJECT}-$ENV{SAI_OVN}")
104			endif()
105			add_test(NAME st_ssproxy COMMAND
106				${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh
107				ssproxy $<TARGET_FILE:lws-minimal-secure-streams-proxy>
108				-i ${CTEST_SOCKET_PATH} )
109			set_tests_properties(st_ssproxy PROPERTIES WORKING_DIRECTORY . FIXTURES_SETUP ssproxy TIMEOUT 800)
110
111			add_test(NAME ki_ssproxy COMMAND
112				${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh
113				ssproxy $<TARGET_FILE:lws-minimal-secure-streams-proxy>
114				-i ${CTEST_SOCKET_PATH})
115			set_tests_properties(ki_ssproxy PROPERTIES FIXTURES_CLEANUP ssproxy)
116
117			#
118			# the client part that will connect to the proxy
119			#
120
121			if (VALGRIND)
122				message("testing via valgrind")
123				add_test(NAME sspc-minimal COMMAND
124					${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
125					$<TARGET_FILE:lws-minimal-secure-streams-client> -i +${CTEST_SOCKET_PATH})
126			else()
127				add_test(NAME sspc-minimal COMMAND lws-minimal-secure-streams-client -i +${CTEST_SOCKET_PATH})
128			endif()
129
130			set(fixlist "ssproxy")
131			if (DEFINED ENV{SAI_OVN})
132				list(APPEND fixlist "res_ssproxy")
133			endif()
134
135			set_tests_properties(sspc-minimal PROPERTIES
136				WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/secure-streams/minimal-secure-streams
137				FIXTURES_REQUIRED "${fixlist}"
138				TIMEOUT 40)
139
140		endif()
141
142	endif()
143
144	if (websockets_shared)
145		target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS})
146		add_dependencies(${SAMP} websockets_shared)
147	else()
148		target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS})
149	endif()
150
151	CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\ni#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)\n return 0;\n #else\n fail\n #endif\n return 0;\n}\n" HAS_LWS_WITH_SECURE_STREAMS_PROXY_API)
152
153	if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API)
154		add_compile_options(-DLWS_SS_USE_SSPC)
155
156		add_executable(${SAMP}-client minimal-secure-streams.c)
157		if (websockets_shared)
158			target_link_libraries(${SAMP}-client websockets_shared ${LIBWEBSOCKETS_DEP_LIBS})
159			add_dependencies(${SAMP}-client websockets_shared)
160		else()
161			target_link_libraries(${SAMP}-client websockets ${LIBWEBSOCKETS_DEP_LIBS})
162		endif()
163	endif()
164
165endif()
166