From a09de0c8b2ed0f1481502d3b023375609362d9e3 Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Fri, 1 Sep 2017 20:41:12 +0100 Subject: COMPMID-415: Rename and move tests The boost validation is now "standalone" in validation_old and builds as arm_compute_validation_old. The new validation builds now as arm_compute_validation. Change-Id: Ib93ba848a25680ac60afb92b461d574a0757150d Reviewed-on: http://mpd-gerrit.cambridge.arm.com/86187 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- tests/framework/printers/JSONPrinter.cpp | 168 +++++++++++++++++++++++++++++ tests/framework/printers/JSONPrinter.h | 64 +++++++++++ tests/framework/printers/PrettyPrinter.cpp | 140 ++++++++++++++++++++++++ tests/framework/printers/PrettyPrinter.h | 69 ++++++++++++ tests/framework/printers/Printer.cpp | 48 +++++++++ tests/framework/printers/Printer.h | 129 ++++++++++++++++++++++ tests/framework/printers/Printers.cpp | 57 ++++++++++ tests/framework/printers/Printers.h | 75 +++++++++++++ 8 files changed, 750 insertions(+) create mode 100644 tests/framework/printers/JSONPrinter.cpp create mode 100644 tests/framework/printers/JSONPrinter.h create mode 100644 tests/framework/printers/PrettyPrinter.cpp create mode 100644 tests/framework/printers/PrettyPrinter.h create mode 100644 tests/framework/printers/Printer.cpp create mode 100644 tests/framework/printers/Printer.h create mode 100644 tests/framework/printers/Printers.cpp create mode 100644 tests/framework/printers/Printers.h (limited to 'tests/framework/printers') diff --git a/tests/framework/printers/JSONPrinter.cpp b/tests/framework/printers/JSONPrinter.cpp new file mode 100644 index 0000000000..5b30389eca --- /dev/null +++ b/tests/framework/printers/JSONPrinter.cpp @@ -0,0 +1,168 @@ +/* + * 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. + */ +#include "JSONPrinter.h" + +#include "tests/framework/Framework.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +void JSONPrinter::print_separator(bool &flag) +{ + if(flag) + { + flag = false; + } + else + { + *_stream << ","; + } +} + +void JSONPrinter::print_entry(const std::string &name, const std::string &value) +{ + print_separator(_first_entry); + + *_stream << R"(")" << name << R"(" : ")" << value << R"(")"; +} + +void JSONPrinter::print_global_header() +{ + *_stream << "{"; +} + +void JSONPrinter::print_global_footer() +{ + *_stream << "}\n"; +} + +void JSONPrinter::print_run_header() +{ + print_separator(_first_entry); + + *_stream << R"("tests" : {)"; +} + +void JSONPrinter::print_run_footer() +{ + *_stream << "}"; +} + +void JSONPrinter::print_test_header(const TestInfo &info) +{ + print_separator(_first_test); + + _first_test_entry = true; + *_stream << R"(")" << info.name << R"(" : {)"; +} + +void JSONPrinter::print_test_footer() +{ + *_stream << "}"; +} + +void JSONPrinter::print_errors_header() +{ + print_separator(_first_test_entry); + + _first_error = true; + *_stream << R"("errors" : [)"; +} + +void JSONPrinter::print_errors_footer() +{ + *_stream << "]"; +} + +void JSONPrinter::print_error(const std::exception &error) +{ + std::stringstream error_log; + error_log.str(error.what()); + + for(std::string line; !std::getline(error_log, line).fail();) + { + print_separator(_first_error); + + *_stream << R"(")" << line << R"(")"; + } +} + +void JSONPrinter::print_measurements(const Profiler::MeasurementsMap &measurements) +{ + print_separator(_first_test_entry); + + *_stream << R"("measurements" : {)"; + + for(auto i_it = measurements.cbegin(), i_end = measurements.cend(); i_it != i_end;) + { + *_stream << R"(")" << i_it->first << R"(" : {)"; + + auto add_measurements = [](double a, const Instrument::Measurement & b) + { + return a + b.value; + }; + + auto cmp_measurements = [](const Instrument::Measurement & a, const Instrument::Measurement & b) + { + return a.value < b.value; + }; + + double sum_values = std::accumulate(i_it->second.cbegin(), i_it->second.cend(), 0., add_measurements); + int num_values = i_it->second.size(); + const auto minmax_values = std::minmax_element(i_it->second.begin(), i_it->second.end(), cmp_measurements); + + if(num_values > 2) + { + sum_values -= minmax_values.first->value + minmax_values.second->value; + num_values -= 2; + } + + auto measurement_to_string = [](const Instrument::Measurement & measurement) + { + return support::cpp11::to_string(measurement.value); + }; + + *_stream << R"("avg" : )" << (sum_values / num_values) << ","; + *_stream << R"("min" : )" << minmax_values.first->value << ","; + *_stream << R"("max" : )" << minmax_values.second->value << ","; + *_stream << R"("raw" : [)" << join(i_it->second.begin(), i_it->second.end(), ",", measurement_to_string) << "],"; + *_stream << R"("unit" : ")" << minmax_values.first->unit << R"(")"; + *_stream << "}"; + + if(++i_it != i_end) + { + *_stream << ","; + } + } + + *_stream << "}"; +} +} // namespace framework +} // namespace test +} // namespace arm_compute diff --git a/tests/framework/printers/JSONPrinter.h b/tests/framework/printers/JSONPrinter.h new file mode 100644 index 0000000000..14c8b35cb9 --- /dev/null +++ b/tests/framework/printers/JSONPrinter.h @@ -0,0 +1,64 @@ +/* + * 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_JSONPRINTER +#define ARM_COMPUTE_TEST_JSONPRINTER + +#include "Printer.h" + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +/** Implementation of a @ref Printer that produces JSON output. */ +class JSONPrinter : public Printer +{ +public: + using Printer::Printer; + + void print_entry(const std::string &name, const std::string &value) override; + void print_global_header() override; + void print_global_footer() override; + void print_run_header() override; + void print_run_footer() override; + void print_test_header(const TestInfo &info) override; + void print_test_footer() override; + void print_errors_header() override; + void print_errors_footer() override; + void print_error(const std::exception &error) override; + void print_measurements(const Profiler::MeasurementsMap &measurements) override; + +private: + void print_separator(bool &flag); + + bool _first_entry{ true }; + bool _first_test{ true }; + bool _first_test_entry{ true }; + bool _first_error{ true }; +}; +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_JSONPRINTER */ diff --git a/tests/framework/printers/PrettyPrinter.cpp b/tests/framework/printers/PrettyPrinter.cpp new file mode 100644 index 0000000000..ec32e5296e --- /dev/null +++ b/tests/framework/printers/PrettyPrinter.cpp @@ -0,0 +1,140 @@ +/* + * 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. + */ +#include "PrettyPrinter.h" + +#include "tests/framework/Framework.h" + +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +std::string PrettyPrinter::begin_color(const std::string &color) const +{ + if(!_color_output) + { + return ""; + } + + return "\033[0;3" + color + "m"; +} + +std::string PrettyPrinter::end_color() const +{ + if(!_color_output) + { + return ""; + } + + return "\033[m"; +} + +void PrettyPrinter::set_color_output(bool color_output) +{ + _color_output = color_output; +} + +void PrettyPrinter::print_entry(const std::string &name, const std::string &value) +{ + *_stream << begin_color("4") << name << " = " << value << end_color() << "\n"; +} + +void PrettyPrinter::print_global_header() +{ +} + +void PrettyPrinter::print_global_footer() +{ +} + +void PrettyPrinter::print_run_header() +{ +} + +void PrettyPrinter::print_run_footer() +{ +} + +void PrettyPrinter::print_test_header(const TestInfo &info) +{ + *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n"; +} + +void PrettyPrinter::print_test_footer() +{ +} + +void PrettyPrinter::print_errors_header() +{ +} + +void PrettyPrinter::print_errors_footer() +{ +} + +void PrettyPrinter::print_error(const std::exception &error) +{ + *_stream << begin_color("1") << "ERROR: " << error.what() << end_color() << "\n"; +} + +void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements) +{ + for(const auto &instrument : measurements) + { + *_stream << begin_color("3") << " " << instrument.first << ":"; + + auto add_measurements = [](double a, const Instrument::Measurement & b) + { + return a + b.value; + }; + + auto cmp_measurements = [](const Instrument::Measurement & a, const Instrument::Measurement & b) + { + return a.value < b.value; + }; + + double sum_values = std::accumulate(instrument.second.begin(), instrument.second.end(), 0., add_measurements); + int num_values = instrument.second.size(); + const auto minmax_values = std::minmax_element(instrument.second.begin(), instrument.second.end(), cmp_measurements); + + if(num_values > 2) + { + sum_values -= minmax_values.first->value + minmax_values.second->value; + num_values -= 2; + } + + Instrument::Measurement avg{ sum_values / num_values, minmax_values.first->unit }; + + *_stream << " "; + *_stream << "AVG=" << avg << ", "; + *_stream << "MIN=" << *minmax_values.first << ", "; + *_stream << "MAX=" << *minmax_values.second << end_color() << "\n"; + } +} +} // namespace framework +} // namespace test +} // namespace arm_compute diff --git a/tests/framework/printers/PrettyPrinter.h b/tests/framework/printers/PrettyPrinter.h new file mode 100644 index 0000000000..fa7b7b2c59 --- /dev/null +++ b/tests/framework/printers/PrettyPrinter.h @@ -0,0 +1,69 @@ +/* + * 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_PRETTYPRINTER +#define ARM_COMPUTE_TEST_PRETTYPRINTER + +#include "Printer.h" + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +/** Implementation of a @ref Printer that produces human readable output. */ +class PrettyPrinter : public Printer +{ +public: + using Printer::Printer; + + /** Set if the output is colored. + * + * @param[in] color_output True if the output is colored. + */ + void set_color_output(bool color_output); + + void print_entry(const std::string &name, const std::string &value) override; + void print_global_header() override; + void print_global_footer() override; + void print_run_header() override; + void print_run_footer() override; + void print_test_header(const TestInfo &info) override; + void print_test_footer() override; + void print_errors_header() override; + void print_errors_footer() override; + void print_error(const std::exception &error) override; + void print_measurements(const Profiler::MeasurementsMap &measurements) override; + +private: + std::string begin_color(const std::string &color) const; + std::string end_color() const; + + bool _color_output{ true }; +}; +} // namespace framework +} // namespace test +} // namespace arm_compute + +#endif /* ARM_COMPUTE_TEST_PRETTYPRINTER */ diff --git a/tests/framework/printers/Printer.cpp b/tests/framework/printers/Printer.cpp new file mode 100644 index 0000000000..e034c2ed43 --- /dev/null +++ b/tests/framework/printers/Printer.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ +#include "Printer.h" + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +Printer::Printer(std::ostream &stream) + : _stream{ &stream } +{ +} + +void Printer::print(const std::string &str) +{ + *_stream << str; +} + +void Printer::set_stream(std::ostream &stream) +{ + _stream = &stream; +} +} // namespace framework +} // namespace test +} // namespace arm_compute diff --git a/tests/framework/printers/Printer.h b/tests/framework/printers/Printer.h new file mode 100644 index 0000000000..198d84d466 --- /dev/null +++ b/tests/framework/printers/Printer.h @@ -0,0 +1,129 @@ +/* + * 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_PRINTER +#define ARM_COMPUTE_TEST_PRINTER + +#include "tests/framework/Profiler.h" + +#include +#include +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +struct TestInfo; + +/** Abstract printer class used by the @ref Framework to present output. */ +class Printer +{ +public: + /** Default constructor. + * + * Prints values to std::cout. + * */ + Printer() = default; + + /** Construct printer with given output stream. + * + * @param[out] stream Output stream. + */ + Printer(std::ostream &stream); + + Printer(const Printer &) = delete; + Printer &operator=(const Printer &) = delete; + Printer(Printer &&) = default; + Printer &operator=(Printer &&) = default; + + virtual ~Printer() = default; + + /** Print given string. + * + * @param[in] str String. + */ + void print(const std::string &str); + + /** Print an entry consisting of a (name, value) pair. + * + * @param[in] name Description of the value. + * @param[in] value Value. + */ + virtual void print_entry(const std::string &name, const std::string &value) = 0; + + /** Print global header. */ + virtual void print_global_header() = 0; + + /** Print global footer. */ + virtual void print_global_footer() = 0; + + /** Print header before running all tests. */ + virtual void print_run_header() = 0; + + /** Print footer after running all tests. */ + virtual void print_run_footer() = 0; + + /** Print header before a test. + * + * @param[in] info Test info. + */ + virtual void print_test_header(const TestInfo &info) = 0; + + /** Print footer after a test. */ + virtual void print_test_footer() = 0; + + /** Print header before errors. */ + virtual void print_errors_header() = 0; + + /** Print footer after errors. */ + virtual void print_errors_footer() = 0; + + /** Print test error. + * + * @param[in] error Description of the error. + */ + virtual void print_error(const std::exception &error) = 0; + + /** Print measurements for a test. + * + * @param[in] measurements Measurements as collected by a @ref Profiler. + */ + virtual void print_measurements(const Profiler::MeasurementsMap &measurements) = 0; + + /** Set the output stream. + * + * @param[out] stream Output stream. + */ + void set_stream(std::ostream &stream); + +protected: + std::ostream *_stream{ &std::cout }; +}; +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_PRINTER */ diff --git a/tests/framework/printers/Printers.cpp b/tests/framework/printers/Printers.cpp new file mode 100644 index 0000000000..6e11b63a9a --- /dev/null +++ b/tests/framework/printers/Printers.cpp @@ -0,0 +1,57 @@ +/* + * 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. + */ +#include "Printers.h" + +#include "../Utils.h" + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +LogFormat log_format_from_name(const std::string &name) +{ + static const std::map formats = + { + { "pretty", LogFormat::PRETTY }, + { "none", LogFormat::NONE }, + { "json", LogFormat::JSON }, + }; + + try + { + return formats.at(tolower(name)); + } + catch(const std::out_of_range &) + { + throw std::invalid_argument(name); + } +} +} // namespace framework +} // namespace test +} // namespace arm_compute diff --git a/tests/framework/printers/Printers.h b/tests/framework/printers/Printers.h new file mode 100644 index 0000000000..53867e2dff --- /dev/null +++ b/tests/framework/printers/Printers.h @@ -0,0 +1,75 @@ +/* + * 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_PRINTERS +#define ARM_COMPUTE_TEST_PRINTERS + +#include "JSONPrinter.h" +#include "PrettyPrinter.h" + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +enum class LogFormat +{ + NONE, + JSON, + PRETTY +}; + +LogFormat log_format_from_name(const std::string &name); + +inline ::std::stringstream &operator>>(::std::stringstream &stream, LogFormat &format) +{ + std::string value; + stream >> value; + format = log_format_from_name(value); + return stream; +} + +inline ::std::stringstream &operator<<(::std::stringstream &stream, LogFormat format) +{ + switch(format) + { + case LogFormat::PRETTY: + stream << "PRETTY"; + break; + case LogFormat::NONE: + stream << "NONE"; + break; + case LogFormat::JSON: + stream << "JSON"; + break; + default: + throw std::invalid_argument("Unsupported log format"); + } + + return stream; +} +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_PRINTERS */ -- cgit v1.2.1