A class that holds the configuration for a UA service.
Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the test with session, configuration and logger.
        /// </summary>
        public TestBase(
            string name,
            Session session,
            ServerTestConfiguration configuration,
            ReportMessageEventHandler reportMessage,
            ReportProgressEventHandler reportProgress,
            TestBase template)
        {
            m_name = name;
            m_session = session;
            m_configuration = configuration;
            m_reportMessage = reportMessage;
            m_reportProgress = reportProgress;

            if (template != null && Object.ReferenceEquals(session, template.m_session))
            {
                m_blockSize = template.BlockSize;
                m_availableNodes = template.m_availableNodes;
                m_writeableVariables = template.m_writeableVariables;
            }
            else
            {
                m_blockSize = 1000;
                m_availableNodes = new NodeIdDictionary<Node>();
                m_writeableVariables = new List<VariableNode>();
            }
        }
Ejemplo n.º 2
0
        public void Initialize(ServerTestConfiguration configuration)
        {
            m_configuration = configuration;
            
            NodesTV.Nodes.Clear();

            if (m_configuration != null)
            {
                IterationsCTRL.Value = (decimal)m_configuration.Iterations;

                if (m_configuration.Coverage != 0)
                {
                    CoverageCTRL.Value = (decimal)m_configuration.Coverage;
                }
                else
                {
                    CoverageCTRL.Value = 100;
                }

                if (m_configuration.ConnectToAllEndpoints)
                {
                    EndpointSelectionCB.SelectedItem = EndpointSelection.All;
                }
                else
                {
                    EndpointSelectionCB.SelectedItem = m_configuration.EndpointSelection;
                }

                AddTestCases(null, m_configuration.TestCases, null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  Loads the configuration from the application configuration file.
        /// </summary>
        public static ServerTestConfiguration Load(XmlElementCollection extensions)
        {
            if (extensions == null || extensions.Count == 0)
            {
                return(new ServerTestConfiguration());
            }

            foreach (XmlElement element in extensions)
            {
                if (element.NamespaceURI != "http://opcfoundation.org/UA/SDK/ServerTest/Configuration.xsd")
                {
                    continue;
                }

                XmlNodeReader reader = new XmlNodeReader(element);

                try {
                    DataContractSerializer  serializer    = new DataContractSerializer(typeof(ServerTestConfiguration));
                    ServerTestConfiguration configuration = serializer.ReadObject(reader) as ServerTestConfiguration;

                    if (configuration.Iterations <= 0)
                    {
                        configuration.Iterations = 1;
                    }

                    return(configuration);
                } finally {
                    reader.Close();
                }
            }

            return(new ServerTestConfiguration());
        }
        /// <summary>
        ///  Loads the configuration from a file on disk.
        /// </summary>
        public static ServerTestConfiguration Load(string filePath, ServerTestConfiguration masterConfiguration)
        {
		    XmlTextReader reader = new XmlTextReader(filePath);

            try
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(ServerTestConfiguration));
                ServerTestConfiguration configuration = serializer.ReadObject(reader) as ServerTestConfiguration;
                configuration.m_filePath = filePath;

                if (configuration.Iterations <= 0)
                {
                    configuration.Iterations = 1;
                }

                if (masterConfiguration != null)
                {
                    ListOfServerTestCase replacements = new ListOfServerTestCase();

                    for (int ii = 0; ii < masterConfiguration.TestCases.Count; ii++)
                    {
                        ServerTestCase template = masterConfiguration.TestCases[ii];
                        
                        // create replacement that is disabled by default.
                        ServerTestCase replacement = new ServerTestCase();

                        replacement.Name = template.Name;
                        replacement.Parent = template.Parent;
                        replacement.Enabled = false;
                        replacement.Breakpoint = false;

                        replacements.Add(replacement);

                        // load settings from saved test case.
                        for (int jj = 0; jj < configuration.TestCases.Count; jj++)
                        {
                            ServerTestCase actual = configuration.TestCases[jj];

                            if (actual.Name == template.Name && actual.Parent == template.Parent)
                            {
                                replacement.Enabled = actual.Enabled;
                                replacement.Breakpoint = actual.Breakpoint;
                                break;
                            }
                        }
                    }

                    // replace the test cases.
                    configuration.TestCases = replacements;
                }

                return configuration;
            }
            finally
            {
                reader.Close();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///  Loads the configuration from a file on disk.
        /// </summary>
        public static ServerTestConfiguration Load(string filePath, ServerTestConfiguration masterConfiguration)
        {
            XmlTextReader reader = new XmlTextReader(filePath);

            try
            {
                DataContractSerializer  serializer    = new DataContractSerializer(typeof(ServerTestConfiguration));
                ServerTestConfiguration configuration = serializer.ReadObject(reader) as ServerTestConfiguration;
                configuration.m_filePath = filePath;

                if (configuration.Iterations <= 0)
                {
                    configuration.Iterations = 1;
                }

                if (masterConfiguration != null)
                {
                    ListOfServerTestCase replacements = new ListOfServerTestCase();

                    for (int ii = 0; ii < masterConfiguration.TestCases.Count; ii++)
                    {
                        ServerTestCase template = masterConfiguration.TestCases[ii];

                        // create replacement that is disabled by default.
                        ServerTestCase replacement = new ServerTestCase();

                        replacement.Name       = template.Name;
                        replacement.Parent     = template.Parent;
                        replacement.Enabled    = false;
                        replacement.Breakpoint = false;

                        replacements.Add(replacement);

                        // load settings from saved test case.
                        for (int jj = 0; jj < configuration.TestCases.Count; jj++)
                        {
                            ServerTestCase actual = configuration.TestCases[jj];

                            if (actual.Name == template.Name && actual.Parent == template.Parent)
                            {
                                replacement.Enabled    = actual.Enabled;
                                replacement.Breakpoint = actual.Breakpoint;
                                break;
                            }
                        }
                    }

                    // replace the test cases.
                    configuration.TestCases = replacements;
                }

                return(configuration);
            }
            finally
            {
                reader.Close();
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public TranslatePathTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
     :
     base("TranslatePath", session, configuration, reportMessage, reportProgress, template)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public TranslatePathTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
 : 
     base("TranslatePath", session, configuration, reportMessage, reportProgress, template)
 {
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads the test configuration from a file.
        /// </summary>
        private void LoadConfiguration(string filePath)
        {
            // load the new configuration.
            m_testConfiguration = ServerTestConfiguration.Load(filePath, m_testConfiguration);

            // update the file list.
            Utils.UpdateRecentFileList("Server Test Client", filePath, 4);

            // update the control.
            TestCasesCTRL.Initialize(m_testConfiguration);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public SessionTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
     :
     base("Activate", session, configuration, reportMessage, reportProgress, template)
 {
     m_errorEvent = new ManualResetEvent(false);
     m_messages   = new Dictionary <uint, List <uint> >();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public SessionTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
 : 
     base("Activate", session, configuration, reportMessage, reportProgress, template)
 {
     m_errorEvent = new ManualResetEvent(false);
     m_messages = new Dictionary<uint,List<uint>>();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public BrowseTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
 : 
     base("Browse", session, configuration, reportMessage, reportProgress, template)
 {
     m_view = new ViewDescription();
     m_view.ViewId = null;
     m_view.Timestamp = DateTime.MinValue;
     m_view.ViewVersion = 0;
     m_maxReferencesPerNode = 0;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public SubscribeTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
 : 
     base("Subscribe", session, configuration, reportMessage, reportProgress, template)
 {
     m_subscriptions = new List<Subscription>();
     m_errorEvent = new ManualResetEvent(false);
     m_acknowledgements = new SubscriptionAcknowledgementCollection();
     m_publishPipelineDepth = 10;
     m_idealTimingError = 400;
     m_maximumTimingError = 500;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public WriteTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
     :
     base("Write", session, configuration, reportMessage, reportProgress, template)
 {
     m_generator = new Opc.Ua.Test.DataGenerator(new Opc.Ua.Test.RandomSource(configuration.Seed));
     m_generator.NamespaceUris        = Session.NamespaceUris;
     m_generator.ServerUris           = Session.ServerUris;
     m_generator.MaxArrayLength       = 3;
     m_generator.MaxStringLength      = 10;
     m_generator.MaxXmlElementCount   = 3;
     m_generator.MaxXmlAttributeCount = 3;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public CallTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
 : 
     base("Call", session, configuration, reportMessage, reportProgress, template)
 {
     m_generator = new Opc.Ua.Test.DataGenerator(new Opc.Ua.Test.RandomSource(configuration.Seed));
     m_generator.NamespaceUris = Session.NamespaceUris;
     m_generator.ServerUris = Session.ServerUris;
     m_generator.MaxArrayLength = 3;
     m_generator.MaxStringLength = 10;
     m_generator.MaxXmlElementCount = 3;
     m_generator.MaxXmlAttributeCount = 3;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates the test object.
        /// </summary>
        public MonitoredItemTest(
            Session session,
            ServerTestConfiguration configuration,
            ReportMessageEventHandler reportMessage,
            ReportProgressEventHandler reportProgress,
            TestBase template)
        : 
            base("MonitoredItem", session, configuration, reportMessage, reportProgress, template)
        {
            m_generator = new Opc.Ua.Test.DataGenerator(new Opc.Ua.Test.RandomSource(configuration.Seed));
            m_generator.NamespaceUris = Session.NamespaceUris;
            m_generator.ServerUris = Session.ServerUris;
            m_generator.MaxArrayLength = 3;
            m_generator.MaxStringLength = 10;
            m_generator.MaxXmlElementCount = 3;
            m_generator.MaxXmlAttributeCount = 3;
            m_comparer = new Opc.Ua.Test.DataComparer(Session.MessageContext);
            m_comparer.ThrowOnError = false;
            
            m_errorEvent = new ManualResetEvent(false);
            m_maximumTimingError = 300;

            m_variables = new List<TestVariable>();    
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Loads the test configuration from a file.
        /// </summary>
        private void LoadConfiguration(string filePath)
        {
            // load the new configuration.
            m_testConfiguration = ServerTestConfiguration.Load(filePath, m_testConfiguration);

            // update the file list.
            Utils.UpdateRecentFileList("Server Test Client", filePath, 4);

            // update the control.
            TestCasesCTRL.Initialize(m_testConfiguration);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Runs the testcases against the endpoint.
        /// </summary>
        /// <param name="endpoint">The endpoint to test.</param>
        /// <param name="testcases">The testcases to run.</param>
        public void Run(ConfiguredEndpoint endpoint, ServerTestConfiguration testConfiguration)
        {
            // save the test configuration.
            m_testConfiguration = testConfiguration;
            m_stopped = false;

            // create the binding factory.
            m_bindingFactory = BindingFactory.Create(m_configuration, m_messageContext);

            while (!m_stopped)
            {
                try
                { 
                    Report("Test run started.");

                    // update from server.
                    if (endpoint.UpdateBeforeConnect)
                    {
                        endpoint.UpdateFromServer(m_bindingFactory);
                        Report("Updated endpoint from the discovery endpoint.");
                    }
                    
                    // validate the server certificate.
                    byte[] certificateData = endpoint.Description.ServerCertificate;

                    try
                    {
                        X509Certificate2 certificate = CertificateFactory.Create(certificateData, true);
                        m_configuration.CertificateValidator.Validate(certificate);
                    }
                    catch (ServiceResultException e)
                    {
                        if (e.StatusCode != StatusCodes.BadCertificateUntrusted)
                        {
                            throw new ServiceResultException(e, StatusCodes.BadCertificateInvalid);
                        }
                        
                        // automatically trust the certificate if it is untrusted.
                        m_configuration.CertificateValidator.Update(m_configuration.SecurityConfiguration);
                    }

                    m_defaultEndpoint = endpoint;
                    
                    // fetch all endpoints from the server.
                    m_endpoints = GetEndpoints(endpoint);
                    Report("Fetched all endpoints supported by the server.");
                }
                catch (Exception e)
                {
                    Report(e, "Could not connect to server");
                    return;
                }

                m_endpointCount = 0;
                m_totalEndpointCount = 0;
                m_testCount = 0;
                m_failedTestCount = 0;
                m_iterationCount = 0;
                m_totalIterationCount = 0;

                uint totalCount = 0;
                uint failedCount = 0;
                uint endpointCount = 0;

                if (m_testConfiguration.EndpointSelection != EndpointSelection.Single)
                {
                    EndpointSelection selection = m_testConfiguration.EndpointSelection;

                    foreach (ConfiguredEndpoint current in m_endpoints.Endpoints)
                    {
                        if (IsEndpointSelected(current, selection, false))
                        {
                            m_totalEndpointCount++;
                        }

                        if (current.Description.EncodingSupport == BinaryEncodingSupport.Optional)
                        {
                            if (IsEndpointSelected(current, selection, true))
                            {
                                m_totalEndpointCount++;
                            }
                        }
                    }

                    foreach (ConfiguredEndpoint current in m_endpoints.Endpoints)
                    {
                        if (IsEndpointSelected(current, selection, false))
                        {
                            m_endpointCount++;

                            // check if test stopped.
                            if (m_stopped)
                            {
                                break;
                            }

                            DoTestForEndpoint(current, ref totalCount, ref failedCount);
                            endpointCount++;
                        }

                        if (current.Description.EncodingSupport == BinaryEncodingSupport.Optional)
                        {         
                            if (IsEndpointSelected(current, selection, true))
                            {                   
                                m_endpointCount++;
                             
                                // check if test stopped.
                                if (m_stopped)
                                {
                                    break;
                                }
                                
                                current.Configuration.UseBinaryEncoding = !current.Configuration.UseBinaryEncoding;
                                DoTestForEndpoint(current, ref totalCount, ref failedCount);
                                endpointCount++;
                            }
                        }
                    }
                }
                else
                {
                    m_endpointCount++;
                    m_totalEndpointCount = 1;

                    DoTestForEndpoint(m_defaultEndpoint, ref totalCount, ref failedCount);
                    endpointCount++;
                }

                if (failedCount > 0)
                {
                    Report("WARNING: {0} tests failed. {1} tests run.", failedCount, totalCount);
                }
                else
                {
                    Report("{0} tests completed successfully for {1} endpoints.", totalCount, endpointCount);
                    DumpPerfData();
                }

                if (!m_testConfiguration.Continuous)
                {
                    break;
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Runs the testcases against the endpoint.
        /// </summary>
        /// <param name="endpoint">The endpoint to test.</param>
        /// <param name="testcases">The testcases to run.</param>
        public void Run(ConfiguredEndpoint endpoint, ServerTestConfiguration testConfiguration)
        {
            // save the test configuration.
            m_testConfiguration = testConfiguration;
            m_stopped           = false;

            // create the binding factory.
            m_bindingFactory = BindingFactory.Create(m_configuration, m_messageContext);

            while (!m_stopped)
            {
                try {
                    Report("Test run started.");

                    // update from server.
                    if (endpoint.UpdateBeforeConnect)
                    {
                        endpoint.UpdateFromServer(m_bindingFactory);
                        Report("Updated endpoint from the discovery endpoint.");
                    }

                    // validate the server certificate.
                    byte[] certificateData = endpoint.Description.ServerCertificate;

                    try {
                        X509Certificate2 certificate = CertificateFactory.Create(certificateData, true);
                        m_configuration.CertificateValidator.Validate(certificate);
                    } catch (ServiceResultException e) {
                        if (e.StatusCode != StatusCodes.BadCertificateUntrusted)
                        {
                            throw new ServiceResultException(e, StatusCodes.BadCertificateInvalid);
                        }

                        // automatically trust the certificate if it is untrusted.
                        m_configuration.CertificateValidator.Update(m_configuration.SecurityConfiguration);
                    }

                    m_defaultEndpoint = endpoint;

                    // fetch all endpoints from the server.
                    m_endpoints = GetEndpoints(endpoint);
                    Report("Fetched all endpoints supported by the server.");
                } catch (Exception e) {
                    Report(e, "Could not connect to server");
                    return;
                }

                m_endpointCount       = 0;
                m_totalEndpointCount  = 0;
                m_testCount           = 0;
                m_failedTestCount     = 0;
                m_iterationCount      = 0;
                m_totalIterationCount = 0;

                uint totalCount    = 0;
                uint failedCount   = 0;
                uint endpointCount = 0;

                if (m_testConfiguration.EndpointSelection != EndpointSelection.Single)
                {
                    EndpointSelection selection = m_testConfiguration.EndpointSelection;

                    foreach (ConfiguredEndpoint current in m_endpoints.Endpoints)
                    {
                        if (IsEndpointSelected(current, selection, false))
                        {
                            m_totalEndpointCount++;
                        }

                        if (current.Description.EncodingSupport == BinaryEncodingSupport.Optional)
                        {
                            if (IsEndpointSelected(current, selection, true))
                            {
                                m_totalEndpointCount++;
                            }
                        }
                    }

                    foreach (ConfiguredEndpoint current in m_endpoints.Endpoints)
                    {
                        if (IsEndpointSelected(current, selection, false))
                        {
                            m_endpointCount++;

                            // check if test stopped.
                            if (m_stopped)
                            {
                                break;
                            }

                            DoTestForEndpoint(current, ref totalCount, ref failedCount);
                            endpointCount++;
                        }

                        if (current.Description.EncodingSupport == BinaryEncodingSupport.Optional)
                        {
                            if (IsEndpointSelected(current, selection, true))
                            {
                                m_endpointCount++;

                                // check if test stopped.
                                if (m_stopped)
                                {
                                    break;
                                }

                                current.Configuration.UseBinaryEncoding = !current.Configuration.UseBinaryEncoding;
                                DoTestForEndpoint(current, ref totalCount, ref failedCount);
                                endpointCount++;
                            }
                        }
                    }
                }
                else
                {
                    m_endpointCount++;
                    m_totalEndpointCount = 1;

                    DoTestForEndpoint(m_defaultEndpoint, ref totalCount, ref failedCount);
                    endpointCount++;
                }

                if (failedCount > 0)
                {
                    Report("WARNING: {0} tests failed. {1} tests run.", failedCount, totalCount);
                }
                else
                {
                    Report("{0} tests completed successfully for {1} endpoints.", totalCount, endpointCount);
                    DumpPerfData();
                }

                if (!m_testConfiguration.Continuous)
                {
                    break;
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Runs the test in a console.
        /// </summary>
        private static void RunInConsole(string endpointUrl)
        {
            ApplicationConfiguration m_configuration = GuiUtils.DoStartupChecks("Opc.Ua.ServerTestTool", ApplicationType.Client, null, true);

            if (m_configuration == null)
            {
                return;
            }

            GuiUtils.OverrideUaTcpImplementation(m_configuration);

            m_configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
            ServerTestConfiguration m_testConfiguration = ServerTestConfiguration.Load(m_configuration.Extensions);

            m_testConfiguration.Coverage              = 30;
            m_testConfiguration.EndpointSelection     = EndpointSelection.All;
            m_testConfiguration.ConnectToAllEndpoints = true;

            // initialize the log file.
            m_logFilePath = null;

            if (m_configuration.TraceConfiguration != null)
            {
                m_logFilePath = Utils.GetAbsoluteFilePath(m_configuration.TraceConfiguration.OutputFilePath, true, false, true);
                FileInfo file = new FileInfo(m_logFilePath);
                m_logFilePath  = file.DirectoryName;
                m_logFilePath += "\\Opc.Ua.ServerTestTool";
            }

            if (String.IsNullOrEmpty(m_logFilePath))
            {
                m_logFilePath = m_configuration.SourceFilePath;
            }

            if (!String.IsNullOrEmpty(m_logFilePath))
            {
                try
                {
                    m_logFilePath += ".";
                    m_logFilePath += Utils.GetAssemblyBuildNumber();
                    m_logFilePath += ".log.txt";

                    using (StreamWriter logWriter = new StreamWriter(File.Open(m_logFilePath, FileMode.Create)))
                    {
                        logWriter.WriteLine(Utils.Format("Logging Started at {0:hh:mm:ss}", DateTime.Now));
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            // create the test client.
            ServerTestClient testClient = new ServerTestClient(m_configuration);

            ConfiguredEndpointCollection collection = new ConfiguredEndpointCollection();
            ConfiguredEndpoint           endpoint   = collection.Create(endpointUrl);

            testClient.ReportResult += new EventHandler <ServerTestClient.ReportResultEventArgs>(TestClient_ReportTestResult);
            testClient.Run(endpoint, m_testConfiguration);
        }