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

This commit is contained in:
faumaray committed 2026-12-05 13:02:45 +03:00
1 parent 6befa6b5e2
commit 9d7c801e2d
9 files changed
+458 -2

No files matched your search

+1
View File
@@ -50,6 +50,7 @@ add_library(VoidBuild_Core STATIC
src/Config/Presets.cpp src/Config/Presets.cpp
src/Config/Scaffold.cpp src/Config/Scaffold.cpp
src/Daemon/Daemon.cpp src/Daemon/Daemon.cpp
src/Report/Cdash.cpp
src/Editor/CompDb.cpp src/Editor/CompDb.cpp
src/Watch/Linux/Watcher.cpp src/Watch/Linux/Watcher.cpp
src/Package/Toml.cpp src/Package/Toml.cpp
+2
View File
@@ -360,6 +360,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
- **Wave 133 (CTest-Style Fixtures)**: added `.fixture_setup()`, `.fixture_required()` and `.fixture_cleanup()` on targets (round-tripped through the descriptor JSON). The parallel test runner now pulls fixture setup/cleanup tests in automatically, orders them with prerequisites (setup before users, cleanup after every user), and skips dependents when a setup fails. `FullV1Tests.test_fixtures_setup_required_cleanup_ordering` verifies the order (setup first, cleanup last) and the skip-on-failed-setup path. - **Wave 133 (CTest-Style Fixtures)**: added `.fixture_setup()`, `.fixture_required()` and `.fixture_cleanup()` on targets (round-tripped through the descriptor JSON). The parallel test runner now pulls fixture setup/cleanup tests in automatically, orders them with prerequisites (setup before users, cleanup after every user), and skips dependents when a setup fails. `FullV1Tests.test_fixtures_setup_required_cleanup_ordering` verifies the order (setup first, cleanup last) and the skip-on-failed-setup path.
- **Wave 134 (CDash Reporting)**: added `Void::Build::Report` (`src/Report/Cdash.cpp`) with CTest-compatible `Test.xml` rendering and multipart submission to `<cdash>/submit.php?project=...`; `vbs test` gained `--cdash URL`, `--cdash-project`, `--cdash-build` and `--cdash-output FILE`. The upload uses Void::Net when linked and a POSIX HTTP/1.1 fallback otherwise. `RegistryTests.cdash_test_report_output_and_submission` captures the submission with a loopback server and checks the XML and multipart fields.
## Remaining future scope ## Remaining future scope
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order. - **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
+1
View File
@@ -134,4 +134,5 @@ Base HEAD: `fe0d1a6`
| Wave 131 (warm-build latency + plugin tests) | Stat-fingerprint memo for descriptor identity/header hashes; generated VS Code test harness | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; vbs warm 92 ms vs 209 ms baseline, generated harness passes under Node, full CTest 8/8) | `src/Config/Frontend.cpp`, `src/Editor/CompDb.cpp`, `tests/FullV1Tests.cpp`, `benchmarks/compare.sh`, docs | | Wave 131 (warm-build latency + plugin tests) | Stat-fingerprint memo for descriptor identity/header hashes; generated VS Code test harness | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; vbs warm 92 ms vs 209 ms baseline, generated harness passes under Node, full CTest 8/8) | `src/Config/Frontend.cpp`, `src/Editor/CompDb.cpp`, `tests/FullV1Tests.cpp`, `benchmarks/compare.sh`, docs |
| Wave 132 (Test labels, resource locks, parallel tests) | `.label()`/`.resource()` SDK, `--label` filter, parallel test runner with exclusive resources | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `include/Void/Build.hpp`, `sdk/Build.cpp`, `src/Main.cpp`, `src/Graph/Graph.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 132 (Test labels, resource locks, parallel tests) | `.label()`/`.resource()` SDK, `--label` filter, parallel test runner with exclusive resources | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `include/Void/Build.hpp`, `sdk/Build.cpp`, `src/Main.cpp`, `src/Graph/Graph.cpp`, `tests/FullV1Tests.cpp`, docs |
| Wave 133 (CTest-style fixtures) | `.fixture_setup/required/cleanup` SDK; runner pulls in helpers, orders setup->users->cleanup, skips dependents on failed setup | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `include/Void/Build.hpp`, `sdk/Build.cpp`, `src/Main.cpp`, `src/Graph/Graph.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 133 (CTest-style fixtures) | `.fixture_setup/required/cleanup` SDK; runner pulls in helpers, orders setup->users->cleanup, skips dependents on failed setup | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `include/Void/Build.hpp`, `sdk/Build.cpp`, `src/Main.cpp`, `src/Graph/Graph.cpp`, `tests/FullV1Tests.cpp`, docs |
| Wave 134 (CDash reporting) | `Report::Cdash` Test.xml + multipart submission; `vbs test --cdash/--cdash-project/--cdash-build/--cdash-output` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E captures the submission, full CTest 8/8) | `src/Report/Cdash.cpp`, `include/Void/Build/Report/Cdash.hpp`, `src/Main.cpp`, `tests/RegistryTests.cpp`, docs |
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
+12
View File
@@ -1764,6 +1764,18 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30
the run fails and `bad_use` never passes. the run fails and `bad_use` never passes.
- Full CTest: **8 / 8 passed** in 302.00 s. - Full CTest: **8 / 8 passed** in 302.00 s.
## CDash Reporting (GCC 16.2, pin `0002e74`)
- `vbs test --cdash-output FILE` writes a CTest-compatible `Test.xml` (`Site`/`Testing`/
`TestList` with `Status`, `Name`, `Output`, `ElapsedTime`).
- `vbs test --cdash URL --cdash-project NAME [--cdash-build NAME]` POSTs a
`multipart/form-data` submission (`type=Test`, `project`, `build`, `content=Test.xml`) to
`<URL>/submit.php?project=NAME`.
- `RegistryTests.cdash_test_report_output_and_submission` **passed** (2.50 s): a loopback HTTP
server captured the POST (query `project=Demo`, multipart content type, `Test` field and the
embedded XML), and the written report contains both a passed and a failed test.
- Full CTest: **8 / 8 passed** in 305.48 s.
## Limits and Unrun Checks ## Limits and Unrun Checks
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
+2 -2
View File
@@ -15,7 +15,7 @@ build2 documentation was **not** available through Context7; build2 statements b
| Remote / distributed execution workers | Deferred | `20`, R-015 | | Remote / distributed execution workers | Deferred | `20`, R-015 |
| VoidLibrary's own `build.cpp` | Open | `recipes/VoidLibrary/` builds it inside VBS, but VoidLibrary is not yet migrated | | VoidLibrary's own `build.cpp` | Open | `recipes/VoidLibrary/` builds it inside VBS, but VoidLibrary is not yet migrated |
| Installer generators | Partial | deterministic tar + self-extracting `sh` + SBOM + Ed25519; DEB/RPM/MSI/DMG-style generators missing | | Installer generators | Partial | deterministic tar + self-extracting `sh` + SBOM + Ed25519; DEB/RPM/MSI/DMG-style generators missing |
| Test-runner parity | Partial | `VOID_TEST` runner; fixtures/labels/resource locks/timeouts/JUnit done; CDash missing | | Test-runner parity | Done | `VOID_TEST` runner; fixtures/labels/resource locks/timeouts/JUnit/CDash |
| IDE ecosystem | Partial | `vbs ide` + CompDB + daemon protocol; no File API shim, presets import, or plugins | | IDE ecosystem | Partial | `vbs ide` + CompDB + daemon protocol; no File API shim, presets import, or plugins |
| CI on real runners, sanitizers, fuzzing | Unverified | the GitHub Actions workflow is a template that has never run | | CI on real runners, sanitizers, fuzzing | Unverified | the GitHub Actions workflow is a template that has never run |
@@ -54,7 +54,7 @@ Concrete work this implies:
| Package/registry | External (vcpkg, Conan, FetchContent) | wrapdb, subprojects | cppget.org / brep | **Built-in registry + solver + lock + binary variants + signatures + SBOM** | federation, mirrors, key distribution | | Package/registry | External (vcpkg, Conan, FetchContent) | wrapdb, subprojects | cppget.org / brep | **Built-in registry + solver + lock + binary variants + signatures + SBOM** | federation, mirrors, key distribution |
| Install/package | `install()`, `install(EXPORT)`, CPack (TGZ/ZIP/DEB/RPM/WIX/DMG/NuGet/APK…) | `install_data`, `install_headers`, dist scripts | install module | prefix staging, components, relocatable CMake + native exports, tar, self-extracting `sh`, **stored ZIP**, **DEB (dpkg-validated)**, SBOM, **Ed25519-signed archives with checksums** | **RPM (rpm 6.1-validated)**, **WiX source for MSI** (candle/light on Windows), DMG-style | | Install/package | `install()`, `install(EXPORT)`, CPack (TGZ/ZIP/DEB/RPM/WIX/DMG/NuGet/APK…) | `install_data`, `install_headers`, dist scripts | install module | prefix staging, components, relocatable CMake + native exports, tar, self-extracting `sh`, **stored ZIP**, **DEB (dpkg-validated)**, SBOM, **Ed25519-signed archives with checksums** | **RPM (rpm 6.1-validated)**, **WiX source for MSI** (candle/light on Windows), DMG-style |
| IDE integration | File API, presets, every IDE | `meson-info` introspection | limited | `vbs ide generate/query`, CompDB, daemon protocol | File API shim, `CMakePresets.json` import, plugins | | IDE integration | File API, presets, every IDE | `meson-info` introspection | limited | `vbs ide generate/query`, CompDB, daemon protocol | File API shim, `CMakePresets.json` import, plugins |
| Test runner | CTest: fixtures, labels, resource locks, timeouts, JUnit/CDash | `meson test`: suites, timeouts, JUnit | test module | `VOID_TEST` runner; `vbs test --junit --test-timeout --label`; parallel tests with resource locks and fixtures | CDash | | Test runner | CTest: fixtures, labels, resource locks, timeouts, JUnit/CDash | `meson test`: suites, timeouts, JUnit | test module | `VOID_TEST` runner; `vbs test --junit --test-timeout --label`; parallel tests with resource locks and fixtures; CDash submission | - |
| Incremental / cache | compiler depfiles, ccache external | depfiles, ccache | internal caching model | **content-addressed state, immutable snapshots, remote action cache** | scale benchmarks | | Incremental / cache | compiler depfiles, ccache external | depfiles, ccache | internal caching model | **content-addressed state, immutable snapshots, remote action cache** | scale benchmarks |
| Modules / PCH / unity / LTO / sanitizers | yes (with generator quirks) | yes | yes | **native with capability probing** | more compilers | | Modules / PCH / unity / LTO / sanitizers | yes (with generator quirks) | yes | yes | **native with capability probing** | more compilers |
| Reproducibility | opt-in | opt-in | partial | **default deterministic** (epoch, prefix maps, canonical mtimes) | cross-platform determinism | | Reproducibility | opt-in | opt-in | partial | **default deterministic** (epoch, prefix maps, canonical mtimes) | cross-platform determinism |
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Report {
// One test result as reported to CDash.
struct CdashTestResult {
std::string name;
bool passed{true};
double elapsed_seconds{0.0};
std::string output;
};
struct CdashReportOptions {
std::string site_name; // <Site Name="...">, usually the machine host name.
std::string build_name; // CDash build name, e.g. "vbs-debug".
std::string build_stamp; // CDash build stamp, e.g. "20261205-1015-Experimental".
std::string os_name;
std::string generator{"vbs"};
std::vector<CdashTestResult> tests;
};
// CTest-compatible Test.xml consumed by CDash's submit.php.
[[nodiscard]] std::string render_cdash_test_xml(const CdashReportOptions &options);
struct CdashSubmission {
std::string content_type;
std::string body;
};
// multipart/form-data payload for `<cdash>/submit.php?project=<project>`.
[[nodiscard]] CdashSubmission build_cdash_submission(const CdashReportOptions &options,
std::string_view project);
// Uploads a Test.xml report. `cdash_url` is the CDash base URL (e.g. http://host/cdash).
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
submit_cdash_report(std::string_view cdash_url, std::string_view project,
const CdashReportOptions &options);
} // namespace Void::Build::Report
+54
View File
@@ -27,6 +27,7 @@
#include <Void/Build/Provenance/Verification.hpp> #include <Void/Build/Provenance/Verification.hpp>
#include <Void/Build/Provider/Provider.hpp> #include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/Provider/Translator.hpp> #include <Void/Build/Provider/Translator.hpp>
#include <Void/Build/Report/Cdash.hpp>
#include <Void/Build/SelfHost/TestRegistryGen.hpp> #include <Void/Build/SelfHost/TestRegistryGen.hpp>
#include <Void/Build/Snapshot/Snapshot.hpp> #include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Build/State/StateStore.hpp> #include <Void/Build/State/StateStore.hpp>
@@ -57,6 +58,7 @@
#include <condition_variable> #include <condition_variable>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <ctime>
#include <filesystem> #include <filesystem>
#include <format> #include <format>
#include <functional> #include <functional>
@@ -391,6 +393,10 @@ struct BuildCmdOptions {
std::optional<std::string> target_os_arg; std::optional<std::string> target_os_arg;
std::optional<std::string> target_arch_arg; std::optional<std::string> target_arch_arg;
std::optional<std::string> junit_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"}; std::string test_timeout_arg{"300"};
bool publish_editor_selection{true}; bool publish_editor_selection{true};
bool no_cache{false}; 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); Void::Log::debug("Build", "Total wall time: {:.2f}s", total_sw.elapsed_ms() / 1000.0);
return all_ok ? 0 : 1; 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)", .option_default("--test-timeout", "", "Per-test timeout in seconds (1..86400)",
build_opts.test_timeout_arg, "300") build_opts.test_timeout_arg, "300")
.option("--junit", "", "Write a JUnit XML report of test results", build_opts.junit_arg) .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", .option("--editor-profile", "", "Editor profile for compile_commands.json",
build_opts.editor_profile) build_opts.editor_profile)
.option_many("--build-source", "", "Additional build description source", .option_many("--build-source", "", "Additional build description source",
+257
View File
@@ -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 += "&amp;";
break;
case '<':
out += "&lt;";
break;
case '>':
out += "&gt;";
break;
case '"':
out += "&quot;";
break;
case '\'':
out += "&apos;";
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
+83
View File
@@ -2267,3 +2267,86 @@ VOID_TEST(RegistryTests, worker_action_queue_enqueue_lease_and_complete) {
} }
(*svc)->stop_http(); (*svc)->stop_http();
} }
// `vbs test --cdash-output FILE --cdash URL`: writes a CDash Test.xml report and submits it as
// multipart/form-data to submit.php (captured by a loopback HTTP server).
VOID_TEST(RegistryTests, cdash_test_report_output_and_submission) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_cdash_"};
const auto proj = tmp / "proj";
const auto bdir = tmp / "build";
std::filesystem::create_directories(proj / "tests");
(void)Platform::atomic_write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.test("cdn_pass")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"tests/pass.cpp"})
.label("cdash");
p.test("cdn_fail")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"tests/fail.cpp"})
.label("cdash");
}
)cpp",
false);
(void)Platform::atomic_write_file(proj / "tests" / "pass.cpp", "int main() { return 0; }\n",
false);
(void)Platform::atomic_write_file(proj / "tests" / "fail.cpp", "int main() { return 1; }\n",
false);
std::mutex capture_mutex;
std::string captured_body;
std::string captured_type;
std::string captured_target;
HttpServer server;
auto started = server.start({}, [&](const HttpRequest &req) {
std::lock_guard lock{capture_mutex};
captured_body = req.body;
captured_target = req.raw_target;
if (const auto it = req.headers.find("content-type"); it != req.headers.end()) {
captured_type = it->second;
}
return HttpResponse::json(200, "{}");
});
Void::Testing::require(started.has_value());
const std::string cdash_url = "http://127.0.0.1:" + std::to_string(server.bound_port());
const auto report_path = tmp / "Test.xml";
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = {"test", "--project", proj.string(),
"--build-dir", bdir.string(), "--label",
"cdash", "--cdash-output", report_path.string(),
"--cdash", cdash_url, "--cdash-project",
"Demo"};
req.timeout = std::chrono::seconds{300};
auto res = Platform::run_supervised(req);
// The intentionally failing test fails the run, but the report is still produced.
Void::Testing::expect(res.has_value() && !res->succeeded());
auto xml = Void::FileSystem::read_file(report_path);
Void::Testing::require(xml.has_value());
Void::Testing::expect(xml->find("<Site BuildName=\"vbs\"") != std::string::npos);
Void::Testing::expect(xml->find("<Test Status=\"passed\">") != std::string::npos);
Void::Testing::expect(xml->find("<Test Status=\"failed\">") != std::string::npos);
Void::Testing::expect(xml->find("<Name>cdn_pass</Name>") != std::string::npos);
Void::Testing::expect(xml->find("<Name>cdn_fail</Name>") != std::string::npos);
{
std::lock_guard lock{capture_mutex};
Void::Testing::expect(!captured_body.empty());
Void::Testing::expect(captured_target.find("submit.php") != std::string::npos);
Void::Testing::expect(captured_target.find("project=Demo") != std::string::npos);
Void::Testing::expect(captured_type.find("multipart/form-data") != std::string::npos);
Void::Testing::expect(captured_body.find("name=\"type\"") != std::string::npos);
Void::Testing::expect(captured_body.find("\r\nTest\r\n") != std::string::npos);
Void::Testing::expect(captured_body.find("name=\"content\"; filename=\"Test.xml\"") !=
std::string::npos);
Void::Testing::expect(captured_body.find("<Site BuildName=\"vbs\"") != std::string::npos);
}
server.stop();
}