blob: 75de6838578b1819da266817aa88a27242c25dfb [file] [log] [blame]
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2018 Arm Limited.
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +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_EXCEPTIONS
25#define ARM_COMPUTE_TEST_EXCEPTIONS
26
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010027#include <istream>
28#include <ostream>
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010029#include <stdexcept>
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010030#include <string>
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010031
32namespace arm_compute
33{
34namespace test
35{
36namespace framework
37{
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010038/** 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 */
50enum class LogLevel
51{
52 NONE,
53 CONFIG,
54 TESTS,
55 ERRORS,
56 DEBUG,
57 MEASUREMENTS,
58 ALL,
59};
60
61LogLevel 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);
64std::string to_string(LogLevel level);
65
Anthony Barbierf6705ec2017-09-28 12:01:10 +010066/** Error class for when some external assets are missing */
67class FileNotFound : public std::runtime_error
68{
69public:
70 /** Construct error with message
71 *
72 * @param[in] msg Error message
73 */
74 FileNotFound(const std::string &msg);
75};
76
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010077/** Error class for failures during test execution. */
78class TestError : public std::runtime_error
79{
80public:
81 using std::runtime_error::runtime_error;
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010082
83 /** Construct error with severity.
84 *
Moritz Pflanzer24a82462017-08-04 11:34:44 +010085 * @param[in] msg Error message.
86 * @param[in] level Severity level.
87 * @param[in] context Context.
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010088 */
Moritz Pflanzer24a82462017-08-04 11:34:44 +010089 TestError(const std::string &msg, LogLevel level, std::string context = "");
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010090
91 /** Severity of the error.
92 *
93 * @return Severity.
94 */
95 LogLevel level() const;
96
Alex Gildayc357c472018-03-21 13:54:09 +000097 /** Get the error message.
98 *
99 * @return error message.
100 */
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100101 const char *what() const noexcept override;
102
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100103private:
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100104 LogLevel _level{ LogLevel::ERRORS };
105 std::string _msg{};
106 std::string _context{};
107 std::string _combined{};
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100108};
109} // namespace framework
110} // namespace test
111} // namespace arm_compute
112#endif /* ARM_COMPUTE_TEST_EXCEPTIONS */