VirtualBox

Ignore:
Timestamp:
Jun 22, 2018 7:40:23 AM (7 years ago)
Author:
vboxsync
Message:

Runtime/fuzzing: Add some simple statistics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/fuzz/fuzzmastercmd.cpp

    r72578 r72649  
    9191    /** Flag whether to shutdown. */
    9292    bool                        fShutdown;
     93    /** Flag whether to send a response along with the ACK. */
     94    bool                        fAckResponse;
     95    /** The response message. */
     96    char                        aszResponse[_1K];
    9397} RTFUZZCMDMASTER;
    9498/** Pointer to a fuzzing master command state. */
     
    813817static int rtFuzzCmdMasterProcessJsonReqQueryStats(PRTFUZZCMDMASTER pThis, RTJSONVAL hJsonRoot, PRTERRINFO pErrInfo)
    814818{
    815     RT_NOREF(pThis, hJsonRoot, pErrInfo);
    816     return VERR_NOT_IMPLEMENTED;
     819    PRTFUZZRUN pFuzzRun;
     820    int rc = rtFuzzCmdMasterQueryFuzzRunFromJson(pThis, hJsonRoot, "Id", pErrInfo, &pFuzzRun);
     821    if (RT_SUCCESS(rc))
     822    {
     823        RTFUZZOBSSTATS Stats;
     824        rc = RTFuzzObsQueryStats(pFuzzRun->hFuzzObs, &Stats);
     825        if (RT_SUCCESS(rc))
     826        {
     827            const char s_szStats[] = "{ \"FuzzedInputsPerSec\": %u\n"
     828                                     "  \"FuzzedInputs\":       %u\n"
     829                                     "  \"FuzzedInputsHang\":   %u\n"
     830                                     "  \"FuzzedInputsCrash\":   %u\n}";
     831            ssize_t cch = RTStrPrintf2(&pThis->aszResponse[0], sizeof(pThis->aszResponse), s_szStats, Stats.cFuzzedInputsPerSec,
     832                                       Stats.cFuzzedInputs, Stats.cFuzzedInputsHang, Stats.cFuzzedInputsCrash);
     833            if (cch > 0)
     834                pThis->fAckResponse = true;
     835            else
     836                rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_BUFFER_OVERFLOW, "Request error: Response data buffer overflow", rc);
     837        }
     838        else
     839            rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to query fuzzing statistics with %Rrc", rc);
     840    }
     841
     842    return rc;
    817843}
    818844
     
    902928 * @returns nothing.
    903929 * @param   hSocket             The socket handle to send the ACK to.
    904  */
    905 static void rtFuzzCmdMasterTcpSendAck(RTSOCKET hSocket)
     930 * @param   pszResponse         Additional response data.
     931 */
     932static void rtFuzzCmdMasterTcpSendAck(RTSOCKET hSocket, const char *pszResponse)
    906933{
    907934    const char s_szSucc[] = "{ \"Status\": \"ACK\" }\n";
    908     RTTcpWrite(hSocket, s_szSucc, sizeof(s_szSucc));
     935    const char s_szSuccResp[] = "{ \"Status\": \"ACK\"\n  \"Response\":\n    %s\n }\n";
     936    if (pszResponse)
     937    {
     938        char szTmp[_1K];
     939        ssize_t cchResp = RTStrPrintf2(szTmp, sizeof(szTmp), s_szSuccResp, pszResponse);
     940        if (cchResp > 0)
     941            RTTcpWrite(hSocket, szTmp, cchResp);
     942        else
     943            RTTcpWrite(hSocket, s_szSucc, strlen(s_szSucc));
     944    }
     945    else
     946        RTTcpWrite(hSocket, s_szSucc, sizeof(s_szSucc));
    909947}
    910948
     
    924962    if (pErrInfo)
    925963    {
    926         char szTmp[1024];
     964        char szTmp[_1K];
    927965        ssize_t cchResp = RTStrPrintf2(szTmp, sizeof(szTmp), s_szFailInfo, pErrInfo->pszMsg);
    928966        if (cchResp > 0)
     
    9731011                    RTErrInfoInitStatic(&ErrInfo);
    9741012
     1013                    pThis->fAckResponse = false;
     1014                    RT_ZERO(pThis->aszResponse);
    9751015                    rc = RTJsonParseFromBuf(&hJsonReq, pbReq, cbReq, &ErrInfo.Core);
    9761016                    if (RT_SUCCESS(rc))
     
    9781018                        rc = rtFuzzCmdMasterProcessJsonReq(pThis, hJsonReq, &ErrInfo.Core);
    9791019                        if (RT_SUCCESS(rc))
    980                             rtFuzzCmdMasterTcpSendAck(hSocket);
     1020                            rtFuzzCmdMasterTcpSendAck(hSocket, pThis->fAckResponse ? pThis->aszResponse : NULL);
    9811021                        else
    9821022                            rtFuzzCmdMasterTcpSendNAck(hSocket, &ErrInfo.Core);
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