feat(plugin): Integration of nodesetLoader functionality within open62541 (#5371)

This commit is contained in:
keba-uso 2022-09-22 16:48:23 +02:00 committed by Julius Pfrommer
parent b457206d24
commit 779e6b7902
32 changed files with 1741 additions and 15 deletions

4
.gitignore vendored
View File

@ -77,12 +77,14 @@ Makefile
/exampleClient
/exampleClient_legacy
/src_generated/
/build
**/build
/cmake-build*
/tools/certs/certs/*
Pipfile
Pipfile.lock
.vscode
**/libxml2
debian/*
# clangd cache
.cache/

4
.gitmodules vendored
View File

@ -9,3 +9,7 @@
path = deps/mqtt-c
url = https://github.com/LiamBindle/MQTT-C.git
branch = master
[submodule "deps/nodesetLoader"]
path = deps/nodesetLoader
url = https://github.com/open62541/nodesetLoader
branch = master

View File

@ -165,6 +165,7 @@ option(UA_ENABLE_DA "Enable OPC UA DataAccess (Part 8) definitions" ON)
option(UA_ENABLE_HISTORIZING "Enable basic support for historical access (client and server)" OFF)
option(UA_ENABLE_DISCOVERY "Enable Discovery Service (LDS)" OFF)
option(UA_ENABLE_JSON_ENCODING "Enable JSON encoding" ON)
option(UA_ENABLE_NODESETLOADER "Enable nodesetLoader public API" OFF)
set(MULTITHREADING_DEFAULT 0)
if(WIN32 OR UNIX)
@ -1228,6 +1229,22 @@ if(UA_BUILD_FUZZING OR UA_BUILD_OSS_FUZZ)
${PROJECT_SOURCE_DIR}/tests/fuzz/custom_memory_manager.c)
endif()
if(UA_ENABLE_NODESETLOADER)
# This is required because of issues with policy CMP0077.
# Source: https://stackoverflow.com/a/54404924
option(ENABLE_BUILD_INTO_OPEN62541 "make nodesetLoader part of the open62541 library" off)
set(ENABLE_BUILD_INTO_OPEN62541 on)
add_subdirectory(${PROJECT_SOURCE_DIR}/deps/nodesetLoader)
list(APPEND lib_sources ${NODESETLOADER_SOURCES})
list(APPEND default_plugin_headers
${PROJECT_SOURCE_DIR}/plugins/include/open62541/plugin/nodesetloader.h)
list(APPEND default_plugin_sources
${PROJECT_SOURCE_DIR}/plugins/ua_nodesetloader.c)
list(APPEND open62541_LIBRARIES ${NODESETLOADER_DEPS_LIBS})
endif()
#########################
# Generate source files #
#########################
@ -1513,6 +1530,10 @@ else()
"${PROJECT_SOURCE_DIR}/src/pubsub"
"${PROJECT_BINARY_DIR}/src_generated")
if(UA_ENABLE_NODESETLOADER)
include_directories_public(${NODESETLOADER_PUBLIC_INCLUDES})
endif()
# Private includes
include_directories_private("${PROJECT_BINARY_DIR}")
@ -1525,12 +1546,14 @@ else()
if(UA_ENABLE_ENCRYPTION_LIBRESSL)
include_directories_private(${LIBRESSL_INCLUDE_DIR})
endif()
if(UA_ENABLE_NODESETLOADER)
include_directories_private(${NODESETLOADER_PRIVATE_INCLUDES})
endif()
# Option-specific includes
if(UA_ENABLE_DISCOVERY)
include_directories_private("${PROJECT_SOURCE_DIR}/src/client")
endif()
endif()
add_dependencies(open62541-object open62541-code-generation)

1
deps/nodesetLoader vendored Submodule

@ -0,0 +1 @@
Subproject commit a05fdd843a38c34c64a6aaa25b68e5c90af0d182

View File

@ -274,3 +274,10 @@ if(UA_ENABLE_PUBSUB)
endif()
endif()
endif()
###########################
# Nodeser Loader Examples #
###########################
if(UA_ENABLE_NODESETLOADER)
add_subdirectory(nodeset_loader)
endif()

View File

@ -20,7 +20,7 @@ int main(void) {
/* Attention! Here the custom datatypes are allocated on the stack. So they
* cannot be accessed from parallel (worker) threads. */
UA_DataTypeArray customDataTypes = {NULL, 4, types};
UA_DataTypeArray customDataTypes = {NULL, 4, types, UA_FALSE};
UA_Client *client = UA_Client_new();
UA_ClientConfig *cc = UA_Client_getConfig(client);

View File

@ -279,7 +279,7 @@ int main(void) {
/* Attention! Here the custom datatypes are allocated on the stack. So they
* cannot be accessed from parallel (worker) threads. */
UA_DataTypeArray customDataTypes = {config->customDataTypes, 4, types};
UA_DataTypeArray customDataTypes = {config->customDataTypes, 4, types, UA_FALSE};
config->customDataTypes = &customDataTypes;
add3DPointDataType(server);

View File

@ -15,7 +15,7 @@
UA_Boolean running = true;
UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTNODESET_COUNT, UA_TYPES_TESTNODESET};
UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTNODESET_COUNT, UA_TYPES_TESTNODESET, UA_FALSE};
static void stopHandler(int sign) {
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");

View File

@ -0,0 +1,8 @@
###########################
# Nodeset Loader Examples #
###########################
if(UA_NAMESPACE_ZERO STREQUAL "FULL")
add_example(nodeset_loader nodeset_loader.c)
add_example(server_nodeset_loader server_nodeset_loader.c)
endif()

View File

@ -0,0 +1,34 @@
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/nodesetloader.h>
UA_Boolean running = true;
static void stopHandler(int sign) {
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
running = false;
}
int main(int argc, const char *argv[]) {
signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);
UA_Server *server = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
UA_Server_run_startup(server);
for (int cnt = 1; cnt < argc; cnt++) {
if (!UA_Server_loadNodeset(server, argv[cnt], NULL)) {
printf("Nodeset %s could not be loaded, exit\n", argv[cnt]);
return EXIT_FAILURE;
}
}
UA_Server_run_shutdown(server);
UA_Server_delete(server);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,33 @@
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/nodesetloader.h>
UA_Boolean running = true;
static void stopHandler(int sign) {
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
running = false;
}
int main(int argc, const char *argv[]) {
signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);
UA_Server *server = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
for (int cnt = 1; cnt < argc; cnt++) {
if (!UA_Server_loadNodeset(server, argv[cnt], NULL)) {
printf("Nodeset %s could not be loaded, exit\n", argv[cnt]);
return EXIT_FAILURE;
}
}
UA_StatusCode retval = UA_Server_run(server, &running);
UA_Server_delete(server);
return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -276,7 +276,7 @@ static int run(UA_String *transportProfile,
types[0] = PointType;
types[0].members = pointMembers;
UA_DataTypeArray customDataTypes = {config->customDataTypes, 1, types};
UA_DataTypeArray customDataTypes = {config->customDataTypes, 1, types, UA_FALSE};
config->customDataTypes = &customDataTypes;
add3DPointDataType(server);

View File

@ -328,7 +328,7 @@ run(UA_String *transportProfile, UA_NetworkAddressUrlDataType *networkAddressUrl
types[0] = PointType;
types[0].members = pointMembers;
UA_DataTypeArray customDataTypes = {config->customDataTypes, 1, types};
UA_DataTypeArray customDataTypes = {config->customDataTypes, 1, types, UA_FALSE};
config->customDataTypes = &customDataTypes;
add3DPointDataType(server);

View File

@ -1074,6 +1074,9 @@ typedef struct UA_DataTypeArray {
const struct UA_DataTypeArray *next;
const size_t typesSize;
const UA_DataType *types;
UA_Boolean cleanup; /* Free the array structure and its content
when the client or server configuration
containing it is cleaned up */
} UA_DataTypeArray;
/* Returns the offset and type of a structure member. The return value is false

View File

@ -0,0 +1,24 @@
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
*
* Copyright 2019 (c) Julius Pfrommer, Fraunhofer IOSB
*/
#ifndef UA_NODESET_LOADER_DEFAULT_H_
#define UA_NODESET_LOADER_DEFAULT_H_
#include <open62541/util.h>
_UA_BEGIN_DECLS
typedef void UA_NodeSetLoaderOptions;
/* Load the typemodel at runtime, without the need to statically compile the model.
* This is an alternative to the Python nodeset compiler approach. */
UA_EXPORT UA_StatusCode
UA_Server_loadNodeset(UA_Server *server, const char *nodeset2XmlFilePath,
UA_NodeSetLoaderOptions *options);
_UA_END_DECLS
#endif /* UA_NODESET_LOADER_DEFAULT_H_ */

View File

@ -0,0 +1,20 @@
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
*
* Copyright 2014-2019 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
* Copyright 2017 (c) Julian Grothoff
* Copyright 2017 (c) Stefan Profanter, fortiss GmbH
*/
#include <open62541/plugin/nodesetloader.h>
#include <NodesetLoader/backendOpen62541.h>
#include <NodesetLoader/dataTypes.h>
#include <open62541/server.h>
UA_StatusCode
UA_Server_loadNodeset(UA_Server *server, const char *nodeset2XmlFilePath,
UA_NodeSetLoaderOptions *options) {
return NodesetLoader_loadFile(server,
nodeset2XmlFilePath,
(NodesetLoader_ExtensionInterface*)options);
}

View File

@ -104,6 +104,9 @@ UA_ClientConfig_clear(UA_ClientConfig *config) {
}
config->sessionLocaleIds = NULL;
config->sessionLocaleIdsSize = 0;
/* Custom Data Types */
UA_cleanupDataTypeWithCustom(config->customDataTypes);
}
static void

View File

@ -8,6 +8,8 @@
#include <open62541/server.h>
#include "ua_server_internal.h"
void
UA_ServerConfig_clean(UA_ServerConfig *config) {
if(!config)
@ -100,6 +102,9 @@ UA_ServerConfig_clean(UA_ServerConfig *config) {
}
#endif
#endif /* UA_ENABLE_PUBSUB */
/* Custom Data Types */
UA_cleanupDataTypeWithCustom(config->customDataTypes);
}
#ifdef UA_ENABLE_PUBSUB

View File

@ -83,6 +83,27 @@ UA_findDataType(const UA_NodeId *typeId) {
return UA_findDataTypeWithCustom(typeId, NULL);
}
void
UA_cleanupDataTypeWithCustom(const UA_DataTypeArray *customTypes) {
while (customTypes) {
const UA_DataTypeArray *next = customTypes->next;
if (customTypes->cleanup) {
for(size_t i = 0; i < customTypes->typesSize; ++i) {
const UA_DataType *type = &customTypes->types[i];
UA_free((void*)(uintptr_t)type->typeName);
for(size_t j = 0; j < type->membersSize; ++j) {
const UA_DataTypeMember *m = &type->members[j];
UA_free((void*)(uintptr_t)m->memberName);
}
UA_free((void*)type->members);
}
UA_free((void*)(uintptr_t)customTypes->types);
UA_free((void*)(uintptr_t)customTypes);
}
customTypes = next;
}
}
/***************************/
/* Random Number Generator */
/***************************/

View File

@ -175,6 +175,9 @@ const UA_DataType *
UA_findDataTypeWithCustom(const UA_NodeId *typeId,
const UA_DataTypeArray *customTypes);
void
UA_cleanupDataTypeWithCustom(const UA_DataTypeArray *customTypes);
/* Get the number of optional fields contained in an structure type */
size_t UA_EXPORT
getCountOfOptionalFields(const UA_DataType *type);

View File

@ -139,6 +139,10 @@ if(UA_ENABLE_PUBSUB)
endif()
endif()
if(UA_ENABLE_NODESETLOADER)
list(APPEND test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_nodesetloader.c)
endif()
if(UA_NAMESPACE_ZERO STREQUAL "FULL")
set(NODESET_COMPILER_OUTPUT_DIR "${CMAKE_BINARY_DIR}/src_generated/tests")
@ -416,6 +420,11 @@ endif()
# Tests for Nodeset Compiler
add_subdirectory(nodeset-compiler)
# Tests for Nodeset Loader
if(UA_ENABLE_NODESETLOADER)
add_subdirectory(nodeset-loader)
endif()
# Tests for interfaces
if(UA_NAMESPACE_ZERO STREQUAL "FULL")
add_executable(check_interfaces server/check_interfaces.c ${NODESET_COMPILER_OUTPUT_DIR}/namespace_tests_interfaces_generated.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)

View File

@ -79,7 +79,7 @@ static const UA_DataType PointType = {
members
};
const UA_DataTypeArray customDataTypes = {NULL, 1, &PointType};
const UA_DataTypeArray customDataTypes = {NULL, 1, &PointType, UA_FALSE};
typedef struct {
UA_Int16 a;
@ -129,7 +129,7 @@ static const UA_DataType OptType = {
Opt_members
};
const UA_DataTypeArray customDataTypesOptStruct = {&customDataTypes, 2, &OptType};
const UA_DataTypeArray customDataTypesOptStruct = {&customDataTypes, 2, &OptType, UA_FALSE};
typedef struct {
UA_String description;
@ -178,7 +178,7 @@ static const UA_DataType ArrayOptType = {
ArrayOptStruct_members
};
const UA_DataTypeArray customDataTypesOptArrayStruct = {&customDataTypesOptStruct, 3, &ArrayOptType};
const UA_DataTypeArray customDataTypesOptArrayStruct = {&customDataTypesOptStruct, 3, &ArrayOptType, UA_FALSE};
typedef enum {UA_UNISWITCH_NONE = 0, UA_UNISWITCH_OPTIONA = 1, UA_UNISWITCH_OPTIONB = 2} UA_UniSwitch;
@ -219,7 +219,7 @@ static const UA_DataType UniType = {
Uni_members
};
const UA_DataTypeArray customDataTypesUnion = {&customDataTypesOptArrayStruct, 2, &UniType};
const UA_DataTypeArray customDataTypesUnion = {&customDataTypesOptArrayStruct, 2, &UniType, UA_FALSE};
typedef enum {
UA_SELFCONTAININGUNIONSWITCH_NONE = 0,
@ -270,7 +270,7 @@ const UA_DataType selfContainingUnionType = {
SelfContainingUnion_members /* .members */
};
const UA_DataTypeArray customDataTypesSelfContainingUnion = {NULL, 1, &selfContainingUnionType};
const UA_DataTypeArray customDataTypesSelfContainingUnion = {NULL, 1, &selfContainingUnionType, UA_FALSE};
START_TEST(parseCustomScalar) {
Point p;

View File

@ -14,7 +14,7 @@
#include "unistd.h"
UA_Server *server = NULL;
UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTS_TESTNODESET_COUNT, UA_TYPES_TESTS_TESTNODESET};
UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTS_TESTNODESET_COUNT, UA_TYPES_TESTS_TESTNODESET, UA_FALSE};
UA_UInt16 testNamespaceIndex = (UA_UInt16) -1;
static void setup(void) {

View File

@ -0,0 +1,13 @@
####################################################
# Test nodeset loader on a subset of nodeset files #
####################################################
if(UA_NAMESPACE_ZERO STREQUAL "FULL")
add_compile_definitions(OPEN62541_NODESET_DIR="${UA_NODESET_DIR}/")
ua_add_test(check_nodeset_loader_di.c)
ua_add_test(check_nodeset_loader_adi.c)
ua_add_test(check_nodeset_loader_autoid.c)
ua_add_test(check_nodeset_loader_plc.c)
ua_add_test(check_nodeset_loader_input.c)
ua_add_test(check_nodeset_loader_ua_nodeset.c)
endif()

View File

@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/nodesetloader.h>
#include "check.h"
#include "testing_clock.h"
UA_Server *server = NULL;
static void setup(void) {
server = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
UA_Server_run_startup(server);
}
static void teardown(void) {
UA_Server_run_shutdown(server);
UA_Server_delete(server);
}
START_TEST(Server_loadDiNodeset) {
bool retVal = UA_Server_loadNodeset(server,
OPEN62541_NODESET_DIR "DI/Opc.Ua.Di.NodeSet2.xml", NULL);
ck_assert_uint_eq(retVal, true);
}
END_TEST
START_TEST(Server_loadAdiNodeset) {
bool retVal = UA_Server_loadNodeset(server,
OPEN62541_NODESET_DIR "ADI/Opc.Ua.Adi.NodeSet2.xml", NULL);
ck_assert_uint_eq(retVal, true);
}
END_TEST
static Suite* testSuite_Client(void) {
Suite *s = suite_create("Server Nodeset Loader");
TCase *tc_server = tcase_create("Server DI and ADI nodeset");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, Server_loadDiNodeset);
tcase_add_test(tc_server, Server_loadAdiNodeset);
suite_add_tcase(s, tc_server);
return s;
}
int main(void) {
Suite *s = testSuite_Client();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr,CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/nodesetloader.h>
#include "check.h"
#include "testing_clock.h"
UA_Server *server = NULL;
static void setup(void) {
server = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
UA_Server_run_startup(server);
}
static void teardown(void) {
UA_Server_run_shutdown(server);
UA_Server_delete(server);
}
START_TEST(Server_loadDiNodeset) {
bool retVal = UA_Server_loadNodeset(server,
OPEN62541_NODESET_DIR "DI/Opc.Ua.Di.NodeSet2.xml", NULL);
ck_assert_uint_eq(retVal, true);
}
END_TEST
START_TEST(Server_loadAutoIDNodeset) {
bool retVal = UA_Server_loadNodeset(server,
OPEN62541_NODESET_DIR "AutoID/Opc.Ua.AutoID.NodeSet2.xml", NULL);
ck_assert_uint_eq(retVal, true);
}
END_TEST
static Suite* testSuite_Client(void) {
Suite *s = suite_create("Server Nodeset Loader");
TCase *tc_server = tcase_create("Server DI and AutoID nodeset");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, Server_loadDiNodeset);
tcase_add_test(tc_server, Server_loadAutoIDNodeset);
suite_add_tcase(s, tc_server);
return s;
}
int main(void) {
Suite *s = testSuite_Client();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr,CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -0,0 +1,49 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/nodesetloader.h>
#include "check.h"
#include "testing_clock.h"
UA_Server *server = NULL;
static void setup(void) {
server = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
UA_Server_run_startup(server);
}
static void teardown(void) {
UA_Server_run_shutdown(server);
UA_Server_delete(server);
}
START_TEST(Server_loadDiNodeset) {
bool retVal = UA_Server_loadNodeset(server,
OPEN62541_NODESET_DIR "DI/Opc.Ua.Di.NodeSet2.xml", NULL);
ck_assert_uint_eq(retVal, true);
}
END_TEST
static Suite* testSuite_Client(void) {
Suite *s = suite_create("Server Nodeset Loader");
TCase *tc_server = tcase_create("Server DI nodeset");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, Server_loadDiNodeset);
suite_add_tcase(s, tc_server);
return s;
}
int main(void) {
Suite *s = testSuite_Client();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr,CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -0,0 +1,61 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/nodesetloader.h>
#include "check.h"
#include "testing_clock.h"
UA_Server *server = NULL;
char **nodesetPaths = NULL;
int nodesetsNum = 0;
static void setup(void) {
server = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
UA_Server_run_startup(server);
}
static void teardown(void) {
UA_Server_run_shutdown(server);
UA_Server_delete(server);
}
START_TEST(Server_loadInputNodesets) {
for (int cnt = 0; cnt < nodesetsNum; cnt++) {
bool retVal = UA_Server_loadNodeset(server, nodesetPaths[cnt], NULL);
ck_assert_uint_eq(retVal, true);
}
}
END_TEST
static Suite* testSuite_Client(void) {
Suite *s = suite_create("Server Nodeset Loader");
TCase *tc_server = tcase_create("Server load input nodesets");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, Server_loadInputNodesets);
suite_add_tcase(s, tc_server);
return s;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
nodesetPaths = (char**)malloc(sizeof(char*));
nodesetPaths[0] = OPEN62541_NODESET_DIR "DI/Opc.Ua.Di.NodeSet2.xml";
nodesetsNum = 1;
}
else {
nodesetPaths = &argv[1];
nodesetsNum = argc - 1;
}
Suite *s = testSuite_Client();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr,CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/plugin/nodesetloader.h>
#include "check.h"
#include "testing_clock.h"
UA_Server *server = NULL;
static void setup(void) {
server = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
UA_Server_run_startup(server);
}
static void teardown(void) {
UA_Server_run_shutdown(server);
UA_Server_delete(server);
}
START_TEST(Server_loadDiNodeset) {
bool retVal = UA_Server_loadNodeset(server,
OPEN62541_NODESET_DIR "DI/Opc.Ua.Di.NodeSet2.xml", NULL);
ck_assert_uint_eq(retVal, true);
}
END_TEST
START_TEST(Server_loadPlcNodeset) {
bool retVal = UA_Server_loadNodeset(server,
OPEN62541_NODESET_DIR "PLCopen/Opc.Ua.PLCopen.NodeSet2_V1.02.xml", NULL);
ck_assert_uint_eq(retVal, true);
}
END_TEST
static Suite* testSuite_Client(void) {
Suite *s = suite_create("Server Nodeset Loader");
TCase *tc_server = tcase_create("Server DI and PLCopen nodeset");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, Server_loadDiNodeset);
tcase_add_test(tc_server, Server_loadPlcNodeset);
suite_add_tcase(s, tc_server);
return s;
}
int main(void) {
Suite *s = testSuite_Client();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr,CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

File diff suppressed because it is too large Load Diff

View File

@ -148,7 +148,7 @@ static UA_DataType PointType = {
members
};
UA_DataTypeArray customDataTypes = {NULL, 1, &PointType};
UA_DataTypeArray customDataTypes = {NULL, 1, &PointType, UA_FALSE};
START_TEST(Server_LocalMonitoredItem_CustomType) {
callbackCount = 0;

View File

@ -292,7 +292,8 @@ _UA_END_DECLS
writec("\nstatic UA_DataTypeArray custom" + arr + " = {")
writec(" NULL,")
writec(" " + arr + "_COUNT,")
writec(" " + arr + "\n};")
writec(" " + arr + ",")
writec(" UA_FALSE\n};")
writec("""
UA_StatusCode %s(UA_Server *server) {