aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test/script/script.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/test/script/script.hxx')
-rw-r--r--libbuild2/test/script/script.hxx132
1 files changed, 124 insertions, 8 deletions
diff --git a/libbuild2/test/script/script.hxx b/libbuild2/test/script/script.hxx
index 6356501..9409b01 100644
--- a/libbuild2/test/script/script.hxx
+++ b/libbuild2/test/script/script.hxx
@@ -4,8 +4,6 @@
#ifndef LIBBUILD2_TEST_SCRIPT_SCRIPT_HXX
#define LIBBUILD2_TEST_SCRIPT_SCRIPT_HXX
-#include <set>
-
#include <libbuild2/types.hxx>
#include <libbuild2/forward.hxx>
#include <libbuild2/utility.hxx>
@@ -23,11 +21,19 @@ namespace build2
namespace script
{
using build2::script::line;
+ using build2::script::line_type;
using build2::script::lines;
using build2::script::redirect;
using build2::script::redirect_type;
- using build2::script::line_type;
+ using build2::script::command;
+ using build2::script::expr_term;
using build2::script::command_expr;
+ using build2::script::iteration_index;
+ using build2::script::environment_vars;
+ using build2::script::deadline;
+ using build2::script::timeout;
+ using build2::script::pipe_command;
+ using build2::script::command_function;
class parser; // Required by VC for 'friend class parser' declaration.
@@ -91,18 +97,58 @@ namespace build2
scope_state state = scope_state::unknown;
- void
- set_variable (string&& name,
+ // The command expression execution nesting level. Can be maintained
+ // by the runner to, for example, only perform some housekeeping on
+ // the topmost level (add the test id to the diagnostics, etc).
+ //
+ // Note that the command expression execution can be nested, so that
+ // the outer expression execution is not completed before all the
+ // inner expressions are executed. As for example in:
+ //
+ // echo 'a b' | for x
+ // echo 'c d' | for y
+ // test $x $y
+ // end
+ // end
+ //
+ size_t exec_level = 0;
+
+ // Test program paths.
+ //
+ // Currently always contains a single element (see test_program() for
+ // details). While in the future there can be more of them, the zero
+ // index will always refer to the test variable value and can
+ // potentially be NULL (see reset_special() for details).
+ //
+ small_vector<const path*, 1> test_programs;
+
+ virtual void
+ set_variable (string name,
names&&,
const string& attrs,
const location&) override;
+ // Merge the command execution environment variable (un)sets from this
+ // and outer scopes.
+ //
+ virtual const environment_vars&
+ exported_variables (environment_vars& storage) override;
+
// Noop since the temporary directory is a working directory and so
// is created before the scope commands execution.
//
virtual void
create_temp_dir () override {assert (false);};
+ // Return true if this is a test program path.
+ //
+ // Note that currently the test program is only specified via the test
+ // variable ($0 effectively). In the future we may invent some other
+ // means of marking a program as a test (builtin, etc).
+ //
+ bool
+ test_program (const path&);
+
// Variables.
//
public:
@@ -168,10 +214,29 @@ namespace build2
class group: public scope
{
public:
- vector<unique_ptr<scope>> scopes;
+ group (const string& id, group& p): scope (id, &p, p.root) {}
public:
- group (const string& id, group& p): scope (id, &p, p.root) {}
+ vector<unique_ptr<scope>> scopes;
+
+ // The test group execution deadline and the individual test timeout.
+ //
+ optional<deadline> group_deadline;
+ optional<timeout> test_timeout;
+
+ // Parse the argument having the '[<group-timeout>]/[<test-timeout>]'
+ // form, where the values are expressed in seconds and either of them
+ // (but not both) can be omitted, and set the group deadline and test
+ // timeout respectively, if specified. Reset them to nullopt on zero.
+ //
+ virtual void
+ set_timeout (const string&, bool success, const location&) override;
+
+ // Return the nearest of the own deadline and the enclosing groups
+ // deadlines.
+ //
+ virtual optional<deadline>
+ effective_deadline () override;
protected:
group (const string& id, script& r): scope (id, nullptr, r) {}
@@ -207,6 +272,29 @@ namespace build2
public:
test (const string& id, group& p): scope (id, &p, p.root) {}
+ public:
+ // The whole test and the remaining test fragment execution deadlines.
+ //
+ // The former is based on the minimum of the test timeouts set for the
+ // enclosing scopes and is calculated on the first deadline() call.
+ // The later is set by set_timeout() from the timeout builtin call
+ // during the test execution.
+ //
+ optional<optional<deadline>> test_deadline; // calculated<specified<>>
+ optional<deadline> fragment_deadline;
+
+ // Parse the specified in seconds timeout and set the remaining test
+ // 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 test and fragment execution deadlines,
+ // calculating the former on the first call.
+ //
+ virtual optional<deadline>
+ effective_deadline () override;
+
// Pre-parse data.
//
public:
@@ -239,12 +327,27 @@ namespace build2
variable_pool var_pool;
mutable shared_mutex var_pool_mutex;
+ // Used to compose a test command.
+ //
+ // Changing any of their values requires resetting the $* and $N
+ // special aliases.
+ //
const variable& test_var; // test
const variable& options_var; // test.options
const variable& arguments_var; // test.arguments
const variable& redirects_var; // test.redirects
const variable& cleanups_var; // test.cleanups
+ bool
+ test_command_var (const string& name) const
+ {
+ return name == test_var.name ||
+ name == options_var.name ||
+ name == arguments_var.name ||
+ name == redirects_var.name ||
+ name == cleanups_var.name;
+ }
+
const variable& wd_var; // $~
const variable& id_var; // $@
const variable& cmd_var; // $*
@@ -254,6 +357,13 @@ namespace build2
class script: public script_base, public group
{
public:
+ // The test operation deadline and the individual test timeout (see
+ // the config.test.timeout variable for details).
+ //
+ optional<deadline> operation_deadline;
+ optional<timeout> test_timeout;
+
+ public:
script (const target& test_target,
const testscript& script_target,
const dir_path& root_wd);
@@ -263,6 +373,12 @@ namespace build2
script& operator= (script&&) = delete;
script& operator= (const script&) = delete;
+ // Return the nearest of the test operation and group execution
+ // deadlines.
+ //
+ virtual optional<deadline>
+ effective_deadline () override;
+
// Pre-parse data.
//
private:
@@ -283,7 +399,7 @@ namespace build2
}
};
- std::set<path_name_value, compare_paths> paths_;
+ set<path_name_value, compare_paths> paths_;
};
}
}