aborting google test execution

2,232 views
Skip to first unread message

ben

unread,
Apr 26, 2011, 5:46:07 PM4/26/11
to Google C++ Testing Framework
Hi, I run about 800 tests and I would like to know how to terminate
the gtest execution. If I do Control-C it would only skip the current
executed test and will pass to the next so I would like to know if it
catches any other signal that you can send from the keyboard to abort
the following tests.

I can do Ctrl-Z and then kill it but I am looking for a better way to
do it.

Thanks!

Vlad Losev

unread,
Apr 28, 2011, 12:33:08 PM4/28/11
to ben, Google C++ Testing Framework
Hi ben,

The tests should be perfectly interruptible. Are you running them from some kind of script? What OS are you using?


Thanks!

- Vlad

Benjamin

unread,
Apr 28, 2011, 2:31:20 PM4/28/11
to Vlad Losev, Google C++ Testing Framework
I run directly the gtest executable in RHEL 6 and Suse, no script is involved so if I do --gtest_list_tests I get a number of tests, when I run it:

$ ./gtest-unit 
...
[ RUN ] Test_Case.Test1
[ OK ] Test_Case.Test1 (10 ms) 
[ RUN ] Test_Case.Test2 
[ OK ] Test_Case.Test2(10 ms)
....

So what's currently happening is that if I do Ctr-c on Test1 it passes to execute Test2. What I am expecting is to have a way to let gtest know on any given test that it should abort executing the remaining tests and go directly to the global tear-down.

Is that possible?

Benjamin

2011/4/28 Vlad Losev <vl...@losev.com>

Vlad Losev

unread,
Apr 28, 2011, 2:42:25 PM4/28/11
to Benjamin, Google C++ Testing Framework
Does gtest report a failure in the test you interrupt? If so, my wild guess is that some code in the test binary converts SIGINT into a C++ exception. gtest is converting uncaught C++  exceptions into failures. Try running your test with --gtest_catch_exceptions=0 to see if that is the case.

Benjamin

unread,
Apr 28, 2011, 3:11:02 PM4/28/11
to Vlad Losev, Google C++ Testing Framework
Just ran what you recommended.

Using --gtest_catch_exceptions=0 and then ctr-c causes the current executed test to fail, if I leave ctr-c until all tests exited, I get all exited tests failed.
Not using --gtest_catch_exceptions behaves exactly the same. 

2011/4/28 Vlad Losev <vl...@losev.com>

Benjamin

unread,
Apr 28, 2011, 3:22:24 PM4/28/11
to Vlad Losev, Google C++ Testing Framework
Just to give you some more info, each gtest does a system() call to a python script.

2011/4/28 Vlad Losev <vl...@losev.com>

Vlad Losev

unread,
Apr 28, 2011, 3:58:37 PM4/28/11
to Benjamin, Google C++ Testing Framework
That is the reason. While you are in the system() call, SIGINT is ignored. 'man system' give info on how to deal with that.

Benjamin

unread,
Apr 28, 2011, 4:09:11 PM4/28/11
to Vlad Losev, Google C++ Testing Framework
thanks a lot!

the man system part describing how to start dealing with it:

As mentioned, system() ignores SIGINT and SIGQUIT. This may make programs that call it from a loop uninterruptible, unless they take care themselves to check the exit status of the child. E.g.

while(something) {
    int ret = system("foo");
    if (WIFSIGNALED(ret) &&
        (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
            break;

2011/4/28 Vlad Losev <vl...@losev.com>
Reply all
Reply to author
Forward
0 new messages