xref: /aosp_15_r20/external/ComputeLibrary/tests/framework/printers/Printer.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2018,2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef ARM_COMPUTE_TEST_PRINTER
25 #define ARM_COMPUTE_TEST_PRINTER
26 
27 #include "tests/framework/Profiler.h"
28 
29 #include <fstream>
30 #include <iostream>
31 #include <ostream>
32 #include <stdexcept>
33 
34 namespace arm_compute
35 {
36 namespace test
37 {
38 namespace framework
39 {
40 struct TestInfo;
41 
42 /** Abstract printer class used by the @ref Framework to present output. */
43 class Printer
44 {
45 public:
46     /** Default constructor.
47      *
48      * Prints values to std::cout.
49      * */
50     Printer() = default;
51 
52     /** Construct printer with given output stream.
53      *
54      * @param[out] stream Output stream.
55      */
56     Printer(std::ostream &stream);
57 
58     /** Prevent instances of this class from being copy constructed */
59     Printer(const Printer &) = delete;
60     /** Prevent instances of this class from being copied */
61     Printer &operator=(const Printer &) = delete;
62     /** Allow instances of this class to be move constructed */
63     Printer(Printer &&) = default;
64     /** Allow instances of this class to be moved */
65     Printer &operator=(Printer &&) = default;
66 
67     /** Default destructor. */
68     virtual ~Printer() = default;
69 
70     /** Print given string.
71      *
72      * @param[in] str String.
73      */
74     void print(const std::string &str);
75 
76     /** Print an entry consisting of a (name, value) pair.
77      *
78      * @param[in] name  Description of the value.
79      * @param[in] value Value.
80      */
81     virtual void print_entry(const std::string &name, const std::string &value) = 0;
82 
83     /** Print global header. */
84     virtual void print_global_header() = 0;
85 
86     /** Print global footer. */
87     virtual void print_global_footer() = 0;
88 
89     /** Print header before running all tests. */
90     virtual void print_run_header() = 0;
91 
92     /** Print footer after running all tests. */
93     virtual void print_run_footer() = 0;
94 
95     /** Print header before a test.
96      *
97      * @param[in] info Test info.
98      */
99     virtual void print_test_header(const TestInfo &info) = 0;
100 
101     /** Print footer after a test. */
102     virtual void print_test_footer() = 0;
103 
104     /** Print header before errors. */
105     virtual void print_errors_header() = 0;
106 
107     /** Print footer after errors. */
108     virtual void print_errors_footer() = 0;
109 
110     /** Print the list of all the tests
111      *
112      * @param[in] infos List of tests to print
113      */
114     virtual void print_list_tests(const std::vector<TestInfo> &infos) = 0;
115     /** Print test error.
116      *
117      * @param[in] error    Description of the error.
118      * @param[in] expected Whether the error was expected or not.
119      */
120     virtual void print_error(const std::exception &error, bool expected) = 0;
121 
122     /** Print test log info.
123      *
124      * @param[in] info Description of the log.
125      */
126     virtual void print_info(const std::string &info) = 0;
127 
128     /** Print header data.
129      *
130      * @param[in] header_data JSON formmated header data.
131      */
132     virtual void print_profiler_header(const std::string &header_data) = 0;
133 
134     /** Print measurements for a test.
135      *
136      * @param[in] measurements Measurements as collected by a @ref Profiler.
137      */
138     virtual void print_measurements(const Profiler::MeasurementsMap &measurements) = 0;
139 
140     /** Set the output stream.
141      *
142      * @param[out] stream Output stream.
143      */
144     void set_stream(std::ostream &stream);
145 
146 protected:
147     std::ostream *_stream{ &std::cout };
148 };
149 } // namespace framework
150 } // namespace test
151 } // namespace arm_compute
152 #endif /* ARM_COMPUTE_TEST_PRINTER */
153