aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test/common.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/test/common.cxx')
-rw-r--r--libbuild2/test/common.cxx78
1 files changed, 74 insertions, 4 deletions
diff --git a/libbuild2/test/common.cxx b/libbuild2/test/common.cxx
index f50d289..89f3dd6 100644
--- a/libbuild2/test/common.cxx
+++ b/libbuild2/test/common.cxx
@@ -6,6 +6,10 @@
#include <libbuild2/target.hxx>
#include <libbuild2/algorithm.hxx>
+#include <libbuild2/script/timeout.hxx>
+
+#include <libbuild2/test/module.hxx>
+
using namespace std;
namespace build2
@@ -146,8 +150,7 @@ namespace build2
t.name == n->value && // Name matches.
tt.name == n->type && // Target type matches.
d == n->dir && // Directory matches.
- (search_existing (*n, *root_) == &t ||
- search_existing (*n, *root_, d) == &t);
+ search_existing (*n, *root_) == &t;
if (r)
break;
@@ -194,8 +197,7 @@ namespace build2
t.name == n->value &&
tt.name == n->type &&
d == n->dir &&
- (search_existing (*n, *root_) == &t ||
- search_existing (*n, *root_, d) == &t);
+ search_existing (*n, *root_) == &t;
if (!r)
continue; // Not our target.
@@ -215,5 +217,73 @@ namespace build2
return r;
}
+
+ optional<timestamp> common::
+ operation_deadline () const
+ {
+ if (!operation_timeout)
+ return nullopt;
+
+ duration::rep r (operation_deadline_.load (memory_order_consume));
+
+ if (r == timestamp_unknown_rep)
+ {
+ duration::rep t (timestamp (system_clock::now () + *operation_timeout).
+ time_since_epoch ().count ());
+
+ if (operation_deadline_.compare_exchange_strong (r,
+ t,
+ memory_order_release,
+ memory_order_consume))
+ r = t;
+ }
+
+ return timestamp (duration (r));
+ }
+
+ // Helpers.
+ //
+ optional<timestamp>
+ operation_deadline (const target& t)
+ {
+ optional<timestamp> r;
+
+ for (const scope* s (t.base_scope ().root_scope ());
+ s != nullptr;
+ s = s->parent_scope ()->root_scope ())
+ {
+ if (auto* m = s->find_module<module> (module::name))
+ r = earlier (r, m->operation_deadline ());
+ }
+
+ return r;
+ }
+
+ optional<duration>
+ test_timeout (const target& t)
+ {
+ optional<duration> r;
+
+ for (const scope* s (t.base_scope ().root_scope ());
+ s != nullptr;
+ s = s->parent_scope ()->root_scope ())
+ {
+ if (auto* m = s->find_module<module> (module::name))
+ r = earlier (r, m->test_timeout);
+ }
+
+ return r;
+ }
+
+ optional<timestamp>
+ test_deadline (const target& t)
+ {
+ optional<timestamp> r (operation_deadline (t));
+
+ if (optional<duration> d = test_timeout (t))
+ r = earlier (r, system_clock::now () + *d);
+
+ return r;
+ }
}
}