Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/boost/test/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
namespace boost {
namespace debug {

#ifdef BOOST_TEST_HAS_DEBUG_SUPPORT

// ************************************************************************** //
// ************** check if program is running under debugger ************** //
// ************************************************************************** //
Expand Down Expand Up @@ -71,6 +73,8 @@ std::string BOOST_TEST_DECL set_debugger( unit_test::const_string dbg_id, dbg_st

bool BOOST_TEST_DECL attach_debugger( bool break_or_continue = true );

#endif

// ************************************************************************** //
// ************** switch on/off detect memory leaks feature ************** //
// ************************************************************************** //
Expand Down
9 changes: 9 additions & 0 deletions include/boost/test/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// Boost
#include <boost/config.hpp> // compilers workarounds
#include <boost/predef.h>
#include <boost/detail/workaround.hpp>

#if defined(_WIN32) && !defined(BOOST_DISABLE_WIN32) && \
Expand Down Expand Up @@ -120,4 +121,12 @@ class type_info;
#define BOOST_PP_VARIADICS 1
#endif

// Used to turn on/off debugging support.
#define BOOST_TEST_HAS_DEBUG_SUPPORT
// Under Windows Runtime (WinRT) accessing registry, creating processes, etc..
// are not supported so turn off debugging support.
#if BOOST_PLAT_WINDOWS_RUNTIME
#undef BOOST_TEST_HAS_DEBUG_SUPPORT
#endif

#endif // BOOST_TEST_CONFIG_HPP_071894GER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to add definitions like

#if !defined(UNDER_CE) && !BOOST_PLAT_WINDOWS_RUNTIME
  #define BOOST_TEST_HAS_GETENV_SUPPORT
  #define BOOST_TEST_HAS_SETENV_SUPPORT  
#endif 

and then to propagate these macros in the code, like in cpp_main.cpp

12 changes: 10 additions & 2 deletions include/boost/test/impl/cpp_main.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// Boost
#include <boost/cstdlib.hpp> // for exit codes
#include <boost/config.hpp> // for workarounds
#include <boost/predef/platform.h>

// STL
#include <iostream>
Expand Down Expand Up @@ -69,7 +70,11 @@ prg_exec_monitor_main( int (*cpp_main)( int argc, char* argv[] ), int argc, char
int result = 0;

try {
boost::unit_test::const_string p( std::getenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS" ) );
boost::unit_test::const_string p;
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be

#if defined(BOOST_TEST_HAS_GETENV_SUPPORT)

to enable the functionality on all platforms except the ones that do not support the environment variables (CE + winRT). What do you think?

p = std::getenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS" );
#endif

::boost::execution_monitor ex_mon;

ex_mon.p_catch_system_errors.value = p != "no";
Expand Down Expand Up @@ -102,7 +107,10 @@ prg_exec_monitor_main( int (*cpp_main)( int argc, char* argv[] ), int argc, char
// like the clutter. Use an environment variable to avoid command
// line argument modifications; for use in production programs
// that's a no-no in some organizations.
::boost::unit_test::const_string p( std::getenv( "BOOST_PRG_MON_CONFIRM" ) );
::boost::unit_test::const_string p;
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same remark here)

p = std::getenv( "BOOST_PRG_MON_CONFIRM" );
#endif
if( p != "no" ) {
std::cerr << std::flush << "no errors detected" << std::endl;
}
Expand Down
10 changes: 8 additions & 2 deletions include/boost/test/impl/debug.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boost/test/debug.hpp>
#include <boost/test/debug_config.hpp>
#include <boost/predef/platform.h>

// Implementation on Windows
#if defined(_WIN32) && !defined(UNDER_CE) && !defined(BOOST_DISABLE_WIN32) // ******* WIN32
Expand All @@ -30,7 +31,9 @@

// SYSTEM API
# include <windows.h>
# if !BOOST_PLAT_WINDOWS_RUNTIME
# include <winreg.h>
# endif
# include <cstdio>
# include <cstring>

Expand Down Expand Up @@ -113,6 +116,8 @@ namespace debug {

using unit_test::const_string;

#ifdef BOOST_TEST_HAS_DEBUG_SUPPORT

// ************************************************************************** //
// ************** debug::info_t ************** //
// ************************************************************************** //
Expand Down Expand Up @@ -913,6 +918,8 @@ attach_debugger( bool break_or_continue )

//____________________________________________________________________________//

#endif // BOOST_TEST_HAS_DEBUG_SUPPORT

// ************************************************************************** //
// ************** switch on/off detect memory leaks feature ************** //
// ************************************************************************** //
Expand All @@ -934,8 +941,7 @@ detect_memory_leaks( bool on_off, unit_test::const_string report_file )
if( report_file.is_empty() )
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
else {
HANDLE hreport_f = ::CreateFileA( report_file.begin(),
GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hreport_f = ::fopen(report_file.begin(), "w");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing this? Is the memory leak detection available on winRT?

_CrtSetReportFile(_CRT_WARN, hreport_f );
}
}
Expand Down
2 changes: 2 additions & 0 deletions include/boost/test/impl/exception_safety.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,10 @@ exception_safety_tester::assertion_result( unit_test::assertion_result ar )
void
exception_safety_tester::failure_point()
{
#ifdef BOOST_TEST_HAS_DEBUG_SUPPORT
if( m_exec_path_counter == m_break_exec_path )
debug::debugger_break();
#endif

throw unique_exception();
}
Expand Down
13 changes: 11 additions & 2 deletions include/boost/test/impl/execution_monitor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,12 @@ static void boost_execution_monitor_jumping_signal_handler( int sig, siginfo_t*

static void boost_execution_monitor_attaching_signal_handler( int sig, siginfo_t* info, void* context )
{
if( !debug::attach_debugger( false ) )
bool successfully_attached = false;
#ifdef BOOST_TEST_HAS_DEBUG_SUPPORT
successfully_attached = debug::attach_debugger( false );
#endif

if( !successfully_attached )
boost_execution_monitor_jumping_signal_handler( sig, info, context );

// debugger attached; it will handle the signal
Expand Down Expand Up @@ -930,13 +935,15 @@ system_signal_exception::operator()( unsigned int id, _EXCEPTION_POINTERS* exps
}
}

#ifdef BOOST_TEST_HAS_DEBUG_SUPPORT
if( !!m_em->p_auto_start_dbg && debug::attach_debugger( false ) ) {
m_em->p_catch_system_errors.value = false;
#if BOOST_WORKAROUND( BOOST_MSVC, <= 1310)
_set_se_translator( &seh_catch_preventer );
#endif
return EXCEPTION_CONTINUE_EXECUTION;
}
#endif

m_se_id = id;
if( m_se_id == EXCEPTION_ACCESS_VIOLATION && exps->ExceptionRecord->NumberParameters == 2 ) {
Expand Down Expand Up @@ -1173,9 +1180,11 @@ execution_monitor::execution_monitor()
int
execution_monitor::execute( boost::function<int ()> const& F )
{
#ifdef BOOST_TEST_HAS_DEBUG_SUPPORT
if( debug::under_debugger() )
p_catch_system_errors.value = false;

#endif

try {
detail::fpe_except_guard G( p_detect_fp_exceptions );
unit_test::ut_detail::ignore_unused_variable_warning( G );
Expand Down
24 changes: 14 additions & 10 deletions include/boost/test/impl/unit_test_parameters.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define BOOST_TEST_UNIT_TEST_PARAMETERS_IPP_012205GER

// Boost.Test

#include <boost/test/unit_test_parameters.hpp>
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <boost/test/utils/basic_cstring/compare.hpp>
Expand All @@ -32,17 +31,9 @@
#include <boost/test/utils/runtime/cla/dual_name_parameter.hpp>
#include <boost/test/utils/runtime/cla/parser.hpp>

namespace rt = boost::runtime;
namespace cla = rt::cla;

#ifndef UNDER_CE
#include <boost/test/utils/runtime/env/variable.hpp>

namespace env = rt::env;
#endif

// Boost
#include <boost/config.hpp>
#include <boost/predef/platform.h>
#include <boost/test/detail/suppress_warnings.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/test/detail/enable_warnings.hpp>
Expand All @@ -53,6 +44,17 @@ namespace env = rt::env;
#include <iostream>
#include <fstream>

namespace rt = boost::runtime;
namespace cla = rt::cla;

#ifndef UNDER_CE
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this last line is erroneous, since we want the environment variable support on eg linux or OSX. Could be replaced by

#if defined(BOOST_TEST_HAS_GETENV_SUPPORT) || defined(BOOST_TEST_HAS_SETENV_SUPPORT)

?

#include <boost/test/utils/runtime/env/variable.hpp>

namespace env = rt::env;
#endif
#endif

#include <boost/test/detail/suppress_warnings.hpp>

//____________________________________________________________________________//
Expand Down Expand Up @@ -244,7 +246,9 @@ retrieve_parameter( const_string parameter_name, cla::parser const& s_cla_parser
boost::optional<T> v;

#ifndef UNDER_CE
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same remark as for line 74 in file cpp_main.ipp

env::get( parameter_2_env_var(parameter_name), v );
#endif
#endif

if( v )
Expand Down
9 changes: 9 additions & 0 deletions include/boost/test/utils/runtime/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// Boost
#include <boost/config.hpp>
#include <boost/predef/platform.h>
#ifdef BOOST_MSVC
# pragma warning(disable: 4511) // copy constructor could not be generated
# pragma warning(disable: 4512) // assignment operator could not be generated
Expand Down Expand Up @@ -77,6 +78,7 @@ extern "C" int putenv( const char * );
#endif

#ifndef UNDER_CE
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be

#if !defined(UNDER_CE) && !BOOST_PLAT_WINDOWS_RUNTIME

instead? Could be also replaced by

#if defined(BOOST_TEST_HAS_SETENV_SUPPORT)

What do you think?

#if defined(__COMO__) && 0
inline void
putenv_impl( cstring name, cstring value )
Expand All @@ -100,15 +102,18 @@ putenv_impl( cstring name, cstring value )
}
#endif
#endif
#endif

#ifdef BOOST_MSVC
#pragma warning(pop)
#endif

#define BOOST_RT_PARAM_LITERAL( l ) l
#define BOOST_RT_PARAM_CSTRING_LITERAL( l ) cstring( l, sizeof( l ) - 1 )
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean

#if defined(BOOST_TEST_HAS_GETENV_SUPPORT)
#define BOOST_RT_PARAM_GETENV getenv
#endif

#if defined(BOOST_TEST_HAS_SETENV_SUPPORT)
#define BOOST_RT_PARAM_PUTENV ::boost::BOOST_RT_PARAM_NAMESPACE::putenv_impl
#endif

?

#define BOOST_RT_PARAM_GETENV getenv
#define BOOST_RT_PARAM_PUTENV ::boost::BOOST_RT_PARAM_NAMESPACE::putenv_impl
#endif
#define BOOST_RT_PARAM_EXCEPTION_INHERIT_STD

//____________________________________________________________________________//
Expand All @@ -123,6 +128,7 @@ typedef wrap_wstringstream format_stream;
typedef std::wostream out_stream;

#ifndef UNDER_CE
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same remark as line 81 here

inline void
putenv_impl( cstring name, cstring value )
{
Expand All @@ -136,11 +142,14 @@ putenv_impl( cstring name, cstring value )
wputenv( const_cast<wchar_t*>( fs.str().c_str() ) );
}
#endif
#endif

#define BOOST_RT_PARAM_LITERAL( l ) L ## l
#define BOOST_RT_PARAM_CSTRING_LITERAL( l ) cstring( L ## l, sizeof( L ## l )/sizeof(wchar_t) - 1 )
#if BOOST_PLAT_WINDOWS_DESKTOP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same remark as line 121 here

#define BOOST_RT_PARAM_GETENV wgetenv
#define BOOST_RT_PARAM_PUTENV putenv_impl
#endif

# endif
#endif
Expand Down
7 changes: 7 additions & 0 deletions include/boost/test/utils/runtime/env/environment.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// (C) Copyright Gennadiy Rozental 2005-2012.
// (C) Copyright Microsoft Corporation 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
Expand All @@ -15,10 +16,16 @@
#ifndef BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER
#define BOOST_RT_ENV_ENVIRONMENT_HPP_062604GER

#include <boost/predef/platform.h>

#ifdef UNDER_CE
#error Windows CE does not support environment variables.
#endif

#if BOOST_PLAT_WINDOWS_RUNTIME
#error Windows Runtime does not support environment variables.
#endif

// Boost.Runtime.Parameter
#include <boost/test/utils/runtime/config.hpp>
#include <boost/test/utils/runtime/fwd.hpp>
Expand Down
7 changes: 7 additions & 0 deletions include/boost/test/utils/runtime/env/variable.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// (C) Copyright Gennadiy Rozental 2005-2012.
// (C) Copyright Microsoft Corporation 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
Expand All @@ -15,10 +16,16 @@
#ifndef BOOST_RT_ENV_VARIABLE_HPP_062604GER
#define BOOST_RT_ENV_VARIABLE_HPP_062604GER

#include <boost/predef/platform.h>

#ifdef UNDER_CE
#error Windows CE does not support environment variables.
#endif

#if BOOST_PLAT_WINDOWS_RUNTIME
#error Windows Runtime does not support environment variables.
#endif

// Boost.Runtime.Parameter
#include <boost/test/utils/runtime/config.hpp>
#include <boost/test/utils/runtime/fwd.hpp>
Expand Down