aboutsummaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorMoritz Pflanzer <moritz.pflanzer@arm.com>2017-07-18 16:21:16 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-09-17 14:16:42 +0100
commitc7d1503008e74496836f99d64c082d4c9ae8f1ca (patch)
tree0aad8f56fe4c9359b08476bc7e5577fd21c1f6fe /framework
parent81bf196a8ea44be9b42a9f9b6f8eca3f016c36e2 (diff)
downloadComputeLibrary-c7d1503008e74496836f99d64c082d4c9ae8f1ca.tar.gz
COMPMID-415: Build new validation
Change-Id: I7409693f40ba3941b9d90f28c5d292c376e185c5 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/80939 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'framework')
-rw-r--r--framework/Asserts.h121
-rw-r--r--framework/Framework.cpp25
-rw-r--r--framework/Framework.h32
3 files changed, 110 insertions, 68 deletions
diff --git a/framework/Asserts.h b/framework/Asserts.h
index a1424372e9..fd745d10e0 100644
--- a/framework/Asserts.h
+++ b/framework/Asserts.h
@@ -32,6 +32,8 @@
namespace arm_compute
{
+namespace test
+{
namespace framework
{
namespace detail
@@ -53,85 +55,78 @@ inline T &&make_printable(T &&value)
{
return value;
}
-} // namespace detail
-} // namespace framework
-} // namespace arm_compute
-template <typename T>
-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());
+#define ARM_COMPUTE_TEST_INFO(INFO) \
+ { \
+ std::stringstream info; \
+ info << INFO; \
+ arm_compute::test::framework::Framework::get().add_test_info(info.str()); \
}
-}
-template <typename T>
-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());
+#define ARM_COMPUTE_TEST_COMP_FACTORY(SEVERITY, SEVERITY_NAME, COMP, COMP_NAME, ERROR_CALL) \
+ template <typename T, typename U> \
+ void ARM_COMPUTE_##SEVERITY##_##COMP_NAME##_IMPL(T &&x, U &&y, const std::string &x_str, const std::string &y_str) \
+ { \
+ if(!(x COMP y)) \
+ { \
+ std::stringstream msg; \
+ msg << #SEVERITY_NAME " '" << x_str << " " #COMP " " << y_str << "' failed. [" \
+ << std::boolalpha << arm_compute::test::framework::detail::make_printable(x) \
+ << " " #COMP " " \
+ << std::boolalpha << arm_compute::test::framework::detail::make_printable(y) \
+ << "]\n"; \
+ arm_compute::test::framework::Framework::get().print_test_info(msg); \
+ ERROR_CALL \
+ } \
+ arm_compute::test::framework::Framework::get().clear_test_info(); \
}
-}
-template <typename T>
-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());
- }
-}
+ARM_COMPUTE_TEST_COMP_FACTORY(EXPECT, Expectation, ==, EQUAL, arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str());)
+ARM_COMPUTE_TEST_COMP_FACTORY(EXPECT, Expectation, !=, NOT_EQUAL, arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str());)
+ARM_COMPUTE_TEST_COMP_FACTORY(ASSERT, Assertion, ==, EQUAL, throw arm_compute::test::framework::TestError(msg.str());)
+ARM_COMPUTE_TEST_COMP_FACTORY(ASSERT, Assertion, !=, NOT_EQUAL, throw arm_compute::test::framework::TestError(msg.str());)
-template <typename T>
-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_NOT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_ASSERT_NOT_EQUAL_IMPL(X, Y, #X, #Y)
-#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()); \
- } \
+#define ARM_COMPUTE_ASSERT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_ASSERT_EQUAL_IMPL(X, Y, #X, #Y)
+
+#define ARM_COMPUTE_EXPECT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_EXPECT_EQUAL_IMPL(X, Y, #X, #Y)
+
+#define ARM_COMPUTE_EXPECT_NOT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_EXPECT_NOT_EQUAL_IMPL(X, Y, #X, #Y)
+
+#define ARM_COMPUTE_ASSERT(X) \
+ do \
+ { \
+ const auto &x = X; \
+ if(!x) \
+ { \
+ std::stringstream msg; \
+ msg << "Assertion '" #X "' failed.\n"; \
+ arm_compute::test::framework::Framework::get().print_test_info(msg); \
+ throw arm_compute::test::framework::TestError(msg.str()); \
+ } \
+ arm_compute::test::framework::Framework::get().clear_test_info(); \
} while(false)
-#define ARM_COMPUTE_EXPECT(X, MSG) \
+#define ARM_COMPUTE_EXPECT(X) \
do \
{ \
const auto &x = X; \
if(!x) \
{ \
std::stringstream msg; \
- msg << "Failed assertion: " << #X << "\n" \
- << MSG; \
+ msg << "Expectation '" #X "' failed.\n"; \
+ arm_compute::test::framework::Framework::get().print_test_info(msg); \
arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); \
} \
+ arm_compute::test::framework::Framework::get().clear_test_info(); \
} while(false)
+} // namespace detail
+} // namespace framework
+} // namespace test
+} // namespace arm_compute
#endif /* ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS */
diff --git a/framework/Framework.cpp b/framework/Framework.cpp
index 343168426c..f2ecff98f4 100644
--- a/framework/Framework.cpp
+++ b/framework/Framework.cpp
@@ -127,6 +127,31 @@ void Framework::pop_suite()
_test_suite_name.pop_back();
}
+void Framework::add_test_info(std::string info)
+{
+ _test_info.emplace_back(std::move(info));
+}
+
+void Framework::clear_test_info()
+{
+ _test_info.clear();
+}
+
+bool Framework::has_test_info() const
+{
+ return !_test_info.empty();
+}
+
+void Framework::print_test_info(std::ostream &os) const
+{
+ os << "CONTEXT:\n";
+
+ for(const auto &str : _test_info)
+ {
+ os << " " << str << "\n";
+ }
+}
+
void Framework::log_test_start(const std::string &test_name)
{
if(_printer != nullptr)
diff --git a/framework/Framework.h b/framework/Framework.h
index bdaf806e21..4f60fed721 100644
--- a/framework/Framework.h
+++ b/framework/Framework.h
@@ -127,6 +127,27 @@ public:
template <typename T, typename D>
void add_data_test_case(std::string test_name, DatasetMode mode, std::string description, D &&data);
+ /** Add info string for the next expectation/assertion.
+ *
+ * @param[in] info Info string.
+ */
+ void add_test_info(std::string info);
+
+ /** Clear the collected test info. */
+ void clear_test_info();
+
+ /** Check if any info has been registered.
+ *
+ * @return True if there is test info.
+ */
+ bool has_test_info() const;
+
+ /** Print test info.
+ *
+ * @param[out] os Output stream.
+ */
+ void print_test_info(std::ostream &os) const;
+
/** Tell the framework that execution of a test starts.
*
* @param[in] test_name Name of the started test case.
@@ -257,11 +278,12 @@ private:
using create_function = std::unique_ptr<Instrument>();
std::map<InstrumentType, create_function *> _available_instruments{};
- InstrumentType _instruments{ InstrumentType::NONE };
- std::regex _test_name_filter{ ".*" };
- int64_t _test_id_filter{ -1 };
- DatasetMode _dataset_mode{ DatasetMode::ALL };
- TestResult *_current_test_result{ nullptr };
+ InstrumentType _instruments{ InstrumentType::NONE };
+ std::regex _test_name_filter{ ".*" };
+ int64_t _test_id_filter{ -1 };
+ DatasetMode _dataset_mode{ DatasetMode::ALL };
+ TestResult *_current_test_result{ nullptr };
+ std::vector<std::string> _test_info{};
};
template <typename T>