From b7c2a99f847d3baef1710be5cf34f978514101dd Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Tue, 18 Jul 2017 14:37:35 +0100 Subject: COMPMID-415: Cleanup framework Change-Id: Ibd5a95a8337ac96bdc1b61af29efa430b4abe2b6 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/80938 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- framework/Asserts.h | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 framework/Asserts.h (limited to 'framework/Asserts.h') diff --git a/framework/Asserts.h b/framework/Asserts.h new file mode 100644 index 0000000000..a1424372e9 --- /dev/null +++ b/framework/Asserts.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS +#define ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS + +#include "Exceptions.h" +#include "Framework.h" + +#include +#include + +namespace arm_compute +{ +namespace framework +{ +namespace detail +{ +// Cast char values to int so that their numeric value are printed. +inline int make_printable(int8_t value) +{ + return value; +} + +inline unsigned int make_printable(uint8_t value) +{ + return value; +} + +// Everything else can be printed as its own type. +template +inline T &&make_printable(T &&value) +{ + return value; +} +} // namespace detail +} // namespace framework +} // namespace arm_compute + +template +void ARM_COMPUTE_ASSERT_EQUAL(T &&x, T &&y) +{ + if(x != y) + { + std::stringstream msg; + msg << "Assertion " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " == " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + throw arm_compute::test::framework::TestError(msg.str()); + } +} + +template +void ARM_COMPUTE_EXPECT_EQUAL(T &&x, T &&y) +{ + if(x != y) + { + std::stringstream msg; + msg << "Expectation " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " == " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); + } +} + +template +void ARM_COMPUTE_ASSERT_NOT_EQUAL(T &&x, T &&y) +{ + if(x == y) + { + std::stringstream msg; + msg << "Assertion " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " != " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + throw arm_compute::test::framework::TestError(msg.str()); + } +} + +template +void ARM_COMPUTE_EXPECT_NOT_EQUAL(T &&x, T &&y) +{ + if(x == y) + { + std::stringstream msg; + msg << "Expectation " + << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " != " + << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed."; + arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); + } +} + +#define ARM_COMPUTE_ASSERT(X, MSG) \ + do \ + { \ + const auto &x = X; \ + if(!x) \ + { \ + std::stringstream msg; \ + msg << "Failed assertion: " << #X << "\n" \ + << MSG; \ + throw arm_compute::test::framework::TestError(msg.str()); \ + } \ + } while(false) + +#define ARM_COMPUTE_EXPECT(X, MSG) \ + do \ + { \ + const auto &x = X; \ + if(!x) \ + { \ + std::stringstream msg; \ + msg << "Failed assertion: " << #X << "\n" \ + << MSG; \ + arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); \ + } \ + } while(false) +#endif /* ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS */ -- cgit v1.2.1