From d616f0ccb0f6600a1e7005c5ce6240aaf561b138 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 27 Jan 2016 14:31:24 -0800 Subject: [PATCH] Fix FindFirstEqualByte tests - On some platforms, the bytes array was not large enough to fill a vector. Ex: https://travis-ci.org/aspnet/KestrelHttpServer/builds/105277870#L2633 - Additionally test FindFirstEqualByte with only one bit set in the array --- .../MemoryPoolIterator2Tests.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs index 046f032fc2..cb11398a42 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/MemoryPoolIterator2Tests.cs @@ -21,31 +21,43 @@ namespace Microsoft.AspNetCore.Server.KestrelTests } [Fact] - public void FindFirstByte() + public void FindFirstEqualByte() { - var bytes = new byte[] { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); bytes[i] = 0; } + + for (int i = 0; i < Vector.Count; i++) + { + bytes[i] = 1; + Vector vector = new Vector(bytes); + Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByte(ref vector)); + bytes[i] = 0; + } } [Fact] - public void _FindFirstByte() + public void FindFirstEqualByteSlow() { - var bytes = new byte[] { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + var bytes = Enumerable.Repeat(0xff, Vector.Count).ToArray(); for (int i = 0; i < Vector.Count; i++) { Vector vector = new Vector(bytes); Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); bytes[i] = 0; } + + for (int i = 0; i < Vector.Count; i++) + { + bytes[i] = 1; + Vector vector = new Vector(bytes); + Assert.Equal(i, MemoryPoolIterator2.FindFirstEqualByteSlow(ref vector)); + bytes[i] = 0; + } } [Theory]