FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
taskflow/unittests/test_priorities.cpp at task_isolation · ModuleWorks/taskflow · GitHub
ModuleWorks
/
taskflow
Public
forked from
taskflow/taskflow
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
taskflow
/
unittests
/
test_priorities.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
113 lines (78 loc) · 2.59 KB
Breadcrumbs
taskflow
/
unittests
/
test_priorities.cpp
Copy path
File metadata and controls
113 lines (78 loc) · 2.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
define
DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#
include
<
doctest.h
>
#
include
<
taskflow/taskflow.hpp
>
TEST_CASE
(
"
SimplePriority.Sequential
"
*
doctest::timeout
(
300
)) {
tf::Executor
executor
(
1
);
tf::Taskflow taskflow;
int
counter =
0
;
auto
[A, B, C, D, E] = taskflow.
emplace
(
[&] () { counter =
0
; },
[&] () {
REQUIRE
(counter ==
0
); counter++; },
[&] () {
REQUIRE
(counter ==
2
); counter++; },
[&] () {
REQUIRE
(counter ==
1
); counter++; },
[&] () { }
);
A.
precede
(B, C, D);
E.
succeed
(B, C, D);
REQUIRE
(B.
priority
() == tf::TaskPriority::
HIGH
);
REQUIRE
(C.
priority
() == tf::TaskPriority::
HIGH
);
REQUIRE
(D.
priority
() == tf::TaskPriority::
HIGH
);
B.
priority
(tf::TaskPriority::
HIGH
);
C.
priority
(tf::TaskPriority::
LOW
);
D.
priority
(tf::TaskPriority::
NORMAL
);
REQUIRE
(B.
priority
() == tf::TaskPriority::
HIGH
);
REQUIRE
(C.
priority
() == tf::TaskPriority::
LOW
);
REQUIRE
(D.
priority
() == tf::TaskPriority::
NORMAL
);
executor.
run_n
(taskflow,
100
).
wait
();
}
TEST_CASE
(
"
RandomPriority.Sequential
"
*
doctest::timeout
(
300
)) {
tf::Executor
executor
(
1
);
tf::Taskflow taskflow;
const
auto
MAX_P
=
static_cast
<
unsigned
>(tf::TaskPriority::
MAX
);
auto
beg = taskflow.
emplace
([](){});
auto
end = taskflow.
emplace
([](){});
size_t
counters[
MAX_P
];
size_t
priorities[
MAX_P
];
for
(
unsigned
p=
0
; p<
MAX_P
; p++) {
counters[p] =
0
;
priorities[p] =
0
;
}
for
(
size_t
i=
0
; i<
10000
; i++) {
unsigned
p = ::
rand
() %
MAX_P
;
taskflow.
emplace
([p, &counters](){ counters[p]++; })
.
priority
(
static_cast
<tf::TaskPriority>(p))
.
succeed
(beg)
.
precede
(end);
priorities[p]++;
}
executor.
run
(taskflow).
wait
();
for
(
unsigned
p=
0
; p<
MAX_P
; p++) {
REQUIRE
(priorities[p] == counters[p]);
}
}
TEST_CASE
(
"
RandomPriority.Parallel
"
*
doctest::timeout
(
300
)) {
tf::Executor executor;
tf::Taskflow taskflow;
const
auto
MAX_P
=
static_cast
<
unsigned
>(tf::TaskPriority::
MAX
);
auto
beg = taskflow.
emplace
([](){});
auto
end = taskflow.
emplace
([](){});
std::atomic<
size_t
> counters[
MAX_P
];
size_t
priorities[
MAX_P
];
for
(
unsigned
p=
0
; p<
MAX_P
; p++) {
counters[p] =
0
;
priorities[p] =
0
;
}
for
(
size_t
i=
0
; i<
10000
; i++) {
unsigned
p = ::
rand
() %
MAX_P
;
taskflow.
emplace
([p, &counters](){ counters[p]++; })
.
priority
(
static_cast
<tf::TaskPriority>(p))
.
succeed
(beg)
.
precede
(end);
priorities[p]++;
}
executor.
run_n
(taskflow,
2
).
wait
();
for
(
unsigned
p=
0
; p<
MAX_P
; p++) {
REQUIRE
(counters[p]!=
0
);
//
std::cout << priorities[p] << ' ' << counters[p] << '\n';
}
}
Back
|
FazBrowse Home
|
New Git URL