diff --git a/appveyor.yml b/appveyor.yml index d380a3f58..c9bb51683 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,6 +9,6 @@ build: test_script: - cmd: >- - vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net462\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration&TestCategory!=LongRunning" --blame + vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net462\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame - vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net7.0\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration&TestCategory!=LongRunning" --blame \ No newline at end of file + vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net7.0\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame diff --git a/src/Renci.SshNet.Tests/Classes/Common/ASCIIEncodingTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ASCIIEncodingTest.cs deleted file mode 100644 index 6e614b523..000000000 --- a/src/Renci.SshNet.Tests/Classes/Common/ASCIIEncodingTest.cs +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using System.Diagnostics; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - [TestClass] - public class ASCIIEncodingTest : TestBase - { - private Random _random; - private Encoding _ascii; - - [TestInitialize] - public void SetUp() - { - _random = new Random(); - _ascii = SshData.Ascii; - } - - [TestMethod] - public void GetByteCount_Chars() - { - var chars = new[] { 'B', 'e', 'l', 'g', 'i', 'u', 'm' }; - - var actual = _ascii.GetByteCount(chars); - - Assert.AreEqual(chars.Length, actual); - } - - [TestMethod] - public void GetBytes_CharArray() - { - var chars = new[] {'B', 'e', 'l', 'g', 'i', 'u', 'm'}; - - var actual = _ascii.GetBytes(chars); - - Assert.IsNotNull(actual); - Assert.AreEqual(7, actual.Length); - Assert.AreEqual(0x42, actual[0]); - Assert.AreEqual(0x65, actual[1]); - Assert.AreEqual(0x6c, actual[2]); - Assert.AreEqual(0x67, actual[3]); - Assert.AreEqual(0x69, actual[4]); - Assert.AreEqual(0x75, actual[5]); - Assert.AreEqual(0x6d ,actual[6]); - } - - [TestMethod] - public void GetCharCount_Bytes() - { - var bytes = new byte[] { 0x42, 0x65, 0x6c, 0x67, 0x69, 0x75, 0x6d }; - - var actual = _ascii.GetCharCount(bytes); - - Assert.AreEqual(bytes.Length, actual); - } - - [TestMethod] - public void GetChars_Bytes() - { - var bytes = new byte[] {0x42, 0x65, 0x6c, 0x67, 0x69, 0x75, 0x6d}; - - var actual = _ascii.GetChars(bytes); - - Assert.AreEqual("Belgium", new string(actual)); - } - - [TestMethod] - public void GetChars_Bytes_DefaultFallback() - { - var bytes = new byte[] { 0x42, 0x65, 0x6c, 0x80, 0x69, 0x75, 0x6d }; - - var actual = _ascii.GetChars(bytes); - - Assert.AreEqual("Bel?ium", new string(actual)); - } - - [TestMethod] - public void GetMaxByteCount_ShouldReturnCharCountPlusOneWhenCharCountIsNonNegative() - { - var charCount = _random.Next(0, 20000); - - var actual = _ascii.GetMaxByteCount(charCount); - - Assert.AreEqual(++charCount, actual); - } - - [TestMethod] - public void GetMaxByteCount_ShouldThrowArgumentOutOfRangeExceptionWhenCharCountIsNegative() - { - var charCount = _random.Next(-5000, -1); - - try - { - var actual = _ascii.GetMaxByteCount(charCount); - Assert.Fail(actual.ToString(CultureInfo.InvariantCulture)); - } - catch (ArgumentOutOfRangeException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("charCount", ex.ParamName); - } - } - - [TestMethod] - public void GetMaxCharCount_ShouldReturnByteCountWhenByteCountIsNonNegative() - { - var byteCount = _random.Next(0, 20000); - - var actual = _ascii.GetMaxCharCount(byteCount); - - Assert.AreEqual(byteCount, actual); - } - - [TestMethod] - public void GetMaxCharCount_ShouldThrowArgumentOutOfRangeExceptionWhenByteCountIsNegative() - { - var byteCount = _random.Next(-5000, -1); - - try - { - var actual = _ascii.GetMaxCharCount(byteCount); - Assert.Fail(actual.ToString(CultureInfo.InvariantCulture)); - } - catch (ArgumentOutOfRangeException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("byteCount", ex.ParamName); - } - } - - [TestMethod] - public void GetPreamble() - { - var actual = _ascii.GetPreamble(); - - Assert.AreEqual(0, actual.Length); - } - - [TestMethod] - public void IsSingleByte() - { - Assert.IsTrue(_ascii.IsSingleByte); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void GetBytes_Performance() - { - const string input = "eererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqs"; - const int loopCount = 10000000; - var result = new byte[input.Length]; - - var corefxAscii = new System.Text.ASCIIEncoding(); - var sshAscii = _ascii; - - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - corefxAscii.GetBytes(input, 0, input.Length, result, 0); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - - stopWatch.Reset(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - sshAscii.GetBytes(input, 0, input.Length, result, 0); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void GetChars_Performance() - { - var input = new byte[2000]; - new Random().NextBytes(input); - const int loopCount = 100000; - - var corefxAscii = new System.Text.ASCIIEncoding(); - var sshAscii = _ascii; - - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - var actual = corefxAscii.GetChars(input); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - - stopWatch.Reset(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - var actual = sshAscii.GetChars(input); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - - } -} \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs index 0640697a2..af5613e87 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs @@ -11,7 +11,6 @@ //#define FEATURE_NUMERICS_BIGINTEGER using System; -using System.Diagnostics; using System.Globalization; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -1559,61 +1558,6 @@ public void Bug16526() } } - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void ToArray_Performance() - { - const int loopCount = 100000000; - var bigInteger = new BigInteger(Huge_a); - - var stopWatch = new Stopwatch(); - - GC.Collect(); - _ = GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - _ = bigInteger.ToByteArray(); - } - - GC.Collect(); - _ = GC.WaitForFullGCComplete(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Ctor_ByteArray_Performance() - { - const int loopCount = 100000000; - - var stopWatch = new Stopwatch(); - - GC.Collect(); - _ = GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - _ = new BigInteger(Huge_a); - } - - GC.Collect(); - _ = GC.WaitForFullGCComplete(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - [TestMethod] public void MinusOne() { diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Concat.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Concat.cs index 1b3785f8f..ad961bfc4 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Concat.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Concat.cs @@ -1,7 +1,5 @@ using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; @@ -96,85 +94,6 @@ public void ShouldConcatSecondToFirstWhenBothAreNotEmpty() Assert.AreEqual(second[1], actual[5]); } - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_FirstEmpty() - { - var first = Array.Empty(); - var second = CreateBuffer(50000); - const int runs = 10000; - - Performance(first, second, runs); - } - - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_SecondEmpty() - { - var first = CreateBuffer(50000); - var second = Array.Empty(); - const int runs = 10000; - - Performance(first, second, runs); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_BothNotEmpty() - { - var first = CreateBuffer(50000); - var second = CreateBuffer(20000); - const int runs = 10000; - - Performance(first, second, runs); - } - - private static void Performance(byte[] first, byte[] second, int runs) - { - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Start(); - - for (var i = 0; i < runs; i++) - { - var result = Extensions.Concat(first, second); - var resultLength = result.Length; - } - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - - stopWatch.Reset(); - stopWatch.Start(); - - for (var i = 0; i < runs; i++) - { - var result = Enumerable.Concat(first, second); - var resultLength = result.ToArray().Length; - } - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - private byte[] CreateBuffer(int length) { var buffer = new byte[length]; diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs index c59fd5843..8d1d18076 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; @@ -96,95 +95,6 @@ public void ShouldReturnTrueWhenLeftIsSameAsRight() Assert.IsTrue(Extensions.IsEqualTo(left, left)); } - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_Equal() - { - var buffer = CreateBuffer(50000); - var left = buffer.Concat(new byte[] {0x0a}); - var right = buffer.Concat(new byte[] {0x0a}); - const int runs = 10000; - - Performance(left, right, runs); - } - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_NotEqual_DifferentLength() - { - var left = CreateBuffer(50000); - var right = left.Concat(new byte[] {0x0a}); - const int runs = 10000; - - Performance(left, right, runs); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_NotEqual_SameLength() - { - var buffer = CreateBuffer(50000); - var left = buffer.Concat(new byte[] {0x0a}); - var right = buffer.Concat(new byte[] {0x0b}); - const int runs = 10000; - - Performance(left, right, runs); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_Same() - { - var left = CreateBuffer(50000); - var right = left.Concat(new byte[] {0x0a}); - const int runs = 10000; - - Performance(left, right, runs); - } - - private static void Performance(byte[] left, byte[] right, int runs) - { - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Start(); - - for (var i = 0; i < runs; i++) - { - _ = Extensions.IsEqualTo(left, right); - } - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - - stopWatch.Reset(); - stopWatch.Start(); - - for (var i = 0; i < runs; i++) - { - var result = System.Linq.Enumerable.SequenceEqual(left, right); - } - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - private byte[] CreateBuffer(int length) { var buffer = new byte[length]; diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs index 3d734da19..05a090611 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Take_Count.cs @@ -1,7 +1,5 @@ using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; @@ -94,95 +92,6 @@ public void ShouldThrowArgumentExceptionWhenCountIsGreaterThanLengthOfValue() } } - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_All() - { - var value = CreateBuffer(50000); - var count = value.Length; - const int runs = 10000; - - Performance(value, count, runs); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_LargeCount() - { - var value = CreateBuffer(50000); - const int count = 40000; - const int runs = 1000000; - - Performance(value, count, runs); - } - - [TestMethod] - [TestCategory("LongRunning")] - [TestCategory("Performance")] - public void Performance_LargeArray_SmallCount() - { - var value = CreateBuffer(50000); - const int count = 50; - const int runs = 1000000; - - Performance(value, count, runs); - } - - [TestMethod] - [TestCategory("Performance")] - public void Performance_LargeArray_ZeroCount() - { - var value = CreateBuffer(50000); - const int count = 0; - const int runs = 1000000; - - Performance(value, count, runs); - } - - private static void Performance(byte[] value, int count, int runs) - { - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Start(); - - for (var i = 0; i < runs; i++) - { - var result = Extensions.Take(value, count); - var resultLength = result.Length; - } - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - - stopWatch.Reset(); - stopWatch.Start(); - - for (var i = 0; i < runs; i++) - { - var result = Enumerable.Take(value, count); - var resultLength = result.ToArray().Length; - } - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - private byte[] CreateBuffer(int length) { var buffer = new byte[length];