def do_test(arch, tx_clk, tx_phy, seed):
    rand = random.Random()
    rand.seed(seed)

    dev_address = get_dut_address()
    ep = 0

    # The inter-frame gap is to give the DUT time to print its output
    packets = []

    AppendSetupToken(packets, ep)
    packets.append(TxDataPacket(rand, length=3, pid=3, bad_crc=True))
    #packets.append(RxHandshakePacket())

    AppendSetupToken(packets, ep)
    packets.append(TxDataPacket(rand, length=8, pid=3, bad_crc=False))
    packets.append(RxHandshakePacket(timeout=11))

    # Note, quite big gap to allow checking.

    packets.append(
        TokenPacket(
            inter_pkt_gap=2000,
            pid=0xe1,  #OUT
            address=dev_address,
            endpoint=ep))

    packets.append(TxDataPacket(rand, length=10, pid=0xb))

    packets.append(RxHandshakePacket())

    packets.append(
        TokenPacket(
            inter_pkt_gap=2000,
            pid=0x69,  #OUT
            address=dev_address,
            endpoint=ep))

    #Expect 0-length
    packets.append(RxDataPacket(rand, length=0, pid=0x4b))

    # Send ACK
    packets.append(TxHandshakePacket())

    do_rx_test(arch,
               tx_clk,
               tx_phy,
               packets,
               __file__,
               seed,
               level='smoke',
               extra_tasks=[])
Beispiel #2
0
def test_session(ep, address, bus_speed):

    pktLength = 10
    ied = 500

    session = UsbSession(bus_speed=bus_speed,
                         run_enumeration=False,
                         device_address=address)

    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=pktLength,
        ))

    # Expect NAK's from DUT
    session.add_event(
        TokenPacket(
            pid=USB_PID["IN"],
            address=address,
            endpoint=ep,
        ))
    session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))

    session.add_event(
        TokenPacket(
            pid=USB_PID["OUT"],
            address=address,
            endpoint=ep,
            interEventDelay=ied,
        ))

    session.add_event(
        TxDataPacket(
            dataPayload=session.getPayload_out(ep, pktLength),
            pid=USB_PID["DATA0"],
        ))

    session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))

    return session
def do_test(arch, tx_clk, tx_phy, seed):
    rand = random.Random()
    rand.seed(seed)

    ep = 0

    # The inter-frame gap is to give the DUT time to print its output
    packets = []

    # SETUP transaction
    AppendSetupToken(packets, ep)
    packets.append(TxDataPacket(rand, length=8, pid=3))
    packets.append(RxHandshakePacket(timeout=11))

    # IN transaction
    # Note, quite big gap to allow checking.
    packets.append(TokenPacket(
        inter_pkt_gap=2000,
        pid=0x69,  #IN
        endpoint=ep))
    packets.append(RxDataPacket(rand, length=10, pid=0x4b))
    packets.append(TxHandshakePacket())

    # Send 0 length OUT transaction
    packets.append(TokenPacket(
        inter_pkt_gap=2000,
        pid=0xe1,  #OUT
        endpoint=ep))
    packets.append(TxDataPacket(rand, length=0, pid=0xb))
    packets.append(RxHandshakePacket())

    # Send ACK
    packets.append(TxHandshakePacket())

    do_rx_test(arch,
               tx_clk,
               tx_phy,
               packets,
               __file__,
               seed,
               level='smoke',
               extra_tasks=[])
Beispiel #4
0
def test_session(ep, address, bus_speed):

    pktLength = 10
    ied = 4000

    session = UsbSession(bus_speed=bus_speed,
                         run_enumeration=False,
                         device_address=address)

    for pktLength in range(10, 14):

        if pktLength == 12:
            session.add_event(
                TokenPacket(
                    pid=USB_PID["IN"],
                    address=address,
                    endpoint=ep,
                    interEventDelay=ied,
                ))
            session.add_event(
                RxDataPacket(
                    dataPayload=session.getPayload_in(ep,
                                                      pktLength,
                                                      resend=True),
                    pid=USB_PID["DATA0"],
                ))
            session.add_event(TxHandshakePacket(pid=0xFF))

        session.add_event(
            UsbTransaction(
                session,
                deviceAddress=address,
                endpointNumber=ep,
                endpointType="BULK",
                transType="IN",
                dataLength=pktLength,
                interEventDelay=ied,
            ))

    return session
