robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 18 | */ |
| 19 | /* ported from SPIE section2/filesuite/stream2.c, by Airong Zhang */ |
| 20 | |
| 21 | /*====================================================================== |
| 22 | =================== TESTPLAN SEGMENT =================== |
| 23 | >KEYS: < fseek() mknod() fopen() |
| 24 | >WHAT: < 1) |
| 25 | >HOW: < 1) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | >BUGS: < |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 27 | ======================================================================*/ |
| 28 | |
| 29 | #include <stdio.h> |
robbiew | a70576c | 2003-03-04 18:33:41 +0000 | [diff] [blame] | 30 | #include <errno.h> |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 31 | #include <fcntl.h> |
| 32 | #include <unistd.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include "test.h" |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 36 | |
| 37 | char *TCID = "stream02"; |
| 38 | int TST_TOTAL = 1; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 39 | int local_flag; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 40 | |
| 41 | #define PASSED 1 |
| 42 | #define FAILED 0 |
| 43 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 44 | char progname[] = "stream02()"; |
| 45 | char tempfile1[40] = ""; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 46 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 47 | /* XXX: add cleanup + setup. */ |
| 48 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 49 | /*--------------------------------------------------------------------*/ |
| 50 | int main(int ac, char *av[]) |
| 51 | { |
| 52 | FILE *stream; |
| 53 | int fd; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 54 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 55 | const char *msg; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 56 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 57 | /* |
| 58 | * parse standard options |
| 59 | */ |
| 60 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 61 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 62 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 63 | local_flag = PASSED; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 64 | tst_tmpdir(); |
| 65 | |
| 66 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 67 | |
| 68 | sprintf(tempfile1, "stream1.%d", getpid()); |
| 69 | /*--------------------------------------------------------------------*/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 70 | //block0: |
| 71 | if (mknod(tempfile1, (S_IFIFO | 0666), 0) != 0) { |
| 72 | tst_resm(TFAIL, "mknod failed in block0: %s", |
| 73 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 74 | local_flag = FAILED; |
| 75 | goto block1; |
| 76 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | if ((stream = fopen(tempfile1, "w+")) == NULL) { |
| 78 | tst_resm(TFAIL, "fopen(%s) w+ failed for pipe file: %s", |
| 79 | tempfile1, strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 80 | local_flag = FAILED; |
robbiew | 631dd65 | 2003-06-10 15:00:41 +0000 | [diff] [blame] | 81 | } else { |
| 82 | fclose(stream); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 83 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 84 | if ((stream = fopen(tempfile1, "a+")) == NULL) { |
| 85 | tst_resm(TFAIL, "fopen(%s) a+ failed: %s", tempfile1, |
| 86 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 87 | local_flag = FAILED; |
robbiew | 631dd65 | 2003-06-10 15:00:41 +0000 | [diff] [blame] | 88 | } else { |
| 89 | fclose(stream); |
| 90 | unlink(tempfile1); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 91 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 92 | if (local_flag == PASSED) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 93 | tst_resm(TPASS, "Test passed in block0."); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 94 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | tst_resm(TFAIL, "Test failed in block0."); |
| 96 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 97 | local_flag = PASSED; |
| 98 | |
| 99 | /*--------------------------------------------------------------------*/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 100 | block1: |
| 101 | if ((fd = open("/dev/tty", O_WRONLY)) >= 0) { |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 102 | close(fd); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | if ((stream = fopen("/dev/tty", "w")) == NULL) { |
| 104 | tst_resm(TFAIL | TERRNO, |
| 105 | "fopen(/dev/tty) write failed"); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 106 | local_flag = FAILED; |
robbiew | 631dd65 | 2003-06-10 15:00:41 +0000 | [diff] [blame] | 107 | } else { |
| 108 | fclose(stream); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 109 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 110 | } |
| 111 | if (local_flag == PASSED) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 112 | tst_resm(TPASS, "Test passed in block1."); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 113 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 114 | tst_resm(TFAIL, "Test failed in block1."); |
| 115 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 116 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 117 | /*--------------------------------------------------------------------*/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 118 | } /* end for */ |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 119 | tst_rmdir(); |
| 120 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 121 | } |