Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | |
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 | |
| 58 | Printer(const Printer &) = delete; |
| 59 | Printer &operator=(const Printer &) = delete; |
| 60 | Printer(Printer &&) = default; |
| 61 | Printer &operator=(Printer &&) = default; |
| 62 | |
| 63 | virtual ~Printer() = default; |
| 64 | |
| 65 | /** Print given string. |
| 66 | * |
| 67 | * @param[in] str String. |
| 68 | */ |
| 69 | void print(const std::string &str); |
| 70 | |
| 71 | /** Print an entry consisting of a (name, value) pair. |
| 72 | * |
| 73 | * @param[in] name Description of the value. |
| 74 | * @param[in] value Value. |
| 75 | */ |
| 76 | virtual void print_entry(const std::string &name, const std::string &value) = 0; |
| 77 | |
| 78 | /** Print global header. */ |
| 79 | virtual void print_global_header() = 0; |
| 80 | |
| 81 | /** Print global footer. */ |
| 82 | virtual void print_global_footer() = 0; |
| 83 | |
| 84 | /** Print header before running all tests. */ |
| 85 | virtual void print_run_header() = 0; |
| 86 | |
| 87 | /** Print footer after running all tests. */ |
| 88 | virtual void print_run_footer() = 0; |
| 89 | |
| 90 | /** Print header before a test. |
| 91 | * |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 92 | * @param[in] info Test info. |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 93 | */ |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 94 | virtual void print_test_header(const TestInfo &info) = 0; |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 95 | |
| 96 | /** Print footer after a test. */ |
| 97 | virtual void print_test_footer() = 0; |
| 98 | |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 99 | /** Print header before errors. */ |
| 100 | virtual void print_errors_header() = 0; |
| 101 | |
| 102 | /** Print footer after errors. */ |
| 103 | virtual void print_errors_footer() = 0; |
| 104 | |
Anthony Barbier | dbfb31c | 2017-11-24 11:24:45 +0000 | [diff] [blame^] | 105 | /** Print the list of all the tests |
| 106 | * |
| 107 | * @param[in] infos List of tests to print |
| 108 | */ |
| 109 | virtual void print_list_tests(const std::vector<TestInfo> &infos) = 0; |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 110 | /** Print test error. |
| 111 | * |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 112 | * @param[in] error Description of the error. |
| 113 | * @param[in] expected Whether the error was expected or not. |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 114 | */ |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 115 | virtual void print_error(const std::exception &error, bool expected) = 0; |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 116 | |
steniu01 | 172c58d | 2017-08-31 13:49:08 +0100 | [diff] [blame] | 117 | /** Print test log info. |
| 118 | * |
| 119 | * @param[in] info Description of the log. |
| 120 | */ |
| 121 | virtual void print_info(const std::string &info) = 0; |
| 122 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 123 | /** Print measurements for a test. |
| 124 | * |
| 125 | * @param[in] measurements Measurements as collected by a @ref Profiler. |
| 126 | */ |
| 127 | virtual void print_measurements(const Profiler::MeasurementsMap &measurements) = 0; |
| 128 | |
| 129 | /** Set the output stream. |
| 130 | * |
| 131 | * @param[out] stream Output stream. |
| 132 | */ |
| 133 | void set_stream(std::ostream &stream); |
| 134 | |
| 135 | protected: |
| 136 | std::ostream *_stream{ &std::cout }; |
| 137 | }; |
| 138 | } // namespace framework |
| 139 | } // namespace test |
| 140 | } // namespace arm_compute |
| 141 | #endif /* ARM_COMPUTE_TEST_PRINTER */ |