From 26e53ce18eb4eca10362a0844ec638516109d0a4 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 15 May 2018 11:13:14 +0900 Subject: [PATCH] [USB][Non-ACR][Release the interface before activating configuration and Retry timed-out transfers] Change-Id: Ia24c0b958d5ad893aad8989abc5fbf6cdc697537 Signed-off-by: lokilee73 --- .../Tizen.Usb.Tests/testcase/TSUsbBulkEndpoint.cs | 64 +++++++++++++-------- .../testcase/TSUsbInterruptEndpoint.cs | 65 ++++++++++++++-------- 2 files changed, 81 insertions(+), 48 deletions(-) diff --git a/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbBulkEndpoint.cs b/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbBulkEndpoint.cs index a4e7d74..3cbd3e1 100755 --- a/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbBulkEndpoint.cs +++ b/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbBulkEndpoint.cs @@ -85,30 +85,46 @@ namespace Tizen.System.Usb.Tests if (inEndpoint != null && outEndpoint != null) { - if (!testUsbDevice.IsOpened) testUsbDevice.Open(); - Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state"); - - testInterfaces.Value.Release(); - testConfig.Value.SetAsActive(); - testInterfaces.Value.Claim(true); - - // TEST CODE - byte[] outBytes = Encoding.ASCII.GetBytes("HELLO"); - Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}"); - int sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 0); - Helper.Log($"Check"); - Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}"); - Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}"); - - byte[] inBytes = new byte[10]; - int receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 0); - Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}"); - - Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes"); - for (int i = 0; i < receivedBytes; ++i) - Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}"); - - Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}"); + bool timed_out; + int retry = 5; + + do + { + try { + if (!testUsbDevice.IsOpened) testUsbDevice.Open(); + Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state"); + + testInterfaces.Value.Release(); + testConfig.Value.SetAsActive(); + testInterfaces.Value.Claim(true); + + // TEST CODE + byte[] outBytes = Encoding.ASCII.GetBytes("HELLO"); + Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}"); + int sentBytes = 0; + int receivedBytes = 0; + byte[] inBytes = new byte[10]; + + timed_out = false; + sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 2000); + Helper.Log($"Check"); + Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}"); + Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}"); + receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 2000); + + Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}"); + Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes"); + for (int i = 0; i < receivedBytes; ++i) + Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}"); + + Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}"); + } + catch (TimeoutException) { + Helper.Log("Transfer timed out"); + timed_out = true; + Assert.IsTrue(retry-- > 0, "Transfer timed out too many times"); + } + } while (timed_out); } testInterfaces.Value.Release(); diff --git a/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbInterruptEndpoint.cs b/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbInterruptEndpoint.cs index 7d1b4e2..b2bf6d5 100755 --- a/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbInterruptEndpoint.cs +++ b/tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbInterruptEndpoint.cs @@ -85,30 +85,47 @@ namespace Tizen.System.Usb.Tests if (inEndpoint != null && outEndpoint != null) { - if (!testUsbDevice.IsOpened) testUsbDevice.Open(); - Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state"); - - testInterfaces.Value.Release(); - testConfig.Value.SetAsActive(); - testInterfaces.Value.Claim(true); - - // TEST CODE - byte[] outBytes = Encoding.ASCII.GetBytes("HELLO"); - Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}"); - int sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 0); - Helper.Log($"Check"); - Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}"); - Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}"); - - byte[] inBytes = new byte[10]; - int receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 0); - Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}"); - - Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes"); - for (int i = 0; i < receivedBytes; ++i) - Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}"); - - Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}"); + bool timed_out; + int retry = 5; + + do + { + try { + if (!testUsbDevice.IsOpened) testUsbDevice.Open(); + Assert.IsTrue(testUsbDevice.IsOpened, "Device under test should be in open state"); + + + testInterfaces.Value.Release(); + testConfig.Value.SetAsActive(); + testInterfaces.Value.Claim(true); + + // TEST CODE + byte[] outBytes = Encoding.ASCII.GetBytes("HELLO"); + Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, inBytes.Lenght: {outBytes.Length}"); + int sentBytes = 0; + int receivedBytes = 0; + byte[] inBytes = new byte[10]; + + timed_out = false; + sentBytes = outEndpoint.Transfer(outBytes, outBytes.Length, 2000); + Helper.Log($"Check"); + Assert.IsTrue(sentBytes == outBytes.Length, $"Wrong transferred byte length, Expected: {sentBytes}, Actual: {outBytes.Length}"); + Helper.Log($"inBytes: {Encoding.Default.GetString(outBytes)}, sentBytes: {sentBytes}"); + receivedBytes = inEndpoint.Transfer(inBytes, inBytes.Length, 2000); + + Helper.Log($"outBytes: {Encoding.Default.GetString(inBytes)}, receivedBytes: {receivedBytes}"); + Assert.IsTrue(sentBytes == receivedBytes, $"Expected: {sentBytes} bytes, Actual: {receivedBytes} bytes"); + for (int i = 0; i < receivedBytes; ++i) + Assert.IsTrue(inBytes[i] == outBytes[i], $"Expected: {inBytes[i]} Actual: {outBytes[i]}"); + + Helper.Log($"inBytes: {Encoding.Default.GetString(inBytes)}, outBytes: {Encoding.Default.GetString(outBytes)}"); + } + catch (TimeoutException) { + Helper.Log("Transfer timed out"); + timed_out = true; + Assert.IsTrue(retry-- > 0, "Transfer timed out too many times"); + } + } while (timed_out); } testInterfaces.Value.Release(); -- 2.7.4