Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 Arm Limited. |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 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 | |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 27 | #include "tests/framework/Profiler.h" |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 28 | |
| 29 | #include <fstream> |
| 30 | #include <iostream> |
| 31 | #include <ostream> |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 32 | #include <stdexcept> |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
| 38 | namespace framework |
| 39 | { |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 40 | struct TestInfo; |
| 41 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 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 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 58 | /** Prevent instances of this class from being copy constructed */ |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 59 | Printer(const Printer &) = delete; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 60 | /** Prevent instances of this class from being copied */ |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 61 | Printer &operator=(const Printer &) = delete; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 62 | /** Allow instances of this class to be move constructed */ |
| 63 | Printer(Printer &&) = default; |
| 64 | /** Allow instances of this class to be moved */ |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 65 | Printer &operator=(Printer &&) = default; |
| 66 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 67 | /** Default destructor. */ |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 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 | * |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 97 | * @param[in] info Test info. |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 98 | */ |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 99 | virtual void print_test_header(const TestInfo &info) = 0; |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 100 | |
| 101 | /** Print footer after a test. */ |
| 102 | virtual void print_test_footer() = 0; |
| 103 | |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 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 | |
Anthony Barbier | dbfb31c | 2017-11-24 11:24:45 +0000 | [diff] [blame] | 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; |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 115 | /** Print test error. |
| 116 | * |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 117 | * @param[in] error Description of the error. |
| 118 | * @param[in] expected Whether the error was expected or not. |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 119 | */ |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 120 | virtual void print_error(const std::exception &error, bool expected) = 0; |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 121 | |
steniu01 | 172c58d | 2017-08-31 13:49:08 +0100 | [diff] [blame] | 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 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 128 | /** Print measurements for a test. |
| 129 | * |
| 130 | * @param[in] measurements Measurements as collected by a @ref Profiler. |
| 131 | */ |
| 132 | virtual void print_measurements(const Profiler::MeasurementsMap &measurements) = 0; |
| 133 | |
| 134 | /** Set the output stream. |
| 135 | * |
| 136 | * @param[out] stream Output stream. |
| 137 | */ |
| 138 | void set_stream(std::ostream &stream); |
| 139 | |
| 140 | protected: |
| 141 | std::ostream *_stream{ &std::cout }; |
| 142 | }; |
| 143 | } // namespace framework |
| 144 | } // namespace test |
| 145 | } // namespace arm_compute |
| 146 | #endif /* ARM_COMPUTE_TEST_PRINTER */ |