summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/stdio_threading/fread
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/stdio_threading/fread')
-rw-r--r--src/regress/lib/libc/stdio_threading/fread/Makefile6
-rwxr-xr-xsrc/regress/lib/libc/stdio_threading/fread/fread_test.c71
2 files changed, 77 insertions, 0 deletions
diff --git a/src/regress/lib/libc/stdio_threading/fread/Makefile b/src/regress/lib/libc/stdio_threading/fread/Makefile
new file mode 100644
index 0000000000..25196dd7ab
--- /dev/null
+++ b/src/regress/lib/libc/stdio_threading/fread/Makefile
@@ -0,0 +1,6 @@
1TOPDIR=${.CURDIR}
2PROG=fread_test
3CFLAGS+=-I${TOPDIR}/../include/
4LDFLAGS+=-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
new file mode 100755
index 0000000000..b2372f5ab6
--- /dev/null
+++ b/src/regress/lib/libc/stdio_threading/fread/fread_test.c
@@ -0,0 +1,71 @@
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
21void
22fread_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
43int
44main(void)
45{
46 char sfn[24];
47 char buf[sizeof(TEXT)];
48 FILE *sfp;
49 int fd, i;
50
51 strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn));
52 if ((fd = mkstemp(sfn)) == -1 ||
53 (sfp = fdopen(fd, "w+")) == NULL) {
54 if (fd != -1) {
55 unlink(sfn);
56 close(fd);
57 }
58 err(1, "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}