Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +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 | fc95ed2 | 2017-07-05 11:07:07 +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_EXCEPTIONS |
| 25 | #define ARM_COMPUTE_TEST_EXCEPTIONS |
| 26 | |
Moritz Pflanzer | 2ac5040 | 2017-07-24 15:52:54 +0100 | [diff] [blame] | 27 | #include <istream> |
| 28 | #include <ostream> |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 29 | #include <stdexcept> |
Moritz Pflanzer | 2ac5040 | 2017-07-24 15:52:54 +0100 | [diff] [blame] | 30 | #include <string> |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace framework |
| 37 | { |
Moritz Pflanzer | 2ac5040 | 2017-07-24 15:52:54 +0100 | [diff] [blame] | 38 | /** Severity of the information. |
| 39 | * |
| 40 | * Each category includes the ones above it. |
| 41 | * |
| 42 | * NONE == Only for filtering. Not used to tag information. |
| 43 | * CONFIG == Configuration info. |
| 44 | * TESTS == Information about the tests. |
| 45 | * ERRORS == Violated assertions/expectations. |
| 46 | * DEBUG == More violated assertions/expectations. |
| 47 | * MEASUREMENTS == Information about measurements. |
| 48 | * ALL == Only for filtering. Not used to tag information. |
| 49 | */ |
| 50 | enum class LogLevel |
| 51 | { |
| 52 | NONE, |
| 53 | CONFIG, |
| 54 | TESTS, |
| 55 | ERRORS, |
| 56 | DEBUG, |
| 57 | MEASUREMENTS, |
| 58 | ALL, |
| 59 | }; |
| 60 | |
| 61 | LogLevel log_level_from_name(const std::string &name); |
| 62 | ::std::istream &operator>>(::std::istream &stream, LogLevel &level); |
| 63 | ::std::ostream &operator<<(::std::ostream &stream, LogLevel level); |
| 64 | std::string to_string(LogLevel level); |
| 65 | |
Anthony Barbier | f6705ec | 2017-09-28 12:01:10 +0100 | [diff] [blame] | 66 | /** Error class for when some external assets are missing */ |
| 67 | class FileNotFound : public std::runtime_error |
| 68 | { |
| 69 | public: |
| 70 | /** Construct error with message |
| 71 | * |
| 72 | * @param[in] msg Error message |
| 73 | */ |
| 74 | FileNotFound(const std::string &msg); |
| 75 | }; |
| 76 | |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 77 | /** Error class for failures during test execution. */ |
| 78 | class TestError : public std::runtime_error |
| 79 | { |
| 80 | public: |
| 81 | using std::runtime_error::runtime_error; |
Moritz Pflanzer | 2ac5040 | 2017-07-24 15:52:54 +0100 | [diff] [blame] | 82 | |
| 83 | /** Construct error with severity. |
| 84 | * |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 85 | * @param[in] msg Error message. |
| 86 | * @param[in] level Severity level. |
| 87 | * @param[in] context Context. |
Moritz Pflanzer | 2ac5040 | 2017-07-24 15:52:54 +0100 | [diff] [blame] | 88 | */ |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 89 | TestError(const std::string &msg, LogLevel level, std::string context = ""); |
Moritz Pflanzer | 2ac5040 | 2017-07-24 15:52:54 +0100 | [diff] [blame] | 90 | |
| 91 | /** Severity of the error. |
| 92 | * |
| 93 | * @return Severity. |
| 94 | */ |
| 95 | LogLevel level() const; |
| 96 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 97 | /** Get the error message. |
| 98 | * |
| 99 | * @return error message. |
| 100 | */ |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 101 | const char *what() const noexcept override; |
| 102 | |
Moritz Pflanzer | 2ac5040 | 2017-07-24 15:52:54 +0100 | [diff] [blame] | 103 | private: |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 104 | LogLevel _level{ LogLevel::ERRORS }; |
| 105 | std::string _msg{}; |
| 106 | std::string _context{}; |
| 107 | std::string _combined{}; |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 108 | }; |
| 109 | } // namespace framework |
| 110 | } // namespace test |
| 111 | } // namespace arm_compute |
| 112 | #endif /* ARM_COMPUTE_TEST_EXCEPTIONS */ |