check_discovery.c 22 KB

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