Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
5c1e44a9
Commit
5c1e44a9
authored
Aug 27, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added bactrace tests
parent
75adf9e7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
6 deletions
+50
-6
tests/CMakeLists.txt
tests/CMakeLists.txt
+2
-1
tests/test_backtrace.cpp
tests/test_backtrace.cpp
+36
-0
tests/test_sink.h
tests/test_sink.h
+12
-5
No files found.
tests/CMakeLists.txt
View file @
5c1e44a9
...
@@ -23,7 +23,8 @@ set(SPDLOG_UTESTS_SOURCES
...
@@ -23,7 +23,8 @@ set(SPDLOG_UTESTS_SOURCES
test_sink.h
test_sink.h
test_fmt_helper.cpp
test_fmt_helper.cpp
test_stdout_api.cpp
test_stdout_api.cpp
test_dup_filter.cpp
)
test_dup_filter.cpp
test_backtrace.cpp
)
if
(
NOT SPDLOG_NO_EXCEPTIONS
)
if
(
NOT SPDLOG_NO_EXCEPTIONS
)
list
(
APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp
)
list
(
APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp
)
...
...
tests/test_backtrace.cpp
0 → 100644
View file @
5c1e44a9
#include "includes.h"
#include "test_sink.h"
TEST_CASE
(
"bactrace1"
,
"[bactrace]"
)
{
using
spdlog
::
sinks
::
test_sink_st
;
auto
test_sink
=
std
::
make_shared
<
test_sink_st
>
();
int
backtrace_size
=
5
;
spdlog
::
logger
logger
(
"test"
,
test_sink
);
logger
.
set_pattern
(
"%v"
);
logger
.
enable_backtrace
(
backtrace_size
);
logger
.
info
(
"info message"
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
logger
.
debug
(
"debug message {}"
,
i
);
REQUIRE
(
test_sink
->
lines
().
size
()
==
1
);
REQUIRE
(
test_sink
->
lines
()[
0
]
==
"info message"
);
logger
.
dump_backtrace
();
REQUIRE
(
test_sink
->
lines
().
size
()
==
8
);
REQUIRE
(
test_sink
->
lines
()[
1
]
==
"****************** Backtrace Start ******************"
);
for
(
int
i
=
0
;
i
<
backtrace_size
;
i
++
)
{
REQUIRE
(
test_sink
->
lines
()[
i
+
2
]
==
fmt
::
format
(
"debug message {}"
,
100
-
backtrace_size
+
i
));
}
REQUIRE
(
test_sink
->
lines
()[
7
]
==
"****************** Backtrace End ********************"
);
}
tests/test_sink.h
View file @
5c1e44a9
...
@@ -18,6 +18,7 @@ namespace sinks {
...
@@ -18,6 +18,7 @@ namespace sinks {
template
<
class
Mutex
>
template
<
class
Mutex
>
class
test_sink
:
public
base_sink
<
Mutex
>
class
test_sink
:
public
base_sink
<
Mutex
>
{
{
const
size_t
lines_to_save
=
100
;
public:
public:
size_t
msg_counter
()
size_t
msg_counter
()
{
{
...
@@ -33,23 +34,29 @@ public:
...
@@ -33,23 +34,29 @@ public:
void
set_delay
(
std
::
chrono
::
milliseconds
delay
)
void
set_delay
(
std
::
chrono
::
milliseconds
delay
)
{
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
delay_
=
delay
;
delay_
=
delay
;
}
}
// return last output without the eol
// return last output without the eol
std
::
string
last_output
()
std
::
vector
<
std
::
string
>
lines
()
{
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
mutex_
);
auto
eol_len
=
strlen
(
spdlog
::
details
::
os
::
default_eol
);
return
lines_
;
return
std
::
string
(
last_output_
.
begin
(),
last_output_
.
end
()
-
eol_len
);
}
}
protected:
protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
{
fmt
::
memory_buffer
formatted
;
fmt
::
memory_buffer
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
last_output_
.
assign
(
formatted
.
begin
(),
formatted
.
end
());
// save the line without the eol
auto
eol_len
=
strlen
(
details
::
os
::
default_eol
);
if
(
lines_
.
size
()
<
lines_to_save
)
{
lines_
.
emplace_back
(
formatted
.
begin
(),
formatted
.
end
()
-
eol_len
);
}
msg_counter_
++
;
msg_counter_
++
;
std
::
this_thread
::
sleep_for
(
delay_
);
std
::
this_thread
::
sleep_for
(
delay_
);
}
}
...
@@ -62,7 +69,7 @@ protected:
...
@@ -62,7 +69,7 @@ protected:
size_t
msg_counter_
{
0
};
size_t
msg_counter_
{
0
};
size_t
flush_counter_
{
0
};
size_t
flush_counter_
{
0
};
std
::
chrono
::
milliseconds
delay_
{
std
::
chrono
::
milliseconds
::
zero
()};
std
::
chrono
::
milliseconds
delay_
{
std
::
chrono
::
milliseconds
::
zero
()};
std
::
string
last_output
_
;
std
::
vector
<
std
::
string
>
lines
_
;
};
};
using
test_sink_mt
=
test_sink
<
std
::
mutex
>
;
using
test_sink_mt
=
test_sink
<
std
::
mutex
>
;
...
...
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