diff options
-rw-r--r-- | framework/Framework.cpp | 40 | ||||
-rw-r--r-- | framework/Framework.h | 17 | ||||
-rw-r--r-- | framework/printers/JSONPrinter.cpp | 133 | ||||
-rw-r--r-- | framework/printers/JSONPrinter.h | 59 | ||||
-rw-r--r-- | framework/printers/PrettyPrinter.cpp | 125 | ||||
-rw-r--r-- | framework/printers/PrettyPrinter.h | 66 | ||||
-rw-r--r-- | framework/printers/Printer.cpp | 48 | ||||
-rw-r--r-- | framework/printers/Printer.h | 114 | ||||
-rw-r--r-- | framework/printers/Printers.cpp | 55 | ||||
-rw-r--r-- | framework/printers/Printers.h | 75 |
10 files changed, 730 insertions, 2 deletions
diff --git a/framework/Framework.cpp b/framework/Framework.cpp index 692e17cb91..72fa1981fc 100644 --- a/framework/Framework.cpp +++ b/framework/Framework.cpp @@ -123,7 +123,10 @@ void Framework::pop_suite() void Framework::log_test_start(const std::string &test_name) { - static_cast<void>(test_name); + if(_printer != nullptr) + { + _printer->print_test_header(test_name); + } } void Framework::log_test_skipped(const std::string &test_name) @@ -133,7 +136,11 @@ void Framework::log_test_skipped(const std::string &test_name) void Framework::log_test_end(const std::string &test_name) { - static_cast<void>(test_name); + if(_printer != nullptr) + { + _printer->print_measurements(_test_results.at(test_name).measurements); + _printer->print_test_footer(); + } } void Framework::log_failed_expectation(const std::string &msg) @@ -256,6 +263,11 @@ bool Framework::run() _test_results.clear(); _runtime = std::chrono::seconds{ 0 }; + if(_printer != nullptr) + { + _printer->print_run_header(); + } + const auto start = std::chrono::high_resolution_clock::now(); int id = 0; @@ -278,6 +290,11 @@ bool Framework::run() const auto end = std::chrono::high_resolution_clock::now(); + if(_printer != nullptr) + { + _printer->print_run_footer(); + } + _runtime = std::chrono::duration_cast<std::chrono::seconds>(end - start); int passed = 0; @@ -296,6 +313,20 @@ void Framework::set_test_result(std::string test_case_name, TestResult result) _test_results.emplace(std::move(test_case_name), std::move(result)); } +void Framework::print_test_results(Printer &printer) const +{ + printer.print_run_header(); + + for(const auto &test : _test_results) + { + printer.print_test_header(test.first); + printer.print_measurements(test.second.measurements); + printer.print_test_footer(); + } + + printer.print_run_footer(); +} + Profiler Framework::get_profiler() const { Profiler profiler; @@ -311,6 +342,11 @@ Profiler Framework::get_profiler() const return profiler; } +void Framework::set_printer(Printer *printer) +{ + _printer = printer; +} + std::vector<Framework::TestId> Framework::test_ids() const { std::vector<TestId> ids; diff --git a/framework/Framework.h b/framework/Framework.h index fbc95badd6..fbb6b9c04c 100644 --- a/framework/Framework.h +++ b/framework/Framework.h @@ -30,6 +30,7 @@ #include "TestResult.h" #include "Utils.h" #include "instruments/Instruments.h" +#include "printers/Printer.h" #include <algorithm> #include <chrono> @@ -190,6 +191,15 @@ public: */ void set_test_result(std::string test_case_name, TestResult result); + /** Use the specified printer to output test results from the last run. + * + * This method can be used if the test results need to be obtained using a + * different printer than the one managed by the framework. + * + * @param[in] printer Printer used to output results. + */ + void print_test_results(Printer &printer) const; + /** Factory method to obtain a configured profiler. * * The profiler enables all instruments that have been passed to the @ref @@ -199,6 +209,12 @@ public: */ Profiler get_profiler() const; + /** Set the printer used for the output of test results. + * + * @param[in] printer Pointer to a printer. + */ + void set_printer(Printer *printer); + /** List of @ref TestId's. * * @return Vector with all test ids. @@ -231,6 +247,7 @@ private: std::chrono::seconds _runtime{ 0 }; int _num_iterations{ 1 }; bool _throw_errors{ false }; + Printer *_printer{ nullptr }; using create_function = std::unique_ptr<Instrument>(); std::map<InstrumentType, create_function *> _available_instruments{}; diff --git a/framework/printers/JSONPrinter.cpp b/framework/printers/JSONPrinter.cpp new file mode 100644 index 0000000000..66973bb1ab --- /dev/null +++ b/framework/printers/JSONPrinter.cpp @@ -0,0 +1,133 @@ +/* + * 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 <algorithm> + +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 std::string &name) +{ + print_separator(_first_test); + + *_stream << R"(")" << name << R"(" : {)"; +} + +void JSONPrinter::print_test_footer() +{ + *_stream << "}"; +} + +void JSONPrinter::print_measurements(const Profiler::MeasurementsMap &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 << ","; + } + } +} +} // namespace framework +} // namespace test +} // namespace arm_compute diff --git a/framework/printers/JSONPrinter.h b/framework/printers/JSONPrinter.h new file mode 100644 index 0000000000..3cc5578ecd --- /dev/null +++ b/framework/printers/JSONPrinter.h @@ -0,0 +1,59 @@ +/* + * 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 std::string &name) override; + void print_test_footer() override; + void print_measurements(const Profiler::MeasurementsMap &measurements) override; + +private: + void print_separator(bool &flag); + + bool _first_test{ true }; + bool _first_entry{ true }; +}; +} // namespace framework +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_JSONPRINTER */ diff --git a/framework/printers/PrettyPrinter.cpp b/framework/printers/PrettyPrinter.cpp new file mode 100644 index 0000000000..77fb6404a8 --- /dev/null +++ b/framework/printers/PrettyPrinter.cpp @@ -0,0 +1,125 @@ +/* + * 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 <algorithm> + +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 std::string &name) +{ + *_stream << begin_color("2") << "Running '" << name << "'" << end_color() << "\n"; +} + +void PrettyPrinter::print_test_footer() +{ +} + +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/framework/printers/PrettyPrinter.h b/framework/printers/PrettyPrinter.h new file mode 100644 index 0000000000..bf3f12943d --- /dev/null +++ b/framework/printers/PrettyPrinter.h @@ -0,0 +1,66 @@ +/* + * 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 std::string &name) override; + void print_test_footer() 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/framework/printers/Printer.cpp b/framework/printers/Printer.cpp new file mode 100644 index 0000000000..e034c2ed43 --- /dev/null +++ b/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/framework/printers/Printer.h b/framework/printers/Printer.h new file mode 100644 index 0000000000..7e1936413b --- /dev/null +++ b/framework/printers/Printer.h @@ -0,0 +1,114 @@ +/* + * 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 "../Profiler.h" + +#include <fstream> +#include <iostream> +#include <ostream> + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +/** 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] name test_name. + */ + virtual void print_test_header(const std::string &name) = 0; + + /** Print footer after a test. */ + virtual void print_test_footer() = 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/framework/printers/Printers.cpp b/framework/printers/Printers.cpp new file mode 100644 index 0000000000..6b53a0c33d --- /dev/null +++ b/framework/printers/Printers.cpp @@ -0,0 +1,55 @@ +/* + * 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 <map> +#include <stdexcept> + +namespace arm_compute +{ +namespace test +{ +namespace framework +{ +LogFormat log_format_from_name(const std::string &name) +{ + static const std::map<std::string, LogFormat> formats = + { + { "pretty", LogFormat::PRETTY }, + { "none", LogFormat::NONE }, + { "json", LogFormat::JSON }, + }; + + try + { + return formats.at(name); + } + catch(const std::out_of_range &) + { + throw std::invalid_argument(name); + } +} +} // namespace framework +} // namespace test +} // namespace arm_compute diff --git a/framework/printers/Printers.h b/framework/printers/Printers.h new file mode 100644 index 0000000000..53867e2dff --- /dev/null +++ b/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 */ |