xref: /aosp_15_r20/external/deqp/framework/common/tcuResultCollector.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Test result collector
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuResultCollector.hpp"
25 #include "tcuTestContext.hpp"
26 #include "tcuTestLog.hpp"
27 
28 namespace tcu
29 {
30 
testResultSeverity(qpTestResult testResult)31 static int testResultSeverity(qpTestResult testResult)
32 {
33     switch (testResult)
34     {
35     case QP_TEST_RESULT_LAST:
36         return -1;
37     case QP_TEST_RESULT_PASS:
38         return 0;
39     case QP_TEST_RESULT_PENDING:
40         return 10;
41     case QP_TEST_RESULT_NOT_SUPPORTED:
42         return 20;
43     case QP_TEST_RESULT_QUALITY_WARNING:
44         return 30;
45     case QP_TEST_RESULT_COMPATIBILITY_WARNING:
46         return 40;
47     case QP_TEST_RESULT_TIMEOUT:
48         return 50;
49     case QP_TEST_RESULT_WAIVER:
50         return 60;
51     case QP_TEST_RESULT_FAIL:
52         return 100;
53     case QP_TEST_RESULT_RESOURCE_ERROR:
54         return 110;
55     case QP_TEST_RESULT_INTERNAL_ERROR:
56         return 120;
57     case QP_TEST_RESULT_CRASH:
58         return 150;
59     default:
60         DE_FATAL("Impossible case");
61     }
62     return 0;
63 }
64 
ResultCollector(void)65 ResultCollector::ResultCollector(void) : m_log(DE_NULL), m_prefix(""), m_result(QP_TEST_RESULT_LAST), m_message("Pass")
66 {
67 }
68 
ResultCollector(TestLog & log,const std::string & prefix)69 ResultCollector::ResultCollector(TestLog &log, const std::string &prefix)
70     : m_log(&log)
71     , m_prefix(prefix)
72     , m_result(QP_TEST_RESULT_LAST)
73     , m_message("Pass")
74 {
75 }
76 
getResult(void) const77 qpTestResult ResultCollector::getResult(void) const
78 {
79     if (m_result == QP_TEST_RESULT_LAST)
80         return QP_TEST_RESULT_PASS;
81     else
82         return m_result;
83 }
84 
addResult(qpTestResult result,const std::string & msg)85 void ResultCollector::addResult(qpTestResult result, const std::string &msg)
86 {
87     if (m_log != DE_NULL)
88         (*m_log) << TestLog::Message << m_prefix << msg << TestLog::EndMessage;
89 
90     if (testResultSeverity(result) > testResultSeverity(m_result))
91     {
92         m_result  = result;
93         m_message = msg;
94     }
95 }
96 
checkResult(bool condition,qpTestResult result,const std::string & msg)97 bool ResultCollector::checkResult(bool condition, qpTestResult result, const std::string &msg)
98 {
99     if (!condition)
100         addResult(result, msg);
101     return condition;
102 }
103 
fail(const std::string & msg)104 void ResultCollector::fail(const std::string &msg)
105 {
106     addResult(QP_TEST_RESULT_FAIL, msg);
107 }
108 
check(bool condition,const std::string & msg)109 bool ResultCollector::check(bool condition, const std::string &msg)
110 {
111     return checkResult(condition, QP_TEST_RESULT_FAIL, msg);
112 }
113 
setTestContextResult(TestContext & testCtx)114 void ResultCollector::setTestContextResult(TestContext &testCtx)
115 {
116     testCtx.setTestResult(getResult(), getMessage().c_str());
117 }
118 
119 } // namespace tcu
120