From 22d66c9bbd39a477df2a07f1c265d8aaa7441bf4 Mon Sep 17 00:00:00 2001 From: Philippe Lieser Date: Tue, 25 Jul 2023 13:01:18 +0200 Subject: [PATCH] Add compiler and architecture information to xml report --- src/build-data/buildh.in | 1 + src/tests/runner/test_xml_reporter.cpp | 40 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in index 67a6293b64f..4802e0bf08f 100644 --- a/src/build-data/buildh.in +++ b/src/build-data/buildh.in @@ -97,6 +97,7 @@ #define BOTAN_HAS_SANITIZER_%{i|upper} %{endfor} +#define BOTAN_TARGET_ARCH "%{arch}" #define BOTAN_TARGET_ARCH_IS_%{arch|upper} %{if endian} #define BOTAN_TARGET_CPU_IS_%{endian|upper}_ENDIAN diff --git a/src/tests/runner/test_xml_reporter.cpp b/src/tests/runner/test_xml_reporter.cpp index 4fcbe8d2e71..5bb59a07369 100644 --- a/src/tests/runner/test_xml_reporter.cpp +++ b/src/tests/runner/test_xml_reporter.cpp @@ -9,17 +9,54 @@ #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM) + #include #include #include #include #include + #include #include namespace Botan_Tests { namespace { +std::string full_compiler_version_string() { + #if defined(BOTAN_BUILD_COMPILER_IS_CLANG) || defined(BOTAN_BUILD_COMPILER_IS_GCC) + return __VERSION__; + #elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) + // See https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros + // If the version number of the Microsoft C/C++ compiler is 15.00.20706.01, + // the _MSC_FULL_VER macro evaluates to 150020706. + constexpr int major = _MSC_FULL_VER / 10000000; + constexpr int minor = (_MSC_FULL_VER % 10000000) / 100000; + constexpr int patch = _MSC_FULL_VER % 100000; + constexpr int build = _MSC_BUILD; + + std::ostringstream oss; + + oss << std::setfill('0') << std::setw(2) << major << "." << std::setw(2) << minor << "." << std::setw(5) << patch + << "." << std::setw(2) << build << std::endl; + + return oss.str(); + #else + return "unknown"; + #endif +} + +std::string full_compiler_name_string() { + #if defined(BOTAN_BUILD_COMPILER_IS_CLANG) + return "clang"; + #elif defined(BOTAN_BUILD_COMPILER_IS_GCC) + return "gcc"; + #elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) + return "Microsoft Visual C++"; + #else + return "unknown"; + #endif +} + std::tm* localtime(const time_t* timer, std::tm* buffer) { #if defined(BOTAN_BUILD_COMPILER_IS_MSVC) || defined(BOTAN_TARGET_OS_IS_MINGW) || \ defined(BOTAN_TARGET_OS_IS_CYGWIN) || defined(BOTAN_TARGET_OS_IS_WINDOWS) @@ -53,6 +90,9 @@ std::string format(const std::chrono::nanoseconds& dur) { XmlReporter::XmlReporter(const Test_Options& opts, std::string output_dir) : Reporter(opts), m_output_dir(std::move(output_dir)) { + set_property("architecture", BOTAN_TARGET_ARCH); + set_property("compiler", full_compiler_name_string()); + set_property("compiler_version", full_compiler_version_string()); set_property("timestamp", format(std::chrono::system_clock::now())); auto custom_props = opts.report_properties(); for(const auto& prop : custom_props) {