VirtualBox

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

ValidationKit/SerialTest: Add read verification test as a counterpart to the simple write test

File:
1 edited

Legend:

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

    r85121 r86015  
    165165static DECLCALLBACK(int) serialTestRunReadWrite(PSERIALTEST pSerialTest);
    166166static DECLCALLBACK(int) serialTestRunWrite(PSERIALTEST pSerialTest);
     167static DECLCALLBACK(int) serialTestRunReadVerify(PSERIALTEST pSerialTest);
    167168static DECLCALLBACK(int) serialTestRunStsLines(PSERIALTEST pSerialTest);
    168169
     
    170171static const SERIALTESTDESC g_aSerialTests[] =
    171172{
    172     {"readwrite", "Simple Read/Write test on the same serial port",       serialTestRunReadWrite },
    173     {"write",     "Simple write test (verification done somewhere else)", serialTestRunWrite     },
    174     {"stslines",  "Testing the status line setting and receiving",        serialTestRunStsLines  }
     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   }
    175177};
    176178
     
    345347 * @param   hTest               The test handle to report errors to.
    346348 * @param   pSerBuf             The RX buffer pointer.
    347  * @param   iCntTx              The current TX counter value the RX buffer should never get ahead of.
     349 * @param   iCntTx              The current TX counter value the RX buffer should never get ahead of,
     350 *                              UINT32_MAX disables this check.
    348351 */
    349352static bool serialTestRxBufVerify(RTTEST hTest, PSERIALTESTTXRXBUFCNT pSerBuf, uint32_t iCntTx)
     
    475478        if (fEvts & RTSERIALPORT_EVT_F_DATA_TX)
    476479            rc = serialTestTxBufSend(pSerialTest->hSerialPort, &SerBufTx);
     480    }
     481
     482    uint64_t tsRuntime = RTTimeNanoTS() - tsStart;
     483    size_t cNsPerByte = tsRuntime / g_cbTx;
     484    uint64_t cbBytesPerSec = RT_NS_1SEC / cNsPerByte;
     485    RTTestValue(pSerialTest->hTest, "Throughput", cbBytesPerSec, RTTESTUNIT_BYTES_PER_SEC);
     486
     487    return rc;
     488}
     489
     490
     491/**
     492 * Runs the counterpart to the write test, reading and verifying data.
     493 *
     494 * @returns IPRT status code.
     495 * @param   pSerialTest         The serial test configuration.
     496 */
     497static DECLCALLBACK(int) serialTestRunReadVerify(PSERIALTEST pSerialTest)
     498{
     499    int rc = VINF_SUCCESS;
     500    uint64_t tsStart = RTTimeNanoTS();
     501    bool fFailed = false;
     502    SERIALTESTTXRXBUFCNT SerBufRx;
     503
     504    serialTestRxBufInit(&SerBufRx, g_cbTx);
     505
     506    while (   RT_SUCCESS(rc)
     507           && SerBufRx.cbTxRxLeft)
     508    {
     509        uint32_t fEvts = 0;
     510        uint32_t fEvtsQuery = RTSERIALPORT_EVT_F_DATA_RX;
     511
     512        rc = RTSerialPortEvtPoll(pSerialTest->hSerialPort, fEvtsQuery, &fEvts, RT_INDEFINITE_WAIT);
     513        if (RT_FAILURE(rc))
     514            break;
     515
     516        if (fEvts & RTSERIALPORT_EVT_F_DATA_RX)
     517        {
     518            rc = serialTestRxBufRecv(pSerialTest->hSerialPort, &SerBufRx);
     519            if (RT_FAILURE(rc))
     520                break;
     521
     522            bool fRes = serialTestRxBufVerify(pSerialTest->hTest, &SerBufRx, UINT32_MAX);
     523            if (fRes && !fFailed)
     524            {
     525                fFailed = true;
     526                serialTestFailed(pSerialTest->hTest, "Data corruption/loss detected\n");
     527            }
     528        }
    477529    }
    478530
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