[PATCH v2 2/2] nptl: Convert tst-setuid2 to test-driver

Sunil Pandey skpgkp2@gmail.com
Sat Jan 11 22:44:37 GMT 2025


On Fri, Sep 30, 2022 at 7:11 AM Adhemerval Zanella Netto via Libc-alpha <
libc-alpha@sourceware.org> wrote:

>
>
> On 30/09/22 09:19, Yu Chien Peter Lin wrote:
> > Use <support/test-driver.c> and replace pthread calls to its xpthread
> > equivalents.
> >
> > Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
>
> LGTM, thanks.
>
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>
> > ---
> >  nptl/tst-setuid2.c | 52 +++++++++++++---------------------------------
> >  1 file changed, 15 insertions(+), 37 deletions(-)
> >
> > diff --git a/nptl/tst-setuid2.c b/nptl/tst-setuid2.c
> > index aff3b1a97d..9b7799991c 100644
> > --- a/nptl/tst-setuid2.c
> > +++ b/nptl/tst-setuid2.c
> > @@ -20,6 +20,7 @@
> >  #include <signal.h>
> >  #include <stdbool.h>
> >  #include <stdio.h>
> > +#include <support/xthread.h>
> >  #include <sys/syscall.h>
> >  #include <unistd.h>
> >
> > @@ -36,30 +37,21 @@ static pthread_cond_t cond_recv;
> >  static void *
> >  thread_func (void *ctx __attribute__ ((unused)))
> >  {
> > -  int ret = pthread_mutex_lock (&mutex);
> > -  if (ret != 0)
> > -    FAIL ("pthread_mutex_lock (thread): %d", ret);
> > -
> > +  xpthread_mutex_lock (&mutex);
> >    while (true)
> >      {
> >        if (func_sent != NULL)
> >       {
> >         void (*func) (void) = func_sent;
> > -       ret = pthread_mutex_unlock (&mutex);
> > -       if (ret != 0)
> > -         FAIL ("pthread_mutex_unlock (thread): %d", ret);
> > +       xpthread_mutex_unlock (&mutex);
> > +
> >         func ();
> > -       ret = pthread_mutex_lock (&mutex);
> > -       if (ret != 0)
> > -         FAIL ("pthread_mutex_lock (thread): %d", ret);
> > +
> > +       xpthread_mutex_lock (&mutex);
> >         func_sent = NULL;
> > -       ret = pthread_cond_signal (&cond_recv);
> > -       if (ret != 0)
> > -         FAIL ("pthread_cond_signal (recv): %d", ret);
> > +       xpthread_cond_signal (&cond_recv);
> >       }
> > -      ret = pthread_cond_wait (&cond_send, &mutex);
> > -      if (ret != 0)
> > -     FAIL ("pthread_cond_wait (send): %d", ret);
> > +      xpthread_cond_wait (&cond_send, &mutex);
> >      }
> >    return NULL;
> >  }
> > @@ -67,31 +59,18 @@ thread_func (void *ctx __attribute__ ((unused)))
> >  static void
> >  run_on_thread (void (*func) (void))
> >  {
> > -  int ret = pthread_mutex_lock (&mutex);
> > -  if (ret != 0)
> > -    FAIL ("pthread_mutex_lock (%s): %d", __func__, ret);
> > +  xpthread_mutex_lock (&mutex);
> >    func_sent = func;
> > -  ret = pthread_mutex_unlock (&mutex);
> > -  if (ret != 0)
> > -    FAIL ("pthread_mutex_unlock (%s): %d", __func__, ret);
> > +  xpthread_mutex_unlock (&mutex);
> >
> > -  ret = pthread_cond_signal (&cond_send);
> > -  if (ret != 0)
> > -    FAIL ("pthread_mutex_lock (%s): %d", __func__, ret);
> > -
> > -  ret = pthread_mutex_lock (&mutex);
> > -  if (ret != 0)
> > -    FAIL ("pthread_mutex_lock (%s): %d", __func__, ret);
> > +  xpthread_cond_signal (&cond_send);
> >
> > +  xpthread_mutex_lock (&mutex);
> >    while (func_sent != NULL)
> >      {
> > -      ret = pthread_cond_wait (&cond_recv, &mutex);
> > -      if (ret != 0)
> > -     FAIL ("pthread_mutex_wait (%s): %d", __func__, ret);
> > +      xpthread_cond_wait (&cond_recv, &mutex);
> >      }
> > -  ret = pthread_mutex_unlock (&mutex);
> > -  if (ret != 0)
> > -    FAIL ("pthread_mutex_unlock (%s): %d", __func__, ret);
> > +  xpthread_mutex_unlock (&mutex);
> >  }
> >
> >  static void
> > @@ -141,5 +120,4 @@ do_test (void)
> >    return 0;
> >  }
> >
> > -#define TEST_FUNCTION do_test ()
> > -#include "../test-skeleton.c"
> > +#include <support/test-driver.c>
>

I would like to backport this patch to release branches. Without this
patch, I get following testing errors in 2.36 and earlier branches.

In file included from ../test-skeleton.c:45:0,
                 from tst-setuid2.c:145:
../support/check.h:29:0: error: "FAIL" redefined [-Werror]
 #define FAIL(...) \

tst-setuid2.c:33:0: note: this is the location of the previous definition
 #define FAIL(fmt, ...) \

cc1: all warnings being treated as errors

Any comments or objections?

--Sunil


More information about the Libc-stable mailing list