aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test/operation.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-10-10 17:22:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-11-06 19:32:09 +0300
commitf41599c8e9435f3dfec60b872c2b4ae31177efdd (patch)
tree088f8d9bf906e4a2ed734e034699163c9ccc7306 /libbuild2/test/operation.cxx
parentac76a4fd2afff48a0d5db84592babe5cabef3a2c (diff)
Add support for test timeouts
Diffstat (limited to 'libbuild2/test/operation.cxx')
-rw-r--r--libbuild2/test/operation.cxx36
1 files changed, 35 insertions, 1 deletions
diff --git a/libbuild2/test/operation.cxx b/libbuild2/test/operation.cxx
index e9635cf..0a65bed 100644
--- a/libbuild2/test/operation.cxx
+++ b/libbuild2/test/operation.cxx
@@ -3,7 +3,11 @@
#include <libbuild2/test/operation.hxx>
+#include <libbuild2/rule.hxx>
#include <libbuild2/variable.hxx>
+#include <libbuild2/algorithm.hxx>
+
+#include <libbuild2/test/common.hxx> // test_deadline()
using namespace std;
using namespace butl;
@@ -23,6 +27,36 @@ namespace build2
return mo != disfigure_id ? update_id : 0;
}
+ // Ad hoc rule apply callback.
+ //
+ // If this is not perform(test) or there is no deadline set for the test
+ // execution, then forward the call to the ad hoc rule's apply().
+ // Otherwise, return a recipe that will execute with the deadline if we
+ // can get it and return the noop recipe that just issues a warning if we
+ // can't.
+ //
+ static recipe
+ adhoc_apply (const adhoc_rule& ar, action a, target& t, match_extra& me)
+ {
+ optional<timestamp> d;
+
+ if (a != perform_test_id || !(d = test_deadline (t)))
+ return ar.apply (a, t, me);
+
+ if (const auto* dr = dynamic_cast<const adhoc_rule_with_deadline*> (&ar))
+ {
+ if (recipe r = dr->apply (a, t, me, d))
+ return r;
+ }
+
+ return [] (action a, const target& t)
+ {
+ warn << "unable to impose timeout on test for target " << t
+ << ", skipping";
+ return noop_action (a, t);
+ };
+ }
+
const operation_info op_test {
test_id,
0,
@@ -36,7 +70,7 @@ namespace build2
&test_pre,
nullptr,
nullptr,
- nullptr
+ &adhoc_apply
};
// Also the explicit update-for-test operation alias.