Blame nptl/tst-audit-threads.c

Packit Bot d26337
/* Test multi-threading using LD_AUDIT.
Packit Bot d26337
Packit Bot d26337
   Copyright (C) 2018 Free Software Foundation, Inc.
Packit Bot d26337
   This file is part of the GNU C Library.
Packit Bot d26337
Packit Bot d26337
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot d26337
   modify it under the terms of the GNU Lesser General Public
Packit Bot d26337
   License as published by the Free Software Foundation; either
Packit Bot d26337
   version 2.1 of the License, or (at your option) any later version.
Packit Bot d26337
Packit Bot d26337
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot d26337
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot d26337
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot d26337
   Lesser General Public License for more details.
Packit Bot d26337
Packit Bot d26337
   You should have received a copy of the GNU Lesser General Public
Packit Bot d26337
   License along with the GNU C Library; if not, see
Packit Bot d26337
   <http://www.gnu.org/licenses/>.  */
Packit Bot d26337
Packit Bot d26337
/* This test uses a dummy LD_AUDIT library (test-audit-threads-mod1) and a
Packit Bot d26337
   library with a huge number of functions in order to validate lazy symbol
Packit Bot d26337
   binding with an audit library.  We use one thread per CPU to test that
Packit Bot d26337
   concurrent lazy resolution does not have any defects which would cause
Packit Bot d26337
   the process to fail.  We use an LD_AUDIT library to force the testing of
Packit Bot d26337
   the relocation resolution caching code in the dynamic loader i.e.
Packit Bot d26337
   _dl_runtime_profile and _dl_profile_fixup.  */
Packit Bot d26337
Packit Bot d26337
#include <support/xthread.h>
Packit Bot d26337
#include <strings.h>
Packit Bot d26337
#include <stdlib.h>
Packit Bot d26337
#include <sys/sysinfo.h>
Packit Bot d26337
Packit Bot d26337
static int do_test (void);
Packit Bot d26337
Packit Bot d26337
/* This test usually takes less than 3s to run.  However, there are cases that
Packit Bot d26337
   take up to 30s.  */
Packit Bot d26337
#define TIMEOUT 60
Packit Bot d26337
#define TEST_FUNCTION do_test ()
Packit Bot d26337
#include "../test-skeleton.c"
Packit Bot d26337
Packit Bot d26337
/* Declare the functions we are going to call.  */
Packit Bot d26337
#define externnum
Packit Bot d26337
#include "tst-audit-threads.h"
Packit Bot d26337
#undef externnum
Packit Bot d26337
Packit Bot d26337
int num_threads;
Packit Bot d26337
pthread_barrier_t barrier;
Packit Bot d26337
Packit Bot d26337
void
Packit Bot d26337
sync_all (int num)
Packit Bot d26337
{
Packit Bot d26337
  pthread_barrier_wait (&barrier);
Packit Bot d26337
}
Packit Bot d26337
Packit Bot d26337
void
Packit Bot d26337
call_all_ret_nums (void)
Packit Bot d26337
{
Packit Bot d26337
  /* Call each function one at a time from all threads.  */
Packit Bot d26337
#define callnum
Packit Bot d26337
#include "tst-audit-threads.h"
Packit Bot d26337
#undef callnum
Packit Bot d26337
}
Packit Bot d26337
Packit Bot d26337
void *
Packit Bot d26337
thread_main (void *unused)
Packit Bot d26337
{
Packit Bot d26337
  call_all_ret_nums ();
Packit Bot d26337
  return NULL;
Packit Bot d26337
}
Packit Bot d26337
Packit Bot d26337
#define STR2(X) #X
Packit Bot d26337
#define STR(X) STR2(X)
Packit Bot d26337
Packit Bot d26337
static int
Packit Bot d26337
do_test (void)
Packit Bot d26337
{
Packit Bot d26337
  int i;
Packit Bot d26337
  pthread_t *threads;
Packit Bot d26337
Packit Bot d26337
  num_threads = get_nprocs ();
Packit Bot d26337
  if (num_threads <= 1)
Packit Bot d26337
    num_threads = 2;
Packit Bot d26337
Packit Bot d26337
  /* Used to synchronize all the threads after calling each retNumN.  */
Packit Bot d26337
  xpthread_barrier_init (&barrier, NULL, num_threads);
Packit Bot d26337
Packit Bot d26337
  threads = (pthread_t *) xcalloc (num_threads, sizeof(pthread_t));
Packit Bot d26337
  for (i = 0; i < num_threads; i++)
Packit Bot d26337
    threads[i] = xpthread_create(NULL, thread_main, NULL);
Packit Bot d26337
Packit Bot d26337
  for (i = 0; i < num_threads; i++)
Packit Bot d26337
    xpthread_join(threads[i]);
Packit Bot d26337
Packit Bot d26337
  free (threads);
Packit Bot d26337
Packit Bot d26337
  return 0;
Packit Bot d26337
}