feat(test): labels, exclusive resources and parallel test execution
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
VoidBuildSystem CI / fuzz-clang (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 51s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
VoidBuildSystem CI / fuzz-clang (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 51s
This commit is contained in:
1 parent
e135ae3023
commit
617d783e84
10 files changed
+281
-42
No files matched your search
@@ -331,6 +331,8 @@ ProjectDescription::from_json(std::string_view json_text) {
|
||||
}
|
||||
}
|
||||
t.nondeterministic = get_bool(*to, "nondeterministic", false);
|
||||
t.labels = get_str_array(*to, "labels");
|
||||
t.resources = get_str_array(*to, "resources");
|
||||
t.enabled = get_bool(*to, "enabled", true);
|
||||
t.use_conventional_sources = get_bool(*to, "use_conventional_sources", false);
|
||||
if (const auto *irv = find_key(*to, "install_rule")) {
|
||||
@@ -741,6 +743,8 @@ lower_project_graph(const ProjectDescription &description,
|
||||
summary.name = t.name;
|
||||
summary.kind = t.kind;
|
||||
summary.enabled = t.enabled;
|
||||
summary.labels = t.labels;
|
||||
summary.resources = t.resources;
|
||||
|
||||
// 1. Collect prerequisite action IDs (explicit depends_on + linked target producers).
|
||||
std::vector<std::string> target_prereq_actions;
|
||||
|
||||
+141
-40
@@ -54,6 +54,7 @@
|
||||
#include <cctype>
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
@@ -371,6 +372,7 @@ struct BuildCmdOptions {
|
||||
std::optional<std::string> build_arg;
|
||||
std::vector<std::string> profiles;
|
||||
std::vector<std::string> targets;
|
||||
std::vector<std::string> labels;
|
||||
std::vector<std::string> extra_build_sources;
|
||||
std::optional<std::string> editor_profile;
|
||||
std::optional<std::string> compiler_arg;
|
||||
@@ -830,6 +832,24 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
}
|
||||
|
||||
if (run_tests) {
|
||||
std::optional<std::filesystem::path> wine;
|
||||
if (windows_cross_target) {
|
||||
// Cross-built Windows test binaries execute under Wine (Track C3 Wine-first).
|
||||
auto resolved = Platform::resolve_executable("wine");
|
||||
if (!resolved) {
|
||||
std::cerr << "vbs test: Windows target tests require 'wine' in PATH\n";
|
||||
all_ok = false;
|
||||
} else {
|
||||
wine = *resolved;
|
||||
}
|
||||
}
|
||||
|
||||
struct TestJob {
|
||||
std::string name;
|
||||
std::filesystem::path executable;
|
||||
std::vector<std::string> resources;
|
||||
};
|
||||
std::vector<TestJob> test_jobs;
|
||||
for (const auto &t : graph->targets) {
|
||||
if (t.kind != TargetKind::Test || t.primary_outputs.empty()) {
|
||||
continue;
|
||||
@@ -837,53 +857,133 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
if (!opts.targets.empty() && !std::ranges::contains(opts.targets, t.name)) {
|
||||
continue;
|
||||
}
|
||||
Void::Log::info("Test", "[{}] Running test target '{}'...", prof_name, t.name);
|
||||
const auto tsw = Void::Time::Stopwatch::started();
|
||||
Platform::ProcessRequest treq;
|
||||
if (windows_cross_target) {
|
||||
// Cross-built Windows test binaries execute under Wine (Track C3 Wine-first).
|
||||
auto wine = Platform::resolve_executable("wine");
|
||||
if (!wine) {
|
||||
std::cerr << "vbs test: Windows target tests require 'wine' in PATH\n";
|
||||
all_ok = false;
|
||||
if (!opts.labels.empty() &&
|
||||
!std::ranges::any_of(opts.labels, [&](const std::string &label) {
|
||||
return std::ranges::contains(t.labels, label);
|
||||
})) {
|
||||
continue;
|
||||
}
|
||||
test_jobs.push_back(TestJob{t.name, t.primary_outputs.front(), t.resources});
|
||||
}
|
||||
|
||||
// Tests run in parallel up to --jobs, except that tests sharing a resource are
|
||||
// serialized (a resource is held exclusively while its test runs).
|
||||
std::vector<std::optional<TestRunRecord>> records(test_jobs.size());
|
||||
std::mutex test_mutex;
|
||||
std::condition_variable test_cv;
|
||||
std::set<std::string> held_resources;
|
||||
std::vector<bool> claimed(test_jobs.size(), false);
|
||||
std::size_t remaining = test_jobs.size();
|
||||
const std::size_t worker_count = std::max<std::size_t>(
|
||||
1, std::min<std::size_t>(
|
||||
jobs == 0 ? std::max(1u, std::thread::hardware_concurrency()) : jobs,
|
||||
std::max<std::size_t>(1, test_jobs.size())));
|
||||
const auto any_runnable = [&] {
|
||||
for (std::size_t i = 0; i < test_jobs.size(); ++i) {
|
||||
if (claimed[i]) {
|
||||
continue;
|
||||
}
|
||||
treq.executable = *wine;
|
||||
treq.arguments = {t.primary_outputs.front().string()};
|
||||
} else {
|
||||
treq.executable = t.primary_outputs.front();
|
||||
}
|
||||
treq.working_directory = project_root;
|
||||
treq.timeout = std::chrono::seconds{test_timeout_seconds};
|
||||
auto tres = Platform::run_supervised(treq);
|
||||
TestRunRecord record;
|
||||
record.profile = prof_name;
|
||||
record.name = t.name;
|
||||
record.passed = tres.has_value() && tres->succeeded();
|
||||
record.elapsed_ms = tsw.elapsed_ms();
|
||||
if (tres) {
|
||||
record.output = tres->stdout_data + tres->stderr_data;
|
||||
record.exit_code = tres->exit_code;
|
||||
} else {
|
||||
record.output = tres.error().message();
|
||||
}
|
||||
test_records.push_back(std::move(record));
|
||||
if (!tres || !tres->succeeded()) {
|
||||
Void::Log::error("Test", "[{}] FAILED '{}' ({:.0f} ms)", prof_name, t.name,
|
||||
tsw.elapsed_ms());
|
||||
std::cerr << "vbs test: FAILED '" << t.name << "'\n";
|
||||
if (tres && !tres->stdout_data.empty()) {
|
||||
std::cerr << tres->stdout_data << '\n';
|
||||
if (std::ranges::none_of(test_jobs[i].resources, [&](const std::string &r) {
|
||||
return held_resources.contains(r);
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
if (tres && !tres->stderr_data.empty()) {
|
||||
std::cerr << tres->stderr_data << '\n';
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const auto worker = [&] {
|
||||
for (;;) {
|
||||
std::size_t index = 0;
|
||||
{
|
||||
std::unique_lock lock{test_mutex};
|
||||
test_cv.wait(lock, [&] { return remaining == 0 || any_runnable(); });
|
||||
if (remaining == 0) {
|
||||
return;
|
||||
}
|
||||
for (; index < test_jobs.size(); ++index) {
|
||||
if (claimed[index]) {
|
||||
continue;
|
||||
}
|
||||
if (std::ranges::none_of(test_jobs[index].resources,
|
||||
[&](const std::string &r) {
|
||||
return held_resources.contains(r);
|
||||
})) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
claimed[index] = true;
|
||||
for (const auto &r : test_jobs[index].resources) {
|
||||
held_resources.insert(r);
|
||||
}
|
||||
}
|
||||
const auto &job = test_jobs[index];
|
||||
Void::Log::info("Test", "[{}] Running test target '{}'...", prof_name,
|
||||
job.name);
|
||||
const auto tsw = Void::Time::Stopwatch::started();
|
||||
Platform::ProcessRequest treq;
|
||||
if (wine) {
|
||||
treq.executable = *wine;
|
||||
treq.arguments = {job.executable.string()};
|
||||
} else {
|
||||
treq.executable = job.executable;
|
||||
}
|
||||
treq.working_directory = project_root;
|
||||
treq.timeout = std::chrono::seconds{test_timeout_seconds};
|
||||
auto tres = Platform::run_supervised(treq);
|
||||
TestRunRecord record;
|
||||
record.profile = prof_name;
|
||||
record.name = job.name;
|
||||
record.passed = tres.has_value() && tres->succeeded();
|
||||
record.elapsed_ms = tsw.elapsed_ms();
|
||||
if (tres) {
|
||||
record.output = tres->stdout_data + tres->stderr_data;
|
||||
record.exit_code = tres->exit_code;
|
||||
} else {
|
||||
record.output = tres.error().message();
|
||||
}
|
||||
const bool passed = record.passed;
|
||||
if (!passed) {
|
||||
Void::Log::error("Test", "[{}] FAILED '{}' ({:.0f} ms)", prof_name,
|
||||
job.name, tsw.elapsed_ms());
|
||||
} else {
|
||||
Void::Log::info("Test", "[{}] PASSED '{}' ({:.0f} ms)", prof_name, job.name,
|
||||
tsw.elapsed_ms());
|
||||
}
|
||||
{
|
||||
std::lock_guard lock{test_mutex};
|
||||
for (const auto &r : job.resources) {
|
||||
held_resources.erase(r);
|
||||
}
|
||||
records[index] = std::move(record);
|
||||
--remaining;
|
||||
}
|
||||
test_cv.notify_all();
|
||||
}
|
||||
};
|
||||
std::vector<std::thread> pool;
|
||||
pool.reserve(worker_count);
|
||||
if (!windows_cross_target || wine.has_value()) {
|
||||
for (std::size_t i = 0; i < worker_count; ++i) {
|
||||
pool.emplace_back(worker);
|
||||
}
|
||||
for (auto &thread : pool) {
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
for (auto &record : records) {
|
||||
if (!record) {
|
||||
continue;
|
||||
}
|
||||
if (!record->passed) {
|
||||
std::cerr << "vbs test: FAILED '" << record->name << "'\n";
|
||||
if (!record->output.empty()) {
|
||||
std::cerr << record->output << '\n';
|
||||
}
|
||||
all_ok = false;
|
||||
} else {
|
||||
Void::Log::info("Test", "[{}] PASSED '{}' ({:.0f} ms)", prof_name, t.name,
|
||||
tsw.elapsed_ms());
|
||||
std::cout << "vbs test: PASSED '" << t.name << "'\n";
|
||||
std::cout << "vbs test: PASSED '" << record->name << "'\n";
|
||||
}
|
||||
test_records.push_back(std::move(*record));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3166,6 +3266,7 @@ int main(int argc, char **argv) {
|
||||
.option("--build-dir", "-B", "Build output directory", build_opts.build_arg)
|
||||
.option_many("--profile", "-p", "Profile to build", build_opts.profiles)
|
||||
.option_many("--target", "-t", "Target to build/test", build_opts.targets)
|
||||
.option_many("--label", "", "Only run tests carrying this label", build_opts.labels)
|
||||
.option("--compiler", "", "Override compiler family (gcc|clang)",
|
||||
build_opts.compiler_arg)
|
||||
.option("--target-os", "", "Target operating system (default: host, e.g. windows)",
|
||||
|
||||
Reference in new issue
Block a user