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/build/script/script.cxx | 28 ++++++++++++++++++++++++++-- libbuild2/build/script/script.hxx | 26 ++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) (limited to 'libbuild2/build/script') diff --git a/libbuild2/build/script/script.cxx b/libbuild2/build/script/script.cxx index 3485f54..c6b57c3 100644 --- a/libbuild2/build/script/script.cxx +++ b/libbuild2/build/script/script.cxx @@ -7,6 +7,8 @@ #include +#include + #include using namespace std; @@ -17,12 +19,17 @@ namespace build2 { namespace script { + using build2::script::to_deadline; + // environment // static const optional wd_name ("current directory"); environment:: - environment (action a, const target_type& t, bool temp) + environment (action a, + const target_type& t, + bool temp, + const optional& dl) : build2::script::environment ( t.ctx, cast (t.ctx.global_scope["build.host"]), @@ -32,7 +39,8 @@ namespace build2 redirect (redirect_type::merge, 2), redirect (redirect_type::pass)), target (t), - vars (context, false /* global */) + vars (context, false /* global */), + script_deadline (to_deadline (dl, false /* success */)) { // Set special variables. // @@ -58,8 +66,10 @@ namespace build2 // names ns; for (const target_type* pt: t.prerequisite_targets[a]) + { if (pt != nullptr) pt->as_name (ns); + } assign (var_pool.insert ("<")) = move (ns); } @@ -231,6 +241,20 @@ namespace build2 return r; } + + void environment:: + set_timeout (const string& t, bool success, const location& l) + { + fragment_deadline = + to_deadline (parse_deadline (t, "buildscript timeout", l), + success); + } + + optional environment:: + effective_deadline () + { + return earlier (script_deadline, fragment_deadline); + } } } } diff --git a/libbuild2/build/script/script.hxx b/libbuild2/build/script/script.hxx index f4d70ac..9284813 100644 --- a/libbuild2/build/script/script.hxx +++ b/libbuild2/build/script/script.hxx @@ -26,6 +26,8 @@ namespace build2 using build2::script::redirect_type; using build2::script::expr_term; using build2::script::command_expr; + using build2::script::deadline; + using build2::script::timeout; // Notes: // @@ -83,7 +85,10 @@ namespace build2 public: using target_type = build2::target; - environment (action, const target_type&, bool temp_dir); + environment (action, + const target_type&, + bool temp_dir, + const optional& deadline = nullopt); environment (environment&&) = delete; environment (const environment&) = delete; @@ -98,7 +103,7 @@ namespace build2 // Script-local variable pool and map. // // Note that it may be tempting to reuse the rule-specific variables - // for this but they should no be modified during execution (i.e., + // for this but they should not be modified during execution (i.e., // they are for intra-rule communication; perhaps we could have a // special builtin that sets such variables during match). // @@ -125,12 +130,29 @@ namespace build2 // auto_rmdir temp_dir; + // The whole script and the remaining script fragment execution + // deadlines (the latter is set by the timeout builtin). + // + optional script_deadline; + optional fragment_deadline; + virtual void set_variable (string&& name, names&&, const string& attrs, const location&) override; + // Parse the specified in seconds timeout and set the remaining script + // fragment execution deadline. Reset it to nullopt on zero. + // + virtual void + set_timeout (const string&, bool success, const location&) override; + + // Return the nearest of the script and fragment execution deadlines. + // + virtual optional + effective_deadline () override; + virtual void create_temp_dir () override; -- cgit v1.1