From f41599c8e9435f3dfec60b872c2b4ae31177efdd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 10 Oct 2020 17:22:46 +0300 Subject: Add support for test timeouts --- libbuild2/script/script.hxx | 53 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'libbuild2/script/script.hxx') diff --git a/libbuild2/script/script.hxx b/libbuild2/script/script.hxx index 4a62c77..ecd2c2b 100644 --- a/libbuild2/script/script.hxx +++ b/libbuild2/script/script.hxx @@ -308,8 +308,9 @@ namespace build2 // process_path program; - strings arguments; - environment_vars variables; + strings arguments; + environment_vars variables; // From env builtin. + optional timeout; // From env builtin. optional in; optional out; @@ -363,6 +364,37 @@ namespace build2 ostream& operator<< (ostream&, const command_expr&); + struct timeout + { + duration value; + bool success; + + timeout (duration d, bool s): value (d), success (s) {} + }; + + struct deadline + { + timestamp value; + bool success; + + deadline (timestamp t, bool s): value (t), success (s) {} + }; + + // If timestamps/durations are equal, the failure is less than the + // success. + // + bool + operator< (const deadline&, const deadline&); + + bool + operator< (const timeout&, const timeout&); + + optional + to_deadline (const optional&, bool success); + + optional + to_timeout (const optional&, bool success); + // Script execution environment. // class environment @@ -469,6 +501,23 @@ namespace build2 const string& attrs, const location&) = 0; + // Set the script execution timeout from the timeout builtin call. + // + // The builtin argument semantics is script implementation-dependent. If + // success is true then a process missing this deadline should not be + // considered as failed unless it didn't terminate gracefully and had to + // be killed. + // + virtual void + set_timeout (const string& arg, bool success, const location&) = 0; + + // Return the script execution deadline which can potentially rely on + // factors besides the latest timeout builtin call (variables, scoping, + // etc). + // + virtual optional + effective_deadline () = 0; + // Create the temporary directory and set the temp_dir reference target // to its path. Must only be called if temp_dir is empty. // -- cgit v1.1