1d4afb5ceSopenharmony_ci# If we are being built as part of lws, confirm current build config supports 2d4afb5ceSopenharmony_ci# reqconfig, else skip building ourselves. 3d4afb5ceSopenharmony_ci# 4d4afb5ceSopenharmony_ci# If we are being built externally, confirm installed lws was configured to 5d4afb5ceSopenharmony_ci# support reqconfig, else error out with a helpful message about the problem. 6d4afb5ceSopenharmony_ci# 7d4afb5ceSopenharmony_ci 8d4afb5ceSopenharmony_ciinclude(CheckIncludeFile) 9d4afb5ceSopenharmony_ci 10d4afb5ceSopenharmony_ciMACRO(require_lws_config reqconfig _val result) 11d4afb5ceSopenharmony_ci 12d4afb5ceSopenharmony_ci if (DEFINED ${reqconfig}) 13d4afb5ceSopenharmony_ci if (${reqconfig}) 14d4afb5ceSopenharmony_ci set (rq 1) 15d4afb5ceSopenharmony_ci else() 16d4afb5ceSopenharmony_ci set (rq 0) 17d4afb5ceSopenharmony_ci endif() 18d4afb5ceSopenharmony_ci else() 19d4afb5ceSopenharmony_ci set(rq 0) 20d4afb5ceSopenharmony_ci endif() 21d4afb5ceSopenharmony_ci 22d4afb5ceSopenharmony_ci if (${_val} EQUAL ${rq}) 23d4afb5ceSopenharmony_ci set(SAME 1) 24d4afb5ceSopenharmony_ci else() 25d4afb5ceSopenharmony_ci set(SAME 0) 26d4afb5ceSopenharmony_ci endif() 27d4afb5ceSopenharmony_ci 28d4afb5ceSopenharmony_ci string(COMPARE EQUAL "${result}" requirements _cmp) 29d4afb5ceSopenharmony_ci 30d4afb5ceSopenharmony_ci # we go in the first clause if in-tree 31d4afb5ceSopenharmony_ci if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) 32d4afb5ceSopenharmony_ci if (${_val}) 33d4afb5ceSopenharmony_ci message("${SAMP}: skipping as lws being built without ${reqconfig}") 34d4afb5ceSopenharmony_ci else() 35d4afb5ceSopenharmony_ci message("${SAMP}: skipping as lws built with ${reqconfig}") 36d4afb5ceSopenharmony_ci endif() 37d4afb5ceSopenharmony_ci set(${result} 0) 38d4afb5ceSopenharmony_ci else() 39d4afb5ceSopenharmony_ci if (LWS_WITH_MINIMAL_EXAMPLES) 40d4afb5ceSopenharmony_ci set(MET ${SAME}) 41d4afb5ceSopenharmony_ci else() 42d4afb5ceSopenharmony_ci CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) 43d4afb5ceSopenharmony_ci if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) 44d4afb5ceSopenharmony_ci set(HAS_${reqconfig} 0) 45d4afb5ceSopenharmony_ci else() 46d4afb5ceSopenharmony_ci set(HAS_${reqconfig} 1) 47d4afb5ceSopenharmony_ci endif() 48d4afb5ceSopenharmony_ci if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) 49d4afb5ceSopenharmony_ci set(MET 1) 50d4afb5ceSopenharmony_ci else() 51d4afb5ceSopenharmony_ci set(MET 0) 52d4afb5ceSopenharmony_ci endif() 53d4afb5ceSopenharmony_ci endif() 54d4afb5ceSopenharmony_ci if (NOT MET AND _cmp) 55d4afb5ceSopenharmony_ci if (${_val}) 56d4afb5ceSopenharmony_ci message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") 57d4afb5ceSopenharmony_ci else() 58d4afb5ceSopenharmony_ci message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") 59d4afb5ceSopenharmony_ci endif() 60d4afb5ceSopenharmony_ci endif() 61d4afb5ceSopenharmony_ci 62d4afb5ceSopenharmony_ci endif() 63d4afb5ceSopenharmony_ciENDMACRO() 64d4afb5ceSopenharmony_ci 65d4afb5ceSopenharmony_ciMACRO(require_pthreads result) 66d4afb5ceSopenharmony_ci CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) 67d4afb5ceSopenharmony_ci if (NOT LWS_HAVE_PTHREAD_H) 68d4afb5ceSopenharmony_ci if (LWS_WITH_MINIMAL_EXAMPLES) 69d4afb5ceSopenharmony_ci set(${result} 0) 70d4afb5ceSopenharmony_ci message("${SAMP}: skipping as no pthreads") 71d4afb5ceSopenharmony_ci else() 72d4afb5ceSopenharmony_ci message(FATAL_ERROR "threading support requires pthreads") 73d4afb5ceSopenharmony_ci endif() 74d4afb5ceSopenharmony_ci else() 75d4afb5ceSopenharmony_ci if (WIN32) 76d4afb5ceSopenharmony_ci set(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES}) 77d4afb5ceSopenharmony_ci else() 78d4afb5ceSopenharmony_ci if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "QNX") 79d4afb5ceSopenharmony_ci set(PTHREAD_LIB pthread) 80d4afb5ceSopenharmony_ci endif() 81d4afb5ceSopenharmony_ci endif() 82d4afb5ceSopenharmony_ci endif() 83d4afb5ceSopenharmony_ciENDMACRO() 84d4afb5ceSopenharmony_ci 85d4afb5ceSopenharmony_ciMACRO(sai_resource SR_NAME SR_AMOUNT SR_LEASE SR_SCOPE) 86d4afb5ceSopenharmony_ci if (DEFINED ENV{SAI_OVN}) 87d4afb5ceSopenharmony_ci 88d4afb5ceSopenharmony_ci site_name(HOST_NAME) 89d4afb5ceSopenharmony_ci 90d4afb5ceSopenharmony_ci # 91d4afb5ceSopenharmony_ci # Creates a "test" called res_${SR_SCOPE} that waits to be 92d4afb5ceSopenharmony_ci # given a lease on ${SR_AMOUNT} of a resource ${SR_NAME}, for at 93d4afb5ceSopenharmony_ci # most $SR_LEASE seconds, until the test dependent on it can 94d4afb5ceSopenharmony_ci # proceed. 95d4afb5ceSopenharmony_ci # 96d4afb5ceSopenharmony_ci # We need to keep this sai-resource instance up for the 97d4afb5ceSopenharmony_ci # duration of the actual test it is authorizing, when it 98d4afb5ceSopenharmony_ci # is killed, the resource is then immediately released. 99d4afb5ceSopenharmony_ci # 100d4afb5ceSopenharmony_ci # The resource cookie has to be globally unique within the 101d4afb5ceSopenharmony_ci # distributed builder sessions, so it includes the builder 102d4afb5ceSopenharmony_ci # hostname and builder instance information 103d4afb5ceSopenharmony_ci # 104d4afb5ceSopenharmony_ci 105d4afb5ceSopenharmony_ci add_test(NAME st_res_${SR_SCOPE} COMMAND 106d4afb5ceSopenharmony_ci ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh 107d4afb5ceSopenharmony_ci res_${SR_SCOPE} 108d4afb5ceSopenharmony_ci sai-resource ${SR_NAME} ${SR_AMOUNT} ${SR_LEASE} 109d4afb5ceSopenharmony_ci ${HOST_NAME}-res_${SR_SCOPE}-$ENV{SAI_PROJECT}-$ENV{SAI_OVN}) 110d4afb5ceSopenharmony_ci 111d4afb5ceSopenharmony_ci # allow it to wait for up to 100s for the resource lease 112d4afb5ceSopenharmony_ci 113d4afb5ceSopenharmony_ci set_tests_properties(st_res_${SR_SCOPE} PROPERTIES 114d4afb5ceSopenharmony_ci WORKING_DIRECTORY . 115d4afb5ceSopenharmony_ci FIXTURES_SETUP res_sspcmin 116d4afb5ceSopenharmony_ci TIMEOUT 100) 117d4afb5ceSopenharmony_ci 118d4afb5ceSopenharmony_ci add_test(NAME ki_res_${SR_SCOPE} COMMAND 119d4afb5ceSopenharmony_ci ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh 120d4afb5ceSopenharmony_ci res_${SR_SCOPE} sai-resource ) 121d4afb5ceSopenharmony_ci 122d4afb5ceSopenharmony_ci set_tests_properties(ki_res_${SR_SCOPE} PROPERTIES 123d4afb5ceSopenharmony_ci FIXTURES_CLEANUP res_${SR_SCOPE}) 124d4afb5ceSopenharmony_ci 125d4afb5ceSopenharmony_ci endif() 126d4afb5ceSopenharmony_ciENDMACRO() 127d4afb5ceSopenharmony_ci 128