check_discovery.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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_malloc(sizeof(UA_String));
  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_malloc(sizeof(UA_String));
  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. static void
  217. FindOnNetworkAndCheck(UA_String expectedServerNames[], size_t expectedServerNamesSize,
  218. const char *filterUri, const char *filterLocale,
  219. const char** filterCapabilities, size_t filterCapabilitiesSize) {
  220. UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
  221. UA_ServerOnNetwork* serverOnNetwork = NULL;
  222. size_t serverOnNetworkSize = 0;
  223. size_t serverCapabilityFilterSize = 0;
  224. UA_String *serverCapabilityFilter = NULL;
  225. if(filterCapabilitiesSize) {
  226. serverCapabilityFilterSize = filterCapabilitiesSize;
  227. serverCapabilityFilter = UA_malloc(sizeof(UA_String) * filterCapabilitiesSize);
  228. for(size_t i = 0; i < filterCapabilitiesSize; i++)
  229. serverCapabilityFilter[i] = UA_String_fromChars(filterCapabilities[i]);
  230. }
  231. UA_StatusCode retval =
  232. UA_Client_findServersOnNetwork(client, "opc.tcp://localhost:4840", 0, 0,
  233. serverCapabilityFilterSize, serverCapabilityFilter,
  234. &serverOnNetworkSize, &serverOnNetwork);
  235. if(serverCapabilityFilterSize)
  236. UA_Array_delete(serverCapabilityFilter, serverCapabilityFilterSize,
  237. &UA_TYPES[UA_TYPES_STRING]);
  238. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  239. // only the discovery server is expected
  240. ck_assert_uint_eq(serverOnNetworkSize , expectedServerNamesSize);
  241. if(expectedServerNamesSize > 0)
  242. ck_assert_ptr_ne(serverOnNetwork, NULL);
  243. if(serverOnNetwork != NULL) {
  244. for(size_t i = 0; i < expectedServerNamesSize; i++)
  245. ck_assert(UA_String_equal(&serverOnNetwork[i].serverName,
  246. &expectedServerNames[i]));
  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
  253. GetEndpoints(UA_Client *client, const UA_String* endpointUrl,
  254. size_t* endpointDescriptionsSize,
  255. UA_EndpointDescription** endpointDescriptions,
  256. const char* filterTransportProfileUri) {
  257. UA_GetEndpointsRequest request;
  258. UA_GetEndpointsRequest_init(&request);
  259. //request.requestHeader.authenticationToken = client->authenticationToken;
  260. request.requestHeader.timestamp = UA_DateTime_now();
  261. request.requestHeader.timeoutHint = 10000;
  262. request.endpointUrl = *endpointUrl; // assume the endpointurl outlives the service call
  263. if (filterTransportProfileUri) {
  264. request.profileUrisSize = 1;
  265. request.profileUris = UA_malloc(sizeof(UA_String));
  266. request.profileUris[0] = UA_String_fromChars(filterTransportProfileUri);
  267. }
  268. UA_GetEndpointsResponse response;
  269. UA_GetEndpointsResponse_init(&response);
  270. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_GETENDPOINTSREQUEST],
  271. &response, &UA_TYPES[UA_TYPES_GETENDPOINTSRESPONSE]);
  272. if (filterTransportProfileUri) {
  273. UA_Array_delete(request.profileUris, request.profileUrisSize, &UA_TYPES[UA_TYPES_STRING]);
  274. }
  275. ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
  276. *endpointDescriptionsSize = response.endpointsSize;
  277. *endpointDescriptions =
  278. (UA_EndpointDescription*)UA_Array_new(response.endpointsSize,
  279. &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
  280. for(size_t i=0;i<response.endpointsSize;i++) {
  281. UA_EndpointDescription_init(&(*endpointDescriptions)[i]);
  282. UA_EndpointDescription_copy(&response.endpoints[i], &(*endpointDescriptions)[i]);
  283. }
  284. UA_GetEndpointsResponse_deleteMembers(&response);
  285. return UA_STATUSCODE_GOOD;
  286. }
  287. static void
  288. GetEndpointsAndCheck(const char* discoveryUrl, const char* filterTransportProfileUri,
  289. const UA_String expectedEndpointUrls[], size_t expectedEndpointUrlsSize) {
  290. UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
  291. ck_assert_uint_eq(UA_Client_connect(client, discoveryUrl), UA_STATUSCODE_GOOD);
  292. UA_EndpointDescription* endpointArray = NULL;
  293. size_t endpointArraySize = 0;
  294. UA_String discoveryUrlUA = UA_String_fromChars(discoveryUrl);
  295. UA_StatusCode retval = GetEndpoints(client, &discoveryUrlUA, &endpointArraySize,
  296. &endpointArray, filterTransportProfileUri);
  297. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  298. UA_String_deleteMembers(&discoveryUrlUA);
  299. ck_assert_uint_eq(endpointArraySize , expectedEndpointUrlsSize);
  300. for(size_t j = 0; j < endpointArraySize && j < expectedEndpointUrlsSize; j++) {
  301. UA_EndpointDescription* endpoint = &endpointArray[j];
  302. ck_assert(UA_String_equal(&endpoint->endpointUrl, &expectedEndpointUrls[j]));
  303. }
  304. UA_Array_delete(endpointArray, endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
  305. UA_Client_delete(client);
  306. }
  307. // Test if discovery server lists himself as registered server, before any other registration.
  308. START_TEST(Client_find_discovery) {
  309. const UA_String expectedUris[] = {UA_STRING("urn:open62541.test.local_discovery_server")};
  310. FindAndCheck(expectedUris, 1, NULL, NULL, NULL, NULL);
  311. }
  312. END_TEST
  313. // Test if discovery server lists himself as registered server if it is filtered by his uri
  314. START_TEST(Client_filter_discovery) {
  315. const UA_String expectedUris[] = {UA_STRING("urn:open62541.test.local_discovery_server")};
  316. FindAndCheck(expectedUris, 1, NULL, NULL, "urn:open62541.test.local_discovery_server", NULL);
  317. }
  318. END_TEST
  319. // Test if server filters locale
  320. START_TEST(Client_filter_locale) {
  321. const UA_String expectedUris[] = {
  322. UA_STRING("urn:open62541.test.local_discovery_server"),
  323. UA_STRING("urn:open62541.test.server_register")
  324. };
  325. const UA_String expectedNames[] = {
  326. UA_STRING("LDS Server"),
  327. UA_STRING("Anmeldungsserver")
  328. };
  329. const UA_String expectedLocales[] = {UA_STRING("en"), UA_STRING("de")};
  330. // even if we request en_US, the server will return de_DE because it only has that name.
  331. FindAndCheck(expectedUris, 2, expectedLocales, expectedNames, NULL, "en");
  332. }
  333. END_TEST
  334. // Test if registered server is returned from LDS
  335. START_TEST(Client_find_registered) {
  336. const UA_String expectedUris[] = {
  337. UA_STRING("urn:open62541.test.local_discovery_server"),
  338. UA_STRING("urn:open62541.test.server_register")
  339. };
  340. FindAndCheck(expectedUris, 2, NULL, NULL, NULL, NULL);
  341. }
  342. END_TEST
  343. // Test if registered server is returned from LDS using FindServersOnNetwork
  344. START_TEST(Client_find_on_network_registered) {
  345. char urls[2][64];
  346. UA_String expectedUris[2];
  347. char hostname[256];
  348. ck_assert_uint_eq(gethostname(hostname, 255), 0);
  349. //DNS limits name to max 63 chars (+ \0)
  350. snprintf(urls[0], 64, "LDS_test-%s", hostname);
  351. snprintf(urls[1], 64, "Register_test-%s", hostname);
  352. expectedUris[0] = UA_STRING(urls[0]);
  353. expectedUris[1] = UA_STRING(urls[1]);
  354. FindOnNetworkAndCheck(expectedUris, 2, NULL, NULL, NULL, 0);
  355. // filter by Capabilities
  356. const char* capsLDS[] = {"LDS"};
  357. const char* capsNA[] = {"NA"};
  358. const char* capsMultiple[] = {"LDS", "NA"};
  359. // only LDS expected
  360. FindOnNetworkAndCheck(expectedUris, 1, NULL, NULL, capsLDS, 1);
  361. // only register server expected
  362. FindOnNetworkAndCheck(&expectedUris[1], 1, NULL, NULL, capsNA, 1);
  363. // no server expected
  364. FindOnNetworkAndCheck(NULL, 0, NULL, NULL, capsMultiple, 2);
  365. }
  366. END_TEST
  367. // Test if filtering with uris works
  368. START_TEST(Client_find_filter) {
  369. const UA_String expectedUris[] = {
  370. UA_STRING("urn:open62541.test.server_register")
  371. };
  372. FindAndCheck(expectedUris, 1, NULL, NULL, "urn:open62541.test.server_register", NULL);
  373. }
  374. END_TEST
  375. START_TEST(Client_get_endpoints) {
  376. const UA_String expectedEndpoints[] ={
  377. UA_STRING("opc.tcp://localhost:4840")
  378. };
  379. // general check if expected endpoints are returned
  380. GetEndpointsAndCheck("opc.tcp://localhost:4840", NULL,expectedEndpoints, 1);
  381. // check if filtering transport profile still returns the endpoint
  382. GetEndpointsAndCheck("opc.tcp://localhost:4840",
  383. "http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary",
  384. expectedEndpoints, 1);
  385. // filter transport profily by HTTPS, which should return no endpoint
  386. GetEndpointsAndCheck("opc.tcp://localhost:4840",
  387. "http://opcfoundation.org/UA-Profile/Transport/https-uabinary", NULL, 0);
  388. }
  389. END_TEST
  390. START_TEST(Util_start_lds) {
  391. setup_lds();
  392. }
  393. END_TEST
  394. START_TEST(Util_stop_lds) {
  395. teardown_lds();
  396. }
  397. END_TEST
  398. START_TEST(Util_wait_timeout) {
  399. // wait until server is removed by timeout. Additionally wait a few seconds more to be sure.
  400. UA_sleep(100000 * checkWait);
  401. sleep(1);
  402. }
  403. END_TEST
  404. START_TEST(Util_wait_mdns) {
  405. UA_sleep(1000);
  406. sleep(1);
  407. }
  408. END_TEST
  409. START_TEST(Util_wait_startup) {
  410. UA_sleep(1000);
  411. sleep(1);
  412. }
  413. END_TEST
  414. START_TEST(Util_wait_retry) {
  415. // first retry is after 2 seconds, then 4, so it should be enough to wait 3 seconds
  416. UA_sleep(3000);
  417. sleep(3);
  418. }
  419. END_TEST
  420. static Suite* testSuite_Client(void) {
  421. Suite *s = suite_create("Register Server and Client");
  422. TCase *tc_register = tcase_create("RegisterServer");
  423. tcase_add_unchecked_fixture(tc_register, setup_lds, teardown_lds);
  424. tcase_add_unchecked_fixture(tc_register, setup_register, teardown_register);
  425. tcase_add_test(tc_register, Server_register);
  426. // register two times, just for fun
  427. tcase_add_test(tc_register, Server_register);
  428. tcase_add_test(tc_register, Server_unregister);
  429. tcase_add_test(tc_register, Server_register_periodic);
  430. tcase_add_test(tc_register, Server_unregister_periodic);
  431. suite_add_tcase(s,tc_register);
  432. TCase *tc_register_retry = tcase_create("RegisterServer Retry");
  433. //tcase_add_unchecked_fixture(tc_register, setup_lds, teardown_lds);
  434. tcase_add_unchecked_fixture(tc_register_retry, setup_register, teardown_register);
  435. tcase_add_test(tc_register_retry, Server_register_periodic);
  436. tcase_add_test(tc_register_retry, Util_wait_startup); // wait a bit to let first try run through
  437. // now start LDS
  438. tcase_add_test(tc_register_retry, Util_start_lds);
  439. tcase_add_test(tc_register_retry, Util_wait_retry);
  440. // check if there
  441. tcase_add_test(tc_register_retry, Client_find_registered);
  442. tcase_add_test(tc_register_retry, Server_unregister_periodic);
  443. tcase_add_test(tc_register_retry, Client_find_discovery);
  444. tcase_add_test(tc_register_retry, Util_stop_lds);
  445. suite_add_tcase(s,tc_register_retry);
  446. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  447. TCase *tc_register_find = tcase_create("RegisterServer and FindServers");
  448. tcase_add_unchecked_fixture(tc_register_find, setup_lds, teardown_lds);
  449. tcase_add_unchecked_fixture(tc_register_find, setup_register, teardown_register);
  450. tcase_add_test(tc_register_find, Client_find_discovery);
  451. tcase_add_test(tc_register_find, Server_register);
  452. tcase_add_test(tc_register_find, Client_find_registered);
  453. tcase_add_test(tc_register_find, Util_wait_mdns);
  454. tcase_add_test(tc_register_find, Client_find_on_network_registered);
  455. tcase_add_test(tc_register_find, Client_find_filter);
  456. tcase_add_test(tc_register_find, Client_get_endpoints);
  457. tcase_add_test(tc_register_find, Client_filter_locale);
  458. tcase_add_test(tc_register_find, Server_unregister);
  459. tcase_add_test(tc_register_find, Client_find_discovery);
  460. tcase_add_test(tc_register_find, Client_filter_discovery);
  461. suite_add_tcase(s,tc_register_find);
  462. #endif
  463. // register server again, then wait for timeout and auto unregister
  464. TCase *tc_register_timeout = tcase_create("RegisterServer timeout");
  465. tcase_add_unchecked_fixture(tc_register_timeout, setup_lds, teardown_lds);
  466. tcase_add_unchecked_fixture(tc_register_timeout, setup_register, teardown_register);
  467. tcase_set_timeout(tc_register_timeout, checkWait+2);
  468. tcase_add_test(tc_register_timeout, Server_register);
  469. tcase_add_test(tc_register_timeout, Client_find_registered);
  470. tcase_add_test(tc_register_timeout, Util_wait_timeout);
  471. tcase_add_test(tc_register_timeout, Client_find_discovery);
  472. #ifdef UA_ENABLE_DISCOVERY_SEMAPHORE
  473. // now check if semaphore file works
  474. tcase_add_test(tc_register_timeout, Server_register_semaphore);
  475. tcase_add_test(tc_register_timeout, Client_find_registered);
  476. tcase_add_test(tc_register_timeout, Server_unregister_semaphore);
  477. tcase_add_test(tc_register_timeout, Util_wait_timeout);
  478. tcase_add_test(tc_register_timeout, Client_find_discovery);
  479. #endif
  480. suite_add_tcase(s,tc_register_timeout);
  481. return s;
  482. }
  483. int main(void) {
  484. Suite *s = testSuite_Client();
  485. SRunner *sr = srunner_create(s);
  486. srunner_set_fork_status(sr, CK_NOFORK);
  487. srunner_run_all(sr,CK_NORMAL);
  488. int number_failed = srunner_ntests_failed(sr);
  489. srunner_free(sr);
  490. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  491. }