check_discovery.c 21 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. #if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
  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 <fcntl.h>
  17. #include <check.h>
  18. #ifndef _WIN32
  19. #include <unistd.h>
  20. #endif
  21. #include "server/ua_server_internal.h"
  22. #include "ua_client.h"
  23. #include "ua_config_default.h"
  24. #include "ua_network_tcp.h"
  25. #include "testing_clock.h"
  26. #include "thread_wrapper.h"
  27. // set register timeout to 1 second so we are able to test it.
  28. #define registerTimeout 1
  29. // cleanup is only triggered every 10 seconds, thus wait a bit longer to check
  30. #define checkWait registerTimeout + 11
  31. UA_Server *server_lds;
  32. UA_ServerConfig *config_lds;
  33. UA_Boolean *running_lds;
  34. THREAD_HANDLE server_thread_lds;
  35. THREAD_CALLBACK(serverloop_lds) {
  36. while(*running_lds)
  37. UA_Server_run_iterate(server_lds, true);
  38. return 0;
  39. }
  40. static void setup_lds(void) {
  41. // start LDS server
  42. running_lds = UA_Boolean_new();
  43. *running_lds = true;
  44. config_lds = UA_ServerConfig_new_default();
  45. config_lds->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
  46. UA_String_deleteMembers(&config_lds->applicationDescription.applicationUri);
  47. config_lds->applicationDescription.applicationUri =
  48. UA_STRING_ALLOC("urn:open62541.test.local_discovery_server");
  49. UA_LocalizedText_deleteMembers(&config_lds->applicationDescription.applicationName);
  50. config_lds->applicationDescription.applicationName
  51. = UA_LOCALIZEDTEXT_ALLOC("en", "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. server_lds = UA_Server_new(config_lds);
  59. UA_Server_run_startup(server_lds);
  60. THREAD_CREATE(server_thread_lds, serverloop_lds);
  61. // wait until LDS started
  62. UA_fakeSleep(1000);
  63. UA_realSleep(1000);
  64. }
  65. static void teardown_lds(void) {
  66. *running_lds = false;
  67. THREAD_JOIN(server_thread_lds);
  68. UA_Server_run_shutdown(server_lds);
  69. UA_Boolean_delete(running_lds);
  70. UA_Server_delete(server_lds);
  71. UA_ServerConfig_delete(config_lds);
  72. }
  73. UA_Server *server_register;
  74. UA_ServerConfig *config_register;
  75. UA_Boolean *running_register;
  76. THREAD_HANDLE server_thread_register;
  77. UA_UInt64 periodicRegisterCallbackId;
  78. THREAD_CALLBACK(serverloop_register) {
  79. while(*running_register)
  80. UA_Server_run_iterate(server_register, true);
  81. return 0;
  82. }
  83. static void setup_register(void) {
  84. // start register server
  85. running_register = UA_Boolean_new();
  86. *running_register = true;
  87. config_register = UA_ServerConfig_new_minimal(16664, NULL);
  88. UA_String_deleteMembers(&config_register->applicationDescription.applicationUri);
  89. config_register->applicationDescription.applicationUri =
  90. UA_String_fromChars("urn:open62541.test.server_register");
  91. UA_LocalizedText_deleteMembers(&config_register->applicationDescription.applicationName);
  92. config_register->applicationDescription.applicationName =
  93. UA_LOCALIZEDTEXT_ALLOC("de", "Anmeldungsserver");
  94. config_register->mdnsServerName = UA_String_fromChars("Register_test");
  95. server_register = UA_Server_new(config_register);
  96. UA_Server_run_startup(server_register);
  97. THREAD_CREATE(server_thread_register, serverloop_register);
  98. }
  99. static void teardown_register(void) {
  100. *running_register = false;
  101. THREAD_JOIN(server_thread_register);
  102. UA_Server_run_shutdown(server_register);
  103. UA_Boolean_delete(running_register);
  104. UA_Server_delete(server_register);
  105. UA_ServerConfig_delete(config_register);
  106. }
  107. START_TEST(Server_register) {
  108. UA_StatusCode retval =
  109. UA_Server_register_discovery(server_register, "opc.tcp://localhost:4840", NULL);
  110. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  111. }
  112. END_TEST
  113. START_TEST(Server_unregister) {
  114. UA_StatusCode retval =
  115. UA_Server_unregister_discovery(server_register, "opc.tcp://localhost:4840");
  116. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  117. }
  118. END_TEST
  119. #ifndef WIN32
  120. #define SEMAPHORE_PATH "/tmp/open62541-unit-test-semaphore"
  121. #else
  122. #define SEMAPHORE_PATH ".\\open62541-unit-test-semaphore"
  123. #endif
  124. START_TEST(Server_register_semaphore) {
  125. // create the semaphore
  126. #ifndef WIN32
  127. int fd = open(SEMAPHORE_PATH, O_RDWR|O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
  128. ck_assert_int_ne(fd, -1);
  129. close(fd);
  130. #else
  131. FILE *fp;
  132. fopen_s(&fp, SEMAPHORE_PATH, "ab+");
  133. ck_assert_ptr_ne(fp, NULL);
  134. fclose(fp);
  135. #endif
  136. UA_StatusCode retval =
  137. UA_Server_register_discovery(server_register, "opc.tcp://localhost:4840",
  138. SEMAPHORE_PATH);
  139. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  140. }
  141. END_TEST
  142. START_TEST(Server_unregister_semaphore) {
  143. // delete the semaphore, this should remove the registration automatically on next check
  144. ck_assert_int_eq(remove(SEMAPHORE_PATH), 0);
  145. }
  146. END_TEST
  147. START_TEST(Server_register_periodic) {
  148. // periodic register every minute, first register immediately
  149. UA_StatusCode retval =
  150. UA_Server_addPeriodicServerRegisterCallback(server_register, "opc.tcp://localhost:4840",
  151. 60*1000, 100, &periodicRegisterCallbackId);
  152. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  153. }
  154. END_TEST
  155. START_TEST(Server_unregister_periodic) {
  156. // wait for first register delay
  157. UA_fakeSleep(1000);
  158. UA_realSleep(1000);
  159. UA_Server_removeRepeatedCallback(server_register, periodicRegisterCallbackId);
  160. UA_StatusCode retval = UA_Server_unregister_discovery(server_register,
  161. "opc.tcp://localhost:4840");
  162. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  163. }
  164. END_TEST
  165. static void
  166. FindAndCheck(const UA_String expectedUris[], size_t expectedUrisSize,
  167. const UA_String expectedLocales[],
  168. const UA_String expectedNames[],
  169. const char *filterUri,
  170. const char *filterLocale) {
  171. UA_Client *client = UA_Client_new(UA_ClientConfig_default);
  172. UA_ApplicationDescription* applicationDescriptionArray = NULL;
  173. size_t applicationDescriptionArraySize = 0;
  174. size_t serverUrisSize = 0;
  175. UA_String *serverUris = NULL;
  176. if(filterUri) {
  177. serverUrisSize = 1;
  178. serverUris = UA_String_new();
  179. serverUris[0] = UA_String_fromChars(filterUri);
  180. }
  181. size_t localeIdsSize = 0;
  182. UA_String *localeIds = NULL;
  183. if(filterLocale) {
  184. localeIdsSize = 1;
  185. localeIds = UA_String_new();
  186. localeIds[0] = UA_String_fromChars(filterLocale);
  187. }
  188. UA_StatusCode retval =
  189. UA_Client_findServers(client, "opc.tcp://localhost:4840",
  190. serverUrisSize, serverUris, localeIdsSize, localeIds,
  191. &applicationDescriptionArraySize, &applicationDescriptionArray);
  192. if(filterUri)
  193. UA_Array_delete(serverUris, serverUrisSize, &UA_TYPES[UA_TYPES_STRING]);
  194. if(filterLocale)
  195. UA_Array_delete(localeIds, localeIdsSize, &UA_TYPES[UA_TYPES_STRING]);
  196. ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
  197. // only the discovery server is expected
  198. ck_assert_uint_eq(applicationDescriptionArraySize, expectedUrisSize);
  199. ck_assert(applicationDescriptionArray != NULL);
  200. for(size_t i = 0; i < expectedUrisSize; ++i) {
  201. ck_assert(UA_String_equal(&applicationDescriptionArray[i].applicationUri,
  202. &expectedUris[i]));
  203. if(expectedNames)
  204. ck_assert(UA_String_equal(&applicationDescriptionArray[i].applicationName.text,
  205. &expectedNames[i]));
  206. if (expectedLocales)
  207. ck_assert(UA_String_equal(&applicationDescriptionArray[i].applicationName.locale,
  208. &expectedLocales[i]));
  209. }
  210. UA_Array_delete(applicationDescriptionArray, applicationDescriptionArraySize,
  211. &UA_TYPES[UA_TYPES_APPLICATIONDESCRIPTION]);
  212. UA_Client_disconnect(client);
  213. UA_Client_delete(client);
  214. }
  215. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  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_default);
  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_String*)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_String*)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_default);
  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 if it is filtered by his uri
  308. START_TEST(Client_filter_discovery) {
  309. UA_String expectedUris[1];
  310. expectedUris[0] = 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. UA_String expectedUris[2];
  317. expectedUris[0] = UA_STRING("urn:open62541.test.local_discovery_server"),
  318. expectedUris[1] = UA_STRING("urn:open62541.test.server_register");
  319. UA_String expectedNames[2];
  320. expectedNames[0]= UA_STRING("LDS Server");
  321. expectedNames[1]= UA_STRING("Anmeldungsserver");
  322. UA_String expectedLocales[2];
  323. expectedLocales[0] = UA_STRING("en");
  324. expectedLocales[1] = 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. UA_String expectedUris[1];
  356. expectedUris[0] = UA_STRING("urn:open62541.test.server_register");
  357. FindAndCheck(expectedUris, 1, NULL, NULL, "urn:open62541.test.server_register", NULL);
  358. }
  359. END_TEST
  360. START_TEST(Client_get_endpoints) {
  361. UA_String expectedEndpoints[1];
  362. expectedEndpoints[0] = UA_STRING("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",
  367. "http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary",
  368. expectedEndpoints, 1);
  369. // filter transport profily by HTTPS, which should return no endpoint
  370. GetEndpointsAndCheck("opc.tcp://localhost:4840",
  371. "http://opcfoundation.org/UA-Profile/Transport/https-uabinary", NULL, 0);
  372. }
  373. END_TEST
  374. #endif
  375. // Test if discovery server lists himself as registered server, before any other registration.
  376. START_TEST(Client_find_discovery) {
  377. UA_String expectedUris[1];
  378. expectedUris[0] = UA_STRING("urn:open62541.test.local_discovery_server");
  379. FindAndCheck(expectedUris, 1, NULL, NULL, NULL, NULL);
  380. }
  381. END_TEST
  382. // Test if registered server is returned from LDS
  383. START_TEST(Client_find_registered) {
  384. UA_String expectedUris[2];
  385. expectedUris[0] = UA_STRING("urn:open62541.test.local_discovery_server");
  386. expectedUris[1] = UA_STRING("urn:open62541.test.server_register");
  387. FindAndCheck(expectedUris, 2, NULL, NULL, NULL, NULL);
  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_fakeSleep(100000 * checkWait);
  401. UA_realSleep(1000);
  402. }
  403. END_TEST
  404. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  405. START_TEST(Util_wait_mdns) {
  406. UA_fakeSleep(1000);
  407. UA_realSleep(1000);
  408. }
  409. END_TEST
  410. #endif
  411. START_TEST(Util_wait_startup) {
  412. UA_fakeSleep(1000);
  413. UA_realSleep(1000);
  414. }
  415. END_TEST
  416. START_TEST(Util_wait_retry) {
  417. // first retry is after 2 seconds, then 4, so it should be enough to wait 3 seconds
  418. UA_fakeSleep(3000);
  419. UA_realSleep(3000);
  420. }
  421. END_TEST
  422. static Suite* testSuite_Client(void) {
  423. Suite *s = suite_create("Register Server and Client");
  424. TCase *tc_register = tcase_create("RegisterServer");
  425. tcase_add_unchecked_fixture(tc_register, setup_lds, teardown_lds);
  426. tcase_add_unchecked_fixture(tc_register, setup_register, teardown_register);
  427. tcase_add_test(tc_register, Server_register);
  428. // register two times, just for fun
  429. tcase_add_test(tc_register, Server_register);
  430. tcase_add_test(tc_register, Server_unregister);
  431. tcase_add_test(tc_register, Server_register_periodic);
  432. tcase_add_test(tc_register, Server_unregister_periodic);
  433. suite_add_tcase(s,tc_register);
  434. TCase *tc_register_retry = tcase_create("RegisterServer Retry");
  435. //tcase_add_unchecked_fixture(tc_register, setup_lds, teardown_lds);
  436. tcase_add_unchecked_fixture(tc_register_retry, setup_register, teardown_register);
  437. tcase_add_test(tc_register_retry, Server_register_periodic);
  438. tcase_add_test(tc_register_retry, Util_wait_startup); // wait a bit to let first try run through
  439. // now start LDS
  440. tcase_add_test(tc_register_retry, Util_start_lds);
  441. tcase_add_test(tc_register_retry, Util_wait_retry);
  442. // check if there
  443. tcase_add_test(tc_register_retry, Client_find_registered);
  444. tcase_add_test(tc_register_retry, Server_unregister_periodic);
  445. tcase_add_test(tc_register_retry, Client_find_discovery);
  446. tcase_add_test(tc_register_retry, Util_stop_lds);
  447. suite_add_tcase(s,tc_register_retry);
  448. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  449. TCase *tc_register_find = tcase_create("RegisterServer and FindServers");
  450. tcase_add_unchecked_fixture(tc_register_find, setup_lds, teardown_lds);
  451. tcase_add_unchecked_fixture(tc_register_find, setup_register, teardown_register);
  452. tcase_add_test(tc_register_find, Client_find_discovery);
  453. tcase_add_test(tc_register_find, Server_register);
  454. tcase_add_test(tc_register_find, Client_find_registered);
  455. tcase_add_test(tc_register_find, Util_wait_mdns);
  456. tcase_add_test(tc_register_find, Client_find_on_network_registered);
  457. tcase_add_test(tc_register_find, Client_find_filter);
  458. tcase_add_test(tc_register_find, Client_get_endpoints);
  459. tcase_add_test(tc_register_find, Client_filter_locale);
  460. tcase_add_test(tc_register_find, Server_unregister);
  461. tcase_add_test(tc_register_find, Client_find_discovery);
  462. tcase_add_test(tc_register_find, Client_filter_discovery);
  463. suite_add_tcase(s,tc_register_find);
  464. #endif
  465. // register server again, then wait for timeout and auto unregister
  466. TCase *tc_register_timeout = tcase_create("RegisterServer timeout");
  467. tcase_add_unchecked_fixture(tc_register_timeout, setup_lds, teardown_lds);
  468. tcase_add_unchecked_fixture(tc_register_timeout, setup_register, teardown_register);
  469. tcase_set_timeout(tc_register_timeout, checkWait+2);
  470. tcase_add_test(tc_register_timeout, Server_register);
  471. tcase_add_test(tc_register_timeout, Client_find_registered);
  472. tcase_add_test(tc_register_timeout, Util_wait_timeout);
  473. tcase_add_test(tc_register_timeout, Client_find_discovery);
  474. #ifdef UA_ENABLE_DISCOVERY_SEMAPHORE
  475. // now check if semaphore file works
  476. tcase_add_test(tc_register_timeout, Server_register_semaphore);
  477. tcase_add_test(tc_register_timeout, Client_find_registered);
  478. tcase_add_test(tc_register_timeout, Server_unregister_semaphore);
  479. tcase_add_test(tc_register_timeout, Util_wait_timeout);
  480. tcase_add_test(tc_register_timeout, Client_find_discovery);
  481. #endif
  482. suite_add_tcase(s,tc_register_timeout);
  483. return s;
  484. }
  485. int main(void) {
  486. Suite *s = testSuite_Client();
  487. SRunner *sr = srunner_create(s);
  488. srunner_set_fork_status(sr, CK_NOFORK);
  489. srunner_run_all(sr,CK_NORMAL);
  490. int number_failed = srunner_ntests_failed(sr);
  491. srunner_free(sr);
  492. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  493. }