glib/tests/unix: Do not perform stack memory checks under valgrind

When running the alternate stack tests under valgrind the stack memory
gets corrupted that we've initialized gets somehow corrupted and this
causes a read-error while reading the stack memory area.

No matter if we use instead malloc-allocated or mmap'ed memory areas,
the result is always the same: a memory error while reading it.

  Reading byte 2645
  Reading byte 2646
  Reading byte 2647
  Reading byte 2648
  ==46100== Invalid read of size 1

Now this memory is definitely stack-allocated and unless the valgrind
stack gets corrupted, there's no way it could have been removed.

I quite trust that this is some valgrind problem only though since no
other memory analyzer I've tried (memory sanitizer mostly) has
highlighted any issue with this.

As per this, since the main point of the test was just checking if
signals are delivered properly even when using an alternate stack, I
think that we can just safely run a simpler version of the test when
running under valgrind. This implies assuming that sigaltstack()
does what is supposed to do, without us double-checking it, but I guess
we can trust that (especially because we're still testing it when not
using valgrind).

Closes: #3337
This commit is contained in:
Marco Trevisan (Treviño) 2024-05-08 00:24:49 +02:00
parent 651beec963
commit c894e89720

View File

@ -29,6 +29,7 @@
#include "glib-private.h"
#include "glib-unix.h"
#include "gstdio.h"
#include "gvalgrind.h"
#include <signal.h>
#include <string.h>
@ -588,6 +589,29 @@ test_signal_alternate_stack (int signal)
test_signal (signal);
#if defined (ENABLE_VALGRIND)
if (RUNNING_ON_VALGRIND)
{
/* When running under valgrind, checking for memory differences does
* not work with a weird read error happening way before than the
* stack memory size, it's unclear why but it may be related to how
* valgrind internally implements it.
* However, the point of the test is to make sure that even using an
* alternative stack (that we blindly trust is used), the signals are
* properly delivered, and this can be still tested properly.
*
* See:
* - https://gitlab.gnome.org/GNOME/glib/-/issues/3337
* - https://bugs.kde.org/show_bug.cgi?id=486812
*/
g_test_message ("Running a limited test version under valgrind");
stack.ss_flags = SS_DISABLE;
g_assert_no_errno (sigaltstack (&stack, &old_stack));
return;
}
#endif
/* Very stupid check to ensure that the alternate stack is used instead of
* the default one. This test would fail if SA_ONSTACK wouldn't be set.
*/