Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fail due to SEGFAULT using GNU 9.3.0 #3506

Closed
langroodi opened this issue Jul 31, 2021 · 4 comments
Closed

Test fail due to SEGFAULT using GNU 9.3.0 #3506

langroodi opened this issue Jul 31, 2021 · 4 comments

Comments

@langroodi
Copy link

I have added a new test to my project as follows which caused a segmentation fault while running 'ctest' command:

    TEST(LoggingFrameworkTest, LogMethod)
    {
        const std::string cAppId{"APP01"};
        const LogMode cLogMode{LogMode::kConsole};
        const std::string cCtxId{"CTX01"};
        const std::string cCtxDescription{"Default Test Context"};
        const LogLevel cLogLevel{LogLevel::kWarn};

        LoggingFramework _loggingFramework =
            LoggingFramework::Create(cAppId, cLogMode); // Calling static factory pattern function

       Logger _logger =
            _loggingFramework.CreateLogger(cCtxId, cCtxDescription);
        
        LogStream _logStream;

        ASSERT_NO_THROW(
            _loggingFramework.Log(_logger, cLogLevel, _logStream));
    }

at this part of the code:

    LoggingFramework LoggingFramework::Create(
        std::string appId,
        LogMode logMode,
        LogLevel logLevel,
        std::string appDescription)
    {
        if (logMode == LogMode::kFile)
        {
            throw std::invalid_argument(
                "File logging mode is not feasible within this constructor override.");
        }

        if (logMode == LogMode::kConsole)
        {
            sink::LogSink *_logSink =
                new sink::ConsoleLogSink(appId, appDescription);
            LoggingFramework _result(_logSink, logLevel); // <-- Error occurs here

            return _result;
        }
        else
        {
            throw std::invalid_argument(
                "The log mode is not currently supported.");
        }
    }

The code has been compiled in the Debug mode via GCC 9.3.0 x86-64 Linux-GNU. I even disabled the PTHREADS using gtest_disable_pthreads option, but it did not solve the issue. Following is the link to my CMakeLists:
https://github.com/langroodi/Adaptive-AUTOSAR/blob/master/CMakeLists.txt

When I changed the compiler type in my pipeline from GCC to Clang 10.0 the issue disappeared. The whole project build workspace is generated by CMake 3.16.

I am still using this commit:
8d51ffd
of Google Test without using any object mocking. So, I am not sure the issue is solved in the newer commit or not. Or maybe there is a error in my code.

If you need more information, I would be happy to provide that.

@langroodi langroodi added the bug label Jul 31, 2021
@asoffer
Copy link
Contributor

asoffer commented Aug 2, 2021

Without seeing the constructor for the LoggingFramework object or the stack trace from the segfault we will not be able to help here. Could you produce a Compiler Explorer link reproducing the issue?

@langroodi
Copy link
Author

Without seeing the constructor for the LoggingFramework object or the stack trace from the segfault we will not be able to help here. Could you produce a Compiler Explorer link reproducing the issue?

This is the LoggingFramework constructor:

LoggingFramework::LoggingFramework(
            sink::LogSink *logSink,
            LogLevel logLevel) : mLogSink{logSink},
                                 mDefaultLogLevel{logLevel}
{
}

in which the member initializer assigns a pointer and sets the mDefaultLogLevel enum class.

Following is also the SEGFAULT stack trace generated by the backtrace function while GCC rdynamic switch was enabled:

Error: signal 11:
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN3ara3log7handlerEi+0x38)[0x5555555d7a7b]
/lib/x86_64-linux-gnu/libc.so.6(+0x46210)[0x7ffff7a8f210]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN3ara3log16LoggingFramework3LogERKNS0_6LoggerENS0_8LogLevelERKNS0_9LogStreamE+0x87)[0x5555555da501]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN3ara3log35LoggingFrameworkTest_LogMethod_Test8TestBodyEv+0x285)[0x5555555d7d53]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc+0x69)[0x555555619314]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc+0x5e)[0x555555611101]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing4Test3RunEv+0xf2)[0x5555555e5a04]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing8TestInfo3RunEv+0x140)[0x5555555e6446]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing9TestSuite3RunEv+0x149)[0x5555555e6d43]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing8internal12UnitTestImpl11RunAllTestsEv+0x457)[0x5555555f67e3]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc+0x69)[0x55555561a842]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc+0x5e)[0x55555561233f]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_ZN7testing8UnitTest3RunEv+0xc4)[0x5555555f4f10]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_Z13RUN_ALL_TESTSv+0x15)[0x5555555d8c56]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(main+0x43)[0x5555555d8bd8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x7ffff7a700b3]
/tmp/Adaptive-AUTOSAR/build/ara_log_test(_start+0x2e)[0x5555555d1c7e]
[1] + Done                       "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-usbfsss4.dmm" 1>"/tmp/Microsoft-MIEngine-Out-sxeofyfd.d4i"

This is also the link to the test file which can be built and executed, but I am not sure that Compiler Explorer can support GTest for reproducing the same situation.

@asoffer
Copy link
Contributor

asoffer commented Aug 9, 2021

The segfault seems to be in the Log member function, which is only passed objects constructed that are not related to googletest, making me think it's likely unrelated to googletest. Given that, I'm going to close this. If you find evidence that the crash is related to googletest, please reopen.

Runing the code with something like Address Sanitizer might be instructive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@asoffer @langroodi and others