blob: af0209788ccfceb2a912731b6e5954957bca7668 [file] [log] [blame]
Moritz Pflanzer80fffae2017-07-05 11:02:37 +01001/*
Freddie Liardet59fd7a72021-06-17 13:30:11 +01002 * Copyright (c) 2017-2018,2021 Arm Limited.
Moritz Pflanzer80fffae2017-07-05 11:02:37 +01003 *
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
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010027#include "tests/framework/Profiler.h"
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010028
29#include <fstream>
30#include <iostream>
31#include <ostream>
Moritz Pflanzer24a82462017-08-04 11:34:44 +010032#include <stdexcept>
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010033
34namespace arm_compute
35{
36namespace test
37{
38namespace framework
39{
Moritz Pflanzer542002c2017-07-26 16:03:58 +010040struct TestInfo;
41
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010042/** Abstract printer class used by the @ref Framework to present output. */
43class Printer
44{
45public:
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
Alex Gildayc357c472018-03-21 13:54:09 +000058 /** Prevent instances of this class from being copy constructed */
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010059 Printer(const Printer &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000060 /** Prevent instances of this class from being copied */
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010061 Printer &operator=(const Printer &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000062 /** Allow instances of this class to be move constructed */
63 Printer(Printer &&) = default;
64 /** Allow instances of this class to be moved */
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010065 Printer &operator=(Printer &&) = default;
66
Alex Gildayc357c472018-03-21 13:54:09 +000067 /** Default destructor. */
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010068 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 *
Moritz Pflanzer542002c2017-07-26 16:03:58 +010097 * @param[in] info Test info.
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010098 */
Moritz Pflanzer542002c2017-07-26 16:03:58 +010099 virtual void print_test_header(const TestInfo &info) = 0;
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100100
101 /** Print footer after a test. */
102 virtual void print_test_footer() = 0;
103
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100104 /** 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
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000110 /** 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;
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100115 /** Print test error.
116 *
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100117 * @param[in] error Description of the error.
118 * @param[in] expected Whether the error was expected or not.
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100119 */
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100120 virtual void print_error(const std::exception &error, bool expected) = 0;
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100121
steniu01172c58d2017-08-31 13:49:08 +0100122 /** 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
Freddie Liardet59fd7a72021-06-17 13:30:11 +0100128 /** 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
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100134 /** 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
146protected:
147 std::ostream *_stream{ &std::cout };
148};
149} // namespace framework
150} // namespace test
151} // namespace arm_compute
152#endif /* ARM_COMPUTE_TEST_PRINTER */