summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c
diff options
context:
space:
mode:
authorguenther <>2009-11-19 08:06:06 +0000
committerguenther <>2009-11-19 08:06:06 +0000
commit3bf8c221bc859ae3254fe6b11fb60750f0bae04e (patch)
treed068826e9af472b7f9584e32bdc17e83472df8f4 /src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c
parente9648d2ce662fb0d79072496682efb0718c01e66 (diff)
downloadopenbsd-3bf8c221bc859ae3254fe6b11fb60750f0bae04e.tar.gz
openbsd-3bf8c221bc859ae3254fe6b11fb60750f0bae04e.tar.bz2
openbsd-3bf8c221bc859ae3254fe6b11fb60750f0bae04e.zip
Add regression tests for stdio threading. Originally by blambert with
some further hacking by me
Diffstat (limited to 'src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c')
-rwxr-xr-xsrc/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c
new file mode 100755
index 0000000000..39bfb51ef0
--- /dev/null
+++ b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c
@@ -0,0 +1,66 @@
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
19void
20fwrite_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
38int
39main(void)
40{
41 char sfn[24];
42 char buf[sizeof(TEXT)];
43 FILE *sfp;
44 int fd, i;
45
46 strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn));
47 if ((fd = mkstemp(sfn)) == -1 ||
48 (sfp = fdopen(fd, "w+")) == NULL) {
49 if (fd != -1) {
50 unlink(sfn);
51 close(fd);
52 }
53 err(1, "could not open temporary file");
54 }
55
56 run_threads(fwrite_thread, sfp);
57
58 while (fread(buf, sizeof(char), strlen(TEXT), sfp)) /* verify */
59 if (strncmp(buf, TEXT, sizeof(TEXT)))
60 err(1, "Thread writes were not atomic!!!");
61
62 unlink(sfn);
63 close(fd);
64
65 exit(0);
66}