Subject: bug#48941: [powerpc64le-linux] libfaketime CLOCK_MONOTONIC test hangs

From: Chris Marusich <[email-masked]>
Date: Wed, 09 Jun 2021 21:21:09 -0700

Hi,

On powerpc64le-linux, using Guix commit
7692295f970a292a3f3db31fc21d05efd97dcb25 on top of Debian unstable, the
libfaketime package fails to build because one of its tests hangs.  It
appears to hang during the CLOCK_MONOTONIC test:

--8<---------------cut here---------------start------------->8---
Running the test program with no faked time specified
$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest
pthread_cond_timedwait: CLOCK_REALTIME test
(Intentionally sleeping 1 second...)
pthread_cond_timedwait: CLOCK_MONOTONIC test
(Intentionally sleeping 1 second..., see docs about CLOCK_MONOTONIC test)
--8<---------------cut here---------------end--------------->8---

There is no output after that last line.  It just sits there.  I left it
there for about 24 hours, and it didn't make any progress.  I tried with
--cores=1, too, but the problem still occurred.  Therefore, it probably
isn't a multithreading issue.

On x86_64-linux Guix, using the aforementioned commit, on top of Fedora
32, the tests pass and the libfaketime builds successfully.  Therefore,
this is probably a platform-specific issue.

The README file for libfaketime says:

>  CLOCK_MONOTONIC test: Running "make test" performs a series of tests
>  after successful compilation of the libfaketime library. On some
>  platforms, the "CLOCK_MONOTONIC test" will apparently hang
>  forever. If and only if this happens on your platform, add the CFLAG
>  -DFORCE_MONOTONIC_FIX to src/Makefile and recompile libfaketime. Do
>  not set FORCE_MONOTONIC_FIX on platforms where the test does not
>  hang.

In fact, we do set this in Guix, via the (apparently undocumented)
FAKETIME_COMPILE_CFLAGS environment variable:

--8<---------------cut here---------------start------------->8---
(define-public libfaketime
  (package
    (name "libfaketime")
    ...
    (arguments
     '(#:phases (modify-phases %standard-phases
                  (replace 'configure
                    (lambda* (#:key outputs #:allow-other-keys)
                      (let ((out (assoc-ref outputs "out")))
                        (setenv "CC" "gcc")
                        (setenv "PREFIX" out)

                        ;; XXX: Without this flag, the CLOCK_REALTIME test hangs
                        ;; indefinitely.  See README.packagers for more information.
                        ;; Try removing this for future versions of libfaketime.
                        (setenv "FAKETIME_COMPILE_CFLAGS" "-DFORCE_MONOTONIC_FIX")
    ...
--8<---------------cut here---------------end--------------->8---

In spite of this, the test hangs on powerpc64le-linux.  Out of
curiosity, I tried NOT setting FAKETIME_COMPILE_CFLAGS, but the behavior
was the same: it still got stuck forever on powerpc64le-linux.

-- 
Chris