check_discovery.c 22 KB

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