diff options
| author | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
| commit | b1ddde874c215cc8891531ed92876f091b7eb83e (patch) | |
| tree | edb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/stdio_threading | |
| parent | f0a36529837a161734c802ae4c42e84e42347be2 (diff) | |
| download | openbsd-tb_20250414.tar.gz openbsd-tb_20250414.tar.bz2 openbsd-tb_20250414.zip | |
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/stdio_threading')
14 files changed, 0 insertions, 515 deletions
diff --git a/src/regress/lib/libc/stdio_threading/Makefile b/src/regress/lib/libc/stdio_threading/Makefile deleted file mode 100644 index e42481afc2..0000000000 --- a/src/regress/lib/libc/stdio_threading/Makefile +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | SUBDIR += fopen fread fwrite fgetln fgets fputs | ||
| 2 | |||
| 3 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/Makefile b/src/regress/lib/libc/stdio_threading/fgetln/Makefile deleted file mode 100644 index cad51e2b23..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgetln/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fgetln_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c deleted file mode 100755 index 76d154bb2a..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c +++ /dev/null | |||
| @@ -1,70 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fgetln_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | size_t len; | ||
| 24 | char *buf; | ||
| 25 | int i; | ||
| 26 | |||
| 27 | for (i = 0; i < 4096; i++) { | ||
| 28 | if ((buf = fgetln(file, &len)) == NULL) { | ||
| 29 | |||
| 30 | if (feof(file)) | ||
| 31 | break; | ||
| 32 | |||
| 33 | printf("OMG!!!\n"); | ||
| 34 | fflush(stdout); | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | if (strncmp(buf, TEXT_N, sizeof(TEXT_N))) | ||
| 38 | err(1, "fgetln not atomic!!!"); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | int | ||
| 43 | main(void) | ||
| 44 | { | ||
| 45 | char sfn[24]; | ||
| 46 | FILE *sfp; | ||
| 47 | int fd, i; | ||
| 48 | |||
| 49 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 50 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 51 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 52 | int saved_errno = errno; | ||
| 53 | if (fd != -1) { | ||
| 54 | unlink(sfn); | ||
| 55 | close(fd); | ||
| 56 | } | ||
| 57 | errc(1, saved_errno, "could not open temporary file"); | ||
| 58 | } | ||
| 59 | |||
| 60 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 61 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
| 62 | err(1, "Could not populate test file"); | ||
| 63 | |||
| 64 | run_threads(fgetln_thread, sfp); | ||
| 65 | |||
| 66 | unlink(sfn); | ||
| 67 | close(fd); | ||
| 68 | |||
| 69 | exit(0); | ||
| 70 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/Makefile b/src/regress/lib/libc/stdio_threading/fgets/Makefile deleted file mode 100644 index 52310fd429..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgets/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fgets_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c deleted file mode 100755 index 7c5008e2ad..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fgets_thread(void *v) | ||
| 21 | { | ||
| 22 | char buf[sizeof(TEXT_N) + 1]; | ||
| 23 | FILE *file = v; | ||
| 24 | int i; | ||
| 25 | |||
| 26 | for (i = 0; i < 4096; i++) { | ||
| 27 | if (fgets(buf, sizeof(buf), file) == NULL) { | ||
| 28 | |||
| 29 | if (feof(file)) | ||
| 30 | break; | ||
| 31 | |||
| 32 | printf("OMG!!!\n"); | ||
| 33 | fflush(stdout); | ||
| 34 | break; | ||
| 35 | } | ||
| 36 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 37 | err(1, "Read not atomic!!!"); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | int | ||
| 42 | main(void) | ||
| 43 | { | ||
| 44 | char sfn[24]; | ||
| 45 | FILE *sfp; | ||
| 46 | int fd, i; | ||
| 47 | |||
| 48 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 49 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 50 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 51 | int saved_errno = errno; | ||
| 52 | if (fd != -1) { | ||
| 53 | unlink(sfn); | ||
| 54 | close(fd); | ||
| 55 | } | ||
| 56 | errc(1, saved_errno, "could not open temporary file"); | ||
| 57 | } | ||
| 58 | |||
| 59 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 60 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
| 61 | err(1, "Could not populate test file"); | ||
| 62 | |||
| 63 | run_threads(fgets_thread, sfp); | ||
| 64 | |||
| 65 | unlink(sfn); | ||
| 66 | close(fd); | ||
| 67 | |||
| 68 | exit(0); | ||
| 69 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/Makefile b/src/regress/lib/libc/stdio_threading/fopen/Makefile deleted file mode 100644 index e51deeff1d..0000000000 --- a/src/regress/lib/libc/stdio_threading/fopen/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fopen_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c b/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c deleted file mode 100755 index 89172d9fb7..0000000000 --- a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 1 | /* $OpenBSD: fopen_test.c,v 1.2 2015/01/20 04:41:01 krw Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdio.h> | ||
| 19 | #include <pthread.h> | ||
| 20 | #include "local.h" | ||
| 21 | |||
| 22 | int | ||
| 23 | writefn(void *cookie, const char *buf, int size) | ||
| 24 | { | ||
| 25 | return 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | void | ||
| 29 | fopen_thread(void *v) | ||
| 30 | { | ||
| 31 | FILE *file; | ||
| 32 | int i; | ||
| 33 | |||
| 34 | for (i = 0; i < 4096; i++) { | ||
| 35 | file = fwopen(&i, writefn); | ||
| 36 | if (file != NULL) { | ||
| 37 | fputc('0', file); | ||
| 38 | pthread_yield(); | ||
| 39 | fclose(file); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | int | ||
| 45 | main(void) | ||
| 46 | { | ||
| 47 | run_threads(fopen_thread, NULL); | ||
| 48 | exit(0); | ||
| 49 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/Makefile b/src/regress/lib/libc/stdio_threading/fputs/Makefile deleted file mode 100644 index e561745581..0000000000 --- a/src/regress/lib/libc/stdio_threading/fputs/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fputs_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c deleted file mode 100755 index 93d0f0b6c7..0000000000 --- a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c +++ /dev/null | |||
| @@ -1,67 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fputs_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | for (i = 0; i < 4096; i++) { | ||
| 26 | if (fputs(TEXT, file) != 0) { | ||
| 27 | |||
| 28 | if (feof(file)) | ||
| 29 | break; | ||
| 30 | |||
| 31 | printf("OMG!!!\n"); | ||
| 32 | fflush(stdout); | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(void) | ||
| 40 | { | ||
| 41 | char sfn[24]; | ||
| 42 | char buf[sizeof(TEXT)]; | ||
| 43 | FILE *sfp; | ||
| 44 | int fd; | ||
| 45 | |||
| 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 47 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 49 | int saved_errno = errno; | ||
| 50 | if (fd != -1) { | ||
| 51 | unlink(sfn); | ||
| 52 | close(fd); | ||
| 53 | } | ||
| 54 | errc(1, saved_errno, "could not open temporary file"); | ||
| 55 | } | ||
| 56 | |||
| 57 | run_threads(fputs_thread, sfp); | ||
| 58 | |||
| 59 | while (fgets(buf, sizeof(buf), sfp) != NULL) /* verify */ | ||
| 60 | if (strcmp(buf, TEXT)) | ||
| 61 | err(1, "Thread writes were not atomic!!!"); | ||
| 62 | |||
| 63 | unlink(sfn); | ||
| 64 | close(fd); | ||
| 65 | |||
| 66 | exit(0); | ||
| 67 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/Makefile b/src/regress/lib/libc/stdio_threading/fread/Makefile deleted file mode 100644 index 25196dd7ab..0000000000 --- a/src/regress/lib/libc/stdio_threading/fread/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fread_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/fread_test.c b/src/regress/lib/libc/stdio_threading/fread/fread_test.c deleted file mode 100755 index 6bd734b470..0000000000 --- a/src/regress/lib/libc/stdio_threading/fread/fread_test.c +++ /dev/null | |||
| @@ -1,71 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <pthread.h> | ||
| 19 | #include "local.h" | ||
| 20 | |||
| 21 | void | ||
| 22 | fread_thread(void *v) | ||
| 23 | { | ||
| 24 | char buf[sizeof(TEXT)]; | ||
| 25 | FILE *file = v; | ||
| 26 | int i; | ||
| 27 | |||
| 28 | for (i = 0; i < 4096; i++) { | ||
| 29 | if (fread(buf, sizeof(char), strlen(TEXT), file) == 0) { | ||
| 30 | |||
| 31 | if (feof(file)) | ||
| 32 | break; | ||
| 33 | |||
| 34 | printf("OMG!!!\n"); | ||
| 35 | fflush(stdout); | ||
| 36 | break; | ||
| 37 | } | ||
| 38 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 39 | err(1, "Read not atomic!!!"); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | int | ||
| 44 | main(void) | ||
| 45 | { | ||
| 46 | char sfn[24]; | ||
| 47 | FILE *sfp; | ||
| 48 | int fd, i; | ||
| 49 | |||
| 50 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 51 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 52 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 53 | int saved_errno = errno; | ||
| 54 | if (fd != -1) { | ||
| 55 | unlink(sfn); | ||
| 56 | close(fd); | ||
| 57 | } | ||
| 58 | errc(1, saved_errno, "could not open temporary file"); | ||
| 59 | } | ||
| 60 | |||
| 61 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 62 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), sfp) == 0) | ||
| 63 | err(1, "Could not populate test file"); | ||
| 64 | |||
| 65 | run_threads(fread_thread, sfp); | ||
| 66 | |||
| 67 | unlink(sfn); | ||
| 68 | close(fd); | ||
| 69 | |||
| 70 | exit(0); | ||
| 71 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/Makefile b/src/regress/lib/libc/stdio_threading/fwrite/Makefile deleted file mode 100644 index e79899c475..0000000000 --- a/src/regress/lib/libc/stdio_threading/fwrite/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fwrite_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c deleted file mode 100755 index 86c450cbc9..0000000000 --- a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c +++ /dev/null | |||
| @@ -1,67 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fwrite_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | for (i = 0; i < 4096; i++) { | ||
| 26 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), file) == 0) { | ||
| 27 | |||
| 28 | if (feof(file)) | ||
| 29 | break; | ||
| 30 | |||
| 31 | printf("OMG!!!\n"); | ||
| 32 | fflush(stdout); | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(void) | ||
| 40 | { | ||
| 41 | char sfn[24]; | ||
| 42 | char buf[sizeof(TEXT)]; | ||
| 43 | FILE *sfp; | ||
| 44 | int fd; | ||
| 45 | |||
| 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 47 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 49 | int saved_errno = errno; | ||
| 50 | if (fd != -1) { | ||
| 51 | unlink(sfn); | ||
| 52 | close(fd); | ||
| 53 | } | ||
| 54 | errc(1, saved_errno, "could not open temporary file"); | ||
| 55 | } | ||
| 56 | |||
| 57 | run_threads(fwrite_thread, sfp); | ||
| 58 | |||
| 59 | while (fread(buf, sizeof(char), strlen(TEXT), sfp)) /* verify */ | ||
| 60 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 61 | err(1, "Thread writes were not atomic!!!"); | ||
| 62 | |||
| 63 | unlink(sfn); | ||
| 64 | close(fd); | ||
| 65 | |||
| 66 | exit(0); | ||
| 67 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/include/local.h b/src/regress/lib/libc/stdio_threading/include/local.h deleted file mode 100644 index 7a7822a452..0000000000 --- a/src/regress/lib/libc/stdio_threading/include/local.h +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <err.h> | ||
| 18 | #include <errno.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | #include <unistd.h> | ||
| 23 | #include <pthread.h> | ||
| 24 | |||
| 25 | #define THREAD_COUNT 64 | ||
| 26 | |||
| 27 | #define TEXT "barnacles" | ||
| 28 | #define TEXT_N "barnacles\n" | ||
| 29 | |||
| 30 | void run_threads(void (*)(void *), void *); | ||
| 31 | |||
| 32 | static pthread_rwlock_t start; | ||
| 33 | static void (*real_func)(void *); | ||
| 34 | |||
| 35 | static void * | ||
| 36 | thread(void *arg) | ||
| 37 | { | ||
| 38 | int r; | ||
| 39 | |||
| 40 | if ((r = pthread_rwlock_rdlock(&start))) | ||
| 41 | errc(1, r, "could not obtain lock in thread"); | ||
| 42 | real_func(arg); | ||
| 43 | if ((r = pthread_rwlock_unlock(&start))) | ||
| 44 | errc(1, r, "could not release lock in thread"); | ||
| 45 | return NULL; | ||
| 46 | } | ||
| 47 | |||
| 48 | void | ||
| 49 | run_threads(void (*func)(void *), void *arg) | ||
| 50 | { | ||
| 51 | pthread_t self, pthread[THREAD_COUNT]; | ||
| 52 | int i, r; | ||
| 53 | |||
| 54 | self = pthread_self(); | ||
| 55 | real_func = func; | ||
| 56 | if ((r = pthread_rwlock_init(&start, NULL))) | ||
| 57 | errc(1, r, "could not initialize lock"); | ||
| 58 | |||
| 59 | if ((r = pthread_rwlock_wrlock(&start))) /* block */ | ||
| 60 | errc(1, r, "could not lock lock"); | ||
| 61 | |||
| 62 | for (i = 0; i < THREAD_COUNT; i++) | ||
| 63 | if ((r = pthread_create(&pthread[i], NULL, thread, arg))) { | ||
| 64 | warnc(r, "could not create thread"); | ||
| 65 | pthread[i] = self; | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | if ((r = pthread_rwlock_unlock(&start))) /* unleash */ | ||
| 70 | errc(1, r, "could not release lock"); | ||
| 71 | |||
| 72 | sleep(1); | ||
| 73 | |||
| 74 | if ((r = pthread_rwlock_wrlock(&start))) /* sync */ | ||
| 75 | errx(1, "parent could not sync with children: %s", | ||
| 76 | strerror(r)); | ||
| 77 | |||
| 78 | for (i = 0; i < THREAD_COUNT; i++) | ||
| 79 | if (! pthread_equal(pthread[i], self) && | ||
| 80 | (r = pthread_join(pthread[i], NULL))) | ||
| 81 | warnc(r, "could not join thread"); | ||
| 82 | } | ||
| 83 | |||
