check_server_speed_addnodes.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. /* This example is just to see how fast we can add nodes. The server does not
  4. * open a TCP port. */
  5. #include <open62541/server_config_default.h>
  6. #include "server/ua_services.h"
  7. #include "ua_server_internal.h"
  8. #include "ua_types_encoding_binary.h"
  9. #include <check.h>
  10. #include <time.h>
  11. #include "testing_networklayers.h"
  12. #include "testing_policy.h"
  13. static UA_SecureChannel testChannel;
  14. static UA_SecurityPolicy dummyPolicy;
  15. static UA_Connection testingConnection;
  16. static funcs_called funcsCalled;
  17. static key_sizes keySizes;
  18. static UA_Server *server;
  19. static void setup(void) {
  20. server = UA_Server_new();
  21. UA_ServerConfig_setDefault(UA_Server_getConfig(server));
  22. TestingPolicy(&dummyPolicy, UA_BYTESTRING_NULL, &funcsCalled, &keySizes);
  23. UA_SecureChannel_init(&testChannel);
  24. UA_SecureChannel_setSecurityPolicy(&testChannel, &dummyPolicy, &UA_BYTESTRING_NULL);
  25. testingConnection = createDummyConnection(65535, NULL);
  26. UA_Connection_attachSecureChannel(&testingConnection, &testChannel);
  27. testChannel.connection = &testingConnection;
  28. UA_ServerConfig *config = UA_Server_getConfig(server);
  29. config->logger.log = NULL;
  30. }
  31. static void teardown(void) {
  32. UA_SecureChannel_close(&testChannel);
  33. UA_SecureChannel_deleteMembers(&testChannel);
  34. dummyPolicy.clear(&dummyPolicy);
  35. testingConnection.close(&testingConnection);
  36. UA_Server_delete(server);
  37. }
  38. START_TEST(addVariable) {
  39. /* add a variable node to the address space */
  40. UA_VariableAttributes attr = UA_VariableAttributes_default;
  41. UA_Int32 myInteger = 42;
  42. UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  43. attr.description = UA_LOCALIZEDTEXT("en-US","the answer");
  44. attr.displayName = UA_LOCALIZEDTEXT("en-US","the answer");
  45. UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  46. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  47. UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  48. clock_t begin, finish;
  49. begin = clock();
  50. for(int i = 0; i < 10000; i++) {
  51. UA_Server_addVariableNode(server, UA_NODEID_NULL, parentNodeId,
  52. parentReferenceNodeId, myIntegerName,
  53. UA_NODEID_NULL, attr, NULL, NULL);
  54. if(i % 1000 == 0) {
  55. finish = clock();
  56. double time_spent = (double)(finish - begin) / CLOCKS_PER_SEC;
  57. printf("%i nodes:\t Duration was %f s\n", i, time_spent);
  58. begin = clock();
  59. }
  60. }
  61. }
  62. END_TEST
  63. static Suite * service_speed_suite (void) {
  64. Suite *s = suite_create ("Service Speed");
  65. TCase* tc_addnodes = tcase_create ("AddNodes");
  66. tcase_add_checked_fixture(tc_addnodes, setup, teardown);
  67. tcase_add_test(tc_addnodes, addVariable);
  68. suite_add_tcase(s, tc_addnodes);
  69. return s;
  70. }
  71. int main (void) {
  72. int number_failed = 0;
  73. Suite *s = service_speed_suite();
  74. SRunner *sr = srunner_create(s);
  75. srunner_set_fork_status(sr,CK_NOFORK);
  76. srunner_run_all(sr, CK_NORMAL);
  77. number_failed += srunner_ntests_failed (sr);
  78. srunner_free(sr);
  79. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  80. }