blob: 171c84d4d029fde9de546dcefa740d3f358469c2 [file] [log] [blame]
robbiewbbc75ee2002-05-21 17:03:44 +00001/*
2 *
3 * Copyright (C) Bull S.A. 2001
4 * Copyright (c) International Business Machines Corp., 2001
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * NAME
23 * readv03.c
24 *
25 * DESCRIPTION
26 * Testcase to check the error condition of the readv(2) system call
27 * when fd refers to a directory.
28 *
29 * CALLS
30 * readv()
31 *
32 * ALGORITHM
33 * loop if that option was specified
34 * call readv() when fd refers to a directory.
35 * check the errno value
36 * issue a PASS message if we get EISDIR - errno 21
37 * otherwise, the tests fails
38 * issue a FAIL message
39 * call cleanup
40 *
subrata_modak56207ce2009-03-23 13:35:39 +000041 * USAGE$
robbiewbbc75ee2002-05-21 17:03:44 +000042 * readv03
43 *
44 * HISTORY
45 * 05/2002 Ported by Jacky Malcles
46 *
47 * RESTRICTIONS
48 * None
49 */
50#include <sys/types.h>
51#include <sys/uio.h>
52#include <sys/fcntl.h>
53#include <errno.h>
54#include <string.h>
55#include <sys/stat.h>
56
57#include "test.h"
58#include "usctest.h"
59
60#define K_1 1024
61#define MODES S_IRWXU
62
subrata_modak4bb656a2009-02-26 12:02:09 +000063char buf1[K_1];
robbiewbbc75ee2002-05-21 17:03:44 +000064
subrata_modak4bb656a2009-02-26 12:02:09 +000065struct iovec rd_iovec[1] = {
subrata_modak56207ce2009-03-23 13:35:39 +000066 {buf1, K_1}
robbiewbbc75ee2002-05-21 17:03:44 +000067};
68
69const char *TEST_DIR = "alpha";
70int r_val;
71int fd;
72
robbiewbbc75ee2002-05-21 17:03:44 +000073char *TCID = "readv03";
74int TST_TOTAL = 1;
75extern int Tst_count;
76
77void setup();
78void cleanup();
79
robbiew0c7e81c2003-03-27 17:44:57 +000080int main(int ac, char **av)
robbiewbbc75ee2002-05-21 17:03:44 +000081{
subrata_modak56207ce2009-03-23 13:35:39 +000082 int lc; /* loop counter */
83 char *msg; /* message returned from parse_opts */
robbiewbbc75ee2002-05-21 17:03:44 +000084
85 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -080086 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080087 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak56207ce2009-03-23 13:35:39 +000088 /*NOTREACHED*/}
robbiewbbc75ee2002-05-21 17:03:44 +000089
90 setup();
91
92 /* The following loop checks looping state if -i option given */
93 for (lc = 0; TEST_LOOPING(lc); lc++) {
94
95 /* reset Tst_count in case we are looping */
96 Tst_count = 0;
97
98 if (readv(fd, rd_iovec, 1) < 0) {
99 if (errno != EISDIR) {
100 tst_resm(TFAIL, "expected errno = EISDIR, "
101 "got %d", errno);
102 } else {
103 tst_resm(TPASS, "got EISDIR");
104 }
105 } else {
106 tst_resm(TFAIL, "Error: readv returned a positive "
107 "value");
108 }
109
110 }
111 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000112 /*NOTREACHED*/ return 0;
robbiewbbc75ee2002-05-21 17:03:44 +0000113}
114
115/*
116 * setup() - performs all ONE TIME setup for this test.
117 */
subrata_modak56207ce2009-03-23 13:35:39 +0000118void setup()
robbiewbbc75ee2002-05-21 17:03:44 +0000119{
120
121 /* capture signals */
122 tst_sig(NOFORK, DEF_HANDLER, cleanup);
123
124 /* Pause if that option was specified */
125 TEST_PAUSE;
126
127 /* make a temporary directory and cd to it */
128 tst_tmpdir();
129
subrata_modak56207ce2009-03-23 13:35:39 +0000130 /*
131 * create a new directory and open it
132 */
robbiewbbc75ee2002-05-21 17:03:44 +0000133
subrata_modak56207ce2009-03-23 13:35:39 +0000134 if ((r_val = mkdir(TEST_DIR, MODES)) == -1) {
135 tst_brkm(TBROK, cleanup, "%s - mkdir() in main() "
136 "failed", TCID);
137 }
robbiewbbc75ee2002-05-21 17:03:44 +0000138
subrata_modak56207ce2009-03-23 13:35:39 +0000139 if ((fd = open(TEST_DIR, O_RDONLY)) == -1) {
140 tst_brkm(TBROK, cleanup, "open of directory failed");
141 }
robbiewbbc75ee2002-05-21 17:03:44 +0000142
143}
144
145/*
146 * cleanup() - performs all ONE TIME cleanup for this test at
147 * completion or premature exit.
148 */
subrata_modak56207ce2009-03-23 13:35:39 +0000149void cleanup()
robbiewbbc75ee2002-05-21 17:03:44 +0000150{
151 if (close(fd) < 0) {
152 tst_brkm(TBROK, cleanup, "close failed: errno = %d", errno);
153 }
154 tst_rmdir();
155 tst_exit();
156}