Beispiel #5
0
def test_session(ep, address, bus_speed, core_freq, dummy_threads):

    total_threads = dummy_threads + 2  # 1 thread for xud another for test code
    if (core_freq / total_threads < 100.0) and bus_speed == "HS":
        pytest.xfail("Test doesn't pass without 100MIPS (issue #277)")

    # The large inter-event delay is to give the DUT time to perform checking
    ied = 500

    session = UsbSession(
        bus_speed=bus_speed, run_enumeration=False, device_address=address
    )

    for length in range(10, 15):

        session.add_event(
            UsbTransaction(
                session,
                deviceAddress=address,
                endpointNumber=ep,
                endpointType="BULK",
                transType="OUT",
                dataLength=length,
                interEventDelay=ied,
            )
        )

        # Simulate missing data payload
        if length == 11:
            session.add_event(
                TokenPacket(
                    endpoint=ep,
                    address=address,
                    pid=USB_PID["OUT"],
                    interEventDelay=ied,
                )
            )

    return session
def test_session(ep, address, bus_speed):

    # Note, quite big gap to allow checking
    ied = 4000

    session = UsbSession(bus_speed=bus_speed,
                         run_enumeration=False,
                         device_address=address)

    for pktLength in range(10, 15):

        if pktLength == 12:
            session.add_event(
                TokenPacket(
                    pid=USB_PID["IN"],
                    address=address,
                    endpoint=ep,
                    interEventDelay=ied,
                ))
            session.add_event(
                RxDataPacket(dataPayload=session.getPayload_in(
                    ep, pktLength, resend=True)))
            # Missing ACK - simulate CRC fail at host

        session.add_event(
            UsbTransaction(
                session,
                deviceAddress=address,
                endpointNumber=ep,
                endpointType="BULK",
                transType="IN",
                dataLength=pktLength,
                interEventDelay=ied,
            ))

    return session
Beispiel #7
0
def test_session(ep, address, bus_speed):

    ied = 500

    trafficAddress1 = (address + 1) % 128
    trafficAddress2 = (address + 127) % 128

    start_length = 0
    end_length = start_length + 10

    session = UsbSession(
        bus_speed=bus_speed, run_enumeration=False, device_address=address
    )

    for pktLength in range(start_length, end_length):

        # SETUP to another address (Note, DUT would not see ACK)
        session.add_event(
            TokenPacket(
                pid=USB_PID["SETUP"],
                address=trafficAddress1,
                endpoint=ep,
            )
        )
        session.add_event(
            TxDataPacket(
                dataPayload=[1, 2, 3, 4, 5, 6, 7, 8],
                pid=USB_PID["DATA0"],
            )
        )

        session.add_event(
            UsbTransaction(
                session,
                deviceAddress=address,
                endpointNumber=ep,
                endpointType="CONTROL",
                transType="SETUP",
                dataLength=8,
            )
        )

        session.add_event(
            UsbTransaction(
                session,
                deviceAddress=address,
                endpointNumber=ep,
                endpointType="CONTROL",
                transType="IN",
                dataLength=pktLength,
            )
        )

        # SETUP to another address (Note, DUT would not see ACK)
        session.add_event(
            TokenPacket(
                pid=USB_PID["SETUP"],
                address=trafficAddress2,
                endpoint=ep,
            )
        )
        session.add_event(
            TxDataPacket(
                dataPayload=[1, 2, 3, 4, 5, 6, 7, 8],
                pid=USB_PID["DATA0"],
            )
        )

        session.add_event(
            TokenPacket(
                pid=USB_PID["IN"],
                address=trafficAddress2,
                endpoint=ep,
                interEventDelay=1000,
            )
        )

        # Send 0 length OUT transaction
        session.add_event(
            UsbTransaction(
                session,
                deviceAddress=address,
                endpointNumber=ep,
                endpointType="CONTROL",
                transType="OUT",
                dataLength=0,
            )
        )

    return session
