Failure in Google UT - unit-testing

[----------] 2 tests from VideoMgrTest
[Blast] Log directory is: C:\ProgramData\VMware\VMware Blast
[ RUN ] VideoMgrTest.createVideoMgr
unknown file: error: SEH exception with code 0xc0000005 thrown in TearDown().
[ FAILED ] VideoMgrTest.createVideoMgr (1 ms)
[ RUN ] VideoMgrTest.getFBAddress
unknown file: error: SEH exception with code 0x5 thrown in the test body.
[ FAILED ] VideoMgrTest.getFBAddress (3 ms)
[----------] 2 tests from VideoMgrTest (8 ms total)
[----------] Global test environment tear-down
[==========] 10 tests from 4 test cases ran. (226 ms total)
[ PASSED ] 8 tests.
[ FAILED ] 2 tests, listed below:
[ FAILED ] VideoMgrTest.createVideoMgr
[ FAILED ] VideoMgrTest.getFBAddress
I am getting a failure in Google UT. I have provided the funtion definition as given below. Ita failing with a SEG exception. I know it is access denied but i dont know what is being acceseed
void VideoMgrTest::TearDown()
{
VideoProducerInstance::DestroyInstance();
mVideoMgr = NULL;
}

Runtime exceptions are hard to pin down, and the code snipped you provided are unfortunately insufficient to be of any help.
If you are using Visual Studio to run your unit tests (e.g. using the google test adapter plugin), remember that you CAN debug those tests and that you can enable the capture of run time exections (they are not captured by default). The answer given to a similar question may be of help to you here.
In any case, if I had to give a guess, I'd suspect that a access of a nullpointer is the source of your troubles.

Related

cygwin_exception::open_stackdumpfile google test

I have read a few topics about errors: cygwin_exception::open_stackdumpfile: Dumping stack trace to program.exe.stackdump
But I can't find something that fits my situation.
This is my project: https://github.com/InzynierDomu/LED_tester
I got error in UT:
Building...
Testing...
[==========] Running 9 tests from 3 test suites.
[----------] Global test environment set-up.
0 [main] program 751 cygwin_exception::open_stackdumpfile: Dumping stack trace to program.exe.stackdump
0 [main] program 751 cygwin_exception::open_stackdumpfile: Dumping stack trace to program.exe.stackdump
[----------] 3 tests from PWM_controller_test
[ RUN ] PWM_controller_test.active
[ OK ] PWM_controller_test.active (0 ms)
[ RUN ] PWM_controller_test.set_pwm_up
================================================================================================================================================================================= [FAILED]
I have very similar test in test/native/Color_tester_controller_test and test/native/PWM_controller_test. The first one works properly, the second not with that test.
TEST_F(PWM_controller_test, set_pwm_up)
{
EXPECT_CALL(hal_mock, set_PWM_output(1));
EXPECT_CALL(view_mock, update_duty());
uut.keyboar_reaction(Cursor_move::up);
}
I stack, and maybe anyone has some idea?
EDIT:
It's only Cygwin gcc problem, on MinGW gcc it's work fine /:

googletest with ctest "Unexpected format: " error

