Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
e7dbfde8
Commit
e7dbfde8
authored
Jul 17, 2015
by
kosak
Browse files
Move stack trace logic into custom/ and add a macro to inject it.
parent
fe95bc33
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
36 deletions
+65
-36
include/gtest/internal/custom/gtest.h
include/gtest/internal/custom/gtest.h
+41
-0
src/gtest-internal-inl.h
src/gtest-internal-inl.h
+7
-17
src/gtest.cc
src/gtest.cc
+17
-19
No files found.
include/gtest/internal/custom/gtest.h
0 → 100644
View file @
e7dbfde8
// Copyright 2015, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Injection point for custom user configurations.
// The following macros can be defined:
//
// GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of
// OsStackTraceGetterInterface.
//
// ** Custom implementation starts here **
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
src/gtest-internal-inl.h
View file @
e7dbfde8
...
@@ -433,6 +433,10 @@ class OsStackTraceGetterInterface {
...
@@ -433,6 +433,10 @@ class OsStackTraceGetterInterface {
// CurrentStackTrace() will use to find and hide Google Test stack frames.
// CurrentStackTrace() will use to find and hide Google Test stack frames.
virtual
void
UponLeavingGTest
()
=
0
;
virtual
void
UponLeavingGTest
()
=
0
;
// This string is inserted in place of stack frames that are part of
// Google Test's implementation.
static
const
char
*
const
kElidedFramesMarker
;
private:
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
OsStackTraceGetterInterface
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
OsStackTraceGetterInterface
);
};
};
...
@@ -440,26 +444,12 @@ class OsStackTraceGetterInterface {
...
@@ -440,26 +444,12 @@ class OsStackTraceGetterInterface {
// A working implementation of the OsStackTraceGetterInterface interface.
// A working implementation of the OsStackTraceGetterInterface interface.
class
OsStackTraceGetter
:
public
OsStackTraceGetterInterface
{
class
OsStackTraceGetter
:
public
OsStackTraceGetterInterface
{
public:
public:
OsStackTraceGetter
()
:
caller_frame_
(
NULL
)
{}
OsStackTraceGetter
()
{}
virtual
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
GTEST_LOCK_EXCLUDED_
(
mutex_
);
virtual
void
UponLeavingGTest
()
GTEST_LOCK_EXCLUDED_
(
mutex_
);
virtual
string
CurrentStackTrace
(
int
max_depth
,
int
skip_count
);
virtual
void
UponLeavingGTest
();
// This string is inserted in place of stack frames that are part of
// Google Test's implementation.
static
const
char
*
const
kElidedFramesMarker
;
private:
private:
Mutex
mutex_
;
// protects all internal state
// We save the stack frame below the frame that calls user code.
// We do this because the address of the frame immediately below
// the user code changes between the call to UponLeavingGTest()
// and any calls to CurrentStackTrace() from within the user code.
void
*
caller_frame_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
OsStackTraceGetter
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
OsStackTraceGetter
);
};
};
...
...
src/gtest.cc
View file @
e7dbfde8
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
// The Google C++ Testing Framework (Google Test)
// The Google C++ Testing Framework (Google Test)
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest-spi.h"
#include <ctype.h>
#include <ctype.h>
...
@@ -789,8 +790,12 @@ int UnitTestImpl::test_to_run_count() const {
...
@@ -789,8 +790,12 @@ int UnitTestImpl::test_to_run_count() const {
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
std
::
string
UnitTestImpl
::
CurrentOsStackTraceExceptTop
(
int
skip_count
)
{
std
::
string
UnitTestImpl
::
CurrentOsStackTraceExceptTop
(
int
skip_count
)
{
(
void
)
skip_count
;
return
os_stack_trace_getter
()
->
CurrentStackTrace
(
return
""
;
static_cast
<
int
>
(
GTEST_FLAG
(
stack_trace_depth
)),
skip_count
+
1
// Skips the user-specified number of frames plus this function
// itself.
);
// NOLINT
}
}
// Returns the current time in milliseconds.
// Returns the current time in milliseconds.
...
@@ -3833,26 +3838,15 @@ ScopedTrace::~ScopedTrace()
...
@@ -3833,26 +3838,15 @@ ScopedTrace::~ScopedTrace()
// class OsStackTraceGetter
// class OsStackTraceGetter
// Returns the current OS stack trace as an std::string. Parameters:
const
char
*
const
OsStackTraceGetterInterface
::
kElidedFramesMarker
=
//
"... "
GTEST_NAME_
" internal frames ..."
;
// max_depth - the maximum number of stack frames to be included
// in the trace.
// skip_count - the number of top frames to be skipped; doesn't count
// against max_depth.
//
string
OsStackTraceGetter
::
CurrentStackTrace
(
int
/* max_depth */
,
int
/* skip_count */
)
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
return
""
;
}
void
OsStackTraceGetter
::
UponLeavingGTest
()
string
OsStackTraceGetter
::
CurrentStackTrace
(
int
/*max_depth*/
,
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
int
/*skip_count*/
)
{
return
""
;
}
}
const
char
*
const
void
OsStackTraceGetter
::
UponLeavingGTest
()
{}
OsStackTraceGetter
::
kElidedFramesMarker
=
"... "
GTEST_NAME_
" internal frames ..."
;
// A helper class that creates the premature-exit file in its
// A helper class that creates the premature-exit file in its
// constructor and deletes the file in its destructor.
// constructor and deletes the file in its destructor.
...
@@ -4907,7 +4901,11 @@ void UnitTestImpl::set_os_stack_trace_getter(
...
@@ -4907,7 +4901,11 @@ void UnitTestImpl::set_os_stack_trace_getter(
// getter, and returns it.
// getter, and returns it.
OsStackTraceGetterInterface
*
UnitTestImpl
::
os_stack_trace_getter
()
{
OsStackTraceGetterInterface
*
UnitTestImpl
::
os_stack_trace_getter
()
{
if
(
os_stack_trace_getter_
==
NULL
)
{
if
(
os_stack_trace_getter_
==
NULL
)
{
#ifdef GTEST_OS_STACK_TRACE_GETTER_
os_stack_trace_getter_
=
new
GTEST_OS_STACK_TRACE_GETTER_
;
#else
os_stack_trace_getter_
=
new
OsStackTraceGetter
;
os_stack_trace_getter_
=
new
OsStackTraceGetter
;
#endif // GTEST_OS_STACK_TRACE_GETTER_
}
}
return
os_stack_trace_getter_
;
return
os_stack_trace_getter_
;
...
...
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