check_discovery.c 21 KB

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