check_discovery.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef _XOPEN_SOURCE
  5. # define _XOPEN_SOURCE 500
  6. #endif
  7. #ifndef _DEFAULT_SOURCE
  8. # define _DEFAULT_SOURCE
  9. #endif
  10. // On older systems we need to define _BSD_SOURCE
  11. // _DEFAULT_SOURCE is an alias for that
  12. #ifndef _BSD_SOURCE
  13. # define _BSD_SOURCE
  14. #endif
  15. #include <stdio.h>
  16. #include <unistd.h>
  17. #include <pthread.h>
  18. #include <fcntl.h>
  19. #include <check.h>
  20. #include "server/ua_server_internal.h"
  21. #include "ua_client.h"
  22. #include "ua_config_default.h"
  23. #include "ua_network_tcp.h"
  24. #include "testing_clock.h"
  25. // set register timeout to 1 second so we are able to test it.
  26. #define registerTimeout 1
  27. // cleanup is only triggered every 10 seconds, thus wait a bit longer to check
  28. #define checkWait registerTimeout + 11
  29. UA_Server *server_lds;
  30. UA_ServerConfig *config_lds;
  31. UA_Boolean *running_lds;
  32. pthread_t server_thread_lds;
  33. static void * serverloop_lds(void *_) {
  34. while(*running_lds)
  35. UA_Server_run_iterate(server_lds, true);
  36. return NULL;
  37. }
  38. static void setup_lds(void) {
  39. // start LDS server
  40. running_lds = UA_Boolean_new();
  41. *running_lds = true;
  42. config_lds = UA_ServerConfig_new_default();
  43. config_lds->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
  44. UA_String_deleteMembers(&config_lds->applicationDescription.applicationUri);
  45. config_lds->applicationDescription.applicationUri =
  46. UA_STRING_ALLOC("urn:open62541.test.local_discovery_server");
  47. UA_LocalizedText_deleteMembers(&config_lds->applicationDescription.applicationName);
  48. config_lds->applicationDescription.applicationName
  49. = UA_LOCALIZEDTEXT_ALLOC("en", "LDS Server");
  50. config_lds->mdnsServerName = UA_String_fromChars("LDS_test");
  51. config_lds->serverCapabilitiesSize = 1;
  52. UA_String *caps = UA_String_new();
  53. *caps = UA_String_fromChars("LDS");
  54. config_lds->serverCapabilities = caps;
  55. config_lds->discoveryCleanupTimeout = registerTimeout;
  56. server_lds = UA_Server_new(config_lds);
  57. UA_Server_run_startup(server_lds);
  58. pthread_create(&server_thread_lds, NULL, serverloop_lds, NULL);
  59. // wait until LDS started
  60. UA_fakeSleep(1000);
  61. UA_realSleep(1000);
  62. }
  63. static void teardown_lds(void) {
  64. *running_lds = false;
  65. pthread_join(server_thread_lds, NULL);
  66. UA_Server_run_shutdown(server_lds);
  67. UA_Boolean_delete(running_lds);
  68. UA_Server_delete(server_lds);
  69. UA_ServerConfig_delete(config_lds);
  70. }
  71. UA_Server *server_register;
  72. UA_ServerConfig *config_register;
  73. UA_Boolean *running_register;
  74. pthread_t server_thread_register;
  75. UA_UInt64 periodicRegisterCallbackId;
  76. static void * serverloop_register(void *_) {
  77. while(*running_register)
  78. UA_Server_run_iterate(server_register, true);
  79. return NULL;
  80. }
  81. static void setup_register(void) {
  82. // start register server
  83. running_register = UA_Boolean_new();
  84. *running_register = true;
  85. config_register = UA_ServerConfig_new_minimal(16664, NULL);
  86. UA_String_deleteMembers(&config_register->applicationDescription.applicationUri);
  87. config_register->applicationDescription.applicationUri =
  88. UA_String_fromChars("urn:open62541.test.server_register");
  89. UA_LocalizedText_deleteMembers(&config_register->applicationDescription.applicationName);
  90. config_register->applicationDescription.applicationName =
  91. UA_LOCALIZEDTEXT_ALLOC("de", "Anmeldungsserver");
  92. config_register->mdnsServerName = UA_String_fromChars("Register_test");
  93. server_register = UA_Server_new(config_register);
  94. UA_Server_run_startup(server_register);
  95. pthread_create(&server_thread_register, NULL, serverloop_register, NULL);
  96. }
  97. static void teardown_register(void) {
  98. *running_register = false;
  99. pthread_join(server_thread_register, NULL);
  100. UA_Server_run_shutdown(server_register);
  101. UA_Boolean_delete(running_register);
  102. UA_Server_delete(server_register);
  103. UA_ServerConfig_delete(config_register);
  104. }
  105. START_TEST(Server_register) {
  106. UA_StatusCode retval =
  107. UA_Server_register_discovery(server_register, "opc.tcp://localhost:4840", NULL);
  108. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  109. }
  110. END_TEST
  111. START_TEST(Server_unregister) {
  112. UA_StatusCode retval =
  113. UA_Server_unregister_discovery(server_register, "opc.tcp://localhost:4840");
  114. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  115. }
  116. END_TEST
  117. START_TEST(Server_register_semaphore) {
  118. // create the semaphore
  119. int fd = open("/tmp/open62541-unit-test-semaphore", O_RDWR|O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
  120. ck_assert_int_ne(fd, -1);
  121. close(fd);
  122. UA_StatusCode retval =
  123. UA_Server_register_discovery(server_register, "opc.tcp://localhost:4840",
  124. "/tmp/open62541-unit-test-semaphore");
  125. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  126. }
  127. END_TEST
  128. START_TEST(Server_unregister_semaphore) {
  129. // delete the semaphore, this should remove the registration automatically on next check
  130. ck_assert_int_eq(remove("/tmp/open62541-unit-test-semaphore"), 0);
  131. }
  132. END_TEST
  133. START_TEST(Server_register_periodic) {
  134. // periodic register every minute, first register immediately
  135. UA_StatusCode retval =
  136. UA_Server_addPeriodicServerRegisterCallback(server_register, "opc.tcp://localhost:4840",
  137. 60*1000, 100, &periodicRegisterCallbackId);
  138. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  139. }
  140. END_TEST
  141. START_TEST(Server_unregister_periodic) {
  142. // wait for first register delay
  143. UA_fakeSleep(1000);
  144. UA_realSleep(1000);
  145. UA_Server_removeRepeatedCallback(server_register, periodicRegisterCallbackId);
  146. UA_StatusCode retval = UA_Server_unregister_discovery(server_register,
  147. "opc.tcp://localhost:4840");
  148. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  149. }
  150. END_TEST
  151. static void
  152. FindAndCheck(const UA_String expectedUris[], size_t expectedUrisSize,
  153. const UA_String expectedLocales[],
  154. const UA_String expectedNames[],
  155. const char *filterUri,
  156. const char *filterLocale) {
  157. UA_Client *client = UA_Client_new(UA_ClientConfig_default);
  158. UA_ApplicationDescription* applicationDescriptionArray = NULL;
  159. size_t applicationDescriptionArraySize = 0;
  160. size_t serverUrisSize = 0;
  161. UA_String *serverUris = NULL;
  162. if(filterUri) {
  163. serverUrisSize = 1;
  164. serverUris = UA_String_new();
  165. serverUris[0] = UA_String_fromChars(filterUri);
  166. }
  167. size_t localeIdsSize = 0;
  168. UA_String *localeIds = NULL;
  169. if(filterLocale) {
  170. localeIdsSize = 1;
  171. localeIds = UA_String_new();
  172. localeIds[0] = UA_String_fromChars(filterLocale);
  173. }
  174. UA_StatusCode retval =
  175. UA_Client_findServers(client, "opc.tcp://localhost:4840",
  176. serverUrisSize, serverUris, localeIdsSize, localeIds,
  177. &applicationDescriptionArraySize, &applicationDescriptionArray);
  178. if(filterUri)
  179. UA_Array_delete(serverUris, serverUrisSize, &UA_TYPES[UA_TYPES_STRING]);
  180. if(filterLocale)
  181. UA_Array_delete(localeIds, localeIdsSize, &UA_TYPES[UA_TYPES_STRING]);
  182. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  183. // only the discovery server is expected
  184. ck_assert_uint_eq(applicationDescriptionArraySize, expectedUrisSize);
  185. ck_assert(applicationDescriptionArray != NULL);
  186. for(size_t i = 0; i < expectedUrisSize; ++i) {
  187. ck_assert(UA_String_equal(&applicationDescriptionArray[i].applicationUri,
  188. &expectedUris[i]));
  189. if(expectedNames)
  190. ck_assert(UA_String_equal(&applicationDescriptionArray[i].applicationName.text,
  191. &expectedNames[i]));
  192. if (expectedLocales)
  193. ck_assert(UA_String_equal(&applicationDescriptionArray[i].applicationName.locale,
  194. &expectedLocales[i]));
  195. }
  196. UA_Array_delete(applicationDescriptionArray, applicationDescriptionArraySize,
  197. &UA_TYPES[UA_TYPES_APPLICATIONDESCRIPTION]);
  198. UA_Client_disconnect(client);
  199. UA_Client_delete(client);
  200. }
  201. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  202. static void
  203. FindOnNetworkAndCheck(UA_String expectedServerNames[], size_t expectedServerNamesSize,
  204. const char *filterUri, const char *filterLocale,
  205. const char** filterCapabilities, size_t filterCapabilitiesSize) {
  206. UA_Client *client = UA_Client_new(UA_ClientConfig_default);
  207. UA_ServerOnNetwork* serverOnNetwork = NULL;
  208. size_t serverOnNetworkSize = 0;
  209. size_t serverCapabilityFilterSize = 0;
  210. UA_String *serverCapabilityFilter = NULL;
  211. if(filterCapabilitiesSize) {
  212. serverCapabilityFilterSize = filterCapabilitiesSize;
  213. serverCapabilityFilter = (UA_String*)UA_malloc(sizeof(UA_String) * filterCapabilitiesSize);
  214. for(size_t i = 0; i < filterCapabilitiesSize; i++)
  215. serverCapabilityFilter[i] = UA_String_fromChars(filterCapabilities[i]);
  216. }
  217. UA_StatusCode retval =
  218. UA_Client_findServersOnNetwork(client, "opc.tcp://localhost:4840", 0, 0,
  219. serverCapabilityFilterSize, serverCapabilityFilter,
  220. &serverOnNetworkSize, &serverOnNetwork);
  221. if(serverCapabilityFilterSize)
  222. UA_Array_delete(serverCapabilityFilter, serverCapabilityFilterSize,
  223. &UA_TYPES[UA_TYPES_STRING]);
  224. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  225. // only the discovery server is expected
  226. ck_assert_uint_eq(serverOnNetworkSize , expectedServerNamesSize);
  227. if(expectedServerNamesSize > 0)
  228. ck_assert_ptr_ne(serverOnNetwork, NULL);
  229. if(serverOnNetwork != NULL) {
  230. for(size_t i = 0; i < expectedServerNamesSize; i++)
  231. ck_assert(UA_String_equal(&serverOnNetwork[i].serverName,
  232. &expectedServerNames[i]));
  233. }
  234. UA_Array_delete(serverOnNetwork, serverOnNetworkSize, &UA_TYPES[UA_TYPES_SERVERONNETWORK]);
  235. UA_Client_disconnect(client);
  236. UA_Client_delete(client);
  237. }
  238. static UA_StatusCode
  239. GetEndpoints(UA_Client *client, const UA_String* endpointUrl,
  240. size_t* endpointDescriptionsSize,
  241. UA_EndpointDescription** endpointDescriptions,
  242. const char* filterTransportProfileUri) {
  243. UA_GetEndpointsRequest request;
  244. UA_GetEndpointsRequest_init(&request);
  245. //request.requestHeader.authenticationToken = client->authenticationToken;
  246. request.requestHeader.timestamp = UA_DateTime_now();
  247. request.requestHeader.timeoutHint = 10000;
  248. request.endpointUrl = *endpointUrl; // assume the endpointurl outlives the service call
  249. if (filterTransportProfileUri) {
  250. request.profileUrisSize = 1;
  251. request.profileUris = (UA_String*)UA_malloc(sizeof(UA_String));
  252. request.profileUris[0] = UA_String_fromChars(filterTransportProfileUri);
  253. }
  254. UA_GetEndpointsResponse response;
  255. UA_GetEndpointsResponse_init(&response);
  256. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_GETENDPOINTSREQUEST],
  257. &response, &UA_TYPES[UA_TYPES_GETENDPOINTSRESPONSE]);
  258. if (filterTransportProfileUri) {
  259. UA_Array_delete(request.profileUris, request.profileUrisSize, &UA_TYPES[UA_TYPES_STRING]);
  260. }
  261. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  262. *endpointDescriptionsSize = response.endpointsSize;
  263. *endpointDescriptions =
  264. (UA_EndpointDescription*)UA_Array_new(response.endpointsSize,
  265. &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
  266. for(size_t i=0;i<response.endpointsSize;i++) {
  267. UA_EndpointDescription_init(&(*endpointDescriptions)[i]);
  268. UA_EndpointDescription_copy(&response.endpoints[i], &(*endpointDescriptions)[i]);
  269. }
  270. UA_GetEndpointsResponse_deleteMembers(&response);
  271. return UA_STATUSCODE_GOOD;
  272. }
  273. static void
  274. GetEndpointsAndCheck(const char* discoveryUrl, const char* filterTransportProfileUri,
  275. const UA_String expectedEndpointUrls[], size_t expectedEndpointUrlsSize) {
  276. UA_Client *client = UA_Client_new(UA_ClientConfig_default);
  277. ck_assert_uint_eq(UA_Client_connect(client, discoveryUrl), UA_STATUSCODE_GOOD);
  278. UA_EndpointDescription* endpointArray = NULL;
  279. size_t endpointArraySize = 0;
  280. UA_String discoveryUrlUA = UA_String_fromChars(discoveryUrl);
  281. UA_StatusCode retval = GetEndpoints(client, &discoveryUrlUA, &endpointArraySize,
  282. &endpointArray, filterTransportProfileUri);
  283. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  284. UA_String_deleteMembers(&discoveryUrlUA);
  285. ck_assert_uint_eq(endpointArraySize , expectedEndpointUrlsSize);
  286. for(size_t j = 0; j < endpointArraySize && j < expectedEndpointUrlsSize; j++) {
  287. UA_EndpointDescription* endpoint = &endpointArray[j];
  288. ck_assert(UA_String_equal(&endpoint->endpointUrl, &expectedEndpointUrls[j]));
  289. }
  290. UA_Array_delete(endpointArray, endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
  291. UA_Client_delete(client);
  292. }
  293. // Test if discovery server lists himself as registered server if it is filtered by his uri
  294. START_TEST(Client_filter_discovery) {
  295. const UA_String expectedUris[] = {UA_STRING("urn:open62541.test.local_discovery_server")};
  296. FindAndCheck(expectedUris, 1, NULL, NULL, "urn:open62541.test.local_discovery_server", NULL);
  297. }
  298. END_TEST
  299. // Test if server filters locale
  300. START_TEST(Client_filter_locale) {
  301. const UA_String expectedUris[] = {
  302. UA_STRING("urn:open62541.test.local_discovery_server"),
  303. UA_STRING("urn:open62541.test.server_register")
  304. };
  305. const UA_String expectedNames[] = {
  306. UA_STRING("LDS Server"),
  307. UA_STRING("Anmeldungsserver")
  308. };
  309. const UA_String expectedLocales[] = {UA_STRING("en"), UA_STRING("de")};
  310. // even if we request en-US, the server will return de-DE because it only has that name.
  311. FindAndCheck(expectedUris, 2, expectedLocales, expectedNames, NULL, "en");
  312. }
  313. END_TEST
  314. // Test if registered server is returned from LDS using FindServersOnNetwork
  315. START_TEST(Client_find_on_network_registered) {
  316. char urls[2][64];
  317. UA_String expectedUris[2];
  318. char hostname[256];
  319. ck_assert_uint_eq(gethostname(hostname, 255), 0);
  320. //DNS limits name to max 63 chars (+ \0)
  321. snprintf(urls[0], 64, "LDS_test-%s", hostname);
  322. snprintf(urls[1], 64, "Register_test-%s", hostname);
  323. expectedUris[0] = UA_STRING(urls[0]);
  324. expectedUris[1] = UA_STRING(urls[1]);
  325. FindOnNetworkAndCheck(expectedUris, 2, NULL, NULL, NULL, 0);
  326. // filter by Capabilities
  327. const char* capsLDS[] = {"LDS"};
  328. const char* capsNA[] = {"NA"};
  329. const char* capsMultiple[] = {"LDS", "NA"};
  330. // only LDS expected
  331. FindOnNetworkAndCheck(expectedUris, 1, NULL, NULL, capsLDS, 1);
  332. // only register server expected
  333. FindOnNetworkAndCheck(&expectedUris[1], 1, NULL, NULL, capsNA, 1);
  334. // no server expected
  335. FindOnNetworkAndCheck(NULL, 0, NULL, NULL, capsMultiple, 2);
  336. }
  337. END_TEST
  338. // Test if filtering with uris works
  339. START_TEST(Client_find_filter) {
  340. const UA_String expectedUris[] = {
  341. UA_STRING("urn:open62541.test.server_register")
  342. };
  343. FindAndCheck(expectedUris, 1, NULL, NULL, "urn:open62541.test.server_register", NULL);
  344. }
  345. END_TEST
  346. START_TEST(Client_get_endpoints) {
  347. const UA_String expectedEndpoints[] ={
  348. UA_STRING("opc.tcp://localhost:4840")
  349. };
  350. // general check if expected endpoints are returned
  351. GetEndpointsAndCheck("opc.tcp://localhost:4840", NULL,expectedEndpoints, 1);
  352. // check if filtering transport profile still returns the endpoint
  353. GetEndpointsAndCheck("opc.tcp://localhost:4840",
  354. "http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary",
  355. expectedEndpoints, 1);
  356. // filter transport profily by HTTPS, which should return no endpoint
  357. GetEndpointsAndCheck("opc.tcp://localhost:4840",
  358. "http://opcfoundation.org/UA-Profile/Transport/https-uabinary", NULL, 0);
  359. }
  360. END_TEST
  361. #endif
  362. // Test if discovery server lists himself as registered server, before any other registration.
  363. START_TEST(Client_find_discovery) {
  364. const UA_String expectedUris[] = {UA_STRING("urn:open62541.test.local_discovery_server")};
  365. FindAndCheck(expectedUris, 1, NULL, NULL, NULL, NULL);
  366. }
  367. END_TEST
  368. // Test if registered server is returned from LDS
  369. START_TEST(Client_find_registered) {
  370. const UA_String expectedUris[2] = {
  371. UA_STRING("urn:open62541.test.local_discovery_server"),
  372. UA_STRING("urn:open62541.test.server_register")
  373. };
  374. FindAndCheck(expectedUris, 2, NULL, NULL, NULL, NULL);
  375. }
  376. END_TEST
  377. START_TEST(Util_start_lds) {
  378. setup_lds();
  379. }
  380. END_TEST
  381. START_TEST(Util_stop_lds) {
  382. teardown_lds();
  383. }
  384. END_TEST
  385. START_TEST(Util_wait_timeout) {
  386. // wait until server is removed by timeout. Additionally wait a few seconds more to be sure.
  387. UA_fakeSleep(100000 * checkWait);
  388. UA_realSleep(1000);
  389. }
  390. END_TEST
  391. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  392. START_TEST(Util_wait_mdns) {
  393. UA_fakeSleep(1000);
  394. UA_realSleep(1000);
  395. }
  396. END_TEST
  397. #endif
  398. START_TEST(Util_wait_startup) {
  399. UA_fakeSleep(1000);
  400. UA_realSleep(1000);
  401. }
  402. END_TEST
  403. START_TEST(Util_wait_retry) {
  404. // first retry is after 2 seconds, then 4, so it should be enough to wait 3 seconds
  405. UA_fakeSleep(3000);
  406. UA_realSleep(3000);
  407. }
  408. END_TEST
  409. static Suite* testSuite_Client(void) {
  410. Suite *s = suite_create("Register Server and Client");
  411. TCase *tc_register = tcase_create("RegisterServer");
  412. tcase_add_unchecked_fixture(tc_register, setup_lds, teardown_lds);
  413. tcase_add_unchecked_fixture(tc_register, setup_register, teardown_register);
  414. tcase_add_test(tc_register, Server_register);
  415. // register two times, just for fun
  416. tcase_add_test(tc_register, Server_register);
  417. tcase_add_test(tc_register, Server_unregister);
  418. tcase_add_test(tc_register, Server_register_periodic);
  419. tcase_add_test(tc_register, Server_unregister_periodic);
  420. suite_add_tcase(s,tc_register);
  421. TCase *tc_register_retry = tcase_create("RegisterServer Retry");
  422. //tcase_add_unchecked_fixture(tc_register, setup_lds, teardown_lds);
  423. tcase_add_unchecked_fixture(tc_register_retry, setup_register, teardown_register);
  424. tcase_add_test(tc_register_retry, Server_register_periodic);
  425. tcase_add_test(tc_register_retry, Util_wait_startup); // wait a bit to let first try run through
  426. // now start LDS
  427. tcase_add_test(tc_register_retry, Util_start_lds);
  428. tcase_add_test(tc_register_retry, Util_wait_retry);
  429. // check if there
  430. tcase_add_test(tc_register_retry, Client_find_registered);
  431. tcase_add_test(tc_register_retry, Server_unregister_periodic);
  432. tcase_add_test(tc_register_retry, Client_find_discovery);
  433. tcase_add_test(tc_register_retry, Util_stop_lds);
  434. suite_add_tcase(s,tc_register_retry);
  435. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  436. TCase *tc_register_find = tcase_create("RegisterServer and FindServers");
  437. tcase_add_unchecked_fixture(tc_register_find, setup_lds, teardown_lds);
  438. tcase_add_unchecked_fixture(tc_register_find, setup_register, teardown_register);
  439. tcase_add_test(tc_register_find, Client_find_discovery);
  440. tcase_add_test(tc_register_find, Server_register);
  441. tcase_add_test(tc_register_find, Client_find_registered);
  442. tcase_add_test(tc_register_find, Util_wait_mdns);
  443. tcase_add_test(tc_register_find, Client_find_on_network_registered);
  444. tcase_add_test(tc_register_find, Client_find_filter);
  445. tcase_add_test(tc_register_find, Client_get_endpoints);
  446. tcase_add_test(tc_register_find, Client_filter_locale);
  447. tcase_add_test(tc_register_find, Server_unregister);
  448. tcase_add_test(tc_register_find, Client_find_discovery);
  449. tcase_add_test(tc_register_find, Client_filter_discovery);
  450. suite_add_tcase(s,tc_register_find);
  451. #endif
  452. // register server again, then wait for timeout and auto unregister
  453. TCase *tc_register_timeout = tcase_create("RegisterServer timeout");
  454. tcase_add_unchecked_fixture(tc_register_timeout, setup_lds, teardown_lds);
  455. tcase_add_unchecked_fixture(tc_register_timeout, setup_register, teardown_register);
  456. tcase_set_timeout(tc_register_timeout, checkWait+2);
  457. tcase_add_test(tc_register_timeout, Server_register);
  458. tcase_add_test(tc_register_timeout, Client_find_registered);
  459. tcase_add_test(tc_register_timeout, Util_wait_timeout);
  460. tcase_add_test(tc_register_timeout, Client_find_discovery);
  461. #ifdef UA_ENABLE_DISCOVERY_SEMAPHORE
  462. // now check if semaphore file works
  463. tcase_add_test(tc_register_timeout, Server_register_semaphore);
  464. tcase_add_test(tc_register_timeout, Client_find_registered);
  465. tcase_add_test(tc_register_timeout, Server_unregister_semaphore);
  466. tcase_add_test(tc_register_timeout, Util_wait_timeout);
  467. tcase_add_test(tc_register_timeout, Client_find_discovery);
  468. #endif
  469. suite_add_tcase(s,tc_register_timeout);
  470. return s;
  471. }
  472. int main(void) {
  473. Suite *s = testSuite_Client();
  474. SRunner *sr = srunner_create(s);
  475. srunner_set_fork_status(sr, CK_NOFORK);
  476. srunner_run_all(sr,CK_NORMAL);
  477. int number_failed = srunner_ntests_failed(sr);
  478. srunner_free(sr);
  479. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  480. }