src/third_party/angle/src/tests/test_utils/runner/TestSuite.cpp
// Writes out a TestResults to the Chromium JSON Test Results format.
// https://chromium.googlesource.com/chromium/src.git/+/master/docs/testing/json_test_results_format.md
Writes out a TestResults to the Chromium JSON Test Results format.
Writes out a TestResults to the Chromium JSON Test Results format .
void WriteResultsFile(bool interrupted,
                      const TestResults &testResults,
                      const std::string &outputFile,
                      const char *testSuiteName)
{
    time_t ltime;
    time(&ltime);
    struct tm *timeinfo = gmtime(&ltime);
    ltime               = mktime(timeinfo);
    uint64_t secondsSinceEpoch = static_cast<uint64_t>(ltime);
    js::Document doc;
    doc.SetObject();
    js::Document::AllocatorType &allocator = doc.GetAllocator();
    doc.AddMember("interrupted", interrupted, allocator);
    doc.AddMember("path_delimiter", ".", allocator);
    doc.AddMember("version", 3, allocator);
    doc.AddMember("seconds_since_epoch", secondsSinceEpoch, allocator);
    js::Value tests;
    tests.SetObject();
    std::map<TestResultType, uint32_t> counts;
    for (const auto &resultIter : testResults.results)
    {
        const TestIdentifier &id = resultIter.first;
        const TestResult &result = resultIter.second;
        js::Value jsResult;
        jsResult.SetObject();
        counts[result.type]++;
        std::string actualResult;
        for (uint32_t fail = 0; fail < result.flakyFailures; ++fail)
        {
            actualResult += "FAIL ";
        }
        actualResult += ResultTypeToString(result.type);
        std::string expectedResult;
        if (result.flakyFailures > 0)
        {
            expectedResult = "FAIL PASS";
            jsResult.AddMember("is_flaky", true, allocator);
        }
        else
        {
            expectedResult = "PASS";
        }
        jsResult.AddMember("actual", actualResult, allocator);
        jsResult.AddMember("expected", expectedResult, allocator);
        if (result.type != TestResultType::Pass)
        {
            jsResult.AddMember("is_unexpected", true, allocator);
        }
        js::Value times;
        times.SetArray();
        times.PushBack(result.elapsedTimeSeconds, allocator);
        jsResult.AddMember("times", times, allocator);
        char testName[500];
        id.sprintfName(testName);
        js::Value jsName;
        jsName.SetString(testName, allocator);
        tests.AddMember(jsName, jsResult, allocator);
    }
    js::Value numFailuresByType;
    numFailuresByType.SetObject();
    for (const auto &countIter : counts)
    {
        TestResultType type = countIter.first;
        uint32_t count      = countIter.second;
        js::Value jsCount(count);
        numFailuresByType.AddMember(ResultTypeToJSString(type, &allocator), jsCount, allocator);
    }
    doc.AddMember("num_failures_by_type", numFailuresByType, allocator);
    doc.AddMember("tests", tests, allocator);
    printf("Writing test results to %s\n", outputFile.c_str());
    if (!WriteJsonFile(outputFile, &doc))
    {
        printf("Error writing test results file.\n");
    }
}
void WriteResultsFile ( bool interrupted , const TestResults & testResults , const std :: string & outputFile , const char * testSuiteName ) { time_t ltime ; time ( & ltime ) ; struct tm * timeinfo = gmtime ( & ltime ) ; ltime = mktime ( timeinfo ) ; uint64_t secondsSinceEpoch = static_cast < uint64_t > ( ltime ) ; js :: Document doc ; doc . SetObject ( ) ; js :: Document :: AllocatorType & allocator = doc . GetAllocator ( ) ; doc . AddMember ( " " , interrupted , allocator ) ; doc . AddMember ( " " , " " , allocator ) ; doc . AddMember ( " " , 3 , allocator ) ; doc . AddMember ( " " , secondsSinceEpoch , allocator ) ; js :: Value tests ; tests . SetObject ( ) ; std :: map < TestResultType , uint32_t > counts ; for ( const auto & resultIter : testResults . results ) { const TestIdentifier & id = resultIter . first ; const TestResult & result = resultIter . second ; js :: Value jsResult ; jsResult . SetObject ( ) ; counts [ result . type ] ++ ; std :: string actualResult ; for ( uint32_t fail = 0 ; fail < result . flakyFailures ; ++ fail ) { actualResult += " " ; } actualResult += ResultTypeToString ( result . type ) ; std :: string expectedResult ; if ( result . flakyFailures > 0 ) { expectedResult = " " ; jsResult . AddMember ( " " , true , allocator ) ; } else { expectedResult = " " ; } jsResult . AddMember ( " " , actualResult , allocator ) ; jsResult . AddMember ( " " , expectedResult , allocator ) ; if ( result . type != TestResultType :: Pass ) { jsResult . AddMember ( " " , true , allocator ) ; } js :: Value times ; times . SetArray ( ) ; times . PushBack ( result . elapsedTimeSeconds , allocator ) ; jsResult . AddMember ( " " , times , allocator ) ; char testName [ 500 ] ; id . sprintfName ( testName ) ; js :: Value jsName ; jsName . SetString ( testName , allocator ) ; tests . AddMember ( jsName , jsResult , allocator ) ; } js :: Value numFailuresByType ; numFailuresByType . SetObject ( ) ; for ( const auto & countIter : counts ) { TestResultType type = countIter . first ; uint32_t count = countIter . second ; js :: Value jsCount ( count ) ; numFailuresByType . AddMember ( ResultTypeToJSString ( type , & allocator ) , jsCount , allocator ) ; } doc . AddMember ( " " , numFailuresByType , allocator ) ; doc . AddMember ( " " , tests , allocator ) ; printf ( " \n " , outputFile . c_str ( ) ) ; if ( ! WriteJsonFile ( outputFile , & doc ) ) { printf ( " \n " ) ; } }
Writes out a TestResults to the Chromium JSON Test Results format.
Writes out a TestResults to the Chromium JSON Test Results format .