forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runtimes.cpp
More file actions
85 lines (59 loc) · 2.14 KB
/
test_runtimes.cpp
File metadata and controls
85 lines (59 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
#include <taskflow/taskflow.hpp>
#include <taskflow/algorithm/pipeline.hpp>
// --------------------------------------------------------
// Testcase: Runtime.Schedule.ModuleTask
// --------------------------------------------------------
TEST_CASE("Runtime.Schedule.ModuleTask" * doctest::timeout(300)) {
tf::Taskflow tf;
int value {0};
auto a = tf.emplace([&]() { value = -100; }).name("A");
auto module_task = tf.placeholder().name("module");
auto b = tf.emplace([&]() { value++; }).name("B");
auto c = tf.emplace([&]() { value++; }).name("C");
a.precede(module_task);
module_task.precede(b);
b.precede(c);
tf::Taskflow module_flow;
auto m1 = module_flow.emplace([&]() { value++; }).name("m1");
auto m2 = module_flow.emplace([&]() { value++; }).name("m2");
m1.precede(m2);
module_task.composed_of(module_flow);
auto entrypoint = tf.emplace([]() { return 0; }).name("entrypoint");
auto schedule = tf.emplace([&](tf::Runtime& runtime) {
value++;
runtime.schedule(module_task);
});
entrypoint.precede(schedule, a);
tf::Executor executor;
executor.run(tf).wait();
REQUIRE(value == 5);
}
// --------------------------------------------------------
// Testcase: Runtime.ExternalGraph.Simple
// --------------------------------------------------------
TEST_CASE("Runtime.ExternalGraph.Simple" * doctest::timeout(300)) {
const size_t N = 100;
tf::Executor executor;
tf::Taskflow taskflow;
std::vector<int> results(N, 0);
std::vector<tf::Taskflow> graphs(N);
for(size_t i=0; i<N; i++) {
auto& fb = graphs[i];
auto A = fb.emplace([&res=results[i]]()mutable{ ++res; });
auto B = fb.emplace([&res=results[i]]()mutable{ ++res; });
auto C = fb.emplace([&res=results[i]]()mutable{ ++res; });
auto D = fb.emplace([&res=results[i]]()mutable{ ++res; });
A.precede(B);
B.precede(C);
C.precede(D);
taskflow.emplace([&res=results[i], &graph=graphs[i]](tf::Runtime& rt)mutable{
rt.corun(graph);
});
}
executor.run_n(taskflow, 100).wait();
for(size_t i=0; i<N; i++) {
REQUIRE(results[i] == 400);
}
}