check_discovery.c 22 KB

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