Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 629620 - dev-cpp/gtest-1.8.0 : 20/60 Test #20: gtest-death-test_test ...................***Failed 0.07 sec
Summary: dev-cpp/gtest-1.8.0 : 20/60 Test #20: gtest-death-test_test ....................
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Peter Levine
URL:
Whiteboard:
Keywords: Bug, TESTFAILURE, UPSTREAM
Depends on:
Blocks:
 
Reported: 2017-09-02 08:11 UTC by Toralf Förster
Modified: 2024-01-27 10:47 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge-info.txt (emerge-info.txt,14.54 KB, text/plain)
2017-09-02 08:11 UTC, Toralf Förster
Details
dev-cpp:gtest-1.8.0:20170831-213105.log (dev-cpp:gtest-1.8.0:20170831-213105.log,325.34 KB, text/plain)
2017-09-02 08:11 UTC, Toralf Förster
Details
emerge-history.txt (emerge-history.txt,23.76 KB, text/plain)
2017-09-02 08:11 UTC, Toralf Förster
Details
environment (environment,168.75 KB, text/plain)
2017-09-02 08:11 UTC, Toralf Förster
Details
etc.portage.tbz2 (etc.portage.tbz2,11.64 KB, application/x-bzip)
2017-09-02 08:11 UTC, Toralf Förster
Details
LastTest.log.bz2 (LastTest.log.bz2,55.41 KB, application/x-bzip)
2017-09-02 08:11 UTC, Toralf Förster
Details
logs.tbz2 (logs.tbz2,60.68 KB, application/x-bzip)
2017-09-02 08:11 UTC, Toralf Förster
Details
temp.tbz2 (temp.tbz2,48.17 KB, application/x-bzip)
2017-09-02 08:11 UTC, Toralf Förster
Details
tests.tbz2 (tests.tbz2,56.35 KB, application/x-bzip)
2017-09-02 08:11 UTC, Toralf Förster
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Toralf Förster gentoo-dev 2017-09-02 08:11:02 UTC
19/60 Test #19: gmock_no_rtti_test ......................   Passed    0.02 sec
      Start 20: gtest-death-test_test
20/60 Test #20: gtest-death-test_test ...................***Failed    0.07 sec
      Start 21: gtest_environment_test
21/60 Test #21: gtest_environment_test ..................   Passed    0.01 sec
      Start 22: gtest-filepath_test

  -------------------------------------------------------------------

  This is an unstable amd64 chroot image at a tinderbox (==build bot)
  name: 13.0-desktop_20170828-210912

  -------------------------------------------------------------------

gcc-config -l:
 [1] x86_64-pc-linux-gnu-6.4.0 *

Available Python interpreters, in order of preference:
  [1]   python3.4
  [2]   python2.7 (fallback)




emerge -qpv dev-cpp/gtest
[ebuild  N    ] dev-cpp/gtest-1.8.0  USE="-examples {-test}" ABI_X86="(64) -32 (-x32)"
Comment 1 Toralf Förster gentoo-dev 2017-09-02 08:11:05 UTC
Created attachment 491614 [details]
emerge-info.txt
Comment 2 Toralf Förster gentoo-dev 2017-09-02 08:11:08 UTC
Created attachment 491616 [details]
dev-cpp:gtest-1.8.0:20170831-213105.log
Comment 3 Toralf Förster gentoo-dev 2017-09-02 08:11:12 UTC
Created attachment 491618 [details]
emerge-history.txt
Comment 4 Toralf Förster gentoo-dev 2017-09-02 08:11:15 UTC
Created attachment 491620 [details]
environment
Comment 5 Toralf Förster gentoo-dev 2017-09-02 08:11:19 UTC
Created attachment 491622 [details]
etc.portage.tbz2
Comment 6 Toralf Förster gentoo-dev 2017-09-02 08:11:22 UTC
Created attachment 491624 [details]
LastTest.log.bz2
Comment 7 Toralf Förster gentoo-dev 2017-09-02 08:11:25 UTC
Created attachment 491626 [details]
logs.tbz2
Comment 8 Toralf Förster gentoo-dev 2017-09-02 08:11:29 UTC
Created attachment 491628 [details]
temp.tbz2
Comment 9 Toralf Förster gentoo-dev 2017-09-02 08:11:32 UTC
Created attachment 491630 [details]
tests.tbz2
Comment 10 Peter Levine 2017-09-03 00:18:31 UTC
(In reply to Toralf Förster from comment #0)
> 19/60 Test #19: gmock_no_rtti_test ......................   Passed    0.02
> sec
>       Start 20: gtest-death-test_test
> 20/60 Test #20: gtest-death-test_test ...................***Failed    0.07
> sec
>       Start 21: gtest_environment_test
> 21/60 Test #21: gtest_environment_test ..................   Passed    0.01
> sec
>       Start 22: gtest-filepath_test

Thanks for the report.  I'm finally able to reproduce this.  It only seems to occur on my end when running portage over the network and with usersandbox enabled in FEATURES.
Comment 11 Peter Levine 2017-09-03 00:41:53 UTC
gtest-death-tes[22872]: segfault at 7fb6c2475d58 ip 00007fb6c20ceb37 sp 00007fb6c2475d50 error 6 in libsandbox.so[7fb6c20ca000+13000](In reply to Peter Levine from comment #10)
> (In reply to Toralf Förster from comment #0)
> > 19/60 Test #19: gmock_no_rtti_test ......................   Passed    0.02
> > sec
> >       Start 20: gtest-death-test_test
> > 20/60 Test #20: gtest-death-test_test ...................***Failed    0.07
> > sec
> >       Start 21: gtest_environment_test
> > 21/60 Test #21: gtest_environment_test ..................   Passed    0.01
> > sec
> >       Start 22: gtest-filepath_test
> 
> Thanks for the report.  I'm finally able to reproduce this.  It only seems
> to occur on my end when running portage over the network and with
> usersandbox enabled in FEATURES.

And from dmesg:

gtest-death-tes[22872]: segfault at 7fb6c2475d58 ip 00007fb6c20ceb37 sp 00007fb6c2475d50 error 6 in libsandbox.so[7fb6c20ca000+13000]
Comment 12 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2017-09-03 07:21:52 UTC
Peter, I suppose you're familiar with gdb? ;-) Given sandbox is mostly unmaintained, it would be nice if you could try to see where it fails and if it's implementation fault or just stupid code upstream.
Comment 13 Peter Levine 2017-09-03 08:17:45 UTC
PR: https://github.com/gentoo/gentoo/pull/5605
Comment 14 Peter Levine 2017-09-04 08:42:34 UTC
(In reply to Michał Górny from comment #12)
> Peter, I suppose you're familiar with gdb? ;-) Given sandbox is mostly
> unmaintained, it would be nice if you could try to see where it fails and if
> it's implementation fault or just stupid code upstream.

I have limited experience with gdb.  I'm not that familiar with the inner workings of sandbox.  I understand that it works via LD_PRELOAD to handle system calls.

I have been testing a single test with GDB over SSH via:

> GTEST_BREAK_ON_FAILURE=1 gdb --args /var/tmp/portage/dev-cpp/gtest-1.8.0/work/googletest-release-1.8.0-abi_x86_64.amd64/googlemock/gtest/gtest-death-test_test --gtest_filter="*ThreadsafeDeathTestInChangedDir*"

When I set

> set environment LD_PRELOAD=/usr/lib/libsandbox.so

in GDB it triggers test failure, and when omitted the test succeeds.

When 'testing::GTEST_FLAG(death_test_style)' is set to "threadsafe", death tests are implemented as a call to 'clone()' which then executes the single test via 'execve()'.  Looking at strace output, it seems that where there is a supposed to be a call to 'execve()', in the sandboxed test, there is a segfault.

In the coming few days I'll try to use GDB to narrow down the problem.
Comment 15 Peter Levine 2017-09-25 07:07:30 UTC

(In reply to Peter Levine from comment #10)
> It only seems
> to occur on my end when running portage over the network and with
> usersandbox enabled in FEATURES.

Actually, it seems to just be related to usersandbox.


After further inspection with GDB, I can observe the problem but am not quite sure what's causing it.  When running 

> GTEST_BREAK_ON_FAILURE=1 gdb --args /var/tmp/portage/dev-cpp/gtest-1.8.0/work/googletest-release-1.8.0-abi_x86_64.amd64/googlemock/gtest/gtest-death-test_test --gtest_filter=TestForDeathTest.ThreadsafeDeathTestInChangedDir

and setting 

> set follow-fork-mode child

it shows that 'clone()' is called to spawn another thread, which then calls 'execve()' with arguments to run itself in non-threaded mode.  If run in a sandbox shell, by the time it gets to 'before_syscall()' (in libsandbox.c) and initializes the stack array 'char at_file_buf[SB_PATH_MAX]' (which is 8192 bytes on my system), 'at_file_buf' can't be accessed.  `print at_file_buf` in gdb prints "Cannot access memory at address 0x7fdcf94c9de0".  And indeed, that memory is not a valid memory location on the process' virtual memory map.  Its stack is located at '7ffffffdd000-7ffffffff000' so it doesn't look like a stack overflow.

I'll continue to try and debug further.
Comment 16 Peter Levine 2017-09-25 08:19:06 UTC
OK.

It appears that the memory from mmap() to be use as the child's stack with clone() is way to small.  It's the size of a page (4032 bytes on my end).  Indeed, the address of the stack array causing the segfault is within a page away from the stack's end.  I presume that it's so small because clone() only has to execute one routine with the call to execve().  But the sandbox wrapper environment clearly requires much more stack space.  After editing the stack size to something more sane like 139264, compile, and test, all tests pass even in sandbox.

I'll submit a bug report to gtest in the next couple of days.
Comment 17 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2017-09-25 11:00:00 UTC
You may also want to try a newer (masked) sandbox version if you haven't done that already.
Comment 18 Peter Levine 2017-09-25 18:47:53 UTC
(In reply to Michał Górny from comment #17)
> You may also want to try a newer (masked) sandbox version if you haven't
> done that already.

I've tried both sandbox-2.11-r5 and sandbox-2.10-r4.

Upstream PR:

https://github.com/google/googletest/pull/1274
Comment 19 Peter Levine 2017-11-19 22:28:44 UTC
@Michał Górny

Please take a look at the PR at  https://github.com/gentoo/gentoo/pull/5605 when you get a chance.  I've been adding to it.  Upstream will likely take forever with this.  They may decide not to even fix this on their end, as it might be their opinion that they shouldn't have to alter their thread's stacksize for a downstream wrapper function.  In that case, I could simply maintain the patch downstream or, if it comes to it, alter libsandbox's execve wrapper function to immediately fork its own thread with ample stackspace at invocation.
Comment 20 Larry the Git Cow gentoo-dev 2018-01-09 16:12:37 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c611133fd67da12a870fb9a64c8e8ae298df0e42

commit c611133fd67da12a870fb9a64c8e8ae298df0e42
Author:     Peter Levine <plevine457@gmail.com>
AuthorDate: 2017-09-25 21:37:13 +0000
Commit:     Mike Gilbert <floppym@gentoo.org>
CommitDate: 2018-01-09 16:10:00 +0000

    dev-cpp/gtest: Fix test failure with sandbox
    
    Bug: https://bugs.gentoo.org/629620
    Package-Manager: Portage-2.3.6, Repoman-2.3.2

 .../files/gtest-1.8.0-increase-clone-stack-size.patch      | 14 ++++++++++++++
 dev-cpp/gtest/gtest-1.8.0.ebuild                           |  1 +
 dev-cpp/gtest/gtest-9999.ebuild                            |  1 +
 3 files changed, 16 insertions(+)}