Skip to content

Commit

Permalink
Add compiler and architecture information to xml report
Browse files Browse the repository at this point in the history
  • Loading branch information
lieser committed Jul 25, 2023
1 parent cff50ed commit 22d66c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/build-data/buildh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/tests/runner/test_xml_reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,54 @@

#if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)

#include <botan/build.h>
#include <botan/version.h>
#include <botan/internal/loadstor.h>

#include <iomanip>
#include <numeric>
#include <sstream>
#include <time.h>

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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 22d66c9

Please sign in to comment.