public MFTestResults StressTest4_MarathonSend() { ///<summary> ///1. Starts a server socket listening for TCP ///2. Starts a client socket connected to the server ///3. Verifies that a large amount of data can be sent /// many consecutive times. ///</summary> MFTestResults testResult = MFTestResults.Pass; StressSocketPair testSockets = new StressSocketPair(ProtocolType.Tcp, SocketType.Stream); try { Log.Comment("Testing with port 0"); testSockets.Startup(0, 0); testSockets.socketServer.Listen(1); testSockets.socketClient.Connect(testSockets.epServer); int cBytes = 0; using (Socket sock = testSockets.socketServer.Accept()) { for (int i = 0; i < 100; i++) { cBytes = testSockets.socketClient.Send(testSockets.bufSend); if (cBytes != testSockets.bufSend.Length) throw new Exception("Send failed, wrong length"); if (sock.LocalEndPoint == null) throw new Exception("LocalEndPoint is null"); //Fix? if (testSockets.socketServer.LocalEndPoint.ToString() != sock.LocalEndPoint.ToString()) throw new Exception("LocalEndPoint is incorrect"); if (sock.RemoteEndPoint == null) throw new Exception("RemoteEndPoint is null"); if (testSockets.socketClient.LocalEndPoint.ToString() != sock.RemoteEndPoint.ToString()) throw new Exception("RemoteEndPoint is incorrect"); int cToReceive = cBytes; do { cToReceive -= sock.Receive(testSockets.bufReceive, cBytes - cToReceive, cToReceive, SocketFlags.None); } while (cToReceive > 0); } testSockets.AssertDataReceived(cBytes); testSockets.NewData(); } } catch (System.OutOfMemoryException e) { Log.Exception("Out of Memory Exception is ok on devices with limited memory constraints.", e); } catch (System.Net.Sockets.SocketException e) { Log.Exception("ErrorCode: " + ((SocketException)e).ErrorCode, e); testResult = MFTestResults.Fail; } catch (Exception e) { Log.Exception("Unexpected Exception", e); testResult = MFTestResults.Fail; } finally { testSockets.TearDown(); } return testResult; }
public MFTestResults StressTest2_LargePacketTCP() { ///<summary> ///1. Starts a server socket listening for TCP ///2. Starts a client socket connected to the server ///3. Verifies that a large amount of data can be sent ///</summary> const int c_StartSize = 0x100; const int c_EndSize = 0x10000; MFTestResults testResult = MFTestResults .Pass; int size = c_StartSize; int increment = 2; try { do { StressSocketPair testSockets = new StressSocketPair( ProtocolType.Tcp, SocketType.Stream ); Thread server = new Thread( new ThreadStart( testSockets.StressTestAsyncThreadProc ) ); testSockets.Startup(0, 0); testSockets.NewData( size ); testSockets.socketServer.Listen(1); testSockets.socketClient.Connect(testSockets.epServer); server.Start(); DateTime start = DateTime.Now; int cBytes = testSockets.socketClient.Send(testSockets.bufSend); if (cBytes != testSockets.bufSend.Length) throw new Exception("Send failed, wrong length"); testSockets.SyncPoint.WaitOne(); DateTime end = DateTime.Now; Log.Comment("Successfully received buffer of size " + testSockets.bufReceive.Length); int duration = (end - start).Milliseconds + 1; Log.Comment("Approximate " + testSockets.bufReceive.Length / duration + " Kb/sec rate to send "); testSockets.AssertDataReceived(cBytes); testSockets.TearDown(); testSockets = null; size *= increment; // clean up allocations Debug.GC(true); server.Join(); } while (size <= c_EndSize); } catch( System.Net.Sockets.SocketException e) { Log.Exception("Unexpected SocketException - ErrorCode: " + ((SocketException)e).ErrorCode, e); testResult = MFTestResults.Fail; } catch( System.OutOfMemoryException e) { Log.Exception("System.OutOfMemoryException", e); testResult = MFTestResults .Pass; } catch (Exception e) { Log.Exception("Unexpected Exception", e); testResult = MFTestResults.Fail; } return testResult; }
public MFTestResults StressTest3_LargePacketUDP() { /// <summary> /// 1. Starts a server socket listening for UDP /// 2. Starts a client socket sending UDP packets /// 3. Verifies that a large amount of data can be sent /// </summary> /// MFTestResults testResult = MFTestResults.Pass; StressSocketPair testSockets = new StressSocketPair(ProtocolType.Udp, SocketType.Dgram); try { Log.Comment("Testing with port 0"); testSockets.Startup(0, 0); int cBytes = testSockets.socketClient.SendTo(testSockets.bufSend, testSockets.epServer); if (cBytes != testSockets.bufSend.Length) throw new Exception("Send failed, wrong length"); EndPoint epFrom = new IPEndPoint(IPAddress.Any, 0); cBytes = testSockets.socketServer.ReceiveFrom(testSockets.bufReceive, ref epFrom); if (testSockets.epClient.Address.ToString() != ((IPEndPoint)epFrom).Address.ToString()) throw new Exception("Bad address"); } catch (SocketException e) { Log.Exception("Unexpected Socket Excption - ErrorCode: " + e.ErrorCode.ToString(), e); if (e.ErrorCode == 10047) { Log.Comment("Address family not supported by protocol family."); Log.Comment("This exception is thrown by the device driver that doesnt' implement Loopback for UDP"); } else { testResult = MFTestResults.Fail; Log.Comment("Fail for any other error codes that we don't know about"); } } catch (Exception e) { Log.Exception("Unexpected Exception", e); testResult = MFTestResults.Fail; } finally { testSockets.TearDown(); } return testResult; }
public MFTestResults StressTest1_LargePacketUDP() { ///<summary> ///1. Starts a server socket listening for TCP ///2. Starts a client socket connected to the server ///3. Verifies that a large amount of data can be sent ///</summary> const int c_StartSize = 0x100; const int c_EndSize = 0x176F; bool testResult = true; int size = c_StartSize; int increment = 2; try { do { StressSocketPair testSockets = new StressSocketPair( ProtocolType.Udp, SocketType.Dgram ); testSockets.Startup(0, 0); testSockets.NewData( size ); int cBytes = testSockets.socketClient.SendTo(testSockets.bufSend, testSockets.epServer); if (cBytes != testSockets.bufSend.Length) throw new Exception("Send failed, wrong length"); int cToReceive = cBytes; int spin = 0; do { int avail = testSockets.socketServer.Available; if(avail > 0) { EndPoint epClient = (EndPoint)testSockets.epClient; cToReceive -= testSockets.socketServer.ReceiveFrom( testSockets.bufReceive, cBytes - cToReceive, cToReceive, SocketFlags.None, ref epClient ); } else { Thread.Sleep( 100 ); ++spin; } } while (cToReceive > 0 && spin < 20 ); if(spin == 20) testResult = false; testSockets.AssertDataReceived(cBytes); testSockets.TearDown(); testSockets = null; // clean up allocations Debug.GC(true); size *= increment; } while (size <= c_EndSize); } catch (Exception e) { Log.Exception("Unexpected Exception", e); if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException")) Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode); testResult = false; } Log.Comment( "Max buffer size successfully sent and received was: " + (size / increment).ToString() ); return (testResult ? MFTestResults.Pass : MFTestResults.Pass); }
public MFTestResults StressTest4_MarathonSend() { ///<summary> ///1. Starts a server socket listening for TCP ///2. Starts a client socket connected to the server ///3. Verifies that a large amount of data can be sent /// many consecutive times. ///</summary> MFTestResults testResult = MFTestResults.Pass; StressSocketPair testSockets = new StressSocketPair(ProtocolType.Tcp, SocketType.Stream); try { Log.Comment("Testing with port 0"); testSockets.Startup(0, 0); testSockets.socketServer.Listen(1); testSockets.socketClient.Connect(testSockets.epServer); int cBytes = 0; using (Socket sock = testSockets.socketServer.Accept()) { for (int i = 0; i < 100; i++) { cBytes = testSockets.socketClient.Send(testSockets.bufSend); if (cBytes != testSockets.bufSend.Length) { throw new Exception("Send failed, wrong length"); } if (sock.LocalEndPoint == null) { throw new Exception("LocalEndPoint is null"); } //Fix? if (testSockets.socketServer.LocalEndPoint.ToString() != sock.LocalEndPoint.ToString()) { throw new Exception("LocalEndPoint is incorrect"); } if (sock.RemoteEndPoint == null) { throw new Exception("RemoteEndPoint is null"); } if (testSockets.socketClient.LocalEndPoint.ToString() != sock.RemoteEndPoint.ToString()) { throw new Exception("RemoteEndPoint is incorrect"); } int cToReceive = cBytes; do { cToReceive -= sock.Receive(testSockets.bufReceive, cBytes - cToReceive, cToReceive, SocketFlags.None); }while (cToReceive > 0); } testSockets.AssertDataReceived(cBytes); testSockets.NewData(); } } catch (System.OutOfMemoryException e) { Log.Exception("Out of Memory Exception is ok on devices with limited memory constraints.", e); } catch (System.Net.Sockets.SocketException e) { Log.Exception("ErrorCode: " + ((SocketException)e).ErrorCode, e); testResult = MFTestResults.Fail; } catch (Exception e) { Log.Exception("Unexpected Exception", e); testResult = MFTestResults.Fail; } finally { testSockets.TearDown(); } return(testResult); }
public MFTestResults StressTest3_LargePacketUDP() { /// <summary> /// 1. Starts a server socket listening for UDP /// 2. Starts a client socket sending UDP packets /// 3. Verifies that a large amount of data can be sent /// </summary> /// MFTestResults testResult = MFTestResults.Pass; StressSocketPair testSockets = new StressSocketPair(ProtocolType.Udp, SocketType.Dgram); try { Log.Comment("Testing with port 0"); testSockets.Startup(0, 0); int cBytes = testSockets.socketClient.SendTo(testSockets.bufSend, testSockets.epServer); if (cBytes != testSockets.bufSend.Length) { throw new Exception("Send failed, wrong length"); } EndPoint epFrom = new IPEndPoint(IPAddress.Any, 0); cBytes = testSockets.socketServer.ReceiveFrom(testSockets.bufReceive, ref epFrom); if (testSockets.epClient.Address.ToString() != ((IPEndPoint)epFrom).Address.ToString()) { throw new Exception("Bad address"); } } catch (SocketException e) { Log.Exception("Unexpected Socket Excption - ErrorCode: " + e.ErrorCode.ToString(), e); if (e.ErrorCode == 10047) { Log.Comment("Address family not supported by protocol family."); Log.Comment("This exception is thrown by the device driver that doesnt' implement Loopback for UDP"); } else { testResult = MFTestResults.Fail; Log.Comment("Fail for any other error codes that we don't know about"); } } catch (Exception e) { Log.Exception("Unexpected Exception", e); testResult = MFTestResults.Fail; } finally { testSockets.TearDown(); } return(testResult); }
public MFTestResults StressTest2_LargePacketTCP() { ///<summary> ///1. Starts a server socket listening for TCP ///2. Starts a client socket connected to the server ///3. Verifies that a large amount of data can be sent ///</summary> const int c_StartSize = 0x100; const int c_EndSize = 0x10000; MFTestResults testResult = MFTestResults.Pass; int size = c_StartSize; int increment = 2; try { do { StressSocketPair testSockets = new StressSocketPair( ProtocolType.Tcp, SocketType.Stream); Thread server = new Thread(new ThreadStart( testSockets.StressTestAsyncThreadProc)); testSockets.Startup(0, 0); testSockets.NewData(size); testSockets.socketServer.Listen(1); testSockets.socketClient.Connect(testSockets.epServer); server.Start(); DateTime start = DateTime.Now; int cBytes = testSockets.socketClient.Send(testSockets.bufSend); if (cBytes != testSockets.bufSend.Length) { throw new Exception("Send failed, wrong length"); } testSockets.SyncPoint.WaitOne(); DateTime end = DateTime.Now; Log.Comment("Successfully received buffer of size " + testSockets.bufReceive.Length); int duration = (end - start).Milliseconds + 1; Log.Comment("Approximate " + testSockets.bufReceive.Length / duration + " Kb/sec rate to send "); testSockets.AssertDataReceived(cBytes); testSockets.TearDown(); testSockets = null; size *= increment; // clean up allocations Debug.GC(true); server.Join(); } while (size <= c_EndSize); } catch (System.Net.Sockets.SocketException e) { Log.Exception("Unexpected SocketException - ErrorCode: " + ((SocketException)e).ErrorCode, e); testResult = MFTestResults.Fail; } catch (System.OutOfMemoryException e) { Log.Exception("System.OutOfMemoryException", e); testResult = MFTestResults.Pass; } catch (Exception e) { Log.Exception("Unexpected Exception", e); testResult = MFTestResults.Fail; } return(testResult); }
public MFTestResults StressTest1_LargePacketUDP() { ///<summary> ///1. Starts a server socket listening for TCP ///2. Starts a client socket connected to the server ///3. Verifies that a large amount of data can be sent ///</summary> const int c_StartSize = 0x100; const int c_EndSize = 0x176F; bool testResult = true; int size = c_StartSize; int increment = 2; try { do { StressSocketPair testSockets = new StressSocketPair(ProtocolType.Udp, SocketType.Dgram); testSockets.Startup(0, 0); testSockets.NewData(size); int cBytes = testSockets.socketClient.SendTo(testSockets.bufSend, testSockets.epServer); if (cBytes != testSockets.bufSend.Length) { throw new Exception("Send failed, wrong length"); } int cToReceive = cBytes; int spin = 0; do { int avail = testSockets.socketServer.Available; if (avail > 0) { EndPoint epClient = (EndPoint)testSockets.epClient; cToReceive -= testSockets.socketServer.ReceiveFrom( testSockets.bufReceive, cBytes - cToReceive, cToReceive, SocketFlags.None, ref epClient); } else { Thread.Sleep(100); ++spin; } }while (cToReceive > 0 && spin < 20); if (spin == 20) { testResult = false; } testSockets.AssertDataReceived(cBytes); testSockets.TearDown(); testSockets = null; // clean up allocations Debug.GC(true); size *= increment; } while (size <= c_EndSize); } catch (Exception e) { Log.Exception("Unexpected Exception", e); if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException")) { Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode); } testResult = false; } Log.Comment("Max buffer size successfully sent and received was: " + (size / increment).ToString()); return(testResult ? MFTestResults.Pass : MFTestResults.Pass); }