I've a c++ test class implemented using googletest, so it is perfectly passing on Xcode with following output:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from test_fixture
[ RUN ] test_fixture.test_name
[ OK ] test_fixture.test_name (65609 ms)
[----------] 1 test from test_fixture (65609 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (65609 ms total)
[ PASSED ] 1 test.
But when I try to run the same test on terminal by using ctest command it is giving an strange error Unexpected format: with following output:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from test_fixture
[ RUN ] test_fixture.test_name
Unexpected format: [ RUN ] test_fixture.test_name (it is always printing the above line)
<end of output>
Test time = 29.72 sec
For both Xcode and ctest, the same iOS simulator used, I don't understand why the test output giving conclusion as "FAILED" or "PASSED". I've searched a lot for that error and couldn't find any reasonable answers, so please help.
Update:
It has turned out the ios simulator tool ios-sim has a problem with apps that runs longer than 30 secs (I tried with a googletest class with three empty functions which has delay of 15 secs between them, app crashed on second one), simulator crashes the app but didn't find why yet.
It turns out iOS Simulator tool I was using https://github.com/phonegap/ios-sim.
I've emptied our test classes and added 3 test functions with delay of 15 secs between, if the app runs longer than 30 seconds, ios-sim crashes it.
The solution for this case is to use real devices with the similar project: https://github.com/phonegap/ios-deploy

How to have Eclipse console show the same GoogleTests output as in the terminal?

I use GoogleTest extensively and the output in the cosole looks like this:
When I run the same from within Eclipse (using Eclipse Mars latest as of today) I get the following output with no colors and junk characters (are not visible just pasting the output here):
Running main() from gtest_main.cc
[0;32m[==========] [mRunning 3 tests from 1 test case.
[0;32m[----------] [mGlobal test environment set-up.
[0;32m[----------] [m3 tests from NloptAdapterSuite
[0;32m[ RUN ] [mNloptAdapterSuite.testQuadraticFunction1
[0;32m[ OK ] [mNloptAdapterSuite.testQuadraticFunction1 (1 ms)
[0;32m[ RUN ] [mNloptAdapterSuite.testQuadraticFunction1WithNoise
[0;32m[ OK ] [mNloptAdapterSuite.testQuadraticFunction1WithNoise (1 ms)
[0;32m[ RUN ] [mNloptAdapterSuite.testQuadraticFunction2
[0;32m[ OK ] [mNloptAdapterSuite.testQuadraticFunction2 (1 ms)
[0;32m[----------] [m3 tests from NloptAdapterSuite (3 ms total)
[0;32m[----------] [mGlobal test environment tear-down
[0;32m[==========] [m3 tests from 1 test case ran. (3 ms total)
[0;32m[ PASSED ] [m3 tests.
How can this be fixed to have the same output?
The ANSI Escape in Console plugin that greg-449 linked above worked great for me. After installing it, the gtest output looks like:
I'm on Neon.2 (Eclipse 4.6.2).

Why is Google Test segfaulting?

I'm new to Google Test and I'm playing around with the provided examples. My issue is, when I introduce a failure and set GTEST_BREAK_ON_FAILURE=1 (or use the command line option), GTest will segfault.
I am considering this example. If I insert something like this into any of the tests, I will start to get the segfault:
EXPECT_EQ(8, 2*3);
Just to reiterate, that is only when I have also set GTEST_BREAK_ON_FAILURE=1. I have run from the command line and also with gdb. If that environment variable is not set, it reports the error but does not segfault.
Any clue to what could be causing this/what I am doing wrong? I've been looking for a similar issue, but I haven't run into anything yet.
FYI I am using Google Test version 1.7.0 running on 64 bit CrunchBang Linux 11 "Waldorf".
edit code sample:
// Tests factorial of positive numbers.
TEST(FactorialTest, Positive) {
EXPECT_EQ(1, Factorial(1));
EXPECT_EQ(2, Factorial(2));
EXPECT_EQ(6, Factorial(3));
EXPECT_EQ(40320, Factorial(8));
}
Debugger output:
(gdb) run
Starting program: /home/yourfavoriteprotein/bin/cpp_unit_test_frameworks/gtest-1.7.0/samples/mytest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Running main() from test_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
[ RUN ] FactorialTest.Negative
[ OK ] FactorialTest.Negative (0 ms)
[ RUN ] FactorialTest.Zero
[ OK ] FactorialTest.Zero (0 ms)
[ RUN ] FactorialTest.Positive
sample1_unittest.cc:112: Failure
Value of: 2*3
Actual: 6
Expected: 8
Program received signal SIGSEGV, Segmentation fault.
0x0000000000413427 in testing::UnitTest::AddTestPartResult(testing::TestPartResult::Type, char const*, int, std::string const&, std::string const&) ()
(gdb) quit
GTEST_BREAK_ON_FAILURE=1 means that Google Test drops you into the debugger if a test fails.
It so happens that an easy, portable way to drop you into the debugger is to trigger a segfault.
In other words, this behavior is by design; Google Test deliberately triggers a segfault to make the debugger run. (See here in the Google Test code.)

Google Test not resetting old tests

I'm running into this weird problem with Google Test using Visual Studio 2012. I can successfully set up tests and they run just fine. However, when I make change to any code in the test project and build the project, I receive LNK2005 errors, like this one:
Error 3 error LNK2005: "private: virtual void __thiscall writeStreamTest_writeRandomDouble_Test::TestBody(void)" (?TestBody#writeStreamTest_writeRandomDouble_Test##EAEXXZ) already defined in UtilsTest.obj C:\Users\cye\Desktop\codeCPP\unitTest\unitTest.obj unitTest
However, when I change the name of the test, the test runs fine again. But it not only runs the tests after the name change, but also the tests with the old names. Like this:
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from writeStreamTest
[ RUN ] writeStreamTest.writeRandomDouble
[ OK ] writeStreamTest.writeRandomDouble (0 ms)
[ RUN ] writeStreamTest.writeRandomInt
[ OK ] writeStreamTest.writeRandomInt (0 ms)
[ RUN ] writeStreamTest.writeRandomDouble2
[ OK ] writeStreamTest.writeRandomDouble2 (0 ms)
[ RUN ] writeStreamTest.writeRandomInt2
[ OK ] writeStreamTest.writeRandomInt2 (0 ms)
[----------] 4 tests from writeStreamTest (3 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran. (5 ms total)
[ PASSED ] 4 tests.
It appears that the tests that were included in the last build would be left over. Therefore when I build the code with the same test name, compiler would complaint that the test with the same name already exists.
If I try to comment out all the tests, then call RUN_ALL_TESTS(), the tests that were included in the last build would still run. If I make change and build again, no test will run.
I'm very confused about this issue. Even after I clean and rebuild the project this issue would still occur.
Anyone else ran into this problem before? Thanks very much!