diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-06-07 23:32:58 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-06-07 23:45:25 +0000 |
commit | 314a431d37757ad179e89b83c3cb5720bae26e60 (patch) | |
tree | f78b79204d8c51ba54153542d949b08e1f5a4392 /sysdeps | |
parent | 15e995a8fb94a00d76da03756579ae6ff645b161 (diff) | |
download | glibc-314a431d37757ad179e89b83c3cb5720bae26e60.tar.gz glibc-314a431d37757ad179e89b83c3cb5720bae26e60.tar.xz glibc-314a431d37757ad179e89b83c3cb5720bae26e60.zip |
htl: Enable more tests
* nptl/tst-_res1.c, tst-_res1mod1.c, tst-_res1mod2.c, tst-atfork2.c, tst-atfork2mod.c, tst-fini1.c, tst-fini1mod.c, tst-tls4.c, tst-tls4moda.c, tst-tls4modb.c: Move to... * sysdeps/pthread: ... here. Rename tst-tls4.c to tst-pt-tls4.c to avoid conflicting with elf/tst-tls4.c. * nptl/Makefile: Move corresponding references and rules to... * sysdeps/pthread/Makefile: ... here.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/pthread/Makefile | 41 | ||||
-rw-r--r-- | sysdeps/pthread/tst-_res1.c | 68 | ||||
-rw-r--r-- | sysdeps/pthread/tst-_res1mod1.c | 22 | ||||
-rw-r--r-- | sysdeps/pthread/tst-_res1mod2.c | 1 | ||||
-rw-r--r-- | sysdeps/pthread/tst-atfork2.c | 158 | ||||
-rw-r--r-- | sysdeps/pthread/tst-atfork2mod.c | 57 | ||||
-rw-r--r-- | sysdeps/pthread/tst-fini1.c | 34 | ||||
-rw-r--r-- | sysdeps/pthread/tst-fini1mod.c | 71 | ||||
-rw-r--r-- | sysdeps/pthread/tst-pt-tls4.c | 180 | ||||
-rw-r--r-- | sysdeps/pthread/tst-tls4moda.c | 49 | ||||
-rw-r--r-- | sysdeps/pthread/tst-tls4modb.c | 58 |
11 files changed, 739 insertions, 0 deletions
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile index 5f9610ecbf..2d483c8534 100644 --- a/sysdeps/pthread/Makefile +++ b/sysdeps/pthread/Makefile @@ -117,6 +117,22 @@ tests += tst-cancelx2 tst-cancelx3 tst-cancelx8 tst-cancelx10 \ tst-cancelx12 tst-cancelx14 tst-cancelx15 tst-cancelx18 \ tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3 +ifeq ($(build-shared),yes) +tests += tst-atfork2 tst-pt-tls4 tst-_res1 tst-fini1 +tests-nolibpthread += tst-fini1 +endif + +modules-names += tst-atfork2mod tst-tls4moda tst-tls4modb \ + tst-_res1mod1 tst-_res1mod2 tst-fini1mod +test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names))) + +tst-atfork2mod.so-no-z-defs = yes + +ifeq ($(build-shared),yes) +# Build all the modules even when not actually running test programs. +tests: $(test-modules) +endif + tests-static += tst-locale1 tst-locale2 tests += tst-cond11-static @@ -150,6 +166,15 @@ CFLAGS-tst-pt-align3.c += $(stack-align-test-flags) tst-umask1-ARGS = $(objpfx)tst-umask1.temp +$(objpfx)tst-atfork2: $(libdl) $(shared-thread-library) +LDFLAGS-tst-atfork2 = -rdynamic +tst-atfork2-ENV = MALLOC_TRACE=$(objpfx)tst-atfork2.mtrace +$(objpfx)tst-atfork2mod.so: $(shared-thread-library) + +ifeq ($(build-shared),yes) +$(objpfx)tst-atfork2.out: $(objpfx)tst-atfork2mod.so +endif + ifeq ($(build-shared),yes) $(objpfx)tst-cleanup0.out: /dev/null $(objpfx)tst-cleanup0 $(make-test-out) > $@ 2>&1; \ @@ -164,7 +189,23 @@ else $(objpfx)tst-cancel28: $(common-objpfx)rt/librt.a endif +$(objpfx)tst-fini1: $(shared-thread-library) $(objpfx)tst-fini1mod.so + +$(objpfx)tst-fini1mod.so: $(shared-thread-library) + +$(objpfx)tst-_res1mod2.so: $(objpfx)tst-_res1mod1.so +LDFLAGS-tst-_res1mod1.so = -Wl,-soname,tst-_res1mod1.so +LDFLAGS-tst-_res1mod2.so = -Wl,-soname,tst-_res1mod2.so +$(objpfx)tst-_res1: $(objpfx)tst-_res1mod1.so $(objpfx)tst-_res1mod2.so \ + $(shared-thread-library) + +$(objpfx)tst-pt-tls4: $(libdl) $(shared-thread-library) +$(objpfx)tst-pt-tls4.out: $(objpfx)tst-tls4moda.so $(objpfx)tst-tls4modb.so + +generated += tst-atfork2.mtrace +generated += $(objpfx)tst-atfork2.mtrace \ + $(addsuffix .so,$(strip $(modules-names))) tests-internal += tst-robust8 diff --git a/sysdeps/pthread/tst-_res1.c b/sysdeps/pthread/tst-_res1.c new file mode 100644 index 0000000000..3e186bcb39 --- /dev/null +++ b/sysdeps/pthread/tst-_res1.c @@ -0,0 +1,68 @@ +/* Copyright (C) 2003-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 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 + <https://www.gnu.org/licenses/>. */ + +/* Test whether _res in glibc 2.1.x and earlier (before __res_state() + was introduced) works. Portable programs should never do the + dirty things below. */ + +#include <pthread.h> +#include <resolv.h> +#include <stdlib.h> +#include <stdio.h> + +void *tf (void *resp) +{ + if (resp == &_res || resp == __res_state ()) + abort (); + _res.retry = 24; + return NULL; +} + +void do_test (struct __res_state *resp) +{ + if (resp != &_res || resp != __res_state ()) + abort (); + if (_res.retry != 12) + abort (); +} + +int main (void) +{ +#undef _res + extern struct __res_state _res; + pthread_t th; + + _res.retry = 12; + if (pthread_create (&th, NULL, tf, &_res) != 0) + { + puts ("create failed"); + exit (1); + } + + do_test (&_res); + + if (pthread_join (th, NULL) != 0) + { + puts ("join failed"); + exit (1); + } + + do_test (&_res); + + exit (0); +} diff --git a/sysdeps/pthread/tst-_res1mod1.c b/sysdeps/pthread/tst-_res1mod1.c new file mode 100644 index 0000000000..3af31c4c03 --- /dev/null +++ b/sysdeps/pthread/tst-_res1mod1.c @@ -0,0 +1,22 @@ +/* Copyright (C) 2003-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 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 + <https://www.gnu.org/licenses/>. */ + +#include <resolv.h> +#undef _res + +struct __res_state _res; diff --git a/sysdeps/pthread/tst-_res1mod2.c b/sysdeps/pthread/tst-_res1mod2.c new file mode 100644 index 0000000000..d2a3509c6d --- /dev/null +++ b/sysdeps/pthread/tst-_res1mod2.c @@ -0,0 +1 @@ +/* Nothing. */ diff --git a/sysdeps/pthread/tst-atfork2.c b/sysdeps/pthread/tst-atfork2.c new file mode 100644 index 0000000000..6e4b803413 --- /dev/null +++ b/sysdeps/pthread/tst-atfork2.c @@ -0,0 +1,158 @@ +/* Copyright (C) 2003-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 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 + <https://www.gnu.org/licenses/>. */ + +#include <dlfcn.h> +#include <errno.h> +#include <mcheck.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/wait.h> + + +/* Must be exported. */ +int val; + +static void +prepare (void) +{ + val *= 2; +} + +static void +parent (void) +{ + val += 4; +} + +static void +child (void) +{ + val += 8; +} + + +static int +do_test (void) +{ + mtrace (); + + if (pthread_atfork (prepare, parent, child) != 0) + { + puts ("do_test: atfork failed"); + exit (1); + } + + void *h = dlopen ("tst-atfork2mod.so", RTLD_LAZY); + if (h == NULL) + { + printf ("dlopen failed: %s\n", dlerror ()); + exit (1); + } + + /* First trial of fork. */ + pid_t pid = fork (); + if (pid == -1) + { + puts ("1st fork failed"); + exit (1); + } + + if (pid == 0) + { + /* Child. */ + if (val != 80) + { + printf ("1st: expected val=%d, got %d\n", 80, val); + exit (2); + } + + exit (0); + } + + /* Parent. */ + if (val != 24) + { + printf ("1st: expected val=%d, got %d\n", 24, val); + exit (1); + } + + int status; + if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid) + { + puts ("1st waitpid failed"); + exit (1); + } + + if (status != 0) + exit (status); + + puts ("unloading now"); + + /* Unload the module. */ + if (dlclose (h) != 0) + { + puts ("dlclose failed"); + exit (1); + } + + puts ("2nd fork"); + + /* Second fork trial. */ + val = 1; + pid = fork (); + if (pid == -1) + { + puts ("2nd fork failed"); + exit (1); + } + + if (pid == 0) + { + /* Child. */ + if (val != 10) + { + printf ("2nd: expected val=%d, got %d\n", 10, val); + exit (3); + } + + exit (0); + } + + /* Parent. */ + if (val != 6) + { + printf ("2nd: expected val=%d, got %d\n", 6, val); + exit (1); + } + + if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid) + { + puts ("2nd waitpid failed"); + exit (1); + } + + if (status != 0) + exit (status); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/sysdeps/pthread/tst-atfork2mod.c b/sysdeps/pthread/tst-atfork2mod.c new file mode 100644 index 0000000000..b307a307ec --- /dev/null +++ b/sysdeps/pthread/tst-atfork2mod.c @@ -0,0 +1,57 @@ +/* Copyright (C) 2003-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 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 + <https://www.gnu.org/licenses/>. */ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <dso_handle.h> + + +extern int val; + + +static void +prepare (void) +{ + ++val; +} + +static void +parent (void) +{ + val *= 4; +} + +static void +child (void) +{ + val *= 8; +} + +static void +__attribute__ ((constructor)) +init (void) +{ + printf ("dsohandle = %p\n", __dso_handle); + + if (pthread_atfork (prepare, parent, child) != 0) + { + puts ("init: atfork failed"); + exit (1); + } +} diff --git a/sysdeps/pthread/tst-fini1.c b/sysdeps/pthread/tst-fini1.c new file mode 100644 index 0000000000..d395fad970 --- /dev/null +++ b/sysdeps/pthread/tst-fini1.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2004-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2004. + + 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 + <https://www.gnu.org/licenses/>. */ + +#include <unistd.h> + +extern void m (void); + +int +main (void) +{ + alarm (5); + + m (); + + /* The destructor is supposed to run now. Make sure that if it is + not we will notice it by using 42 as the exit code. In case the + destructor is run it will terminate with status zero. */ + return 42; +} diff --git a/sysdeps/pthread/tst-fini1mod.c b/sysdeps/pthread/tst-fini1mod.c new file mode 100644 index 0000000000..6c10303d34 --- /dev/null +++ b/sysdeps/pthread/tst-fini1mod.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2004-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2004. + + 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 + <https://www.gnu.org/licenses/>. */ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + + +static void * +tf (void *arg) +{ + int fds[2]; + if (pipe (fds) != 0) + { + puts ("pipe failed"); + exit (1); + } + + char buf[10]; + read (fds[0], buf, sizeof (buf)); + + puts ("read returned"); + exit (1); +} + +static pthread_t th; + +static void +__attribute ((destructor)) +dest (void) +{ + if (pthread_cancel (th) != 0) + { + puts ("cancel failed"); + _exit (1); + } + void *r; + if (pthread_join (th, &r) != 0) + { + puts ("join failed"); + _exit (1); + } + /* Exit successfully. */ + _exit (0); +} + +void +m (void) +{ + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("create failed"); + _exit (1); + } +} diff --git a/sysdeps/pthread/tst-pt-tls4.c b/sysdeps/pthread/tst-pt-tls4.c new file mode 100644 index 0000000000..7fd65de79d --- /dev/null +++ b/sysdeps/pthread/tst-pt-tls4.c @@ -0,0 +1,180 @@ +/* Copyright (C) 2003-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 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 + <https://www.gnu.org/licenses/>. */ + +#include <dlfcn.h> +#include <errno.h> +#include <pthread.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#define N 3 + +void (*test1) (void), (*test2) (void); + +pthread_barrier_t b2, b3; + +static void * +tf (void *arg) +{ + int i; + + for (i = 0; i <= (uintptr_t) arg; ++i) + { + int r = pthread_barrier_wait (&b3); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("tf: barrier_wait failed"); + exit (1); + } + } + + test1 (); + + for (i = 0; i < 3; ++i) + { + int r = pthread_barrier_wait (&b3); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("tf: barrier_wait failed"); + exit (1); + } + } + + test2 (); + + for (i = 0; i < 3 - (uintptr_t) arg; ++i) + { + int r = pthread_barrier_wait (&b3); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("tf: barrier_wait failed"); + exit (1); + } + } + + return NULL; +} + +static void * +tf2 (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("tf2: barrier_wait failed"); + exit (1); + } + + int i; + for (i = 0; i < N; ++i) + tf (arg); + return NULL; +} + +int +do_test (void) +{ + pthread_t th[2]; + const char *modules[N] + = { "tst-tls4moda.so", "tst-tls4moda.so", "tst-tls4modb.so" }; + + if (pthread_barrier_init (&b2, NULL, 2) != 0) + { + puts ("barrier_init failed"); + return 1; + } + + if (pthread_barrier_init (&b3, NULL, 3) != 0) + { + puts ("barrier_init failed"); + return 1; + } + + if (pthread_create (&th[0], NULL, tf2, (void *) (uintptr_t) 1)) + { + puts ("pthread_create failed"); + return 1; + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + return 1; + } + + int i; + for (i = 0; i < N; ++i) + { + void *h = dlopen (modules[i], RTLD_LAZY); + if (h == NULL) + { + printf ("dlopen failed %s\n", dlerror ()); + return 1; + } + + test1 = dlsym (h, "test1"); + if (test1 == NULL) + { + printf ("dlsym for test1 failed %s\n", dlerror ()); + return 1; + } + + test2 = dlsym (h, "test2"); + if (test2 == NULL) + { + printf ("dlsym for test2 failed %s\n", dlerror ()); + return 1; + } + + if (pthread_create (&th[1], NULL, tf, (void *) (uintptr_t) 2)) + { + puts ("pthread_create failed"); + return 1; + } + + tf ((void *) (uintptr_t) 0); + + if (pthread_join (th[1], NULL) != 0) + { + puts ("join failed"); + return 1; + } + + if (dlclose (h)) + { + puts ("dlclose failed"); + return 1; + } + + printf ("test %d with %s succeeded\n", i, modules[i]); + } + + if (pthread_join (th[0], NULL) != 0) + { + puts ("join failed"); + return 1; + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/sysdeps/pthread/tst-tls4moda.c b/sysdeps/pthread/tst-tls4moda.c new file mode 100644 index 0000000000..ccff2a797a --- /dev/null +++ b/sysdeps/pthread/tst-tls4moda.c @@ -0,0 +1,49 @@ +/* Copyright (C) 2003-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 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 + <https://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <stdlib.h> + +static __thread unsigned char foo [32] + __attribute__ ((tls_model ("initial-exec"), aligned (sizeof (void *)))); + +void +test1 (void) +{ + size_t s; + + for (s = 0; s < sizeof (foo); ++s) + { + if (foo [s]) + abort (); + foo [s] = s; + } +} + +void +test2 (void) +{ + size_t s; + + for (s = 0; s < sizeof (foo); ++s) + { + if (foo [s] != s) + abort (); + foo [s] = sizeof (foo) - s; + } +} diff --git a/sysdeps/pthread/tst-tls4modb.c b/sysdeps/pthread/tst-tls4modb.c new file mode 100644 index 0000000000..2c29c2d18a --- /dev/null +++ b/sysdeps/pthread/tst-tls4modb.c @@ -0,0 +1,58 @@ +/* Copyright (C) 2003-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 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 + <https://www.gnu.org/licenses/>. */ + +#include <stddef.h> +#include <stdlib.h> + +static int i; +int bar; + +static __thread void *foo [32 / sizeof (void *)] + __attribute__ ((tls_model ("initial-exec"), aligned (sizeof (void *)))) + = { &i, &bar }; + +void +test1 (void) +{ + size_t s; + + if (foo [0] != &i || foo [1] != &bar) + abort (); + + foo [0] = NULL; + foo [1] = NULL; + for (s = 0; s < sizeof (foo) / sizeof (void *); ++s) + { + if (foo [s]) + abort (); + foo [s] = &foo[s]; + } +} + +void +test2 (void) +{ + size_t s; + + for (s = 0; s < sizeof (foo) / sizeof (void *); ++s) + { + if (foo [s] != &foo [s]) + abort (); + foo [s] = &foo [s ^ 1]; + } +} |