Skip to content

Commit

Permalink
Fix sending tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kayoub5 authored and chmorgan committed Mar 14, 2020
1 parent d5290c1 commit e416a44
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
command: sudo bash .circleci/install.sh
- run:
name: Test
command: sudo dotnet test --test-adapter-path:. --logger:junit -f netcoreapp2.1
command: sudo dotnet test --test-adapter-path:. --logger:junit -f netcoreapp2.1 --filter TestCategory!=SendPacket
- store_test_results:
path: Test/TestResults

Expand Down
2 changes: 1 addition & 1 deletion .config/travis/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ fi
# Test on linux
if [ "$TRAVIS_OS_NAME" = "linux" ]
then
sudo dotnet test -f netcoreapp2.1
sudo dotnet test -f netcoreapp2.1 --filter TestCategory!=SendPacket
fi
1 change: 1 addition & 0 deletions Test/PcapDeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class PcapDeviceTest
/// Test that the proper exception is thrown if a user tries to
/// call GetNextPacket() while a capture loop is running.
/// </summary>
[NonParallelizable]
[Test]
public void GetNextPacketExceptionIfCaptureLoopRunning()
{
Expand Down
5 changes: 1 addition & 4 deletions Test/SendPacketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ namespace Test
{
[TestFixture]
[NonParallelizable]
[Category("SendPacket")]
public class SendPacketTest
{
private const string Filter = "ether proto 0x1234";

[Test]
[Ignore("Not sure why test fails")]
public void TestSendPacketTest()
{
var packet = EthernetPacket.RandomPacket();
packet.Type = (EthernetType)0x1234;
var received = RunCapture(Filter, (device) =>
{
device.SendPacket(packet);
// Test hack: MacOS 10.15, delay of 1000ms causes this test to pass on cmorgan's 2019 macbook pro,
// 500ms does not
System.Threading.Thread.Sleep(1000);
});
Assert.That(received, Has.Count.EqualTo(1));
CollectionAssert.AreEquivalent(packet.Bytes, received[0].Data);
Expand Down
13 changes: 0 additions & 13 deletions Test/SendQueueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class SendQueueTest
private static readonly int DeltaMs = 10;

[Test]
[Ignore("Not sure why test fails")]
public void TestNativeTransmitNormal()
{
if (SendQueue.IsHardwareAccelerated)
Expand All @@ -37,7 +36,6 @@ public void TestNativeTransmitNormal()
}

[Test]
[Ignore("Not sure why test fails")]
public void TestNativeTransmitSync()
{
if (SendQueue.IsHardwareAccelerated)
Expand All @@ -54,31 +52,21 @@ public void TestNativeTransmitSync()
}

[Test]
[Ignore("Not sure why test fails")]
public void TestManagedTransmitNormal()
{
var received = RunCapture(Filter, (device) =>
{
GetSendQueue().ManagedTransmit(device, false);

// Test hack: MacOS 10.15, delay of 1000ms causes this test to pass on cmorgan's 2019 macbook pro,
// delay of 500ms does not
System.Threading.Thread.Sleep(1000);
});
AssertGoodTransmitNormal(received);
}

[Test]
[Ignore("Not sure why test fails")]
public void TestManagedTransmitSync()
{
var received = RunCapture(Filter, (device) =>
{
GetSendQueue().ManagedTransmit(device, true);

// Test hack: MacOS 10.15, delay of 2000ms causes this test to pass on cmorgan's 2019 macbook pro,
// delay of 1500ms does not
System.Threading.Thread.Sleep(2000);
});
AssertGoodTransmitSync(received);
}
Expand All @@ -96,7 +84,6 @@ private static void AssertGoodTransmitSync(List<RawCapture> received)
}

[Test]
[Ignore("Not sure why test fails")]
public void TestReturnValue()
{
if (SendQueue.IsHardwareAccelerated)
Expand Down
24 changes: 14 additions & 10 deletions Test/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ internal static PcapDevice GetPcapDevice()
{
Console.WriteLine(ex);
continue;
} finally
}
finally
{
if (device.Opened) device.Close();
}
Expand Down Expand Up @@ -79,22 +80,25 @@ internal static List<RawCapture> RunCapture(string filter, Action<PcapDevice> ro
}
Console.WriteLine($"Using device {device}");
var received = new List<RawCapture>();
device.Open();
device.Open(DeviceMode.Normal, 1);
device.Filter = filter;
void OnPacketArrival(object sender, CaptureEventArgs e)
{
received.Add(e.Packet);
}
device.OnPacketArrival += OnPacketArrival;
device.StartCapture();
try
{
routine(device);
// waiting for any queued packets to be sent
Thread.Sleep(10);
while (true)
{
var packet = device.GetNextPacket();
if (packet == null)
{
break;
}
received.Add(packet);
}
}
finally
{
device.StopCapture();
device.OnPacketArrival -= OnPacketArrival;
device.Close();
}
return received;
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
sudo apt-get install -y libpcap-dev
- script: |
set -e
sudo dotnet test -f netcoreapp2.1 Test/Test.csproj --configuration $(buildConfiguration) --logger trx --filter TestCategory!=Performance
sudo dotnet test -f netcoreapp2.1 Test/Test.csproj --configuration $(buildConfiguration) --logger trx --filter "TestCategory!=Performance&TestCategory!=SendPacket"
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
Expand Down

0 comments on commit e416a44

Please sign in to comment.