From cca76b6db216805267212ab03c8691e8e6960338 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 9 Feb 2020 16:12:35 +0000 Subject: pthread: Move basic tests from nptl to sysdeps/pthread So they can be checked with htl too. --- nptl/Makefile | 2 - nptl/tst-basic1.c | 82 ---------------------------------- nptl/tst-basic2.c | 120 ------------------------------------------------- nptl/tst-basic3.c | 86 ----------------------------------- nptl/tst-basic4.c | 100 ----------------------------------------- nptl/tst-basic5.c | 73 ------------------------------ nptl/tst-basic6.c | 131 ------------------------------------------------------ nptl/tst-basic7.c | 75 ------------------------------- 8 files changed, 669 deletions(-) delete mode 100644 nptl/tst-basic1.c delete mode 100644 nptl/tst-basic2.c delete mode 100644 nptl/tst-basic3.c delete mode 100644 nptl/tst-basic4.c delete mode 100644 nptl/tst-basic5.c delete mode 100644 nptl/tst-basic6.c delete mode 100644 nptl/tst-basic7.c (limited to 'nptl') diff --git a/nptl/Makefile b/nptl/Makefile index f762ea26a3..812d01a4e1 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -262,8 +262,6 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \ tst-sem15 tst-sem16 tst-sem17 \ tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 \ tst-align tst-align3 \ - tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \ - tst-basic7 \ tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \ tst-raise1 \ tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 tst-join7 \ diff --git a/nptl/tst-basic1.c b/nptl/tst-basic1.c deleted file mode 100644 index 6e3012f83d..0000000000 --- a/nptl/tst-basic1.c +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright (C) 2002-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - - -static int do_test (void); - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" - -static pid_t pid; - -static void * -tf (void *a) -{ - if (getpid () != pid) - { - write_message ("pid mismatch\n"); - _exit (1); - } - - return a; -} - - -int -do_test (void) -{ - pid = getpid (); - -#define N 2 - pthread_t t[N]; - int i; - - for (i = 0; i < N; ++i) - if (pthread_create (&t[i], NULL, tf, (void *) (long int) (i + 1)) != 0) - { - write_message ("create failed\n"); - _exit (1); - } - else - printf ("created thread %d\n", i); - - for (i = 0; i < N; ++i) - { - void *r; - int e; - if ((e = pthread_join (t[i], &r)) != 0) - { - printf ("join failed: %d\n", e); - _exit (1); - } - else if (r != (void *) (long int) (i + 1)) - { - write_message ("result wrong\n"); - _exit (1); - } - else - printf ("joined thread %d\n", i); - } - - return 0; -} diff --git a/nptl/tst-basic2.c b/nptl/tst-basic2.c deleted file mode 100644 index ce20e270c4..0000000000 --- a/nptl/tst-basic2.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (C) 2002-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2002. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include - - -#define N 20 - -static pthread_t th[N]; -static pthread_mutex_t lock[N]; - - -static void *tf (void *a) -{ - uintptr_t idx = (uintptr_t) a; - - pthread_mutex_lock (&lock[idx]); - - return pthread_equal (pthread_self (), th[idx]) ? NULL : (void *) 1l; -} - - -int -do_test (void) -{ - if (pthread_equal (pthread_self (), pthread_self ()) == 0) - { - puts ("pthread_equal (pthread_self (), pthread_self ()) failed"); - exit (1); - } - - pthread_attr_t at; - - if (pthread_attr_init (&at) != 0) - { - puts ("attr_init failed"); - return 1; - } - - if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0) - { - puts ("attr_setstacksize failed"); - return 1; - } - - int i; - for (i = 0; i < N; ++i) - { - if (pthread_mutex_init (&lock[i], NULL) != 0) - { - puts ("mutex_init failed"); - exit (1); - } - - if (pthread_mutex_lock (&lock[i]) != 0) - { - puts ("mutex_lock failed"); - exit (1); - } - - if (pthread_create (&th[i], &at, tf, (void *) (long int) i) != 0) - { - puts ("create failed"); - exit (1); - } - - if (pthread_mutex_unlock (&lock[i]) != 0) - { - puts ("mutex_unlock failed"); - exit (1); - } - - printf ("created thread %d\n", i); - } - - if (pthread_attr_destroy (&at) != 0) - { - puts ("attr_destroy failed"); - return 1; - } - - int result = 0; - for (i = 0; i < N; ++i) - { - void *r; - int e; - if ((e = pthread_join (th[i], &r)) != 0) - { - printf ("join failed: %d\n", e); - _exit (1); - } - else if (r != NULL) - result = 1; - } - - return result; -} - - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/nptl/tst-basic3.c b/nptl/tst-basic3.c deleted file mode 100644 index 14eda8a678..0000000000 --- a/nptl/tst-basic3.c +++ /dev/null @@ -1,86 +0,0 @@ -/* Copyright (C) 2003-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include - - -static int nrunning = 1; - - -static void -final_test (void) -{ - puts ("final_test has been called"); - -#define THE_SIGNAL SIGUSR1 - kill (getpid (), SIGUSR1); -} - - -static void * -tf (void *a) -{ - if (pthread_join ((pthread_t) a, NULL) != 0) - { - printf ("join failed while %d are running\n", nrunning); - _exit (1); - } - - printf ("%2d left\n", --nrunning); - - return NULL; -} - - -int -do_test (void) -{ -#define N 20 - pthread_t t[N]; - pthread_t last = pthread_self (); - int i; - - atexit (final_test); - - printf ("starting %d + 1 threads\n", N); - for (i = 0; i < N; ++i) - { - if (pthread_create (&t[i], NULL, tf, (void *) last) != 0) - { - puts ("create failed"); - _exit (1); - } - - ++nrunning; - - last = t[i]; - } - - printf ("%2d left\n", --nrunning); - - pthread_exit (NULL); -} - - -#define EXPECTED_SIGNAL THE_SIGNAL -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/nptl/tst-basic4.c b/nptl/tst-basic4.c deleted file mode 100644 index 78e277717c..0000000000 --- a/nptl/tst-basic4.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 2003-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include -#include -#include - - -static void -final_test (void) -{ - puts ("final_test has been called"); - -#define THE_SIGNAL SIGUSR1 - kill (getpid (), SIGUSR1); -} - - -static void * -tf (void *a) -{ - pid_t pid = fork (); - if (pid == -1) - { - puts ("fork failed"); - exit (1); - } - - if (pid == 0) - { - atexit (final_test); - - pthread_exit (NULL); - } - - int r; - int e = TEMP_FAILURE_RETRY (waitpid (pid, &r, 0)); - if (e != pid) - { - puts ("waitpid failed"); - exit (1); - } - - if (! WIFSIGNALED (r)) - { - puts ("child not signled"); - exit (1); - } - - if (WTERMSIG (r) != THE_SIGNAL) - { - puts ("child's termination signal wrong"); - exit (1); - } - - return NULL; -} - - -int -do_test (void) -{ - pthread_t th; - - if (pthread_create (&th, NULL, tf, NULL) != 0) - { - puts ("create failed"); - _exit (1); - } - - if (pthread_join (th, NULL) != 0) - { - puts ("join failed"); - exit (1); - } - - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/nptl/tst-basic5.c b/nptl/tst-basic5.c deleted file mode 100644 index bc4a12b544..0000000000 --- a/nptl/tst-basic5.c +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (C) 2003-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - - - -int -do_test (void) -{ - int c = pthread_getconcurrency (); - if (c != 0) - { - puts ("initial concurrencylevel wrong"); - exit (1); - } - - if (pthread_setconcurrency (1) != 0) - { - puts ("setconcurrency failed"); - exit (1); - } - - c = pthread_getconcurrency (); - if (c != 1) - { - puts ("getconcurrency didn't return the value previous set"); - exit (1); - } - - int e = pthread_setconcurrency (-1); - if (e == 0) - { - puts ("setconcurrency of negative value didn't failed"); - exit (1); - } - if (e != EINVAL) - { - puts ("setconcurrency didn't return EINVAL for negative value"); - exit (1); - } - - c = pthread_getconcurrency (); - if (c != 1) - { - puts ("invalid getconcurrency changed level"); - exit (1); - } - - return 0; -} - - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/nptl/tst-basic6.c b/nptl/tst-basic6.c deleted file mode 100644 index 38ce40151c..0000000000 --- a/nptl/tst-basic6.c +++ /dev/null @@ -1,131 +0,0 @@ -/* Copyright (C) 2003-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include - - -static char *p; - -static pthread_barrier_t b; -#define BT \ - e = pthread_barrier_wait (&b); \ - if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) \ - { \ - puts ("barrier_wait failed"); \ - exit (1); \ - } - - -static void * -tf (void *a) -{ - int e; - - BT; - - char *p2 = getcwd (NULL, 0); - if (p2 == NULL) - { - puts ("2nd getcwd failed"); - exit (1); - } - - if (strcmp (p, p2) != 0) - { - printf ("initial cwd mismatch: \"%s\" vs \"%s\"\n", p, p2); - exit (1); - } - - free (p); - free (p2); - - if (chdir ("..") != 0) - { - puts ("chdir failed"); - exit (1); - } - - p = getcwd (NULL, 0); - if (p == NULL) - { - puts ("getcwd failed"); - exit (1); - } - - return a; -} - - -int -do_test (void) -{ - if (pthread_barrier_init (&b, NULL, 2) != 0) - { - puts ("barrier_init failed"); - exit (1); - } - - pthread_t th; - if (pthread_create (&th, NULL, tf, NULL) != 0) - { - puts ("create failed"); - exit (1); - } - - p = getcwd (NULL, 0); - if (p == NULL) - { - puts ("getcwd failed"); - exit (1); - } - - int e; - BT; - - if (pthread_join (th, NULL) != 0) - { - puts ("join failed"); - exit (1); - } - - char *p2 = getcwd (NULL, 0); - if (p2 == NULL) - { - puts ("2nd getcwd failed"); - exit (1); - } - - if (strcmp (p, p2) != 0) - { - printf ("cwd after chdir mismatch: \"%s\" vs \"%s\"\n", p, p2); - exit (1); - } - - free (p); - free (p2); - - return 0; -} - - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" diff --git a/nptl/tst-basic7.c b/nptl/tst-basic7.c deleted file mode 100644 index 29a2461efe..0000000000 --- a/nptl/tst-basic7.c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void use_stack (size_t needed); - -void (*use_stack_ptr) (size_t) = use_stack; - -static void -use_stack (size_t needed) -{ - size_t sz = sysconf (_SC_PAGESIZE); - char *buf = alloca (sz); - memset (buf, '\0', sz); - - if (needed > sz) - use_stack_ptr (needed - sz); -} - -static void -use_up_memory (void) -{ - struct rlimit rl; - getrlimit (RLIMIT_AS, &rl); - rl.rlim_cur = 10 * 1024 * 1024; - setrlimit (RLIMIT_AS, &rl); - - char *c; - int PAGESIZE = getpagesize (); - while (1) - { - c = mmap (NULL, PAGESIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); - if (c == MAP_FAILED) - break; - } -} - -static void * -child (void *arg) -{ - sleep (1); - return arg; -} - -static int -do_test (void) -{ - int err; - pthread_t tid; - - /* Allocate the memory needed for the stack. */ - use_stack_ptr (PTHREAD_STACK_MIN); - - use_up_memory (); - - err = pthread_create (&tid, NULL, child, NULL); - if (err != 0) - { - printf ("pthread_create returns %d: %s\n", err, - err == EAGAIN ? "OK" : "FAIL"); - return err != EAGAIN; - } - - /* We did not fail to allocate memory despite the preparation. Oh well. */ - return 0; -} - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" -- cgit 1.4.1