[USB][Non-ACR][Release the interface before activating configuration and Retry timed... 29/178929/1
authorlokilee73 <changjoo.lee@samsung.com>
Tue, 15 May 2018 02:13:14 +0000 (11:13 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Tue, 15 May 2018 02:13:18 +0000 (11:13 +0900)
Change-Id: Ia24c0b958d5ad893aad8989abc5fbf6cdc697537
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbBulkEndpoint.cs
tct-suite-vs/Tizen.Usb.Tests/testcase/TSUsbInterruptEndpoint.cs

index a4e7d74..3cbd3e1 100755 (executable)
@@ -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();
index 7d1b4e2..b2bf6d5 100755 (executable)
@@ -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();