Microsoft.Protocols.TestSuites.Rdpeusb.RdpeusbTestSutie.S3_EUSB_OperateIo_OSRFX2_BulkWriteRead C# (CSharp) Method

S3_EUSB_OperateIo_OSRFX2_BulkWriteRead() private method

private S3_EUSB_OperateIo_OSRFX2_BulkWriteRead ( ) : void
return void
        public void S3_EUSB_OperateIo_OSRFX2_BulkWriteRead()
        {
            LogComment("S3_EUSB_OperateIo_OSRFX2_BulkWriteRead");

            LogComment("1. Creates the control virtual channel, exchanges capabilities then notifies that the channel is created.");
            context.ControlChannel = CreateVirtualChannel();

            LogComment("2. Receives an add virtual channel request.");
            rdpeusbAdapter.ExpectAddVirtualChannel(context.ControlChannel);

            LogComment("3. Creates a new virtual channel for the device.");
            DynamicVirtualChannel channel = CreateVirtualChannel();

            LogComment("4. Receives an add device request.");
            EusbDeviceContext device = rdpeusbAdapter.ExpectAddDevice(channel);

            LogComment("5. Registers a callback to provide the Request Completion Interface to the client.");
            uint interfaceId = IdGenerator.NewId();
            rdpeusbAdapter.RegisterCallback(device, 1, interfaceId);

            LogComment("6. Selects the configuration with index 0.");
            SelectConfiguration(device, 0);

            Site.Assume.IsTrue(
                null != context.SelectedConfig && context.SelectedConfig.NumInterfaces == 1,
                "The configuration for the device must contain one single interface.");
            Site.Assume.IsTrue(
                context.SelectedConfig.Interface[0].NumberOfPipes == 3,
                "The interface of the device must contain 3 endpoints.");

            byte[] data = BulkTransferData;
            uint requestId = IdGenerator.NewId();
            TS_USBD_PIPE_INFORMATION_RESULT[] endpoints = context.SelectedConfig.Interface[0].Pipes;
            byte endpointNum = (byte)EndpointNumber.BulkOut; // Endpoint 6: Bulk, OUT from host to board

            LogComment("7. Writes test data to the bulk write endpoint");
            TS_URB_BULK_OR_INTERRUPT_TRANSFER req = new UrbBuilder(
                URB_FUNCTIONID.URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER,
                requestId,
                0).BuildInterruptTransferRequest(
                endpoints,
                endpointNum,
                TransferFlags.USBD_TRANSFER_DIRECTION_OUT,
                USBD_PIPE_TYPE.UsbdPipeTypeBulk
                );
            rdpeusbAdapter.TransferOutRequest(device, req, data);

            EusbPdu pdu = rdpeusbAdapter.ExpectCompletion(device.VirtualChannel);
            Site.Assert.IsInstanceOfType(
                pdu,
                typeof(EusbUrbCompletionNoDataPdu),
                "The result must be type of EusbUrbCompletionNoDataPdu.");
            EusbUrbCompletionNoDataPdu pduResNoData = (EusbUrbCompletionNoDataPdu)pdu;
            Site.Assert.IsSuccess((int)pduResNoData.HResult, "The EusbUrbCompletionNoDataPdu must indicate successful.");
            ReqCapturer.VerifyUrbCompletionNoData(pduResNoData, req, false, interfaceId);
            Site.Assert.AreEqual(
                (uint)data.Length,
                pduResNoData.OutputBufferSize,
                "The size, in bytes, of data sent to the device of the RequestId that corresponds to a TRANSFER_OUT_REQUEST."
                );

            requestId = IdGenerator.NewId();
            endpointNum = (byte)EndpointNumber.BulkIn; // Endpoint 8: Bulk, IN from board to host

            LogComment("8. Reads data from the bulk read endpoint and verifies they read are same as written data.");
            req = new UrbBuilder(
                URB_FUNCTIONID.URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER,
                requestId,
                0).BuildInterruptTransferRequest(
                endpoints,
                endpointNum,
                TransferFlags.USBD_TRANSFER_DIRECTION_IN,
                USBD_PIPE_TYPE.UsbdPipeTypeBulk);
            rdpeusbAdapter.TransferInRequest(device, req, (uint)data.Length);

            pdu = rdpeusbAdapter.ExpectCompletion(device.VirtualChannel);
            Site.Assert.IsInstanceOfType(
                pdu,
                typeof(EusbUrbCompletionPdu),
                "The result must be type of EusbUrbCompletionPdu.");
            EusbUrbCompletionPdu pduRes = (EusbUrbCompletionPdu)pdu;
            Site.Assert.IsSuccess((int)pduRes.HResult, "The EusbUrbCompletionPdu must indicate successful.");
            ReqCapturer.VerifyUrbCompletion(pduRes, req, interfaceId);
            Site.Assert.AreEqual((uint)data.Length, pduRes.OutputBufferSize, "The size of data read must be same as written.");
            Site.Assert.IsTrue(data.SequenceEqual(pduRes.OutputBuffer), "The data read must be same as written.");

            LogComment("9. Sends retract device request and the channel for the device is expected to be closed.");
            rdpeusbAdapter.RetractDevice(device, USB_RETRACT_REASON.UsbRetractReason_BlockedByPolicy);
        }