1project(lws-minimal-http-client-multi 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-http-client-multi) 9set(SRCS minimal-http-client-multi.c) 10 11set(requirements 1) 12set(MBEDTLS 0) 13require_lws_config(LWS_ROLE_H1 1 requirements) 14require_lws_config(LWS_WITH_CLIENT 1 requirements) 15require_lws_config(LWS_WITH_TLS 1 requirements) 16require_lws_config(LWS_WITH_SYS_STATE 1 requirements) 17 18require_lws_config(LWS_WITH_MBEDTLS 1 MBEDTLS) 19 20 21if (requirements) 22 add_executable(${SAMP} ${SRCS}) 23 24 find_program(VALGRIND "valgrind") 25 26 # 27 # instantiate the server per sai builder instance, they are running in the same 28 # machine context in parallel so they can tread on each other otherwise 29 # 30 set(PORT_HCM_SRV "7670") 31 if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "0") 32 set(PORT_HCM_SRV 7671) 33 endif() 34 if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "1") 35 set(PORT_HCM_SRV 7672) 36 endif() 37 if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "2") 38 set(PORT_HCM_SRV 7673) 39 endif() 40 if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "3") 41 set(PORT_HCM_SRV 7674) 42 endif() 43 44 45# hack 46if (NOT WIN32 AND LWS_WITH_SERVER) 47 48 # 49 # Tests against built server running locally (needs daemonization...) 50 # 51 52if (WIN32) 53 add_test(NAME st_hcm_srv COMMAND cmd.exe /c start /b $<TARGET_FILE:lws-minimal-http-server-tls> --port ${PORT_HCM_SRV}) 54 add_test(NAME ki_hcm_srv COMMAND taskkill /F /IM $<TARGET_FILE_NAME:lws-minimal-http-server-tls> /T) 55 add_test(NAME st_hcmp_srv COMMAND cmd.exe /c start /b $<TARGET_FILE:test-server> -s --port 1${PORT_HCM_SRV}) 56 add_test(NAME ki_hcmp_srv COMMAND taskkill /F /IM $<TARGET_FILE_NAME:test-server> /T) 57else() 58 # 59 # mbedtls is too slow to keep up on some targets, when ctest is in parallel 60 # 61 if (VALGRIND AND NOT MBEDTLS) 62 add_test(NAME st_hcm_srv COMMAND 63 ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh 64 hcm_srv ${VALGRIND} --tool=memcheck $<TARGET_FILE:lws-minimal-http-server-tls> 65 --port ${PORT_HCM_SRV}) 66 add_test(NAME ki_hcm_srv COMMAND 67 ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh 68 hcm_srv ${VALGRIND} $<TARGET_FILE_NAME:lws-minimal-http-server-tls> 69 --port ${PORT_HCM_SRV}) 70 add_test(NAME st_hcmp_srv COMMAND 71 ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh 72 hcmp_srv ${VALGRIND} --tool=memcheck $<TARGET_FILE:test-server> -s 73 -r ${CMAKE_SOURCE_DIR}/destdir/usr/local/share/libwebsockets-test-server/ 74 --port 1${PORT_HCM_SRV}) 75 add_test(NAME ki_hcmp_srv COMMAND 76 ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh 77 hcmp_srv ${VALGRIND} $<TARGET_FILE_NAME:test-server> 78 --port 1${PORT_HCM_SRV}) 79 else() 80 add_test(NAME st_hcm_srv COMMAND 81 ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh 82 hcm_srv $<TARGET_FILE:lws-minimal-http-server-tls> 83 --port ${PORT_HCM_SRV} ) 84 add_test(NAME ki_hcm_srv COMMAND 85 ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh 86 hcm_srv $<TARGET_FILE_NAME:lws-minimal-http-server-tls> 87 --port ${PORT_HCM_SRV}) 88 add_test(NAME st_hcmp_srv COMMAND 89 ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh 90 hcmp_srv $<TARGET_FILE:test-server> -s 91 -r ${CMAKE_SOURCE_DIR}/destdir/usr/local/share/libwebsockets-test-server/ 92 --port 1${PORT_HCM_SRV} ) 93 add_test(NAME ki_hcmp_srv COMMAND 94 ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh 95 hcmp_srv $<TARGET_FILE_NAME:test-server> 96 --port 1${PORT_HCM_SRV}) 97 endif() 98endif() 99 100 set_tests_properties(st_hcm_srv PROPERTIES 101 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-tls 102 FIXTURES_SETUP hcm_srv 103 TIMEOUT 800) 104 set_tests_properties(ki_hcm_srv PROPERTIES 105 FIXTURES_CLEANUP hcm_srv) 106 107 set_tests_properties(st_hcmp_srv PROPERTIES 108 WORKING_DIRECTORY . 109 FIXTURES_SETUP hcmp_srv 110 TIMEOUT 800) 111 set_tests_properties(ki_hcmp_srv PROPERTIES 112 FIXTURES_CLEANUP hcmp_srv) 113 114 # 115 # Tests against local server peer 116 # 117 118 add_test(NAME http-client-multi COMMAND lws-minimal-http-client-multi 119 -l --port ${PORT_HCM_SRV} -d 1151) 120 add_test(NAME http-client-multi-h1 COMMAND lws-minimal-http-client-multi 121 --h1 -l --port ${PORT_HCM_SRV} -d1151) 122 add_test(NAME http-client-multi-pipe COMMAND lws-minimal-http-client-multi 123 -p -l --port ${PORT_HCM_SRV} -d1151) 124 add_test(NAME http-client-multi-h1-pipe COMMAND lws-minimal-http-client-multi 125 --h1 -p -l --port ${PORT_HCM_SRV} -d1151) 126 add_test(NAME http-client-multi-stag COMMAND lws-minimal-http-client-multi 127 -s -l --port ${PORT_HCM_SRV} -d1151) 128 add_test(NAME http-client-multi-stag-h1 COMMAND lws-minimal-http-client-multi 129 --h1 -s -l --port ${PORT_HCM_SRV} -d1151) 130 add_test(NAME http-client-multi-stag-pipe COMMAND lws-minimal-http-client-multi 131 -p -s -l --port ${PORT_HCM_SRV} -d1151) 132 add_test(NAME http-client-multi-stag-h1-pipe COMMAND lws-minimal-http-client-multi 133 --h1 -p -s -l --port ${PORT_HCM_SRV} -d1151) 134 135 # confirm that the pipelined mode really is doing it in one connection 136 add_test(NAME http-client-multi-restrict-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 -p -l --port ${PORT_HCM_SRV}) 137 add_test(NAME http-client-multi-restrict-h1-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 --h1 -p -l --port ${PORT_HCM_SRV}) 138 add_test(NAME http-client-multi-restrict-stag-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 -p -s -l --port ${PORT_HCM_SRV}) 139 add_test(NAME http-client-multi-restrict-stag-h1-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 --h1 -p -s -l --port ${PORT_HCM_SRV}) 140 # confirm that we do fail with a one connection limit and no pipelining 141 add_test(NAME http-client-multi-restrict-nopipe-fail COMMAND lws-minimal-http-client-multi --limit 1 -l --port ${PORT_HCM_SRV} -d1151) 142 set_property(TEST http-client-multi-restrict-nopipe-fail PROPERTY WILL_FAIL TRUE) 143 add_test(NAME http-client-multi-restrict-h1-nopipe-fail COMMAND lws-minimal-http-client-multi --limit 1 --h1 -l --port ${PORT_HCM_SRV} -d1151) 144 set_property(TEST http-client-multi-restrict-h1-nopipe-fail PROPERTY WILL_FAIL TRUE) 145 146 set_tests_properties(http-client-multi-restrict-pipe 147 http-client-multi-restrict-h1-pipe 148 http-client-multi-restrict-stag-pipe 149 http-client-multi-restrict-stag-h1-pipe 150 http-client-multi-restrict-nopipe-fail 151 http-client-multi-restrict-h1-nopipe-fail 152 http-client-multi 153 http-client-multi-h1 154 http-client-multi-pipe 155 http-client-multi-h1-pipe 156 http-client-multi-stag 157 http-client-multi-stag-h1 158 http-client-multi-stag-pipe 159 http-client-multi-stag-h1-pipe 160 PROPERTIES 161 FIXTURES_REQUIRED "hcm_srv" 162 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client-multi 163 TIMEOUT 50) 164 165 # POSTs against local http-server-form-post 166 add_test(NAME http-client-multi-post COMMAND lws-minimal-http-client-multi 167 --post -l --port 1${PORT_HCM_SRV} -d1151) 168 add_test(NAME http-client-multi-post-h1 COMMAND lws-minimal-http-client-multi 169 --post --h1 -l --port 1${PORT_HCM_SRV} -d1151) 170 add_test(NAME http-client-multi-post-pipe COMMAND lws-minimal-http-client-multi 171 --post -p -l --port 1${PORT_HCM_SRV} -d1151) 172 if (VALGRIND) 173 add_test(NAME http-client-multi-post-h1-pipe COMMAND ${VALGRIND} --tool=memcheck $<TARGET_FILE:lws-minimal-http-client-multi> 174 --post --h1 -p -l --port 1${PORT_HCM_SRV} -d1151) 175 else() 176 add_test(NAME http-client-multi-post-h1-pipe COMMAND lws-minimal-http-client-multi 177 --post --h1 -p -l --port 1${PORT_HCM_SRV} -d1151) 178 endif() 179 add_test(NAME http-client-multi-post-stag COMMAND lws-minimal-http-client-multi 180 --post -s -l -d1151 --port 1${PORT_HCM_SRV} -d1151) 181 add_test(NAME http-client-multi-post-stag-h1 COMMAND lws-minimal-http-client-multi 182 --post --h1 -d1151 -s -l --port 1${PORT_HCM_SRV} -d1151) 183 add_test(NAME http-client-multi-post-stag-pipe COMMAND lws-minimal-http-client-multi 184 --post -p -s -l --port 1${PORT_HCM_SRV} -d1151) 185 add_test(NAME http-client-multi-post-stag-h1-pipe COMMAND lws-minimal-http-client-multi 186 --post --h1 -p -s -l --port 1${PORT_HCM_SRV} -d1151) 187 set_tests_properties(http-client-multi-post 188 http-client-multi-post-h1 189 http-client-multi-post-pipe 190 http-client-multi-post-h1-pipe 191 http-client-multi-post-stag 192 http-client-multi-post-stag-h1 193 http-client-multi-post-stag-pipe 194 http-client-multi-post-stag-h1-pipe 195 PROPERTIES 196 FIXTURES_REQUIRED "hcmp_srv" 197 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client-multi 198 TIMEOUT 20) 199 200endif(NOT WIN32 AND LWS_WITH_SERVER) 201 202 if (websockets_shared) 203 target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) 204 add_dependencies(${SAMP} websockets_shared) 205 else() 206 target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) 207 endif() 208endif() 209