1project(lws-minimal-http-client 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) 9set(SRCS minimal-http-client.c) 10 11set(has_fault_injection 1) 12set(has_h2 1) 13set(has_plugins 1) 14set(has_ss_policy_parse 1) 15set(has_no_system_vhost 1) 16set(has_async_dns 1) 17set(has_mbedtls 1) 18 19set(requirements 1) 20 21require_lws_config(LWS_ROLE_H1 1 requirements) 22require_lws_config(LWS_WITH_CLIENT 1 requirements) 23require_lws_config(LWS_WITH_SYS_STATE 1 requirements) 24 25require_lws_config(LWS_ROLE_H2 1 has_h2) 26require_lws_config(LWS_WITH_SYS_FAULT_INJECTION 1 has_fault_injection) 27require_lws_config(LWS_WITH_EVLIB_PLUGINS 1 has_plugins) 28require_lws_config(LWS_WITH_EVENT_LIBS 1 has_plugins) 29 30require_lws_config(LWS_WITH_SECURE_STREAMS 1 has_ss_policy_parse) 31require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 has_ss_policy_parse) 32 33require_lws_config(LWS_WITH_SYS_ASYNC_DNS 0 has_no_system_vhost) 34require_lws_config(LWS_WITH_SYS_NTPCLIENT 0 has_no_system_vhost) 35require_lws_config(LWS_WITH_SYS_DHCP_CLIENT 0 has_no_system_vhost) 36 37require_lws_config(LWS_WITH_SYS_ASYNC_DNS 1 has_async_dns) 38require_lws_config(LWS_WITH_MBEDTLS 1 has_mbedtls) 39 40if (requirements) 41 add_executable(${SAMP} ${SRCS}) 42 43 find_program(VALGRIND "valgrind") 44 45 sai_resource(warmcat_conns 1 40 http_client_warmcat) 46 47 if (LWS_CTEST_INTERNET_AVAILABLE) 48 set(mytests http-client-warmcat-h1) 49 if (has_h2) 50 add_test(NAME http-client-warmcat COMMAND lws-minimal-http-client ) 51 list(APPEND mytests http-client-warmcat) 52 endif() 53 54 55 add_test(NAME http-client-warmcat-h1 COMMAND lws-minimal-http-client --h1) 56 57 if (has_fault_injection) 58 59 # creation related faults 60 61 list(APPEND mytests http-client-fi-ctx1) 62 add_test(NAME http-client-fi-ctx1 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail1") 63 64 # if (has_plugins) 65 # !!! need to actually select an available evlib plugin to trigger this 66 # list(APPEND mytests http-client-fi-pi) 67 # add_test(NAME http-client-fi-pi COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_plugin_init") 68 # endif() 69 70 list(APPEND mytests http-client-fi-ctx2) 71 add_test(NAME http-client-fi-ctx2 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_evlib_sel") 72 73 list(APPEND mytests http-client-fi-ctx3) 74 add_test(NAME http-client-fi-ctx3 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_oom_ctx") 75 76 list(APPEND mytests http-client-fi-ctx4) 77 add_test(NAME http-client-fi-ctx4 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_privdrop") 78 79 list(APPEND mytests http-client-fi-ctx5) 80 add_test(NAME http-client-fi-ctx5 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_maxfds") 81 82 list(APPEND mytests http-client-fi-ctx6) 83 add_test(NAME http-client-fi-ctx6 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_oom_fds") 84 85 list(APPEND mytests http-client-fi-ctx7) 86 add_test(NAME http-client-fi-ctx7 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_plat_init") 87 88 list(APPEND mytests http-client-fi-ctx8) 89 add_test(NAME http-client-fi-ctx8 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_evlib_init") 90 91 list(APPEND mytests http-client-fi-ctx9) 92 add_test(NAME http-client-fi-ctx9 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_evlib_pt") 93 94 if (NOT has_no_system_vhost) 95 96 list(APPEND mytests http-client-fi-ctx10) 97 add_test(NAME http-client-fi-ctx10 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_sys_vh") 98 99 list(APPEND mytests http-client-fi-ctx11) 100 add_test(NAME http-client-fi-ctx11 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_sys_vh_init") 101 102 endif() 103 104 list(APPEND mytests http-client-fi-ctx12) 105 add_test(NAME http-client-fi-ctx12 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "ctx_createfail_def_vh") 106 107 108 list(APPEND mytests http-client-fi-vh1) 109 add_test(NAME http-client-fi-vh1 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "vh/vh_create_oom") 110 111 list(APPEND mytests http-client-fi-vh2) 112 add_test(NAME http-client-fi-vh2 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "vh/vh_create_pcols_oom") 113 114 list(APPEND mytests http-client-fi-vh3) 115 add_test(NAME http-client-fi-vh3 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "vh/vh_create_ssl_srv") 116 117 list(APPEND mytests http-client-fi-vh4) 118 add_test(NAME http-client-fi-vh4 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "vh/vh_create_ssl_cli") 119 120 list(APPEND mytests http-client-fi-vh5) 121 add_test(NAME http-client-fi-vh5 COMMAND lws-minimal-http-client --expected-exit 5 --fault-injection "vh/vh_create_srv_init") 122 123 124 list(APPEND mytests http-client-fi-dnsfail) 125 add_test(NAME http-client-fi-dnsfail COMMAND lws-minimal-http-client --expected-exit 3 --fault-injection "wsi=user/dnsfail") 126 127 if (has_async_dns) 128 list(APPEND mytests http-client-fi-connfail) 129 add_test(NAME http-client-fi-connfail COMMAND lws-minimal-http-client --expected-exit 2 --fault-injection "wsi=user/connfail") 130 else() 131 list(APPEND mytests http-client-fi-connfail) 132 add_test(NAME http-client-fi-connfail COMMAND lws-minimal-http-client --expected-exit 2 --fault-injection "wsi=user/connfail") 133 endif() 134 135 list(APPEND mytests http-client-fi-user-est-fail) 136 add_test(NAME http-client-fi-user-est-fail COMMAND lws-minimal-http-client --expected-exit 3 --fault-injection "wsi/user_reject_at_est") 137 138 endif() 139 if (has_mbedtls) 140 list(APPEND mytests http-client-mbedtls-wrong-ca) 141 add_test(NAME http-client-mbedtls-wrong-ca COMMAND lws-minimal-http-client -w --expected-exit 3) 142 message("... adding mbedtls wrong CA test") 143 else() 144 message("... skipping mbedtls wrong CA test") 145 endif() 146 147 set_tests_properties(${mytests} PROPERTIES 148 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client 149 TIMEOUT 20) 150 151 if (DEFINED ENV{SAI_OVN}) 152 set_tests_properties(${mytests} PROPERTIES 153 FIXTURES_REQUIRED "res_http_client_warmcat") 154 endif() 155 156 endif() 157 158 if (websockets_shared) 159 target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) 160 add_dependencies(${SAMP} websockets_shared) 161 else() 162 target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) 163 endif() 164endif() 165