Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
057bf1b9
Commit
057bf1b9
authored
Aug 14, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some mpmc_q tests
parent
750b520f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
1 deletion
+107
-1
CMakeLists.txt
tests/CMakeLists.txt
+1
-1
test_mpmc_q.cpp
tests/test_mpmc_q.cpp
+106
-0
No files found.
tests/CMakeLists.txt
View file @
057bf1b9
...
@@ -14,7 +14,7 @@ set(SPDLOG_UTESTS_SOURCES
...
@@ -14,7 +14,7 @@ set(SPDLOG_UTESTS_SOURCES
test_macros.cpp
test_macros.cpp
utils.cpp
utils.cpp
utils.h
utils.h
main.cpp
)
main.cpp
test_mpmc_q.cpp
)
add_executable
(
${
PROJECT_NAME
}
${
SPDLOG_UTESTS_SOURCES
}
)
add_executable
(
${
PROJECT_NAME
}
${
SPDLOG_UTESTS_SOURCES
}
)
target_link_libraries
(
${
PROJECT_NAME
}
PRIVATE Threads::Threads
)
target_link_libraries
(
${
PROJECT_NAME
}
PRIVATE Threads::Threads
)
...
...
tests/test_mpmc_q.cpp
0 → 100644
View file @
057bf1b9
#include "includes.h"
using
namespace
std
::
chrono
;
using
std
::
chrono
::
system_clock
;
using
std
::
chrono
::
milliseconds
;
system_clock
::
time_point
now_millis
()
{
return
time_point_cast
<
milliseconds
>
(
system_clock
::
now
());
}
TEST_CASE
(
"dequeue-empty-nowait"
,
"[mpmc_blocking_q]"
)
{
size_t
q_size
=
100
;
milliseconds
tolerance_wait
(
10
);
spdlog
::
details
::
mpmc_blocking_queue
<
int
>
q
(
q_size
);
int
popped_item
;
auto
millis_0
=
now_millis
();
auto
rv
=
q
.
dequeue_for
(
popped_item
,
milliseconds
::
zero
());
auto
millis_1
=
now_millis
();
REQUIRE
(
rv
==
false
);
REQUIRE
((
millis_1
-
millis_0
)
<=
tolerance_wait
);
}
TEST_CASE
(
"dequeue-empty-wait"
,
"[mpmc_blocking_q]"
)
{
size_t
q_size
=
100
;
milliseconds
wait_ms
(
250
);
milliseconds
tolerance_wait
(
10
);
spdlog
::
details
::
mpmc_blocking_queue
<
int
>
q
(
q_size
);
int
popped_item
;
auto
millis_0
=
now_millis
();
auto
rv
=
q
.
dequeue_for
(
popped_item
,
wait_ms
);
auto
millis_1
=
now_millis
();
auto
delta_ms
=
millis_1
-
millis_0
;
REQUIRE
(
rv
==
false
);
REQUIRE
(
delta_ms
>=
wait_ms
);
REQUIRE
(
delta_ms
<=
wait_ms
+
tolerance_wait
);
}
TEST_CASE
(
"enqueue_nowait"
,
"[mpmc_blocking_q]"
)
{
size_t
q_size
=
1
;
spdlog
::
details
::
mpmc_blocking_queue
<
int
>
q
(
q_size
);
milliseconds
tolerance_wait
(
10
);
q
.
enqueue
(
1
);
REQUIRE
(
q
.
overrun_counter
()
==
0
);
auto
millis_0
=
now_millis
();
q
.
enqueue_nowait
(
2
);
auto
millis_1
=
now_millis
();
REQUIRE
((
millis_1
-
millis_0
)
<=
tolerance_wait
);
REQUIRE
(
q
.
overrun_counter
()
==
1
);
}
TEST_CASE
(
"bad_queue"
,
"[mpmc_blocking_q]"
)
{
size_t
q_size
=
0
;
spdlog
::
details
::
mpmc_blocking_queue
<
int
>
q
(
q_size
);
q
.
enqueue_nowait
(
1
);
REQUIRE
(
q
.
overrun_counter
()
==
1
);
int
i
;
REQUIRE
(
q
.
dequeue_for
(
i
,
milliseconds
(
0
))
==
false
);
}
TEST_CASE
(
"empty_queue"
,
"[mpmc_blocking_q]"
)
{
size_t
q_size
=
10
;
spdlog
::
details
::
mpmc_blocking_queue
<
int
>
q
(
q_size
);
int
i
;
REQUIRE
(
q
.
dequeue_for
(
i
,
milliseconds
(
10
))
==
false
);
}
TEST_CASE
(
"full_queue"
,
"[mpmc_blocking_q]"
)
{
size_t
q_size
=
100
;
spdlog
::
details
::
mpmc_blocking_queue
<
int
>
q
(
q_size
);
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
q_size
);
i
++
)
{
q
.
enqueue
(
std
::
move
(
i
));
}
q
.
enqueue_nowait
(
123456
);
REQUIRE
(
q
.
overrun_counter
()
==
1
);
for
(
int
i
=
1
;
i
<
static_cast
<
int
>
(
q_size
);
i
++
)
{
int
item
;
q
.
dequeue_for
(
item
,
milliseconds
(
0
));
REQUIRE
(
item
==
i
);
}
// last item pushed has overridden the oldest.
int
item
;
q
.
dequeue_for
(
item
,
milliseconds
(
0
));
REQUIRE
(
item
==
123456
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment