Bug 202304

Summary: test lib/libutil/pidfile_test:main hangs on many non-x86 platforms
Product: Base System Reporter: Ed Maste <emaste>
Component: testsAssignee: freebsd-testing (Nobody) <testing>
Status: Closed FIXED    
Severity: Affects Some People CC: Andrew, bas.bossink+freebsd, br, brooks, op
Priority: ---    
Version: CURRENT   
Hardware: arm64   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202305
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202307
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=228492
Bug Depends on:    
Bug Blocks: 203349    

Description Ed Maste freebsd_committer freebsd_triage 2015-08-13 18:31:20 UTC
In QEMU; uname -a:
FreeBSD  11.0-CURRENT FreeBSD 11.0-CURRENT #10 r286123+5231893(arm64-submit.3)-dirty: Wed Aug 12 19:43:04 EDT 2015     emaste@feynman:/tank/emaste/obj/arm64.aarch64/tank/emaste/src/freebsd-arm64/sys/GENERIC  arm64

root@:/usr/tests # kyua test lib/libutil
lib/libutil/flopen_test:main  ->  passed  [0.190s]
lib/libutil/grp_test:main  ->  passed  [0.172s]
lib/libutil/humanize_number_test:main  ->  passed  [0.315s]
lib/libutil/pidfile_test:main  ->  [hangs]

the test binary itself works:

root@:/usr/tests # lib/libutil/pidfile_test
1..4
ok 1 - pidfile_uncontested
ok 2 - pidfile_self
ok 3 - pidfile_contested
ok 4 - pidfile_inherited
root@:/usr/tests #
Comment 1 commit-hook freebsd_committer freebsd_triage 2015-08-17 23:19:50 UTC
A commit references this bug:

Author: emaste
Date: Mon Aug 17 23:19:37 UTC 2015
New revision: 286863
URL: https://svnweb.freebsd.org/changeset/base/286863

Log:
  On arm64 disable three tests that hang or panic

  Each issue has a PR open to track. This workaround allows us to run the
  tests to investigate the failures and avoid any new regressions.

  PR:		202304, 202305, 202307
  Reviewed by:	ngie
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D3378

Changes:
  head/lib/libc/tests/sys/Makefile
  head/lib/libproc/tests/proc_test.c
  head/lib/libutil/tests/Makefile
Comment 2 Ed Maste freebsd_committer freebsd_triage 2015-08-31 20:38:47 UTC
It has been reported that this issue affects 32-bit arm as well.
Comment 3 Brooks Davis freebsd_committer freebsd_triage 2016-05-18 21:44:15 UTC
This also occurs on mips64 in QEMU.
Comment 4 Bas Bossink 2016-07-22 23:33:27 UTC
In virtualbox; uname -a:
FreeBSD fb11 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r303113: Thu Jul 21 22:42:16 CEST 2016    bas@fb11:/usr/obj/usr/src/sys/GENERIC  amd64

This problem also occurs only when executing the test program using kyua.
When using the debugger to see where the test executable is hanging, it reveals:
--
(lldb) bt
* thread #1: tid = 100089, 0x0000000800b8e3ea libc.so.7`_select + 10
  * frame #0: 0x0000000800b8e3ea libc.so.7`_select + 10
    frame #1: 0x00000000004012f8 pidfile_test`common_test_pidfile_child(fn="test_pidfile_contested", parent_open=0) + 616 at pidfile_test.c:172 [opt]
    frame #2: 0x0000000000400e37 pidfile_test`main [inlined] test_pidfile_contested + 12 at pidfile_test.c:236 [opt]
    frame #3: 0x0000000000400e2b pidfile_test`main + 139 at pidfile_test.c:272 [opt]
    frame #4: 0x0000000000400cbf pidfile_test`_start + 383
--
Looking at the code we see:
select(0,0,0,0); at line 172

I don't claim to understand the specifics of this bug but in general I would say that blocking with no timeout is a bad idea. I think this test should be changed to include a timeout at line 172.
Next to that the reason why the behavior is different between running the test app with or without kyua still needs to be investigated.
Comment 5 Bas Bossink 2016-07-22 23:44:47 UTC
(In reply to Bas Bossink from comment #4)
Small addition, the problem also occurs when running kyua as a normal user, while running the test executable as a normal users fails due to permission denied errors. However running the test with sudo kyua still hangs.
Comment 6 op 2016-11-04 20:26:21 UTC
This isn't already fixed by this change?

commit a26096b6928229cdee0f385e5690cdb2b8c968dc
Author: br <br@FreeBSD.org>
Date:   Wed Sep 21 11:59:52 2016 +0000

    Use kqueue(2) instead of select(2).
    This helps to ensure we will not lose SIGINT sent by parent to child.
    
    Reviewed by:    sbruno, ngie
    Sponsored by:   DARPA, AFRL
    Sponsored by:   HEIF5
    Differential Revision:  https://reviews.freebsd.org/D7892

 lib/libutil/tests/pidfile_test.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2017-07-19 14:08:00 UTC
A commit references this bug:

Author: emaste
Date: Wed Jul 19 14:07:38 UTC 2017
New revision: 321201
URL: https://svnweb.freebsd.org/changeset/base/321201

Log:
  enable pidfile tests on arm64

  Pidfile tests were disabled on arm64 (in r286863) because they hung.
  They have been fixed (r306098) and so can be enabled now.

  PR:		202304
  Sponsored by:	The FreeBSD Foundation

Changes:
  head/lib/libutil/tests/Makefile