Beispiel #8
0
def test_session(ep, address, bus_speed):

    session = UsbSession(bus_speed=bus_speed,
                         run_enumeration=False,
                         device_address=address)

    # Ping test EP, expect NAK
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
        ))
    session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))

    # And again
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
        ))
    session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))

    # Send packet to "ctrl" EP, DUT should mark test EP as ready
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep + 1,
            endpointType="BULK",
            transType="OUT",
            dataLength=10,
        ))

    # Ping test EP again - expect ACK
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
            interEventDelay=6000,
        ))
    session.add_event(RxHandshakePacket(pid=USB_PID["ACK"]))

    # And again..
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
            interEventDelay=6000,
        ))
    session.add_event(RxHandshakePacket(pid=USB_PID["ACK"]))

    # Send out to EP 2.. expect ack
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=10,
            interEventDelay=6000,
        ))

    # Re-Ping EP 2, expect NAK
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
        ))
    session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))

    # And again
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
        ))
    session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))

    # Send a packet to "ctrl" EP so the DUT knows it can exit.
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep + 1,
            endpointType="BULK",
            transType="OUT",
            dataLength=10,
        ))

    return session
Beispiel #9
0
def test_session(ep, address, bus_speed):

    session = UsbSession(bus_speed=bus_speed,
                         run_enumeration=False,
                         device_address=address)

    # Reserved/Invalid PID
    session.add_event(
        TokenPacket(
            pid=USB_PID["RESERVED"],
            address=address,
            endpoint=ep,
        ))

    # Valid IN but not for DUT
    session.add_event(
        TokenPacket(
            pid=USB_PID["IN"],
            address=address + 1,
            endpoint=ep,
        ))

    # Valid OUT but not for DUT
    session.add_event(
        TokenPacket(
            pid=USB_PID["OUT"],
            address=address + 1,
            endpoint=ep,
        ))

    # Valid OUT transaction
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=10,
        ))

    # Valid SETUP but not for us..
    session.add_event(
        TokenPacket(
            pid=USB_PID["SETUP"],
            address=address + 2,
            endpoint=ep,
        ))

    # Valid OUT transaction
    # Note, quite big gap to allow checking.
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=11,
            interEventDelay=6000,
        ))

    # Valid PING but not for us..
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address + 2,
            endpoint=ep,
        ))

    # Finish with some valid transactions
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=12,
            interEventDelay=6000,
        ))
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=13,
            interEventDelay=6000,
        ))
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=14,
            interEventDelay=6000,
        ))

    return session
