blob: ca0e0e155584090bc0f4a58cf27d405ec6e6c1c6 [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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewbbc75ee2002-05-21 17:03:44 +000019 */
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"
robbiewbbc75ee2002-05-21 17:03:44 +000058
59#define K_1 1024
60#define MODES S_IRWXU
61
subrata_modak4bb656a2009-02-26 12:02:09 +000062char buf1[K_1];
robbiewbbc75ee2002-05-21 17:03:44 +000063
subrata_modak4bb656a2009-02-26 12:02:09 +000064struct iovec rd_iovec[1] = {
subrata_modak56207ce2009-03-23 13:35:39 +000065 {buf1, K_1}
robbiewbbc75ee2002-05-21 17:03:44 +000066};
67
68const char *TEST_DIR = "alpha";
69int r_val;
70int fd;
71
robbiewbbc75ee2002-05-21 17:03:44 +000072char *TCID = "readv03";
73int TST_TOTAL = 1;
robbiewbbc75ee2002-05-21 17:03:44 +000074
75void setup();
76void cleanup();
77
robbiew0c7e81c2003-03-27 17:44:57 +000078int main(int ac, char **av)
robbiewbbc75ee2002-05-21 17:03:44 +000079{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020080 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020081 const char *msg;
robbiewbbc75ee2002-05-21 17:03:44 +000082
Garrett Cooper45e285d2010-11-22 12:19:25 -080083 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080084 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +080085 }
robbiewbbc75ee2002-05-21 17:03:44 +000086
87 setup();
88
89 /* The following loop checks looping state if -i option given */
90 for (lc = 0; TEST_LOOPING(lc); lc++) {
91
Caspar Zhangd59a6592013-03-07 14:59:12 +080092 /* reset tst_count in case we are looping */
93 tst_count = 0;
robbiewbbc75ee2002-05-21 17:03:44 +000094
95 if (readv(fd, rd_iovec, 1) < 0) {
96 if (errno != EISDIR) {
97 tst_resm(TFAIL, "expected errno = EISDIR, "
98 "got %d", errno);
99 } else {
100 tst_resm(TPASS, "got EISDIR");
101 }
102 } else {
103 tst_resm(TFAIL, "Error: readv returned a positive "
104 "value");
105 }
106
107 }
108 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800109 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800110
robbiewbbc75ee2002-05-21 17:03:44 +0000111}
112
113/*
114 * setup() - performs all ONE TIME setup for this test.
115 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400116void setup(void)
robbiewbbc75ee2002-05-21 17:03:44 +0000117{
118
robbiewbbc75ee2002-05-21 17:03:44 +0000119 tst_sig(NOFORK, DEF_HANDLER, cleanup);
120
robbiewbbc75ee2002-05-21 17:03:44 +0000121 TEST_PAUSE;
122
123 /* make a temporary directory and cd to it */
124 tst_tmpdir();
125
subrata_modak56207ce2009-03-23 13:35:39 +0000126 /*
127 * create a new directory and open it
128 */
robbiewbbc75ee2002-05-21 17:03:44 +0000129
subrata_modak56207ce2009-03-23 13:35:39 +0000130 if ((r_val = mkdir(TEST_DIR, MODES)) == -1) {
131 tst_brkm(TBROK, cleanup, "%s - mkdir() in main() "
132 "failed", TCID);
133 }
robbiewbbc75ee2002-05-21 17:03:44 +0000134
subrata_modak56207ce2009-03-23 13:35:39 +0000135 if ((fd = open(TEST_DIR, O_RDONLY)) == -1) {
136 tst_brkm(TBROK, cleanup, "open of directory failed");
137 }
robbiewbbc75ee2002-05-21 17:03:44 +0000138
139}
140
141/*
142 * cleanup() - performs all ONE TIME cleanup for this test at
143 * completion or premature exit.
144 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400145void cleanup(void)
robbiewbbc75ee2002-05-21 17:03:44 +0000146{
147 if (close(fd) < 0) {
148 tst_brkm(TBROK, cleanup, "close failed: errno = %d", errno);
149 }
150 tst_rmdir();
Garrett Cooper2c282152010-12-16 00:55:50 -0800151
Chris Dearmanec6edca2012-10-17 19:54:01 -0700152}