From 9d7c801e2d40a5fdf40eb6aeb6224acc218301c3 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 13:02:45 +0300 Subject: [PATCH] feat(test): report results to CDash --- CMakeLists.txt | 1 + docs/agent-workflow/STATE.md | 2 + docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 12 ++ docs/roadmap/22-superiority-and-gaps.md | 4 +- include/Void/Build/Report/Cdash.hpp | 46 +++++ src/Main.cpp | 54 +++++ src/Report/Cdash.cpp | 257 ++++++++++++++++++++++++ tests/RegistryTests.cpp | 83 ++++++++ 9 files changed, 458 insertions(+), 2 deletions(-) create mode 100644 include/Void/Build/Report/Cdash.hpp create mode 100644 src/Report/Cdash.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a65742..6dd8585 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ add_library(VoidBuild_Core STATIC src/Config/Presets.cpp src/Config/Scaffold.cpp src/Daemon/Daemon.cpp + src/Report/Cdash.cpp src/Editor/CompDb.cpp src/Watch/Linux/Watcher.cpp src/Package/Toml.cpp diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index f335d1a..30e9476 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -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 134 (CDash Reporting)**: added `Void::Build::Report` (`src/Report/Cdash.cpp`) with CTest-compatible `Test.xml` rendering and multipart submission to `/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 - **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. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index 8762376..f3622b1 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -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 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 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) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index fd8c3f3..fc86d6a 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -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. - 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 + `/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 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). diff --git a/docs/roadmap/22-superiority-and-gaps.md b/docs/roadmap/22-superiority-and-gaps.md index 45b4c5a..a7ef8c6 100644 --- a/docs/roadmap/22-superiority-and-gaps.md +++ b/docs/roadmap/22-superiority-and-gaps.md @@ -15,7 +15,7 @@ build2 documentation was **not** available through Context7; build2 statements b | 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 | | 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 | | 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 | | 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 | -| 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 | | 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 | diff --git a/include/Void/Build/Report/Cdash.hpp b/include/Void/Build/Report/Cdash.hpp new file mode 100644 index 0000000..d0fd4c1 --- /dev/null +++ b/include/Void/Build/Report/Cdash.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include +#include + +#include +#include +#include + +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; // , 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 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 `/submit.php?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 +submit_cdash_report(std::string_view cdash_url, std::string_view project, + const CdashReportOptions &options); + +} // namespace Void::Build::Report diff --git a/src/Main.cpp b/src/Main.cpp index c57b80a..759ac09 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -391,6 +393,10 @@ struct BuildCmdOptions { std::optional target_os_arg; std::optional target_arch_arg; std::optional junit_arg; + std::optional cdash_arg; + std::optional cdash_project_arg; + std::optional cdash_build_arg; + std::optional 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", diff --git a/src/Report/Cdash.cpp b/src/Report/Cdash.cpp new file mode 100644 index 0000000..5938f3d --- /dev/null +++ b/src/Report/Cdash.cpp @@ -0,0 +1,257 @@ +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(VBS_HAS_VOID_NET) +#include +#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(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 = "\n"; + xml += std::format("\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 += " \n"; + xml += " " + timestamp + "\n"; + xml += " 0\n"; + xml += " \n"; + for (const auto &test : options.tests) { + xml += std::format(" \n", test.passed ? "passed" : "failed"); + xml += " " + xml_escape(test.name) + "\n"; + xml += " .\n"; + xml += " " + xml_escape(test.name) + "\n"; + xml += " vbs-test\n"; + xml += " .\n"; + xml += " " + xml_escape(test.output) + "\n"; + xml += " " + std::string{test.passed ? "passed" : "failed"} + "\n"; + xml += std::format(" {:.3f}\n", test.elapsed_seconds); + xml += " \n"; + } + xml += " \n"; + xml += " " + timestamp + "\n"; + xml += " 0\n"; + xml += " 0\n"; + xml += " \n"; + xml += "\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 +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(n); + } + std::string raw; + std::array buffer{}; + for (;;) { + const ssize_t n = ::recv(fd, buffer.data(), buffer.size(), 0); + if (n > 0) { + raw.append(buffer.data(), static_cast(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 diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index f690281..fb452c4 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -2267,3 +2267,86 @@ VOID_TEST(RegistryTests, worker_action_queue_enqueue_lease_and_complete) { } (*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(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("find("") != std::string::npos); + Void::Testing::expect(xml->find("") != std::string::npos); + Void::Testing::expect(xml->find("cdn_pass") != std::string::npos); + Void::Testing::expect(xml->find("cdn_fail") != 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("