Compute Library
 22.08
Exceptions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2018 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_EXCEPTIONS
25 #define ARM_COMPUTE_TEST_EXCEPTIONS
26 
27 #include <istream>
28 #include <ostream>
29 #include <stdexcept>
30 #include <string>
31 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace framework
37 {
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,
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 
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 
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;
82 
83  /** Construct error with severity.
84  *
85  * @param[in] msg Error message.
86  * @param[in] level Severity level.
87  * @param[in] context Context.
88  */
89  TestError(const std::string &msg, LogLevel level, std::string context = "");
90 
91  /** Severity of the error.
92  *
93  * @return Severity.
94  */
95  LogLevel level() const;
96 
97  /** Get the error message.
98  *
99  * @return error message.
100  */
101  const char *what() const noexcept override;
102 
103 private:
104  LogLevel _level{ LogLevel::ERRORS };
105  std::string _msg{};
106  std::string _context{};
107  std::string _combined{};
108 };
109 } // namespace framework
110 } // namespace test
111 } // namespace arm_compute
112 #endif /* ARM_COMPUTE_TEST_EXCEPTIONS */
std::string to_string(DatasetMode mode)
Definition: DatasetModes.h:100
LogLevel
Severity of the information.
Definition: Exceptions.h:50
Copyright (c) 2017-2022 Arm Limited.
inline ::std::istream & operator>>(::std::istream &stream, DatasetMode &mode)
Definition: DatasetModes.h:69
Error class for when some external assets are missing.
Definition: Exceptions.h:67
const char * name
LogLevel log_level_from_name(const std::string &name)
Definition: Exceptions.cpp:37
Error class for failures during test execution.
Definition: Exceptions.h:78
inline ::std::ostream & operator<<(::std::ostream &stream, DatasetMode mode)
Definition: DatasetModes.h:77