VirtualBox

Changeset 86016 in vbox for trunk/src


Ignore:
Timestamp:
Sep 3, 2020 8:19:40 AM (4 years ago)
Author:
vboxsync
Message:

ValidationKit/SerialTest: Add simple echo service sending data back to where it was received from

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/serial/SerialTest.cpp

    r86015 r86016  
    167167static DECLCALLBACK(int) serialTestRunReadVerify(PSERIALTEST pSerialTest);
    168168static DECLCALLBACK(int) serialTestRunStsLines(PSERIALTEST pSerialTest);
     169static DECLCALLBACK(int) serialTestRunEcho(PSERIALTEST pSerialTest);
    169170
    170171/** Implemented tests. */
    171172static const SERIALTESTDESC g_aSerialTests[] =
    172173{
    173     {"readwrite",  "Simple Read/Write test on the same serial port",       serialTestRunReadWrite  },
    174     {"write",      "Simple write test (verification done somewhere else)", serialTestRunWrite      },
    175     {"readverify", "Counterpart to write test (reads and verifies data)",  serialTestRunReadVerify },
    176     {"stslines",   "Testing the status line setting and receiving",        serialTestRunStsLines   }
     174    {"readwrite",  "Simple Read/Write test on the same serial port",                 serialTestRunReadWrite  },
     175    {"write",      "Simple write test (verification done somewhere else)",           serialTestRunWrite      },
     176    {"readverify", "Counterpart to write test (reads and verifies data)",            serialTestRunReadVerify },
     177    {"stslines",   "Testing the status line setting and receiving",                  serialTestRunStsLines   },
     178    {"echo",       "Echoes received data back to the sender (not real test)",        serialTestRunEcho       },
    177179};
    178180
     
    688690
    689691/**
     692 * Runs a simple echo service (not a real test on its own).
     693 *
     694 * @returns IPRT status code.
     695 * @param   pSerialTest         The serial test configuration.
     696 */
     697static DECLCALLBACK(int) serialTestRunEcho(PSERIALTEST pSerialTest)
     698{
     699    int rc = VINF_SUCCESS;
     700    uint64_t tsStart = RTTimeNanoTS();
     701    uint8_t abBuf[_1K];
     702    size_t cbLeft = g_cbTx;
     703    size_t cbInBuf = 0;
     704
     705    while (   RT_SUCCESS(rc)
     706           && (   cbLeft
     707               || cbInBuf))
     708    {
     709        uint32_t fEvts = 0;
     710        uint32_t fEvtsQuery = 0;
     711        if (cbInBuf)
     712            fEvtsQuery |= RTSERIALPORT_EVT_F_DATA_TX;
     713        if (cbLeft && cbInBuf < sizeof(abBuf))
     714            fEvtsQuery |= RTSERIALPORT_EVT_F_DATA_RX;
     715
     716        rc = RTSerialPortEvtPoll(pSerialTest->hSerialPort, fEvtsQuery, &fEvts, RT_INDEFINITE_WAIT);
     717        if (RT_FAILURE(rc))
     718            break;
     719
     720        if (fEvts & RTSERIALPORT_EVT_F_DATA_RX)
     721        {
     722            size_t cbThisRead = RT_MIN(cbLeft, sizeof(abBuf) - cbInBuf);
     723            size_t cbRead = 0;
     724            rc = RTSerialPortReadNB(pSerialTest->hSerialPort, &abBuf[cbInBuf], cbThisRead, &cbRead);
     725            if (RT_SUCCESS(rc))
     726            {
     727                cbInBuf += cbRead;
     728                cbLeft  -= cbRead;
     729            }
     730            else if (RT_FAILURE(rc))
     731                break;
     732        }
     733
     734        if (fEvts & RTSERIALPORT_EVT_F_DATA_TX)
     735        {
     736            size_t cbWritten = 0;
     737            rc = RTSerialPortWriteNB(pSerialTest->hSerialPort, &abBuf[0], cbInBuf, &cbWritten);
     738            if (RT_SUCCESS(rc))
     739            {
     740                memmove(&abBuf[0], &abBuf[cbWritten], cbInBuf - cbWritten);
     741                cbInBuf -= cbWritten;
     742            }
     743        }
     744    }
     745
     746    uint64_t tsRuntime = RTTimeNanoTS() - tsStart;
     747    size_t cNsPerByte = tsRuntime / g_cbTx;
     748    uint64_t cbBytesPerSec = RT_NS_1SEC / cNsPerByte;
     749    RTTestValue(pSerialTest->hTest, "Throughput", cbBytesPerSec, RTTESTUNIT_BYTES_PER_SEC);
     750
     751    return rc;
     752}
     753
     754
     755/**
    690756 * Returns an array of test descriptors get from the given string.
    691757 *
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette