feat(test): report results to CDash
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 10s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 14s
VoidBuildSystem CI / fuzz-clang (push) Failing after 8s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 54s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 10s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 14s
VoidBuildSystem CI / fuzz-clang (push) Failing after 8s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 54s
This commit is contained in:
1 parent
6befa6b5e2
commit
9d7c801e2d
9 files changed
+458
-2
No files matched your search
@@ -27,6 +27,7 @@
|
||||
#include <Void/Build/Provenance/Verification.hpp>
|
||||
#include <Void/Build/Provider/Provider.hpp>
|
||||
#include <Void/Build/Provider/Translator.hpp>
|
||||
#include <Void/Build/Report/Cdash.hpp>
|
||||
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
|
||||
#include <Void/Build/Snapshot/Snapshot.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
@@ -57,6 +58,7 @@
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <functional>
|
||||
@@ -391,6 +393,10 @@ struct BuildCmdOptions {
|
||||
std::optional<std::string> target_os_arg;
|
||||
std::optional<std::string> target_arch_arg;
|
||||
std::optional<std::string> junit_arg;
|
||||
std::optional<std::string> cdash_arg;
|
||||
std::optional<std::string> cdash_project_arg;
|
||||
std::optional<std::string> cdash_build_arg;
|
||||
std::optional<std::string> cdash_output_arg;
|
||||
std::string test_timeout_arg{"300"};
|
||||
bool publish_editor_selection{true};
|
||||
bool no_cache{false};
|
||||
@@ -1161,6 +1167,46 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
}
|
||||
}
|
||||
|
||||
// CDash Test.xml report (and optional submission) for CI dashboards.
|
||||
if (run_tests && !test_records.empty() &&
|
||||
(opts.cdash_arg.has_value() || opts.cdash_output_arg.has_value())) {
|
||||
Report::CdashReportOptions cdash;
|
||||
cdash.build_name = opts.cdash_build_arg.value_or("vbs");
|
||||
cdash.os_name = Toolchain::host_os_name();
|
||||
const std::time_t now =
|
||||
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
std::tm tm{};
|
||||
::gmtime_r(&now, &tm);
|
||||
cdash.build_stamp =
|
||||
std::format("{:04d}{:02d}{:02d}-{:02d}{:02d}-Experimental", tm.tm_year + 1900,
|
||||
tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
||||
for (const auto &record : test_records) {
|
||||
cdash.tests.push_back(Report::CdashTestResult{
|
||||
record.name, record.passed, record.elapsed_ms / 1000.0, record.output});
|
||||
}
|
||||
if (opts.cdash_output_arg) {
|
||||
if (auto written = Platform::atomic_write_file(
|
||||
*opts.cdash_output_arg, Report::render_cdash_test_xml(cdash), false);
|
||||
!written) {
|
||||
std::cerr << "vbs test: cannot write CDash report: " << written.error().message()
|
||||
<< '\n';
|
||||
all_ok = false;
|
||||
}
|
||||
}
|
||||
if (opts.cdash_arg) {
|
||||
const std::string project =
|
||||
opts.cdash_project_arg.value_or(project_root.filename().string());
|
||||
if (auto submitted = Report::submit_cdash_report(*opts.cdash_arg, project, cdash);
|
||||
!submitted) {
|
||||
std::cerr << "vbs test: " << submitted.error().message() << '\n';
|
||||
all_ok = false;
|
||||
} else {
|
||||
Void::Log::info("Test", "Submitted CDash test report to {} (project '{}')",
|
||||
*opts.cdash_arg, project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Void::Log::debug("Build", "Total wall time: {:.2f}s", total_sw.elapsed_ms() / 1000.0);
|
||||
return all_ok ? 0 : 1;
|
||||
}
|
||||
@@ -3364,6 +3410,14 @@ int main(int argc, char **argv) {
|
||||
.option_default("--test-timeout", "", "Per-test timeout in seconds (1..86400)",
|
||||
build_opts.test_timeout_arg, "300")
|
||||
.option("--junit", "", "Write a JUnit XML report of test results", build_opts.junit_arg)
|
||||
.option("--cdash", "", "Upload a CDash test report to this base URL",
|
||||
build_opts.cdash_arg)
|
||||
.option("--cdash-project", "", "CDash project name (default: project directory name)",
|
||||
build_opts.cdash_project_arg)
|
||||
.option("--cdash-build", "", "CDash build name (default: vbs)",
|
||||
build_opts.cdash_build_arg)
|
||||
.option("--cdash-output", "", "Write the CDash Test.xml report to this file",
|
||||
build_opts.cdash_output_arg)
|
||||
.option("--editor-profile", "", "Editor profile for compile_commands.json",
|
||||
build_opts.editor_profile)
|
||||
.option_many("--build-source", "", "Additional build description source",
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
#include <Void/Build/Report/Cdash.hpp>
|
||||
|
||||
#include <Void/Core/Scope.hpp>
|
||||
#include <Void/System/Types.hpp>
|
||||
#include <Void/Text/Str.hpp>
|
||||
#include <Void/Text/Url.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <format>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(VBS_HAS_VOID_NET)
|
||||
#include <Void/Net/Http.hpp>
|
||||
#endif
|
||||
|
||||
namespace Void::Build::Report {
|
||||
namespace {
|
||||
|
||||
Void::Result::Error make_error(std::string msg) {
|
||||
return Void::System::make_system_error(Void::System::SystemErrorCode::invalid_argument,
|
||||
std::move(msg));
|
||||
}
|
||||
|
||||
std::string xml_escape(std::string_view text) {
|
||||
std::string out;
|
||||
out.reserve(text.size());
|
||||
for (const char c : text) {
|
||||
switch (c) {
|
||||
case '&':
|
||||
out += "&";
|
||||
break;
|
||||
case '<':
|
||||
out += "<";
|
||||
break;
|
||||
case '>':
|
||||
out += ">";
|
||||
break;
|
||||
case '"':
|
||||
out += """;
|
||||
break;
|
||||
case '\'':
|
||||
out += "'";
|
||||
break;
|
||||
default:
|
||||
if (static_cast<unsigned char>(c) >= 0x20 || c == '\n' || c == '\t') {
|
||||
out.push_back(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string utc_timestamp() {
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const std::time_t seconds = std::chrono::system_clock::to_time_t(now);
|
||||
std::tm tm{};
|
||||
::gmtime_r(&seconds, &tm);
|
||||
return std::format("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}", tm.tm_year + 1900,
|
||||
tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
}
|
||||
|
||||
std::string host_name() {
|
||||
char buffer[256]{};
|
||||
if (::gethostname(buffer, sizeof(buffer) - 1) == 0) {
|
||||
return buffer;
|
||||
}
|
||||
return "localhost";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string render_cdash_test_xml(const CdashReportOptions &options) {
|
||||
const std::string site = options.site_name.empty() ? host_name() : options.site_name;
|
||||
const std::string timestamp = utc_timestamp();
|
||||
std::string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
xml += std::format("<Site BuildName=\"{}\" BuildStamp=\"{}\" Name=\"{}\" Generator=\"{}\" "
|
||||
"OperatingSystem=\"{}\" Hostname=\"{}\">\n",
|
||||
xml_escape(options.build_name), xml_escape(options.build_stamp),
|
||||
xml_escape(site), xml_escape(options.generator), xml_escape(options.os_name),
|
||||
xml_escape(site));
|
||||
xml += " <Testing>\n";
|
||||
xml += " <StartDateTime>" + timestamp + "</StartDateTime>\n";
|
||||
xml += " <StartTestTime>0</StartTestTime>\n";
|
||||
xml += " <TestList>\n";
|
||||
for (const auto &test : options.tests) {
|
||||
xml += std::format(" <Test Status=\"{}\">\n", test.passed ? "passed" : "failed");
|
||||
xml += " <Name>" + xml_escape(test.name) + "</Name>\n";
|
||||
xml += " <Path>.</Path>\n";
|
||||
xml += " <FullName>" + xml_escape(test.name) + "</FullName>\n";
|
||||
xml += " <Command>vbs-test</Command>\n";
|
||||
xml += " <WorkingDirectory>.</WorkingDirectory>\n";
|
||||
xml += " <Output>" + xml_escape(test.output) + "</Output>\n";
|
||||
xml += " <Result>" + std::string{test.passed ? "passed" : "failed"} + "</Result>\n";
|
||||
xml += std::format(" <ElapsedTime>{:.3f}</ElapsedTime>\n", test.elapsed_seconds);
|
||||
xml += " </Test>\n";
|
||||
}
|
||||
xml += " </TestList>\n";
|
||||
xml += " <EndDateTime>" + timestamp + "</EndDateTime>\n";
|
||||
xml += " <EndTestTime>0</EndTestTime>\n";
|
||||
xml += " <ElapsedMinutes>0</ElapsedMinutes>\n";
|
||||
xml += " </Testing>\n";
|
||||
xml += "</Site>\n";
|
||||
return xml;
|
||||
}
|
||||
|
||||
CdashSubmission build_cdash_submission(const CdashReportOptions &options,
|
||||
std::string_view project) {
|
||||
constexpr std::string_view boundary = "vbs-cdash-boundary";
|
||||
const std::string xml = render_cdash_test_xml(options);
|
||||
CdashSubmission submission;
|
||||
submission.content_type = std::format("multipart/form-data; boundary={}", boundary);
|
||||
const auto add_field = [&](std::string_view name, std::string_view value) {
|
||||
submission.body += "--" + std::string{boundary} + "\r\n";
|
||||
submission.body +=
|
||||
"Content-Disposition: form-data; name=\"" + std::string{name} + "\"\r\n\r\n";
|
||||
submission.body += value;
|
||||
submission.body += "\r\n";
|
||||
};
|
||||
add_field("type", "Test");
|
||||
add_field("project", project);
|
||||
add_field("build", options.build_name);
|
||||
submission.body += "--" + std::string{boundary} + "\r\n";
|
||||
submission.body +=
|
||||
"Content-Disposition: form-data; name=\"content\"; filename=\"Test.xml\"\r\n";
|
||||
submission.body += "Content-Type: text/xml\r\n\r\n";
|
||||
submission.body += xml;
|
||||
submission.body += "\r\n--" + std::string{boundary} + "--\r\n";
|
||||
return submission;
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
submit_cdash_report(std::string_view cdash_url, std::string_view project,
|
||||
const CdashReportOptions &options) {
|
||||
// Parse scheme://host[:port][/base].
|
||||
std::string url{cdash_url};
|
||||
while (!url.empty() && url.back() == '/') {
|
||||
url.pop_back();
|
||||
}
|
||||
std::string scheme = "http";
|
||||
if (const auto scheme_end = url.find("://"); scheme_end != std::string::npos) {
|
||||
scheme = url.substr(0, scheme_end);
|
||||
url.erase(0, scheme_end + 3);
|
||||
}
|
||||
if (scheme != "http" && scheme != "https") {
|
||||
return std::unexpected{make_error("CDash URL must be http:// or https://")};
|
||||
}
|
||||
std::string host_port = url;
|
||||
std::string base_path;
|
||||
if (const auto slash = url.find('/'); slash != std::string::npos) {
|
||||
host_port = url.substr(0, slash);
|
||||
base_path = url.substr(slash);
|
||||
}
|
||||
std::string host = host_port;
|
||||
std::string port = scheme == "https" ? "443" : "80";
|
||||
if (const auto colon = host_port.rfind(':'); colon != std::string::npos) {
|
||||
host = host_port.substr(0, colon);
|
||||
port = host_port.substr(colon + 1);
|
||||
}
|
||||
const auto submission = build_cdash_submission(options, project);
|
||||
const std::string path =
|
||||
base_path + "/submit.php?project=" + Void::Encoding::Url::encode(project);
|
||||
|
||||
#if defined(VBS_HAS_VOID_NET)
|
||||
Void::Net::Request request;
|
||||
request.method = Void::Net::Method::Post;
|
||||
request.url = std::format("{}://{}:{}{}", scheme, host, port, path);
|
||||
request.headers.push_back(Void::Net::Header{"Content-Type", submission.content_type});
|
||||
request.body = submission.body;
|
||||
request.timeout = std::chrono::seconds{30};
|
||||
const Void::Net::HttpClient client = Void::Net::HttpClient::secure();
|
||||
auto response = client.send(request);
|
||||
if (!response) {
|
||||
return std::unexpected{
|
||||
make_error(std::format("CDash submission failed: {}", response.error().message()))};
|
||||
}
|
||||
if (response->status < 200 || response->status >= 300) {
|
||||
return std::unexpected{
|
||||
make_error(std::format("CDash submission rejected with HTTP {}: {}", response->status,
|
||||
response->body.substr(0, 200)))};
|
||||
}
|
||||
return {};
|
||||
#else
|
||||
// Plain TCP HTTP/1.1 POST for http:// (Void::Net server transport not linked).
|
||||
if (scheme != "http") {
|
||||
return std::unexpected{
|
||||
make_error("HTTPS CDash submission requires the Void::Net HTTP client")};
|
||||
}
|
||||
struct addrinfo hints{};
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
struct addrinfo *resolved = nullptr;
|
||||
if (::getaddrinfo(host.c_str(), port.c_str(), &hints, &resolved) != 0 || resolved == nullptr) {
|
||||
return std::unexpected{
|
||||
make_error(std::format("CDash submission: cannot resolve host '{}'", host))};
|
||||
}
|
||||
auto free_ai = Void::Scope::on_exit([&] { ::freeaddrinfo(resolved); });
|
||||
const int fd =
|
||||
::socket(resolved->ai_family, resolved->ai_socktype | SOCK_CLOEXEC, resolved->ai_protocol);
|
||||
if (fd < 0) {
|
||||
return std::unexpected{make_error("CDash submission: socket() failed")};
|
||||
}
|
||||
Void::System::OwnedFd guard{fd};
|
||||
struct timeval tv{30, 0};
|
||||
(void)::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
(void)::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||
if (::connect(fd, resolved->ai_addr, resolved->ai_addrlen) != 0) {
|
||||
return std::unexpected{
|
||||
make_error(std::format("CDash submission: connect to {}:{} failed", host, port))};
|
||||
}
|
||||
std::string request =
|
||||
std::format("POST {} HTTP/1.1\r\nHost: {}:{}\r\nConnection: close\r\n"
|
||||
"Content-Type: {}\r\nContent-Length: {}\r\n\r\n",
|
||||
path, host, port, submission.content_type, submission.body.size());
|
||||
request += submission.body;
|
||||
std::size_t sent = 0;
|
||||
while (sent < request.size()) {
|
||||
const ssize_t n = ::send(fd, request.data() + sent, request.size() - sent, MSG_NOSIGNAL);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return std::unexpected{make_error("CDash submission: send() failed")};
|
||||
}
|
||||
sent += static_cast<std::size_t>(n);
|
||||
}
|
||||
std::string raw;
|
||||
std::array<char, 16384> buffer{};
|
||||
for (;;) {
|
||||
const ssize_t n = ::recv(fd, buffer.data(), buffer.size(), 0);
|
||||
if (n > 0) {
|
||||
raw.append(buffer.data(), static_cast<std::size_t>(n));
|
||||
} else if (n == 0) {
|
||||
break;
|
||||
} else if (errno != EINTR) {
|
||||
return std::unexpected{make_error("CDash submission: recv() failed")};
|
||||
}
|
||||
}
|
||||
int status = 0;
|
||||
if (const auto sp = raw.find(' '); sp != std::string::npos) {
|
||||
(void)Void::Str::to_int(std::string_view{raw}.substr(sp + 1, 3), status);
|
||||
}
|
||||
if (status < 200 || status >= 300) {
|
||||
return std::unexpected{
|
||||
make_error(std::format("CDash submission rejected with HTTP {}", status))};
|
||||
}
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Void::Build::Report
|
||||
Reference in new issue
Block a user