#include #include #include

Access violation using boost::log with google test

45 views Asked by At

When I run the following code, I successfully get the "Test Log" printed to the console.

#include <boost/log/trivial.hpp>
#include <boost/log/sources/severity_logger.hpp>

int main()
{
  boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> logger;
  BOOST_LOG_SEV(logger, boost::log::trivial::info) << "Test Log";

  return 0;
}

If I understand correctly this works even though I have not setup any sinks, because boost defaults to sinking to the console if you don't setup any sinks.

When I include this code in a google test project in the same solution I get an access violation. The tests will never pass, but instead reports "unknown file: error: SEH exception with code 0xc0000005 thrown in the test body".

#include "pch.h"
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/trivial.hpp>

TEST(TestCaseName, TestName) {
  EXPECT_EQ(1, 1);
  EXPECT_TRUE(true);
}

TEST(TestCaseName, LogTest1) {
  boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> logger;
  BOOST_LOG_SEV(logger, boost::log::trivial::info) << "Test Log";

  EXPECT_TRUE(true);
}

I am using C++17, visual studio professional 2022, google test, and boost 1.80 downloaded with vcpkg (boost-log:x64-windows, 1.80.0#1).

I would like to know what I can do to avoid the access violation. I have tried setting up dummy sinks and that doesn't work. I have tried setting up a child class for severity logger that does nothing, which works, but would be hard to pass around polymorphically because of the templates boost uses.

I am wondering if this is a common interaction between boost::log and google test? I feel like I am missing something, but I just can't figure out what.

Edit: Here is the debugging info for when I run the debugger on the test.

Breaks on a function called "memmove", line 119 in C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.37.32822\include\xstring

Exception thrown at 0x00007FFD88A01441 (vcruntime140d.dll) in Sample-Test1.exe: 0xC0000005: Access violation writing location 0x000000000000000F.

Stack Trace:

vcruntime140d.dll!00007ffd88a01441()    Unknown
Sample-Test1.exe!std::_Char_traits<char,int>::move(char * const _First1, const char * const _First2, const unsigned __int64 _Count) Line 122    C++
Sample-Test1.exe!std::string::append(const char * const _Ptr, const unsigned __int64 _Count) Line 3276  C++
Sample-Test1.exe!boost::log::v2_mt_nt6::aux::basic_ostringstreambuf<char,std::char_traits<char>,std::allocator<char>>::append(const char * s, unsigned __int64 n) Line 185  C++
Sample-Test1.exe!boost::log::v2_mt_nt6::basic_formatting_ostream<char,std::char_traits<char>,std::allocator<char>>::formatted_write(const char * p, __int64 size) Line 737  C++
Sample-Test1.exe!boost::log::v2_mt_nt6::basic_formatting_ostream<char,std::char_traits<char>,std::allocator<char>>::operator<<(const char * p) Line 441 C++
Sample-Test1.exe!boost::log::v2_mt_nt6::basic_record_ostream<char>::operator<<(const char * p) Line 219 C++
Sample-Test1.exe!TestCaseName_LogTest1_Test::TestBody() Line 12 C++
Sample-Test1.exe!testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test,void>(testing::Test * object, void(testing::Test::*)() method, const char * location) Line 2428    C++
Sample-Test1.exe!testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,void>(testing::Test * object, void(testing::Test::*)() method, const char * location) Line 2479   C++
Sample-Test1.exe!testing::Test::Run() Line 2524 C++
Sample-Test1.exe!testing::TestInfo::Run() Line 2697 C++
Sample-Test1.exe!testing::TestCase::Run() Line 2812 C++
Sample-Test1.exe!testing::internal::UnitTestImpl::RunAllTests() Line 5178   C++
Sample-Test1.exe!testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl,bool>(testing::internal::UnitTestImpl * object, bool(testing::internal::UnitTestImpl::*)() method, const char * location) Line 2428  C++
Sample-Test1.exe!testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl,bool>(testing::internal::UnitTestImpl * object, bool(testing::internal::UnitTestImpl::*)() method, const char * location) Line 2479 C++
Sample-Test1.exe!testing::UnitTest::Run() Line 4786 C++
Sample-Test1.exe!RUN_ALL_TESTS() Line 2342  C++
Sample-Test1.exe!main(int argc, char * * argv) Line 37  C++
Sample-Test1.exe!invoke_main() Line 79  C++
Sample-Test1.exe!__scrt_common_main_seh() Line 288  C++
Sample-Test1.exe!__scrt_common_main() Line 331  C++
Sample-Test1.exe!mainCRTStartup(void * __formal) Line 17    C++
kernel32.dll!00007ffda1727344() Unknown
ntdll.dll!00007ffda25626b1()    Unknown
0

There are 0 answers