feat(test,explain,trace): repetition controls, action explanations, Chrome traces
VoidBuildSystem CI / 1 · Requirements (push) Successful in 5s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 1m54s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m50s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m48s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m8s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m1s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 40s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 16s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 19s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Successful in 6m56s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Successful in 7m3s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Successful in 4m31s
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Successful in 3m51s
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 1 · Requirements (push) Successful in 5s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 1m54s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m50s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m48s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m8s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m1s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 40s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 16s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 19s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Successful in 6m56s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Successful in 7m3s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Successful in 4m31s
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Successful in 3m51s
VoidBuildSystem CI / 5 · Release (push) Skipped
Test runner gains CTest/Meson parity controls: --repeat until-fail|until-pass|after-timeout[:N], --retry N, --shuffle [--shuffle-seed N] and --stop-on-failure (which also skips the remaining profiles). `vbs explain` answers "why would this action run?" without executing anything: Execution::explain_graph compares each selected action against the CAS record (missing record, changed discovered inputs, changed or missing outputs, restorable outputs, shared-remote-cache hits) and reports text or JSON. `vbs build|test --trace FILE` writes a Chrome trace (JSON) with build phase spans (config, toolchain, eval, snapshot, graph, total) and per-action spans from the scheduler events. Verified: new FullV1Tests cases (repetition/shuffle/stop-on-failure and explain/trace) pass, and the CLI contract suite passes.
This commit is contained in:
1 parent
a3afca0e5f
commit
2dec3e9259
5 files changed
+818
-33
No files matched your search
+127
-2
@@ -130,8 +130,7 @@ bool restore_outputs_from_cache(const Graph::ActionNode &action,
|
||||
|
||||
// Build-path-independent path mapping used for shared remote cache keys and records.
|
||||
// Longest prefix wins so nested build/root prefixes are replaced before their parents.
|
||||
struct PathMapper {
|
||||
std::vector<std::pair<std::string, std::string>> pairs;
|
||||
struct PathMapper { std::vector<std::pair<std::string, std::string>> pairs;
|
||||
|
||||
[[nodiscard]] std::string normalize(std::string_view input) const {
|
||||
std::string out{input};
|
||||
@@ -954,4 +953,130 @@ execute_graph(const Graph::BuildGraph &graph, State::StateStore &state,
|
||||
return report;
|
||||
}
|
||||
|
||||
Void::Result::Result<ExplainReport, Void::Result::Error>
|
||||
explain_graph(const Graph::BuildGraph &graph, State::StateStore &state,
|
||||
const ExecutionOptions &options) {
|
||||
auto selected_indices_res = graph.select_action_closure(options.selected_targets);
|
||||
if (!selected_indices_res) {
|
||||
return std::unexpected{selected_indices_res.error()};
|
||||
}
|
||||
|
||||
const auto label_for = [&](const Graph::ActionNode &act) -> std::string {
|
||||
const auto rel_name = [&](const std::filesystem::path &p) -> std::string {
|
||||
if (p.empty()) {
|
||||
return act.target_name;
|
||||
}
|
||||
if (!graph.project_root.empty() && Platform::path_is_within(graph.project_root, p)) {
|
||||
return p.lexically_relative(graph.project_root).generic_string();
|
||||
}
|
||||
return p.filename().string();
|
||||
};
|
||||
switch (act.kind) {
|
||||
case Graph::ActionKind::Compile:
|
||||
return std::format("Compile {}", rel_name(!act.logical_source_file.empty()
|
||||
? act.logical_source_file
|
||||
: act.logical_output_file));
|
||||
case Graph::ActionKind::PrecompiledHeader:
|
||||
return std::format("PCH {}", rel_name(act.logical_source_file));
|
||||
case Graph::ActionKind::HeaderUnit:
|
||||
return std::format("HdrUnit {}", rel_name(act.logical_source_file));
|
||||
case Graph::ActionKind::ModuleScan:
|
||||
return std::format("ModScan {}", rel_name(act.logical_source_file));
|
||||
case Graph::ActionKind::ModuleBmi:
|
||||
return std::format("BMI {}", rel_name(act.logical_source_file));
|
||||
case Graph::ActionKind::Archive:
|
||||
return std::format("Archive {}", rel_name(act.logical_output_file));
|
||||
case Graph::ActionKind::Link:
|
||||
return std::format("Link {}", rel_name(act.logical_output_file));
|
||||
case Graph::ActionKind::Custom:
|
||||
return std::format("Action {}", act.target_name);
|
||||
}
|
||||
return act.id;
|
||||
};
|
||||
|
||||
ExplainReport report;
|
||||
RunDigestCache digest_cache;
|
||||
const PathMapper path_mapper = make_path_mapper(graph);
|
||||
|
||||
for (const std::size_t idx : *selected_indices_res) {
|
||||
const auto &act = graph.actions[idx];
|
||||
ActionExplanation ex;
|
||||
ex.action_id = act.id;
|
||||
ex.target_name = act.target_name;
|
||||
ex.label = label_for(act);
|
||||
ex.cacheable = act.cacheable && !act.nondeterministic;
|
||||
ex.action_key = compute_effective_action_key(act, digest_cache);
|
||||
ex.command = act.executable.string();
|
||||
for (const auto &arg : act.arguments) {
|
||||
ex.command += ' ';
|
||||
ex.command += arg;
|
||||
}
|
||||
|
||||
if (!ex.cacheable) {
|
||||
ex.would_run = true;
|
||||
ex.reason = act.nondeterministic ? "nondeterministic action (never cached)"
|
||||
: "action is not cacheable";
|
||||
} else {
|
||||
auto cached = state.lookup_action(ex.action_key);
|
||||
if (!cached) {
|
||||
return std::unexpected{cached.error()};
|
||||
}
|
||||
if (!cached->has_value()) {
|
||||
ex.would_run = true;
|
||||
ex.reason = "no cached result for this action key";
|
||||
if (state.has_remote_cache()) {
|
||||
const std::string remote_key =
|
||||
compute_remote_action_key(act, graph, digest_cache, path_mapper);
|
||||
auto remote = state.fetch_remote_action(remote_key);
|
||||
if (remote && remote->has_value()) {
|
||||
ex.remote_hit = true;
|
||||
ex.reason += " (available in the shared remote cache)";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const auto &rec = **cached;
|
||||
for (const auto &[path_str, expected_sha] : rec.discovered_inputs) {
|
||||
const auto actual = digest_cache.hash_file(std::filesystem::path{path_str});
|
||||
if (!actual) {
|
||||
ex.changed_inputs.push_back(path_str + " (missing)");
|
||||
} else if (*actual != expected_sha) {
|
||||
ex.changed_inputs.push_back(path_str + " (modified)");
|
||||
}
|
||||
}
|
||||
for (const auto &out : act.declared_outputs) {
|
||||
const auto it = rec.outputs.find(out.string());
|
||||
if (it == rec.outputs.end()) {
|
||||
ex.changed_outputs.push_back(out.string() + " (not recorded)");
|
||||
continue;
|
||||
}
|
||||
const auto actual = digest_cache.hash_file(out);
|
||||
if (!actual) {
|
||||
ex.changed_outputs.push_back(out.string() + " (missing)");
|
||||
} else if (*actual != it->second.sha256) {
|
||||
ex.changed_outputs.push_back(out.string() + " (modified)");
|
||||
}
|
||||
}
|
||||
if (!ex.changed_inputs.empty()) {
|
||||
ex.would_run = true;
|
||||
ex.reason = "inputs changed";
|
||||
} else if (!ex.changed_outputs.empty()) {
|
||||
ex.restorable = true;
|
||||
ex.reason = "outputs changed or missing (restorable from the cache)";
|
||||
} else {
|
||||
ex.reason = "up to date";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ex.would_run) {
|
||||
++report.would_run;
|
||||
} else {
|
||||
++report.up_to_date;
|
||||
}
|
||||
report.actions.push_back(std::move(ex));
|
||||
}
|
||||
report.total = report.actions.size();
|
||||
return report;
|
||||
}
|
||||
|
||||
} // namespace Void::Build::Execution
|
||||
+380
-31
@@ -68,8 +68,10 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <numeric>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
@@ -381,7 +383,9 @@ struct TestRunRecord {
|
||||
std::string profile;
|
||||
std::string name;
|
||||
bool passed{false};
|
||||
bool timed_out{false};
|
||||
int exit_code{-1};
|
||||
int attempts{1};
|
||||
double elapsed_ms{0};
|
||||
std::string output;
|
||||
};
|
||||
@@ -415,6 +419,14 @@ struct BuildCmdOptions {
|
||||
std::optional<std::string> cdash_build_arg;
|
||||
std::optional<std::string> cdash_output_arg;
|
||||
std::string test_timeout_arg{"300"};
|
||||
std::optional<std::string> repeat_arg;
|
||||
std::string retry_arg{"0"};
|
||||
bool shuffle{false};
|
||||
std::optional<std::string> shuffle_seed_arg;
|
||||
bool stop_on_failure{false};
|
||||
bool explain{false};
|
||||
std::string explain_format{"text"};
|
||||
std::optional<std::string> trace_arg;
|
||||
bool publish_editor_selection{true};
|
||||
bool no_cache{false};
|
||||
bool locked{false};
|
||||
@@ -431,9 +443,88 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
<< "' (expected 1..86400 seconds)\n";
|
||||
return 2;
|
||||
}
|
||||
// Test repetition controls (CTest/Meson parity): --repeat MODE[:N], --retry N,
|
||||
// --shuffle [--shuffle-seed N] and --stop-on-failure.
|
||||
enum class RepeatMode { None, UntilFail, UntilPass, AfterTimeout };
|
||||
RepeatMode repeat_mode = RepeatMode::None;
|
||||
int repeat_count = 1;
|
||||
if (opts.repeat_arg && !opts.repeat_arg->empty()) {
|
||||
std::string mode_text = *opts.repeat_arg;
|
||||
std::string count_text;
|
||||
if (const auto colon = mode_text.find(':'); colon != std::string::npos) {
|
||||
count_text = mode_text.substr(colon + 1);
|
||||
mode_text = mode_text.substr(0, colon);
|
||||
}
|
||||
if (mode_text == "until-fail") {
|
||||
repeat_mode = RepeatMode::UntilFail;
|
||||
} else if (mode_text == "until-pass") {
|
||||
repeat_mode = RepeatMode::UntilPass;
|
||||
} else if (mode_text == "after-timeout") {
|
||||
repeat_mode = RepeatMode::AfterTimeout;
|
||||
} else {
|
||||
std::cerr << cmd_name << ": invalid --repeat mode '" << mode_text
|
||||
<< "' (expected until-fail, until-pass or after-timeout)\n";
|
||||
return 2;
|
||||
}
|
||||
repeat_count = 2;
|
||||
if (!count_text.empty() &&
|
||||
(!Void::Str::to_int(count_text, repeat_count) || repeat_count < 1 ||
|
||||
repeat_count > 100)) {
|
||||
std::cerr << cmd_name << ": invalid --repeat count '" << count_text
|
||||
<< "' (expected 1..100)\n";
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
int retry_count = 0;
|
||||
if (!Void::Str::to_int(opts.retry_arg, retry_count) || retry_count < 0 || retry_count > 10) {
|
||||
std::cerr << cmd_name << ": invalid --retry value '" << opts.retry_arg
|
||||
<< "' (expected 0..10)\n";
|
||||
return 2;
|
||||
}
|
||||
std::optional<std::uint64_t> shuffle_seed;
|
||||
if (opts.shuffle && opts.shuffle_seed_arg && !opts.shuffle_seed_arg->empty()) {
|
||||
std::uint64_t parsed_seed = 0;
|
||||
const auto &text = *opts.shuffle_seed_arg;
|
||||
const auto [ptr, ec] = std::from_chars(text.data(), text.data() + text.size(), parsed_seed);
|
||||
if (ec != std::errc{} || ptr != text.data() + text.size()) {
|
||||
std::cerr << cmd_name << ": invalid --shuffle-seed '" << text
|
||||
<< "' (expected an unsigned integer)\n";
|
||||
return 2;
|
||||
}
|
||||
shuffle_seed = parsed_seed;
|
||||
}
|
||||
|
||||
std::vector<TestRunRecord> test_records;
|
||||
const auto total_sw = Void::Time::Stopwatch::started();
|
||||
|
||||
// Chrome-trace collection (`--trace FILE`): build phases and per-action spans.
|
||||
struct TraceEvent {
|
||||
std::string name;
|
||||
std::string category;
|
||||
double ts_us{0};
|
||||
double dur_us{0};
|
||||
std::string detail;
|
||||
};
|
||||
std::vector<TraceEvent> trace_events;
|
||||
std::mutex trace_mutex;
|
||||
std::map<std::string, double> trace_started;
|
||||
const auto trace_epoch = std::chrono::steady_clock::now();
|
||||
const auto trace_now_us = [&] {
|
||||
return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() -
|
||||
trace_epoch)
|
||||
.count();
|
||||
};
|
||||
const auto trace_phase = [&](std::string name, std::string category, double elapsed_ms,
|
||||
std::string detail) {
|
||||
if (!opts.trace_arg) {
|
||||
return;
|
||||
}
|
||||
const double dur = elapsed_ms * 1000.0;
|
||||
std::lock_guard lock{trace_mutex};
|
||||
trace_events.push_back({std::move(name), std::move(category),
|
||||
std::max(0.0, trace_now_us() - dur), dur, std::move(detail)});
|
||||
};
|
||||
|
||||
std::optional<CompilerFamily> compiler_override;
|
||||
if (opts.compiler_arg) {
|
||||
try {
|
||||
@@ -523,6 +614,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
}
|
||||
Void::Log::info("Config", "Build description {} ({:.0f} ms)",
|
||||
compiled->recompiled ? "compiled" : "up to date (cached)", cfg_sw.elapsed_ms());
|
||||
trace_phase("config", "phase", cfg_sw.elapsed_ms(), "compile the build description");
|
||||
|
||||
auto profs = Config::discover_profiles(*compiled, fopts);
|
||||
if (!profs) {
|
||||
@@ -582,11 +674,13 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
ctx.link_options.push_back("--coverage");
|
||||
}
|
||||
|
||||
const auto tc_sw = Void::Time::Stopwatch::started();
|
||||
auto tc = Toolchain::discover_and_probe(ctx, build_root / ".vbs" / "probes");
|
||||
if (!tc) {
|
||||
std::cerr << "vbs: " << tc.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
trace_phase("toolchain", "phase", tc_sw.elapsed_ms(), "discover and probe the toolchain");
|
||||
Void::Log::info("Toolchain", "[{}] Using {} ({}) [{}]", prof_name,
|
||||
compiler_name(tc->family), tc->cxx_compiler.string(), tc->version_banner);
|
||||
|
||||
@@ -601,6 +695,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
Void::Log::info("Eval", "[{}] Evaluated {} target(s), {} dependenc(ies) ({:.0f} ms)",
|
||||
prof_name, desc->targets.size(), desc->dependencies.size(),
|
||||
eval_sw.elapsed_ms());
|
||||
trace_phase("eval", "phase", eval_sw.elapsed_ms(), "evaluate the project description");
|
||||
|
||||
// Load & merge any TOML dependency manifests declared by build.cpp.
|
||||
std::vector<Package::NormalizedDependency> toml_deps;
|
||||
@@ -768,6 +863,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
Void::Log::info("Snapshot", "[{}] Captured snapshot {} ({} file(s), {:.0f} ms)", prof_name,
|
||||
snap->snapshot_id.substr(0, 12), snap->entries.size(),
|
||||
snap_sw.elapsed_ms());
|
||||
trace_phase("snapshot", "phase", snap_sw.elapsed_ms(), "capture the immutable snapshot");
|
||||
|
||||
const auto graph_sw = Void::Time::Stopwatch::started();
|
||||
Graph::GraphLowerOptions gopts{project_root, build_root, &(*snap),
|
||||
@@ -782,6 +878,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
Void::Log::info("Graph", "[{}] Lowered {} action(s) across {} target(s) ({:.0f} ms)",
|
||||
prof_name, graph->actions.size(), graph->targets.size(),
|
||||
graph_sw.elapsed_ms());
|
||||
trace_phase("graph", "phase", graph_sw.elapsed_ms(), "lower the action graph");
|
||||
|
||||
// Publish compdb BEFORE compilation (Plan 09: compile failure does NOT undo selection!).
|
||||
Editor::PublishOptions popts;
|
||||
@@ -801,6 +898,111 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
eopts.jobs = jobs;
|
||||
eopts.use_cache = !opts.no_cache;
|
||||
eopts.selected_targets = opts.targets;
|
||||
if (opts.trace_arg) {
|
||||
eopts.on_event = [&](const Execution::ExecutionEvent &ev) {
|
||||
std::lock_guard lock{trace_mutex};
|
||||
const double now = trace_now_us();
|
||||
if (ev.kind == Execution::ExecutionEvent::Kind::ActionStarted) {
|
||||
trace_started[ev.action_id] = now;
|
||||
return;
|
||||
}
|
||||
const double dur = static_cast<double>(ev.elapsed.count()) * 1000.0;
|
||||
double ts = std::max(0.0, now - dur);
|
||||
if (const auto it = trace_started.find(ev.action_id); it != trace_started.end()) {
|
||||
ts = it->second;
|
||||
trace_started.erase(it);
|
||||
}
|
||||
const char *category =
|
||||
ev.kind == Execution::ExecutionEvent::Kind::ActionCached
|
||||
? "cache"
|
||||
: (ev.kind == Execution::ExecutionEvent::Kind::ActionSucceeded ? "action"
|
||||
: "failed");
|
||||
trace_events.push_back({ev.label, category, ts, dur, ev.message});
|
||||
};
|
||||
}
|
||||
|
||||
if (opts.explain) {
|
||||
auto explained = Execution::explain_graph(*graph, *state, eopts);
|
||||
if (!explained) {
|
||||
std::cerr << "vbs explain: " << explained.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
const auto json_escape = [](std::string_view text) {
|
||||
std::string out;
|
||||
for (const char c : text) {
|
||||
switch (c) {
|
||||
case '"':
|
||||
out += "\\\"";
|
||||
break;
|
||||
case '\\':
|
||||
out += "\\\\";
|
||||
break;
|
||||
case '\n':
|
||||
out += "\\n";
|
||||
break;
|
||||
case '\t':
|
||||
out += "\\t";
|
||||
break;
|
||||
default:
|
||||
out.push_back(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
};
|
||||
if (opts.explain_format == "json") {
|
||||
std::string json = std::format(
|
||||
"{{\"profile\":\"{}\",\"total\":{},\"up_to_date\":{},\"would_run\":{},\"actions\":[",
|
||||
json_escape(prof_name), explained->total, explained->up_to_date,
|
||||
explained->would_run);
|
||||
for (std::size_t i = 0; i < explained->actions.size(); ++i) {
|
||||
const auto &ex = explained->actions[i];
|
||||
if (i > 0) {
|
||||
json += ',';
|
||||
}
|
||||
json += std::format(
|
||||
"{{\"id\":\"{}\",\"target\":\"{}\",\"label\":\"{}\",\"action_key\":\"{}\","
|
||||
"\"cacheable\":{},\"would_run\":{},\"restorable\":{},\"remote_hit\":{},"
|
||||
"\"reason\":\"{}\",\"changed_inputs\":[",
|
||||
json_escape(ex.action_id), json_escape(ex.target_name),
|
||||
json_escape(ex.label), json_escape(ex.action_key),
|
||||
ex.cacheable ? "true" : "false", ex.would_run ? "true" : "false",
|
||||
ex.restorable ? "true" : "false", ex.remote_hit ? "true" : "false",
|
||||
json_escape(ex.reason));
|
||||
for (std::size_t j = 0; j < ex.changed_inputs.size(); ++j) {
|
||||
json += (j > 0 ? "," : "") + std::format("\"{}\"", json_escape(ex.changed_inputs[j]));
|
||||
}
|
||||
json += "],\"changed_outputs\":[";
|
||||
for (std::size_t j = 0; j < ex.changed_outputs.size(); ++j) {
|
||||
json += (j > 0 ? "," : "") +
|
||||
std::format("\"{}\"", json_escape(ex.changed_outputs[j]));
|
||||
}
|
||||
json += std::format("],\"command\":\"{}\"}}", json_escape(ex.command));
|
||||
}
|
||||
json += "]}";
|
||||
std::cout << json << '\n';
|
||||
} else {
|
||||
std::cout << std::format("vbs explain: [{}] {} action(s): {} up to date, {} would run\n",
|
||||
prof_name, explained->total, explained->up_to_date,
|
||||
explained->would_run);
|
||||
for (const auto &ex : explained->actions) {
|
||||
std::cout << std::format(" {:<11} {}", ex.would_run ? "would run" : "up to date",
|
||||
ex.label);
|
||||
if (!ex.reason.empty() && ex.reason != "up to date") {
|
||||
std::cout << " — " << ex.reason;
|
||||
}
|
||||
std::cout << '\n';
|
||||
for (const auto &input : ex.changed_inputs) {
|
||||
std::cout << " input: " << input << '\n';
|
||||
}
|
||||
for (const auto &output : ex.changed_outputs) {
|
||||
std::cout << " output: " << output << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
auto rep = Execution::execute_graph(*graph, *state, eopts);
|
||||
if (!rep) {
|
||||
std::cerr << "vbs: " << rep.error().message() << '\n';
|
||||
@@ -1032,6 +1234,43 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
// Claim order: declaration order, or a seeded shuffle (--shuffle).
|
||||
std::vector<std::size_t> claim_order(test_jobs.size());
|
||||
std::iota(claim_order.begin(), claim_order.end(), std::size_t{0});
|
||||
if (opts.shuffle) {
|
||||
const std::uint64_t seed =
|
||||
shuffle_seed.value_or(static_cast<std::uint64_t>(std::random_device{}()));
|
||||
std::mt19937_64 rng{seed};
|
||||
std::ranges::shuffle(claim_order, rng);
|
||||
Void::Log::info("Test", "[{}] Shuffled {} test(s) (seed {})", prof_name,
|
||||
claim_order.size(), seed);
|
||||
}
|
||||
const auto run_attempt = [&](const TestJob &job) {
|
||||
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;
|
||||
record.timed_out = tres->timed_out;
|
||||
} else {
|
||||
record.output = tres.error().message();
|
||||
}
|
||||
return record;
|
||||
};
|
||||
const auto worker = [&] {
|
||||
for (;;) {
|
||||
std::size_t index = 0;
|
||||
@@ -1041,12 +1280,18 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
if (remaining == 0) {
|
||||
return;
|
||||
}
|
||||
for (; index < test_jobs.size(); ++index) {
|
||||
if (!claimed[index] && prerequisites_done(index) &&
|
||||
resources_free(index)) {
|
||||
std::optional<std::size_t> pick;
|
||||
for (const std::size_t candidate : claim_order) {
|
||||
if (!claimed[candidate] && prerequisites_done(candidate) &&
|
||||
resources_free(candidate)) {
|
||||
pick = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!pick) {
|
||||
continue; // Woken spuriously; wait again.
|
||||
}
|
||||
index = *pick;
|
||||
claimed[index] = true;
|
||||
// A failed fixture setup skips its dependents.
|
||||
const bool blocked =
|
||||
@@ -1068,37 +1313,49 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
}
|
||||
}
|
||||
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();
|
||||
double elapsed_total = 0.0;
|
||||
int attempts = 0;
|
||||
for (;;) {
|
||||
++attempts;
|
||||
Void::Log::info("Test", "[{}] Running test target '{}' (attempt {})...",
|
||||
prof_name, job.name, attempts);
|
||||
record = run_attempt(job);
|
||||
elapsed_total += record.elapsed_ms;
|
||||
bool again = false;
|
||||
switch (repeat_mode) {
|
||||
case RepeatMode::UntilFail:
|
||||
again = record.passed && attempts < repeat_count;
|
||||
break;
|
||||
case RepeatMode::UntilPass:
|
||||
again = !record.passed && attempts < repeat_count;
|
||||
break;
|
||||
case RepeatMode::AfterTimeout:
|
||||
again = record.timed_out && attempts < repeat_count;
|
||||
break;
|
||||
case RepeatMode::None:
|
||||
break;
|
||||
}
|
||||
if (!again && !record.passed && retry_count > 0 &&
|
||||
attempts <= retry_count) {
|
||||
again = true;
|
||||
}
|
||||
if (!again) {
|
||||
break;
|
||||
}
|
||||
Void::Log::warn("Test", "[{}] Repeating '{}' ({})", prof_name, job.name,
|
||||
record.passed ? "repeat policy"
|
||||
: (record.timed_out ? "timed out" : "failed"));
|
||||
}
|
||||
record.attempts = attempts;
|
||||
record.elapsed_ms = elapsed_total;
|
||||
const bool passed = record.passed;
|
||||
if (!passed) {
|
||||
Void::Log::error("Test", "[{}] FAILED '{}' ({:.0f} ms)", prof_name,
|
||||
job.name, tsw.elapsed_ms());
|
||||
Void::Log::error("Test", "[{}] FAILED '{}' after {} attempt(s) ({:.0f} ms)",
|
||||
prof_name, job.name, attempts, elapsed_total);
|
||||
} else {
|
||||
Void::Log::info("Test", "[{}] PASSED '{}' ({:.0f} ms)", prof_name, job.name,
|
||||
tsw.elapsed_ms());
|
||||
Void::Log::info("Test", "[{}] PASSED '{}' after {} attempt(s) ({:.0f} ms)",
|
||||
prof_name, job.name, attempts, elapsed_total);
|
||||
}
|
||||
{
|
||||
std::lock_guard lock{test_mutex};
|
||||
@@ -1109,6 +1366,22 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
completed[index] = true;
|
||||
failed[index] = !passed;
|
||||
--remaining;
|
||||
if (!passed && opts.stop_on_failure) {
|
||||
std::size_t skipped = 0;
|
||||
for (std::size_t i = 0; i < test_jobs.size(); ++i) {
|
||||
if (!claimed[i] && !completed[i]) {
|
||||
claimed[i] = true;
|
||||
completed[i] = true;
|
||||
--remaining;
|
||||
++skipped;
|
||||
}
|
||||
}
|
||||
if (skipped > 0) {
|
||||
Void::Log::warn("Test",
|
||||
"[{}] --stop-on-failure: skipped {} remaining test(s)",
|
||||
prof_name, skipped);
|
||||
}
|
||||
}
|
||||
}
|
||||
test_cv.notify_all();
|
||||
}
|
||||
@@ -1139,6 +1412,10 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
test_records.push_back(std::move(*record));
|
||||
}
|
||||
}
|
||||
if (opts.stop_on_failure && !all_ok) {
|
||||
Void::Log::warn("Test", "--stop-on-failure: skipping the remaining profiles");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// lcov coverage report from the gcov data produced by the instrumented test binaries.
|
||||
@@ -1291,6 +1568,53 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.trace_arg && !opts.trace_arg->empty()) {
|
||||
trace_phase("total", "phase", total_sw.elapsed_ms(), "whole invocation");
|
||||
const auto json_escape = [](std::string_view text) {
|
||||
std::string out;
|
||||
for (const char c : text) {
|
||||
switch (c) {
|
||||
case '"':
|
||||
out += "\\\"";
|
||||
break;
|
||||
case '\\':
|
||||
out += "\\\\";
|
||||
break;
|
||||
case '\n':
|
||||
out += "\\n";
|
||||
break;
|
||||
case '\t':
|
||||
out += "\\t";
|
||||
break;
|
||||
default:
|
||||
out.push_back(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
};
|
||||
std::string json = "{\"traceEvents\":[";
|
||||
for (std::size_t i = 0; i < trace_events.size(); ++i) {
|
||||
const auto &ev = trace_events[i];
|
||||
if (i > 0) {
|
||||
json += ',';
|
||||
}
|
||||
json += std::format(
|
||||
"{{\"name\":\"{}\",\"cat\":\"{}\",\"ph\":\"X\",\"ts\":{:.0f},\"dur\":{:.0f},"
|
||||
"\"pid\":1,\"tid\":1,\"args\":{{\"detail\":\"{}\"}}}}",
|
||||
json_escape(ev.name), json_escape(ev.category), ev.ts_us, ev.dur_us,
|
||||
json_escape(ev.detail));
|
||||
}
|
||||
json += "],\"displayTimeUnit\":\"ms\"}";
|
||||
if (auto written = Platform::atomic_write_file(*opts.trace_arg, json, false); !written) {
|
||||
std::cerr << "vbs: cannot write trace file: " << written.error().message() << '\n';
|
||||
all_ok = false;
|
||||
} else {
|
||||
Void::Log::info("Build", "Wrote {} trace event(s) to {}", trace_events.size(),
|
||||
*opts.trace_arg);
|
||||
}
|
||||
}
|
||||
|
||||
Void::Log::debug("Build", "Total wall time: {:.2f}s", total_sw.elapsed_ms() / 1000.0);
|
||||
return all_ok ? 0 : 1;
|
||||
}
|
||||
@@ -3833,6 +4157,19 @@ int main(int argc, char **argv) {
|
||||
build_opts.target_arch_arg)
|
||||
.option_default("--test-timeout", "", "Per-test timeout in seconds (1..86400)",
|
||||
build_opts.test_timeout_arg, "300")
|
||||
.option("--repeat", "",
|
||||
"Repeat tests: until-fail[:N], until-pass[:N] or after-timeout[:N] (N=1..100)",
|
||||
build_opts.repeat_arg)
|
||||
.option_default("--retry", "", "Retry a failed test up to N times (0..10)",
|
||||
build_opts.retry_arg, "0")
|
||||
.flag("--shuffle", "", "Run tests in a shuffled order", build_opts.shuffle)
|
||||
.option("--shuffle-seed", "", "Seed for --shuffle (default: random)",
|
||||
build_opts.shuffle_seed_arg)
|
||||
.flag("--stop-on-failure", "", "Stop scheduling tests after the first failure",
|
||||
build_opts.stop_on_failure)
|
||||
.option("--trace", "",
|
||||
"Write a Chrome trace (JSON) of build phases and action spans",
|
||||
build_opts.trace_arg)
|
||||
.option("--junit", "", "Write a JUnit XML report of test results", build_opts.junit_arg)
|
||||
.option("--coverage", "", "Build with --coverage and write an lcov report to this directory",
|
||||
build_opts.coverage_arg)
|
||||
@@ -3883,6 +4220,11 @@ int main(int argc, char **argv) {
|
||||
configure_build_or_test(
|
||||
root.subcommand("build", "Configure and build selected profiles and targets"));
|
||||
configure_build_or_test(root.subcommand("test", "Build and run declared test targets"));
|
||||
auto &explain_cmd =
|
||||
root.subcommand("explain", "Explain why each action would run or be reused");
|
||||
configure_build_or_test(explain_cmd);
|
||||
explain_cmd.option_default("--format", "", "Output format: text (default) or json",
|
||||
build_opts.explain_format, "text");
|
||||
|
||||
auto &describe_cmd =
|
||||
root.subcommand("describe", "Evaluate build.cpp and emit versioned graph summary JSON");
|
||||
@@ -4478,7 +4820,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
const std::string_view cmd = parsed.matched_command_path.front();
|
||||
const bool machine_quiet_default =
|
||||
(cmd == "describe") || (cmd == "graph") || (cmd == "doctor") ||
|
||||
(cmd == "describe") || (cmd == "graph") || (cmd == "doctor") || (cmd == "explain") ||
|
||||
(cmd == "compdb" && parsed.matched_command_path.size() >= 2 &&
|
||||
parsed.matched_command_path[1] == "show") ||
|
||||
(cmd == "ide" && parsed.matched_command_path.size() >= 2 &&
|
||||
@@ -4489,8 +4831,15 @@ int main(int argc, char **argv) {
|
||||
: Void::Log::Level::Info);
|
||||
ConsoleLogGuard log_guard{log_level};
|
||||
|
||||
if (cmd == "build" || cmd == "test") {
|
||||
if (cmd == "build" || cmd == "test" || cmd == "explain") {
|
||||
const bool run_tests = cmd == "test";
|
||||
build_opts.explain = cmd == "explain";
|
||||
if (build_opts.explain && build_opts.explain_format != "text" &&
|
||||
build_opts.explain_format != "json") {
|
||||
std::cerr << "vbs explain: unsupported --format '" << build_opts.explain_format
|
||||
<< "' (expected text or json)\n";
|
||||
return 2;
|
||||
}
|
||||
if (Config::is_workspace_root(std::filesystem::path{build_opts.project_arg})) {
|
||||
return execute_workspace(std::move(build_opts), run_tests);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user