Changeset 77658 in vbox for trunk/src/VBox
- Timestamp:
- Mar 11, 2019 8:15:55 PM (6 years ago)
- Location:
- trunk/src/VBox/Runtime/common/fuzz
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/fuzz/fuzz.cpp
r77651 r77658 1628 1628 1629 1629 1630 RTDECL(int) RTFuzzCtxQueryStats(RTFUZZCTX hFuzzCtx, PRTFUZZCTXSTATS pStats) 1631 { 1632 PRTFUZZCTXINT pThis = hFuzzCtx; 1633 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1634 AssertPtrReturn(pStats, VERR_INVALID_POINTER); 1635 1636 pStats->cbMemory = ASMAtomicReadZ(&pThis->cbMemTotal); 1637 pStats->cMutations = ASMAtomicReadU64(&pThis->cMutations); 1638 return VINF_SUCCESS; 1639 } 1640 1641 1630 1642 /** 1631 1643 * Fuzzing context export callback for a single mutation. -
trunk/src/VBox/Runtime/common/fuzz/fuzzmastercmd.cpp
r77652 r77658 620 620 621 621 /** 622 * Sets up the directories for the given fuzzing run. 623 * 624 * @returns IPRT status code. 625 * @param pThis The fuzzing master command state. 626 * @param pFuzzRun The fuzzing run to setup the directories for. 627 * @param pErrInfo Where to store the error information on failure, optional. 628 */ 629 static int rtFuzzCmdMasterFuzzRunSetupDirectories(PRTFUZZCMDMASTER pThis, PRTFUZZRUN pFuzzRun, PRTERRINFO pErrInfo) 630 { 631 /* Create temp directories. */ 632 char szTmpDir[RTPATH_MAX]; 633 int rc = RTPathJoin(&szTmpDir[0], sizeof(szTmpDir), pThis->pszTmpDir, pFuzzRun->pszId); 634 AssertRC(rc); 635 rc = RTDirCreate(szTmpDir, 0700, RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_SET 636 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL); 637 if (rc == VERR_ALREADY_EXISTS) 638 { 639 /* Clear the directory. */ 640 rc = RTDirRemoveRecursive(szTmpDir, RTDIRRMREC_F_CONTENT_ONLY); 641 } 642 643 if (RT_SUCCESS(rc)) 644 { 645 rc = RTFuzzObsSetTmpDirectory(pFuzzRun->hFuzzObs, szTmpDir); 646 if (RT_SUCCESS(rc)) 647 { 648 rc = RTPathJoin(&szTmpDir[0], sizeof(szTmpDir), pThis->pszResultsDir, pFuzzRun->pszId); 649 AssertRC(rc); 650 rc = RTDirCreate(szTmpDir, 0700, RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_SET 651 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL); 652 if (RT_SUCCESS(rc) || rc == VERR_ALREADY_EXISTS) 653 { 654 rc = RTFuzzObsSetResultDirectory(pFuzzRun->hFuzzObs, szTmpDir); 655 if (RT_FAILURE(rc)) 656 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to set results directory to %s", szTmpDir); 657 } 658 else 659 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to create results directory %s", szTmpDir); 660 } 661 else 662 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to set temporary directory to %s", szTmpDir); 663 } 664 else 665 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to create temporary directory %s", szTmpDir); 666 667 return rc; 668 } 669 670 671 /** 622 672 * Creates a new fuzzing run with the given ID. 623 673 * … … 648 698 rc = rtFuzzCmdMasterFuzzRunProcessMiscCfg(pFuzzRun, hJsonRoot, pErrInfo); 649 699 if (RT_SUCCESS(rc)) 700 rc = rtFuzzCmdMasterFuzzRunSetupDirectories(pThis, pFuzzRun, pErrInfo); 701 702 if (RT_SUCCESS(rc)) 650 703 { 651 /* Create temp directories. */ 652 char szTmpDir[RTPATH_MAX]; 653 rc = RTPathJoin(&szTmpDir[0], sizeof(szTmpDir), pThis->pszTmpDir, pFuzzRun->pszId); 654 AssertRC(rc); 655 rc = RTDirCreate(szTmpDir, 0700, RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_SET 656 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL); 704 /* Start fuzzing. */ 705 RTListAppend(&pThis->LstFuzzed, &pFuzzRun->NdFuzzed); 706 rc = RTFuzzObsExecStart(pFuzzRun->hFuzzObs, pFuzzRun->cProcs); 657 707 if (RT_SUCCESS(rc)) 658 { 659 rc = RTFuzzObsSetTmpDirectory(pFuzzRun->hFuzzObs, szTmpDir); 660 if (RT_SUCCESS(rc)) 661 { 662 rc = RTPathJoin(&szTmpDir[0], sizeof(szTmpDir), pThis->pszResultsDir, pFuzzRun->pszId); 663 AssertRC(rc); 664 rc = RTDirCreate(szTmpDir, 0700, RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_SET 665 | RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL); 666 if (RT_SUCCESS(rc)) 667 { 668 rc = RTFuzzObsSetResultDirectory(pFuzzRun->hFuzzObs, szTmpDir); 669 if (RT_SUCCESS(rc)) 670 { 671 /* Start fuzzing. */ 672 RTListAppend(&pThis->LstFuzzed, &pFuzzRun->NdFuzzed); 673 rc = RTFuzzObsExecStart(pFuzzRun->hFuzzObs, pFuzzRun->cProcs); 674 if (RT_SUCCESS(rc)) 675 pFuzzRun->fStarted = true; 676 else 677 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to start fuzzing with %Rrc", rc); 678 } 679 else 680 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to set results directory to %s", szTmpDir); 681 } 682 else 683 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to create results directory %s", szTmpDir); 684 } 685 else 686 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to set temporary directory to %s", szTmpDir); 687 } 708 pFuzzRun->fStarted = true; 688 709 else 689 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to create temporary directory %s", szTmpDir);710 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to start fuzzing with %Rrc", rc); 690 711 } 691 712 } … … 946 967 947 968 /** 969 * Queries the statistics for the given fuzzing run and adds the result to the response. 970 * 971 * @returns IPRT static code. 972 * @param pThis The fuzzing master command state. 973 * @param pFuzzRun The fuzzing run. 974 * @param pszIndent Indentation to use. 975 * @param fLast Flags whether this is the last element in the list. 976 * @param pErrInfo Where to store the error information on failure, optional. 977 */ 978 static int rtFuzzCmdMasterProcessQueryRunStats(PRTFUZZCMDMASTER pThis, PRTFUZZRUN pFuzzRun, 979 const char *pszIndent, bool fLast, PRTERRINFO pErrInfo) 980 { 981 RTFUZZOBSSTATS ObsStats; 982 RTFUZZCTXSTATS CtxStats; 983 RTFUZZCTX hFuzzCtx; 984 985 int rc = RTFuzzObsQueryCtx(pFuzzRun->hFuzzObs, &hFuzzCtx); 986 if (RT_SUCCESS(rc)) 987 { 988 rc = RTFuzzCtxQueryStats(hFuzzCtx, &CtxStats); 989 RTFuzzCtxRelease(hFuzzCtx); 990 } 991 992 if (RT_SUCCESS(rc)) 993 rc = RTFuzzObsQueryStats(pFuzzRun->hFuzzObs, &ObsStats); 994 if (RT_SUCCESS(rc)) 995 { 996 const char s_szStatsFmt[] = "%s{ \n" 997 "%s \"Id\": %s\n" 998 "%s \"FuzzedInputsPerSec\": %u\n" 999 "%s \"FuzzedInputs\": %u\n" 1000 "%s \"FuzzedInputsHang\": %u\n" 1001 "%s \"FuzzedInputsCrash\": %u\n" 1002 "%s \"MemoryUsage\": %zu\n" 1003 "%s \"CorpusSize\": %llu\n" 1004 "%s}%s\n"; 1005 char achStats[_4K]; RT_ZERO(achStats); 1006 ssize_t cchStats = RTStrPrintf2(&achStats[0], sizeof(achStats), 1007 s_szStatsFmt, pszIndent, 1008 pszIndent, pFuzzRun->pszId, 1009 pszIndent, ObsStats.cFuzzedInputsPerSec, 1010 pszIndent, ObsStats.cFuzzedInputs, 1011 pszIndent, ObsStats.cFuzzedInputsHang, 1012 pszIndent, ObsStats.cFuzzedInputsCrash, 1013 pszIndent, CtxStats.cbMemory, 1014 pszIndent, CtxStats.cMutations, 1015 pszIndent, fLast ? "" : ","); 1016 if (RT_LIKELY(cchStats > 0)) 1017 { 1018 rc = RTStrAAppend(&pThis->pszResponse, &achStats[0]); 1019 if (RT_FAILURE(rc)) 1020 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to build statistics response", rc); 1021 } 1022 else 1023 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_BUFFER_OVERFLOW, "Request error: Response data buffer overflow", rc); 1024 } 1025 else 1026 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to query fuzzing statistics with %Rrc", rc); 1027 1028 return rc; 1029 } 1030 1031 1032 /** 948 1033 * Processes the "QueryStats" request. 949 1034 * … … 955 1040 static int rtFuzzCmdMasterProcessJsonReqQueryStats(PRTFUZZCMDMASTER pThis, RTJSONVAL hJsonRoot, PRTERRINFO pErrInfo) 956 1041 { 957 PRTFUZZRUN pFuzzRun; 958 int rc = rtFuzzCmdMasterQueryFuzzRunFromJson(pThis, hJsonRoot, "Id", pErrInfo, &pFuzzRun); 959 if (RT_SUCCESS(rc)) 960 { 961 RTFUZZOBSSTATS Stats; 962 rc = RTFuzzObsQueryStats(pFuzzRun->hFuzzObs, &Stats); 1042 RTJSONVAL hJsonValId; 1043 int rc = RTJsonValueQueryByName(hJsonRoot, "Id", &hJsonValId); 1044 if (RT_SUCCESS(rc)) 1045 { 1046 RTJsonValueRelease(hJsonValId); 1047 PRTFUZZRUN pFuzzRun; 1048 rc = rtFuzzCmdMasterQueryFuzzRunFromJson(pThis, hJsonRoot, "Id", pErrInfo, &pFuzzRun); 963 1049 if (RT_SUCCESS(rc)) 964 { 965 const char s_szStats[] = "{ \"FuzzedInputsPerSec\": %u\n" 966 " \"FuzzedInputs\": %u\n" 967 " \"FuzzedInputsHang\": %u\n" 968 " \"FuzzedInputsCrash\": %u\n}"; 969 pThis->pszResponse = RTStrAPrintf2(s_szStats, Stats.cFuzzedInputsPerSec, 970 Stats.cFuzzedInputs, Stats.cFuzzedInputsHang, Stats.cFuzzedInputsCrash); 971 if (RT_UNLIKELY(!pThis->pszResponse)) 972 rc = rtFuzzCmdMasterErrorRc(pErrInfo, VERR_BUFFER_OVERFLOW, "Request error: Response data buffer overflow", rc); 973 } 974 else 975 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "Request error: Failed to query fuzzing statistics with %Rrc", rc); 976 } 1050 rc = rtFuzzCmdMasterProcessQueryRunStats(pThis, pFuzzRun, " ", 1051 true /*fLast*/, pErrInfo); 1052 } 1053 else if (rc == VERR_NOT_FOUND) 1054 { 1055 /* Id is not there, so collect statistics of all running jobs. */ 1056 rc = RTStrAAppend(&pThis->pszResponse, " [\n"); 1057 if (RT_SUCCESS(rc)) 1058 { 1059 PRTFUZZRUN pRun = NULL; 1060 RTListForEach(&pThis->LstFuzzed, pRun, RTFUZZRUN, NdFuzzed) 1061 { 1062 bool fLast = RTListNodeIsLast(&pThis->LstFuzzed, &pRun->NdFuzzed); 1063 rc = rtFuzzCmdMasterProcessQueryRunStats(pThis, pRun, " ", fLast, pErrInfo); 1064 if (RT_FAILURE(rc)) 1065 break; 1066 } 1067 if (RT_SUCCESS(rc)) 1068 rc = RTStrAAppend(&pThis->pszResponse, " ]\n"); 1069 } 1070 } 1071 else 1072 rc = rtFuzzCmdMasterErrorRc(pErrInfo, rc, "JSON request malformed: Couldn't get \"Id\" value"); 977 1073 978 1074 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.