Beispiel #10
0
    def __init__(
        self,
        session,
        deviceAddress=0,
        endpointNumber=0,
        endpointType="BULK",
        transType="OUT",
        bus_speed="HS",
        eventTime=0,
        dataLength=0,
        interEventDelay=INTER_TRANSACTION_DELAY,
        badDataCrc=False,
        resend=False,
        rxeAssertDelay_data=0,
        halted=False,
        resetDataPid=False,
    ):

        self._deviceAddress = deviceAddress
        self._endpointNumber = endpointNumber
        self._endpointType = endpointType
        self._transType = transType
        self._datalength = dataLength
        self._bus_speed = bus_speed
        self._badDataCrc = badDataCrc
        self._rxeAssertDelay_data = rxeAssertDelay_data
        self._halted = halted

        assert endpointType in USB_EP_TYPES
        assert transType in USB_TRANS_TYPES

        # Populate packet list for a (valid) transaction
        self._packets = []

        # TODO would it be better to generate packets on the fly in drive()
        # rather than create a packet list?
        if transType in ["OUT", "SETUP"]:

            packets = []
            packets.append(
                TokenPacket(
                    interEventDelay=interEventDelay,
                    pid=USB_PID[transType],
                    address=self._deviceAddress,
                    endpoint=self._endpointNumber,
                    data_valid_count=self.data_valid_count,
                ))

            # Don't toggle data pid if we had a bad data crc
            if (self._badDataCrc or self._rxeAssertDelay_data
                    or endpointType == "ISO" or halted):
                togglePid = False
            else:
                togglePid = True

            if halted:
                resetDataPid = True

            expectHandshake = ((not self._badDataCrc)
                               and (not self._rxeAssertDelay_data)
                               and (deviceAddress == session.deviceAddress)
                               and (self._endpointType != "ISO"))

            if expectHandshake or self._endpointType == "ISO":
                resend = False
            else:
                resend = True

            # Generate packet data payload
            packetPayload = session.getPayload_out(endpointNumber,
                                                   dataLength,
                                                   resend=resend)

            # Reset data PID's on SETUP transaction
            if transType == "SETUP":
                pid = session.data_pid_out(endpointNumber,
                                           togglePid=True,
                                           resetDataPid=True)

                # If SETUP trans then we need to reset and toggle the corresponding IN EP's PID also
                in_pid = session.data_pid_in(endpointNumber,
                                             togglePid=True,
                                             resetDataPid=True)
            else:
                pid = session.data_pid_out(endpointNumber,
                                           togglePid=togglePid,
                                           resetDataPid=resetDataPid)

            # Add data packet to packets list
            packets.append(
                TxDataPacket(
                    pid=pid,
                    dataPayload=packetPayload,
                    bad_crc=self._badDataCrc,
                    rxe_assert_time=self._rxeAssertDelay_data,
                ))

            if expectHandshake:
                if halted:
                    packets.append(RxHandshakePacket(pid=USB_PID["STALL"]))
                else:
                    packets.append(RxHandshakePacket())

            self._packets.extend(packets)

        else:

            self._packets.append(
                TokenPacket(
                    interEventDelay=interEventDelay,
                    pid=USB_PID["IN"],
                    address=self._deviceAddress,
                    endpoint=self._endpointNumber,
                    data_valid_count=self.data_valid_count,
                ))

            if (self._badDataCrc or self._rxeAssertDelay_data
                    or self._endpointType == "ISO" or halted):
                togglePid = False
            else:
                togglePid = True

            if halted:
                resetDataPid = True

            pid = session.data_pid_in(endpointNumber,
                                      togglePid=togglePid,
                                      resetDataPid=resetDataPid)

            # Add data packet to packets list
            if not halted:
                # Generate packet data payload
                packetPayload = session.getPayload_in(endpointNumber,
                                                      dataLength)
                self._packets.append(
                    RxDataPacket(pid=pid, dataPayload=packetPayload))

            if self._endpointType != "ISO" and not halted:
                self._packets.append(TxHandshakePacket())

            if halted:
                self._packets.append(RxHandshakePacket(pid=USB_PID["STALL"]))

        super().__init__(time=eventTime)
Beispiel #11
0
def test_session(ep, address, bus_speed):

    pktLength = 10

    session = UsbSession(
        bus_speed=bus_speed, run_enumeration=False, device_address=address
    )

    ep_ctrl = ep + 1

    # Ping EP, expect stall
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
        )
    )
    session.add_event(RxHandshakePacket(pid=USB_PID["STALL"]))

    # And again
    session.add_event(
        TokenPacket(
            pid=USB_PID["PING"],
            address=address,
            endpoint=ep,
        )
    )
    session.add_event(RxHandshakePacket(pid=USB_PID["STALL"]))

    # Valid transaction to another EP informing test code to clear stall
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep_ctrl,
            endpointType="BULK",
            transType="OUT",
            dataLength=pktLength,
        )
    )

    # Expect normal transactions
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=pktLength,
        )
    )

    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=pktLength,
        )
    )

    return session
def test_session(ep, address, bus_speed):

    session = UsbSession(bus_speed=bus_speed,
                         run_enumeration=False,
                         device_address=address)

    # The large inter-frame gap is to give the DUT time to print its output
    interEventDelay = 500

    # Valid OUT transaction
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=10,
            interEventDelay=interEventDelay,
        ))

    # OUT Transaction with invalid DATA PID. XCORE should ignore packet - no ACK
    session.add_event(
        TokenPacket(
            pid=USB_PID["OUT"],
            address=address,
            endpoint=ep,
            interEventDelay=interEventDelay,
        ))

    session.add_event(
        TxDataPacket(
            dataPayload=session.getPayload_out(ep, 11, resend=True),
            pid=USB_PID["DATA1"] & 0xF,
        ))

    # Send some valid OUT transactions
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=11,
            interEventDelay=interEventDelay,
        ))
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=12,
            interEventDelay=interEventDelay,
        ))
    session.add_event(
        UsbTransaction(
            session,
            deviceAddress=address,
            endpointNumber=ep,
            endpointType="BULK",
            transType="OUT",
            dataLength=13,
            interEventDelay=interEventDelay,
        ))

    return session