From 4b822fced97a235fefee89cd442479991ba31d72 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Aug 2024 12:24:22 +0200 Subject: [PATCH] Bump BenchmarkDotNet from 0.13.12 to 0.14.0 and fix some build issues for legacy platforms (#2707) * Bump BenchmarkDotNet from 0.13.12 to 0.14.0 * Fix NetStandard2.0 and Netstandard2.1 ci builds Bumps [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet) from 0.13.12 to 0.14.0. - [Release notes](https://github.com/dotnet/BenchmarkDotNet/releases) - [Commits](https://github.com/dotnet/BenchmarkDotNet/compare/v0.13.12...v0.14.0) --- updated-dependencies: - dependency-name: BenchmarkDotNet dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: Martin Regen --- .../Opc.Ua.Encoders.Fuzz.Tests.csproj | 2 +- .../Subscription/Subscription.cs | 18 ++--- Libraries/Opc.Ua.Server/Session/Session.cs | 69 +++++-------------- .../Types/Encoders/BinaryDecoder.cs | 8 ++- .../Types/Encoders/BinaryEncoder.cs | 3 +- .../Types/Utils/OpcUaCoreEventSource.cs | 4 +- .../Opc.Ua.Configuration.Tests.csproj | 2 +- .../Types/Encoders/EncoderTests.cs | 17 +++-- .../Opc.Ua.PubSub.Tests.csproj | 2 +- .../Opc.Ua.Security.Certificates.Tests.csproj | 2 +- .../Opc.Ua.Server.Tests.csproj | 2 +- Tests/customtest.bat | 4 +- azure-pipelines.yml | 17 +++-- 13 files changed, 62 insertions(+), 88 deletions(-) diff --git a/Fuzzing/Encoders/Fuzz.Tests/Opc.Ua.Encoders.Fuzz.Tests.csproj b/Fuzzing/Encoders/Fuzz.Tests/Opc.Ua.Encoders.Fuzz.Tests.csproj index f99d964b1..0f5f5dd52 100644 --- a/Fuzzing/Encoders/Fuzz.Tests/Opc.Ua.Encoders.Fuzz.Tests.csproj +++ b/Fuzzing/Encoders/Fuzz.Tests/Opc.Ua.Encoders.Fuzz.Tests.csproj @@ -30,7 +30,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Libraries/Opc.Ua.Client/Subscription/Subscription.cs b/Libraries/Opc.Ua.Client/Subscription/Subscription.cs index 944fff43c..5d5fd756f 100644 --- a/Libraries/Opc.Ua.Client/Subscription/Subscription.cs +++ b/Libraries/Opc.Ua.Client/Subscription/Subscription.cs @@ -869,12 +869,13 @@ public bool Transfer(ISession session, uint id, UInt32Collection availableSequen return false; } - if (serverHandles.Count != m_monitoredItems.Count || - clientHandles.Count != m_monitoredItems.Count) + int monitoredItemsCount = m_monitoredItems.Count; + if (serverHandles.Count != monitoredItemsCount || + clientHandles.Count != monitoredItemsCount) { // invalid state Utils.LogError("SubscriptionId {0}: Number of Monitored Items on client and server do not match after transfer {1}!={2}", - Id, serverHandles.Count, m_monitoredItems.Count); + Id, serverHandles.Count, monitoredItemsCount); return false; } @@ -947,12 +948,13 @@ public async Task TransferAsync(ISession session, uint id, UInt32Collectio return false; } - if (serverHandles.Count != m_monitoredItems.Count || - clientHandles.Count != m_monitoredItems.Count) + int monitoredItemsCount = m_monitoredItems.Count; + if (serverHandles.Count != monitoredItemsCount || + clientHandles.Count != monitoredItemsCount) { // invalid state Utils.LogError("SubscriptionId {0}: Number of Monitored Items on client and server do not match after transfer {1}!={2}", - Id, serverHandles.Count, m_monitoredItems.Count); + Id, serverHandles.Count, monitoredItemsCount); return false; } @@ -1531,7 +1533,7 @@ public void AddItem(MonitoredItem monitoredItem) } /// - /// Adds an item to the subscription. + /// Adds items to the subscription. /// public void AddItems(IEnumerable monitoredItems) { @@ -1586,7 +1588,7 @@ public void RemoveItem(MonitoredItem monitoredItem) } /// - /// Removes an item from the subscription. + /// Removes items from the subscription. /// public void RemoveItems(IEnumerable monitoredItems) { diff --git a/Libraries/Opc.Ua.Server/Session/Session.cs b/Libraries/Opc.Ua.Server/Session/Session.cs index 960742b0c..8453ff5eb 100644 --- a/Libraries/Opc.Ua.Server/Session/Session.cs +++ b/Libraries/Opc.Ua.Server/Session/Session.cs @@ -103,60 +103,25 @@ public Session( m_identity = new UserIdentity(); // initialize diagnostics. - m_diagnostics = new SessionDiagnosticsDataType(); - - m_diagnostics.SessionId = null; - m_diagnostics.SessionName = sessionName; - m_diagnostics.ClientDescription = clientDescription; - m_diagnostics.ServerUri = null; - m_diagnostics.EndpointUrl = endpointUrl; - m_diagnostics.LocaleIds = new StringCollection(); - m_diagnostics.ActualSessionTimeout = sessionTimeout; - m_diagnostics.ClientConnectionTime = DateTime.UtcNow; - m_diagnostics.ClientLastContactTime = DateTime.UtcNow; - m_diagnostics.CurrentSubscriptionsCount = 0; - m_diagnostics.CurrentMonitoredItemsCount = 0; - m_diagnostics.CurrentPublishRequestsInQueue = 0; - m_diagnostics.TotalRequestCount = new ServiceCounterDataType(); - m_diagnostics.UnauthorizedRequestCount = 0; - m_diagnostics.ReadCount = new ServiceCounterDataType(); - m_diagnostics.HistoryReadCount = new ServiceCounterDataType(); - m_diagnostics.WriteCount = new ServiceCounterDataType(); - m_diagnostics.HistoryUpdateCount = new ServiceCounterDataType(); - m_diagnostics.CallCount = new ServiceCounterDataType(); - m_diagnostics.CreateMonitoredItemsCount = new ServiceCounterDataType(); - m_diagnostics.ModifyMonitoredItemsCount = new ServiceCounterDataType(); - m_diagnostics.SetMonitoringModeCount = new ServiceCounterDataType(); - m_diagnostics.SetTriggeringCount = new ServiceCounterDataType(); - m_diagnostics.DeleteMonitoredItemsCount = new ServiceCounterDataType(); - m_diagnostics.CreateSubscriptionCount = new ServiceCounterDataType(); - m_diagnostics.ModifySubscriptionCount = new ServiceCounterDataType(); - m_diagnostics.SetPublishingModeCount = new ServiceCounterDataType(); - m_diagnostics.PublishCount = new ServiceCounterDataType(); - m_diagnostics.RepublishCount = new ServiceCounterDataType(); - m_diagnostics.TransferSubscriptionsCount = new ServiceCounterDataType(); - m_diagnostics.DeleteSubscriptionsCount = new ServiceCounterDataType(); - m_diagnostics.AddNodesCount = new ServiceCounterDataType(); - m_diagnostics.AddReferencesCount = new ServiceCounterDataType(); - m_diagnostics.DeleteNodesCount = new ServiceCounterDataType(); - m_diagnostics.DeleteReferencesCount = new ServiceCounterDataType(); - m_diagnostics.BrowseCount = new ServiceCounterDataType(); - m_diagnostics.BrowseNextCount = new ServiceCounterDataType(); - m_diagnostics.TranslateBrowsePathsToNodeIdsCount = new ServiceCounterDataType(); - m_diagnostics.QueryFirstCount = new ServiceCounterDataType(); - m_diagnostics.QueryNextCount = new ServiceCounterDataType(); - m_diagnostics.RegisterNodesCount = new ServiceCounterDataType(); - m_diagnostics.UnregisterNodesCount = new ServiceCounterDataType(); + DateTime now = DateTime.UtcNow; + m_diagnostics = new SessionDiagnosticsDataType { + SessionId = null, + SessionName = sessionName, + ClientDescription = clientDescription, + ServerUri = null, + EndpointUrl = endpointUrl, + ActualSessionTimeout = sessionTimeout, + ClientConnectionTime = now, + ClientLastContactTime = now, + }; // initialize security diagnostics. - m_securityDiagnostics = new SessionSecurityDiagnosticsDataType(); - - m_securityDiagnostics.SessionId = m_sessionId; - m_securityDiagnostics.ClientUserIdOfSession = m_identity.DisplayName; - m_securityDiagnostics.AuthenticationMechanism = m_identity.TokenType.ToString(); - m_securityDiagnostics.Encoding = context.ChannelContext.MessageEncoding.ToString(); - - m_securityDiagnostics.ClientUserIdHistory = new StringCollection(); + m_securityDiagnostics = new SessionSecurityDiagnosticsDataType { + SessionId = m_sessionId, + ClientUserIdOfSession = m_identity.DisplayName, + AuthenticationMechanism = m_identity.TokenType.ToString(), + Encoding = context.ChannelContext.MessageEncoding.ToString(), + }; m_securityDiagnostics.ClientUserIdHistory.Add(m_identity.DisplayName); EndpointDescription description = context.ChannelContext.EndpointDescription; diff --git a/Stack/Opc.Ua.Core/Types/Encoders/BinaryDecoder.cs b/Stack/Opc.Ua.Core/Types/Encoders/BinaryDecoder.cs index 85a96a914..a5f0b531c 100644 --- a/Stack/Opc.Ua.Core/Types/Encoders/BinaryDecoder.cs +++ b/Stack/Opc.Ua.Core/Types/Encoders/BinaryDecoder.cs @@ -516,8 +516,12 @@ public XmlElement ReadXmlElement(string fieldName) try { - // If 0 terminated, decrease length by one before converting to string - var utf8StringLength = bytes[bytes.Length - 1] == 0 ? bytes.Length - 1 : bytes.Length; + // If 0 terminated, decrease length before converting to string + int utf8StringLength = bytes.Length; + while (utf8StringLength > 0 && bytes[utf8StringLength - 1] == 0) + { + utf8StringLength--; + } string xmlString = Encoding.UTF8.GetString(bytes, 0, utf8StringLength); using (StringReader stream = new StringReader(xmlString)) using (XmlReader reader = XmlReader.Create(stream, Utils.DefaultXmlReaderSettings())) diff --git a/Stack/Opc.Ua.Core/Types/Encoders/BinaryEncoder.cs b/Stack/Opc.Ua.Core/Types/Encoders/BinaryEncoder.cs index 7e20c3a78..48522da10 100644 --- a/Stack/Opc.Ua.Core/Types/Encoders/BinaryEncoder.cs +++ b/Stack/Opc.Ua.Core/Types/Encoders/BinaryEncoder.cs @@ -467,8 +467,9 @@ public void WriteString(string fieldName, string value) int count = Encoding.UTF8.GetBytes(value, encodedBytes); WriteByteString(null, encodedBytes.Slice(0, count)); } + else #if NET5_0_OR_GREATER - else if (maxByteCount > maxByteCountPerBuffer) + if (maxByteCount > maxByteCountPerBuffer) { using (var bufferWriter = new ArrayPoolBufferWriter(minByteCountPerBuffer, maxByteCountPerBuffer)) { diff --git a/Stack/Opc.Ua.Core/Types/Utils/OpcUaCoreEventSource.cs b/Stack/Opc.Ua.Core/Types/Utils/OpcUaCoreEventSource.cs index 206c9f871..6200ad713 100644 --- a/Stack/Opc.Ua.Core/Types/Utils/OpcUaCoreEventSource.cs +++ b/Stack/Opc.Ua.Core/Types/Utils/OpcUaCoreEventSource.cs @@ -184,8 +184,8 @@ internal void WriteFormattedMessage(int id, int eventId, string EventName, strin { if (IsEnabled()) { - EventName = EventName ?? ""; - FormattedMessage = FormattedMessage ?? ""; + EventName = EventName ?? string.Empty; + FormattedMessage = FormattedMessage ?? string.Empty; WriteEvent(id, eventId, EventName, FormattedMessage); } } diff --git a/Tests/Opc.Ua.Configuration.Tests/Opc.Ua.Configuration.Tests.csproj b/Tests/Opc.Ua.Configuration.Tests/Opc.Ua.Configuration.Tests.csproj index db3f0cb8f..54fcb9dff 100644 --- a/Tests/Opc.Ua.Configuration.Tests/Opc.Ua.Configuration.Tests.csproj +++ b/Tests/Opc.Ua.Configuration.Tests/Opc.Ua.Configuration.Tests.csproj @@ -19,7 +19,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Tests/Opc.Ua.Core.Tests/Types/Encoders/EncoderTests.cs b/Tests/Opc.Ua.Core.Tests/Types/Encoders/EncoderTests.cs index c195dc1c0..ece1cc4bf 100644 --- a/Tests/Opc.Ua.Core.Tests/Types/Encoders/EncoderTests.cs +++ b/Tests/Opc.Ua.Core.Tests/Types/Encoders/EncoderTests.cs @@ -27,6 +27,10 @@ * http://opcfoundation.org/License/MIT/1.00/ * ======================================================================*/ +#if ECC_SUPPORT && !NETFRAMEWORK +#define SPAN_SUPPORT +#endif + using System; using System.IO; using System.Text; @@ -300,7 +304,7 @@ public void BinaryEncoder_WriteByteString() using (IEncoder encoder = new BinaryEncoder(stream, new ServiceMessageContext(), true)) { encoder.WriteByteString("ByteString1", new byte[] { 0, 1, 2, 3, 4, 5 }, 1, 3); -#if NET5_0_OR_GREATER +#if SPAN_SUPPORT var span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }, 1, 3); var nullspan = new ReadOnlySpan(null); encoder.WriteByteString("ByteString2", span); @@ -314,7 +318,7 @@ public void BinaryEncoder_WriteByteString() { var result = decoder.ReadByteString("ByteString1"); Assert.AreEqual(new byte[] { 1, 2, 3 }, result); -#if NET5_0_OR_GREATER +#if SPAN_SUPPORT result = decoder.ReadByteString("ByteString2"); Assert.AreEqual(new byte[] { 1, 2, 3 }, result); result = decoder.ReadByteString("ByteString3"); @@ -339,7 +343,7 @@ public void XmlEncoder_WriteByteString() using (IEncoder encoder = new XmlEncoder(new XmlQualifiedName("ByteStrings", Namespaces.OpcUaXsd), writer, new ServiceMessageContext())) { encoder.WriteByteString("ByteString1", new byte[] { 0, 1, 2, 3, 4, 5 }, 1, 3); -#if NET5_0_OR_GREATER +#if SPAN_SUPPORT var span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }, 1, 3); var nullspan = new ReadOnlySpan(null); encoder.WriteByteString("ByteString2", span); @@ -354,7 +358,7 @@ public void XmlEncoder_WriteByteString() { var result = decoder.ReadByteString("ByteString1"); Assert.AreEqual(new byte[] { 1, 2, 3 }, result); -#if NET5_0_OR_GREATER +#if SPAN_SUPPORT result = decoder.ReadByteString("ByteString2"); Assert.AreEqual(new byte[] { 1, 2, 3 }, result); result = decoder.ReadByteString("ByteString3"); @@ -377,7 +381,7 @@ public void JsonEncoder_WriteByteString() using (IEncoder encoder = new JsonEncoder(new ServiceMessageContext(), true, false, stream, true)) { encoder.WriteByteString("ByteString1", new byte[] { 0, 1, 2, 3, 4, 5 }, 1, 3); -#if NET5_0_OR_GREATER +#if SPAN_SUPPORT var span = new ReadOnlySpan(new byte[] { 0, 1, 2, 3, 4, 5 }, 1, 3); var nullspan = new ReadOnlySpan(null); encoder.WriteByteString("ByteString2", span); @@ -392,7 +396,7 @@ public void JsonEncoder_WriteByteString() { var result = decoder.ReadByteString("ByteString1"); Assert.AreEqual(new byte[] { 1, 2, 3 }, result); -#if NET5_0_OR_GREATER +#if SPAN_SUPPORT result = decoder.ReadByteString("ByteString2"); Assert.AreEqual(new byte[] { 1, 2, 3 }, result); result = decoder.ReadByteString("ByteString3"); @@ -807,5 +811,4 @@ BuiltInType builtInType #region Private Fields #endregion } - } diff --git a/Tests/Opc.Ua.PubSub.Tests/Opc.Ua.PubSub.Tests.csproj b/Tests/Opc.Ua.PubSub.Tests/Opc.Ua.PubSub.Tests.csproj index 49ac5df0e..f3536fb88 100644 --- a/Tests/Opc.Ua.PubSub.Tests/Opc.Ua.PubSub.Tests.csproj +++ b/Tests/Opc.Ua.PubSub.Tests/Opc.Ua.PubSub.Tests.csproj @@ -20,7 +20,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Tests/Opc.Ua.Security.Certificates.Tests/Opc.Ua.Security.Certificates.Tests.csproj b/Tests/Opc.Ua.Security.Certificates.Tests/Opc.Ua.Security.Certificates.Tests.csproj index f933a90b0..d177b2648 100644 --- a/Tests/Opc.Ua.Security.Certificates.Tests/Opc.Ua.Security.Certificates.Tests.csproj +++ b/Tests/Opc.Ua.Security.Certificates.Tests/Opc.Ua.Security.Certificates.Tests.csproj @@ -34,7 +34,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Tests/Opc.Ua.Server.Tests/Opc.Ua.Server.Tests.csproj b/Tests/Opc.Ua.Server.Tests/Opc.Ua.Server.Tests.csproj index dc9cef719..38e1019ea 100644 --- a/Tests/Opc.Ua.Server.Tests/Opc.Ua.Server.Tests.csproj +++ b/Tests/Opc.Ua.Server.Tests/Opc.Ua.Server.Tests.csproj @@ -20,7 +20,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Tests/customtest.bat b/Tests/customtest.bat index 4ffc64b19..7ae1bbecb 100644 --- a/Tests/customtest.bat +++ b/Tests/customtest.bat @@ -2,12 +2,12 @@ setlocal enabledelayedexpansion echo This script is used to run custom platform tests for the UA Core Library -echo Supported parameters: net462, netstandard2.0, netstandard2.1, net48, net6.0, net8.0 +echo Supported parameters: net462, netstandard2.0, netstandard2.1, net472, net48, net6.0, net8.0 REM Check if the target framework parameter is provided if "%1"=="" ( echo Usage: %0 [TargetFramework] - echo Allowed values for TargetFramework: net462, netstandard2.0, netstandard2.1, net48, net6.0, net8.0, default + echo Allowed values for TargetFramework: net462, netstandard2.0, netstandard2.1, net472, net48, net6.0, net8.0, default goto :eof ) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a97686ef4..1d2ede8b5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -70,27 +70,28 @@ stages: framework: net6.0 agents: '@{ windows = "windows-2022"; linux="ubuntu-22.04"; mac = "macOS-12"}' jobnamesuffix: net60 + customtestarget: net6.0 - stage: testreleasepr dependsOn: [] - displayName: 'Fast .NET 6.0 PR Test' + displayName: 'Fast .NET 8.0 PR Test' condition: and(eq(variables.FullBuild, 'False'), eq(variables.ScheduledBuild, 'False')) jobs: - template: .azurepipelines/test.yml parameters: configuration: Release - framework: net6.0 + framework: net8.0 agents: '@{ windows = "windows-2022"; linux="ubuntu-20.04"}' - jobnamesuffix: net60pr + jobnamesuffix: net80pr - stage: testdebug dependsOn: [build] - displayName: 'Test .NET 6.0 Debug' + displayName: 'Test .NET 8.0 Debug' condition: and(succeeded(), ne(variables.ScheduledBuild, 'False')) jobs: - template: .azurepipelines/test.yml parameters: - framework: net6.0 + framework: net8.0 configuration: Debug - jobnamesuffix: net60debug + jobnamesuffix: net80debug - stage: testnet80 dependsOn: [build] displayName: 'Test .NET 8.0' @@ -101,7 +102,6 @@ stages: framework: net8.0 configuration: Release jobnamesuffix: net80 - customtestarget: net8.0 - stage: testnet462 dependsOn: [build] displayName: 'Test .NET 4.6.2' @@ -159,5 +159,4 @@ stages: configuration: Release poolImage: 'ubuntu-22.04' framework: net8.0 - jobnamesuffix: net60cc - customtestarget: net8.0 + jobnamesuffix: net80cc