blob: 8b12e5957574f11fadd5744efc1d90376ed2b9c2 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
22 * writev01.c
23 *
24 * DESCRIPTION
25 * Testcase to check the basic functionality of writev(2) system call.
26 *
27 * ALGORITHM
28 * Create a IO vector, and attempt to writev() various components of it.
29 *
30 * USAGE: <for command-line>
31 * writev01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
32 * where, -c n : Run n copies concurrently.
33 * -e : Turn on errno logging.
34 * -i n : Execute test n times.
35 * -I x : Execute test for x seconds.
36 * -P x : Pause for x seconds between iterations.
37 * -t : Turn on syscall timing.
38 *
39 * History
40 * 07/2001 John George
41 * -Ported
robbiew4644c7e2002-04-26 14:33:32 +000042 * 04/2002 wjhuie sigset cleanups
robbiew51281002002-06-20 17:02:19 +000043 * 06/2002 Shaobo Li
44 * fix testcase 7, add each testcase comment.
plars865695b2001-08-27 22:15:12 +000045 *
46 * Restrictions
47 * None
48 */
49
50#include <stdio.h>
plars29bcde82002-10-07 17:21:48 +000051#include <sys/types.h>
plars20bc5f22002-10-10 17:37:56 +000052#include <signal.h>
plars865695b2001-08-27 22:15:12 +000053#include <sys/uio.h>
54#include <sys/fcntl.h>
55#include <memory.h>
56#include <errno.h>
57#include <test.h>
58#include <usctest.h>
robbiewb73a6b72003-11-17 15:21:18 +000059#include <sys/mman.h>
plars865695b2001-08-27 22:15:12 +000060
61#define K_1 1024
62#define M_1 K_1 * K_1
63#define G_1 M_1 * K_1
64
65#define NBUFS 4
subrata_modak56207ce2009-03-23 13:35:39 +000066#define CHUNK 64 /* single chunk */
plars865695b2001-08-27 22:15:12 +000067#define MAX_IOVEC 16
68#define DATA_FILE "writev_data_file"
69
70char buf1[K_1], buf2[K_1], buf3[K_1];
71
72struct iovec wr_iovec[MAX_IOVEC] = {
subrata_modak56207ce2009-03-23 13:35:39 +000073 /* iov_base *//* iov_len */
plars865695b2001-08-27 22:15:12 +000074
75 /* testcase# 1 */
subrata_modak56207ce2009-03-23 13:35:39 +000076 {buf1, -1},
77 {(buf1 + CHUNK), CHUNK},
78 {(buf1 + CHUNK * 2), CHUNK},
plars865695b2001-08-27 22:15:12 +000079
80 /* testcase# 2 */
subrata_modak56207ce2009-03-23 13:35:39 +000081 {(buf1 + CHUNK * 3), G_1},
82 {(buf1 + CHUNK * 4), G_1},
83 {(buf1 + CHUNK * 5), G_1},
plars865695b2001-08-27 22:15:12 +000084
85 /* testcase# 3 */
subrata_modak56207ce2009-03-23 13:35:39 +000086 {(buf1 + CHUNK * 6), CHUNK},
87 {(caddr_t) - 1, CHUNK},
88 {(buf1 + CHUNK * 8), CHUNK},
plars865695b2001-08-27 22:15:12 +000089
90 /* testcase# 4 */
subrata_modak56207ce2009-03-23 13:35:39 +000091 {(buf1 + CHUNK * 9), CHUNK},
plars865695b2001-08-27 22:15:12 +000092
93 /* testcase# 5 */
subrata_modak56207ce2009-03-23 13:35:39 +000094 {(buf1 + CHUNK * 10), CHUNK},
plars865695b2001-08-27 22:15:12 +000095
96 /* testcase# 6 */
subrata_modak56207ce2009-03-23 13:35:39 +000097 {(buf1 + CHUNK * 11), CHUNK},
plars865695b2001-08-27 22:15:12 +000098
99 /* testcase# 7 */
subrata_modak56207ce2009-03-23 13:35:39 +0000100 {(buf1 + CHUNK * 12), CHUNK},
plars865695b2001-08-27 22:15:12 +0000101
102 /* testcase# 8 */
subrata_modak56207ce2009-03-23 13:35:39 +0000103 {(buf1 + CHUNK * 13), 0},
plars865695b2001-08-27 22:15:12 +0000104
robbiew51281002002-06-20 17:02:19 +0000105 /* testcase# 7 */
subrata_modak56207ce2009-03-23 13:35:39 +0000106 {(caddr_t) NULL, 0},
107 {(caddr_t) NULL, 0}
plars865695b2001-08-27 22:15:12 +0000108};
109
110char name[K_1], f_name[K_1];
111
subrata_modak56207ce2009-03-23 13:35:39 +0000112char *bad_addr = 0;
robbiewb73a6b72003-11-17 15:21:18 +0000113
plars865695b2001-08-27 22:15:12 +0000114/* 0 terminated list of expected errnos */
subrata_modak56207ce2009-03-23 13:35:39 +0000115int exp_enos[] = { 14, 22, 32, 77, 0 };
plars865695b2001-08-27 22:15:12 +0000116
117int fd[4], in_sighandler;
subrata_modak56207ce2009-03-23 13:35:39 +0000118int pfd[2]; /* pipe fd's */
plars865695b2001-08-27 22:15:12 +0000119char *buf_list[NBUFS];
120int fail;
121
122void sighandler(int);
123long l_seek(int, long, int);
124int fill_mem(char *, int, int);
125int init_buffs(char *[]);
126void setup(void);
127void cleanup(void);
128
129char *TCID = "writev01";
130int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +0000131
robbiew7d5c5172003-03-27 22:54:57 +0000132int main(int argc, char **argv)
plars865695b2001-08-27 22:15:12 +0000133{
134 int nbytes, ret;
135
subrata_modak56207ce2009-03-23 13:35:39 +0000136 int lc; /* loop counter */
137 char *msg; /* message returned from parse_opts */
plars865695b2001-08-27 22:15:12 +0000138
139 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -0800140 if ((msg = parse_opts(argc, argv, NULL, NULL)) !=
141 NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -0800142 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper53740502010-12-16 00:04:01 -0800143 }
plars865695b2001-08-27 22:15:12 +0000144
145 /* set "tstdir", and "testfile" vars */
146 setup();
147
148 /* The following loop checks looping state if -i option given */
149 for (lc = 0; TEST_LOOPING(lc); lc++) {
150
plars865695b2001-08-27 22:15:12 +0000151 /* reset Tst_count in case we are looping */
152 Tst_count = 0;
153
154 buf_list[0] = buf1;
155 buf_list[1] = buf2;
156 buf_list[2] = buf3;
Garrett Cooper45e285d2010-11-22 12:19:25 -0800157 buf_list[3] = NULL;
plars865695b2001-08-27 22:15:12 +0000158
subrata_modak56207ce2009-03-23 13:35:39 +0000159 fd[1] = -1; /* Invalid file descriptor */
plars865695b2001-08-27 22:15:12 +0000160
robbiew4644c7e2002-04-26 14:33:32 +0000161 if (signal(SIGTERM, sighandler) == SIG_ERR) {
162 perror("signal: SIGTERM");
plars865695b2001-08-27 22:15:12 +0000163 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800164 }
plars865695b2001-08-27 22:15:12 +0000165
robbiew4644c7e2002-04-26 14:33:32 +0000166 if (signal(SIGPIPE, sighandler) == SIG_ERR) {
167 perror("signal: SIGPIPE");
plars865695b2001-08-27 22:15:12 +0000168 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800169 }
plars865695b2001-08-27 22:15:12 +0000170
171 init_buffs(buf_list);
172
173 if ((fd[0] = open(f_name, O_WRONLY | O_CREAT, 0666)) < 0) {
174 tst_resm(TFAIL, "open failed: fname = %s, errno = %d",
175 f_name, errno);
176 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800177 } else
subrata_modak56207ce2009-03-23 13:35:39 +0000178 if ((nbytes = write(fd[0], buf_list[2], K_1)) != K_1) {
179 tst_resm(TFAIL,
180 "write failed: nbytes = %d, " "errno = %d",
181 nbytes, errno);
plars865695b2001-08-27 22:15:12 +0000182 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800183 }
plars865695b2001-08-27 22:15:12 +0000184
185 if (close(fd[0]) < 0) {
186 tst_resm(TFAIL, "close failed: errno: %d", errno);
187 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800188 }
plars865695b2001-08-27 22:15:12 +0000189
190 if ((fd[0] = open(f_name, O_RDWR, 0666)) < 0) {
191 tst_resm(TFAIL, "open failed: fname = %s, errno = %d",
192 f_name, errno);
193 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800194 }
robbiew7d5c5172003-03-27 22:54:57 +0000195//block1: /* given vector length -1, writev() return EINVAL. */
plars865695b2001-08-27 22:15:12 +0000196 tst_resm(TINFO, "Enter Block 1");
197 fail = 0;
198
199 TEST(writev(fd[0], wr_iovec, 1));
200 if (TEST_RETURN < 0) {
201 TEST_ERROR_LOG(TEST_ERRNO);
202 if (TEST_ERRNO == EINVAL) {
203 tst_resm(TINFO, "Received EINVAL as expected");
204 } else {
205 tst_resm(TFAIL, "Expected errno = EINVAL, "
206 "got %d", TEST_ERRNO);
207 fail = 1;
208 }
209 } else {
210 tst_resm(TFAIL, "writev() failed to fail");
211 fail = 1;
212 }
213 if (fail) {
214 tst_resm(TINFO, "block 1 FAILED");
215 } else {
216 tst_resm(TINFO, "block 1 PASSED");
217 }
218 tst_resm(TINFO, "Exit block 1");
219
robbiew7d5c5172003-03-27 22:54:57 +0000220//block2:
subrata_modak56207ce2009-03-23 13:35:39 +0000221 /* This testcases doesn't look like what it intent to do
222 * 1. it is not using the wr_iovec initialized
223 * 2. read() and following message is not consistent
224 */
plars865695b2001-08-27 22:15:12 +0000225 tst_resm(TINFO, "Enter block 2");
226 fail = 0;
227
228 if (l_seek(fd[0], CHUNK * 6, 0) < 0) {
229 TEST_ERROR_LOG(errno);
230 tst_resm(TBROK, "block2: 1st lseek failed");
231 fail = 1;
232 }
233
234 if ((ret = writev(fd[0], (wr_iovec + 6), 3)) == CHUNK) {
235 if (l_seek(fd[0], CHUNK * 6, 0) < 0) {
236 TEST_ERROR_LOG(errno);
237 tst_resm(TFAIL, "block2: 2nd lseek failed");
238 fail = 1;
239 }
subrata_modak56207ce2009-03-23 13:35:39 +0000240 if ((nbytes = read(fd[0], buf_list[0], CHUNK)) != CHUNK) {
plars865695b2001-08-27 22:15:12 +0000241 perror("read error");
242 tst_resm(TFAIL, "expected nbytes = 1024, "
243 "got = %d", nbytes);
244 fail = 1;
245 } else if (memcmp((buf_list[0] + CHUNK * 6),
246 (buf_list[2] + CHUNK * 6),
247 CHUNK) != 0) {
248 tst_resm(TFAIL, "Error: writev() over "
249 "wrote %s", f_name);
250 fail = 1;
251 }
252 } else {
253 tst_resm(TFAIL, "writev() failed unexpectedly");
254 fail = 1;
255 }
256 if (fail) {
257 tst_resm(TINFO, "block 2 FAILED");
258 } else {
259 tst_resm(TINFO, "block 2 PASSED");
260 }
261 tst_resm(TINFO, "Exit block 2");
262
robbiew7d5c5172003-03-27 22:54:57 +0000263//block3: /* given 1 bad vector buffer with good ones, writev() success */
plars865695b2001-08-27 22:15:12 +0000264 tst_resm(TINFO, "Enter block 3");
265 fail = 0;
266
267 if (lseek(fd[0], CHUNK * 6, 0) < 0) {
268 TEST_ERROR_LOG(errno);
269 tst_resm(TFAIL, "block3: 1st lseek failed");
270 fail = 1;
271 }
272 if ((nbytes = writev(fd[0], (wr_iovec + 6), 3)) < 0) {
273 TEST_ERROR_LOG(errno);
274 if (errno == EFAULT) {
275 tst_resm(TFAIL, "Got EFAULT");
276 fail = 1;
277 }
278 }
279 if (l_seek(fd[0], 0, 0) < 0) {
280 TEST_ERROR_LOG(errno);
281 tst_resm(TFAIL, "block3: 2nd lseek failed");
282 fail = 1;
283 }
284 if ((nbytes = read(fd[0], buf_list[0], K_1)) != K_1) {
285 perror("read error");
286 tst_resm(TFAIL, "expected nbytes = 1024, got = %d",
287 nbytes);
288 fail = 1;
subrata_modak56207ce2009-03-23 13:35:39 +0000289 } else if (memcmp((buf_list[0] + CHUNK * 6),
290 (buf_list[2] + CHUNK * 6), CHUNK * 3) != 0) {
plars865695b2001-08-27 22:15:12 +0000291 tst_resm(TFAIL, "Error: writev() over wrote %s",
292 f_name);
293 fail = 1;
294 }
295
296 if (fail) {
297 tst_resm(TINFO, "block 3 FAILED");
298 } else {
299 tst_resm(TINFO, "block 3 PASSED");
300 }
301 tst_resm(TINFO, "Exit block 3");
302
robbiew7d5c5172003-03-27 22:54:57 +0000303//block4: /* given bad file discriptor, writev() return EBADF. */
plars865695b2001-08-27 22:15:12 +0000304 tst_resm(TINFO, "Enter block 4");
305 fail = 0;
306
307 TEST(writev(fd[1], (wr_iovec + 9), 1));
308 if (TEST_RETURN < 0) {
309 TEST_ERROR_LOG(TEST_ERRNO);
310 if (TEST_ERRNO == EBADF) {
311 tst_resm(TINFO, "Received EBADF as expected");
312 } else {
313 tst_resm(TFAIL, "expected errno = EBADF, "
314 "got %d", TEST_ERRNO);
315 fail = 1;
316 }
317 } else {
318 tst_resm(TFAIL, "Error: writev() returned a "
319 "positive value");
320 fail = 1;
321 }
322
323 if (fail) {
324 tst_resm(TINFO, "block 4 FAILED");
325 } else {
326 tst_resm(TINFO, "block 4 PASSED");
327 }
328 tst_resm(TINFO, "Exit block 4");
329
robbiew7d5c5172003-03-27 22:54:57 +0000330//block5: /* given invalid vector count, writev() return EINVAL */
plars865695b2001-08-27 22:15:12 +0000331 tst_resm(TINFO, "Enter block 5");
332 fail = 0;
333
334 TEST(writev(fd[0], (wr_iovec + 10), -1));
335 if (TEST_RETURN < 0) {
336 TEST_ERROR_LOG(TEST_ERRNO);
337 if (TEST_ERRNO == EINVAL) {
338 tst_resm(TINFO, "Received EINVAL as expected");
339 } else {
340 tst_resm(TFAIL, "expected errno = EINVAL, "
341 "got %d", TEST_ERRNO);
342 fail = 1;
343 }
344 } else {
345 tst_resm(TFAIL, "Error: writev() returned a "
346 "positive value");
347 fail = 1;
348 }
349
350 if (fail) {
351 tst_resm(TINFO, "block 5 FAILED");
352 } else {
353 tst_resm(TINFO, "block 5 PASSED");
354 }
355 tst_resm(TINFO, "Exit block 5");
356
robbiew7d5c5172003-03-27 22:54:57 +0000357//block6: /* given no buffer vector, writev() success */
plars865695b2001-08-27 22:15:12 +0000358 tst_resm(TINFO, "Enter block 6");
359 fail = 0;
360
361 TEST(writev(fd[0], (wr_iovec + 11), 0));
plars20bc5f22002-10-10 17:37:56 +0000362 if (TEST_RETURN < 0) {
363 TEST_ERROR_LOG(TEST_ERRNO);
364 tst_resm(TFAIL, "writev() failed with unexpected errno "
365 "%d", TEST_ERRNO);
plars29bcde82002-10-07 17:21:48 +0000366 fail = 1;
plars20bc5f22002-10-10 17:37:56 +0000367 } else {
368 tst_resm(TPASS, "writev() wrote 0 iovectors");
plars865695b2001-08-27 22:15:12 +0000369 }
370
371 if (fail) {
372 tst_resm(TINFO, "block 6 FAILED");
373 } else {
374 tst_resm(TINFO, "block 6 PASSED");
375 }
376 tst_resm(TINFO, "Exit block 6");
377
robbiew7d5c5172003-03-27 22:54:57 +0000378//block7:
subrata_modak56207ce2009-03-23 13:35:39 +0000379 /* given 4 vectors, 2 are NULL, 1 with 0 length and 1 with fixed length,
380 * writev() success writing fixed length.
381 */
plars865695b2001-08-27 22:15:12 +0000382 tst_resm(TINFO, "Enter block 7");
383 fail = 0;
384
385 l_seek(fd[0], CHUNK * 12, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000386 if ((ret = writev(fd[0], (wr_iovec + 12), 4)) != CHUNK) {
plars865695b2001-08-27 22:15:12 +0000387 tst_resm(TFAIL, "writev() failed writing %d bytes, "
388 "followed by two NULL vectors", CHUNK);
389 fail = 1;
390 } else {
391 tst_resm(TPASS, "writev passed writing %d bytes, "
392 "followed by two NULL vectors", CHUNK);
393 }
394
395 if (fail) {
396 tst_resm(TINFO, "block 7 FAILED");
397 } else {
398 tst_resm(TINFO, "block 7 PASSED");
399 }
400 tst_resm(TINFO, "Exit block 7");
401
robbiew7d5c5172003-03-27 22:54:57 +0000402//block8: /* try to write to a closed pipe, writev() return EPIPE. */
plars865695b2001-08-27 22:15:12 +0000403 tst_resm(TINFO, "Enter block 8");
404 fail = 0;
405
406 if (pipe(pfd) < 0) {
407 TEST_ERROR_LOG(errno);
408 perror("pipe");
409 tst_resm(TFAIL, "pipe failed: errno = %d", errno);
410 fail = 1;
411 } else {
412 if (close(pfd[0]) < 0) {
413 TEST_ERROR_LOG(errno);
414 perror("close");
415 tst_resm(TFAIL, "close failed: errno = %d",
416 errno);
417 fail = 1;
418 } else if ((writev(pfd[1], (wr_iovec + 12), 1)
subrata_modak56207ce2009-03-23 13:35:39 +0000419 < 0) && in_sighandler) {
plars865695b2001-08-27 22:15:12 +0000420 TEST_ERROR_LOG(errno);
421 if (errno == EPIPE) {
422 tst_resm(TINFO, "Received EPIPE as "
subrata_modak56207ce2009-03-23 13:35:39 +0000423 "expected");
plars865695b2001-08-27 22:15:12 +0000424 } else {
425 tst_resm(TFAIL, "expected errno = "
426 "EPIPE, got %d", errno);
427 fail = 1;
428 }
429 } else {
430 tst_resm(TFAIL, "Error: writev() returned a "
431 "positive value");
432 fail = 1;
433 }
434 }
435 if (fail) {
436 tst_resm(TINFO, "block 8 FAILED");
437 } else {
438 tst_resm(TINFO, "block 8 PASSED");
439 }
440 tst_resm(TINFO, "Exit block 8");
441 }
subrata_modakdad6e1a2007-10-30 10:46:58 +0000442 close(fd[0]);
443 close(fd[1]);
plars865695b2001-08-27 22:15:12 +0000444 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800445 tst_exit();
plars865695b2001-08-27 22:15:12 +0000446}
447
448/*
449 * setup()
450 * performs all ONE TIME setup for this test
451 */
subrata_modak56207ce2009-03-23 13:35:39 +0000452void setup(void)
plars865695b2001-08-27 22:15:12 +0000453{
Garrett Cooper2c282152010-12-16 00:55:50 -0800454
plars865695b2001-08-27 22:15:12 +0000455 tst_sig(FORK, DEF_HANDLER, cleanup);
456
457 /* Set up the expected error numbers for -e option */
458 TEST_EXP_ENOS(exp_enos);
459
460 /* Pause if that option was specified.
461 * TEST_PAUSE contains the code to fork the test with the -i option.
462 * You want to make sure you do this before you create your temporary
463 * directory.
464 */
465 TEST_PAUSE;
466
467 /* Create a unique temporary directory and chdir() to it. */
468 tst_tmpdir();
469
470 strcpy(name, DATA_FILE);
471 sprintf(f_name, "%s.%d", name, getpid());
robbiewb73a6b72003-11-17 15:21:18 +0000472
subrata_modak56207ce2009-03-23 13:35:39 +0000473 bad_addr = mmap(0, 1, PROT_NONE,
474 MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
475 if (bad_addr == MAP_FAILED) {
476 printf("mmap failed\n");
477 }
478 wr_iovec[7].iov_base = bad_addr;
robbiewb73a6b72003-11-17 15:21:18 +0000479
plars865695b2001-08-27 22:15:12 +0000480}
481
482/*
483 * cleanup()
484 * performs all ONE TIME cleanup for this test at
485 * completion or premature exit
486 */
subrata_modak56207ce2009-03-23 13:35:39 +0000487void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000488{
489 /*
490 * print timing stats if that option was specified.
491 * print errno log if that option was specified.
492 */
493 TEST_CLEANUP;
494
495 if (unlink(f_name) < 0) {
496 tst_resm(TFAIL, "unlink Failed--file = %s, errno = %d",
497 f_name, errno);
498 }
499 tst_rmdir();
500
plars865695b2001-08-27 22:15:12 +0000501}
502
subrata_modak56207ce2009-03-23 13:35:39 +0000503int init_buffs(char *pbufs[])
plars865695b2001-08-27 22:15:12 +0000504{
505 int i;
506
Garrett Cooper45e285d2010-11-22 12:19:25 -0800507 for (i = 0; pbufs[i] != NULL; i++) {
plars865695b2001-08-27 22:15:12 +0000508 switch (i) {
509 case 0:
subrata_modak56207ce2009-03-23 13:35:39 +0000510
511 case 1:
512 fill_mem(pbufs[i], 0, 1);
plars865695b2001-08-27 22:15:12 +0000513 break;
514
subrata_modak56207ce2009-03-23 13:35:39 +0000515 case 2:
516 fill_mem(pbufs[i], 1, 0);
517 break;
518
519 default:
520 tst_resm(TFAIL, "Error detected: init_buffs()");
521 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800522 }
plars865695b2001-08-27 22:15:12 +0000523 }
subrata_modak43337a32009-02-26 11:43:51 +0000524 return 0;
plars865695b2001-08-27 22:15:12 +0000525}
526
subrata_modak56207ce2009-03-23 13:35:39 +0000527int fill_mem(char *c_ptr, int c1, int c2)
plars865695b2001-08-27 22:15:12 +0000528{
529 int count;
530
531 for (count = 1; count <= K_1 / CHUNK; count++) {
subrata_modak56207ce2009-03-23 13:35:39 +0000532 if (count & 0x01) { /* if odd */
plars865695b2001-08-27 22:15:12 +0000533 memset(c_ptr, c1, CHUNK);
subrata_modak56207ce2009-03-23 13:35:39 +0000534 } else { /* if even */
plars865695b2001-08-27 22:15:12 +0000535 memset(c_ptr, c2, CHUNK);
536 }
537 }
subrata_modak43337a32009-02-26 11:43:51 +0000538 return 0;
plars865695b2001-08-27 22:15:12 +0000539}
540
subrata_modak56207ce2009-03-23 13:35:39 +0000541void sighandler(int sig)
plars865695b2001-08-27 22:15:12 +0000542{
543 switch (sig) {
subrata_modak56207ce2009-03-23 13:35:39 +0000544 case SIGTERM:
545 break;
plars865695b2001-08-27 22:15:12 +0000546
subrata_modak56207ce2009-03-23 13:35:39 +0000547 case SIGPIPE:
548 ++in_sighandler;
549 return;
plars865695b2001-08-27 22:15:12 +0000550
subrata_modak56207ce2009-03-23 13:35:39 +0000551 default:
552 tst_resm(TFAIL, "sighandler() received invalid "
553 "signal:%d", sig);
554 break;
plars865695b2001-08-27 22:15:12 +0000555 }
556
557 if (unlink(f_name) < 0) {
558 tst_resm(TFAIL, "unlink Failed--file = %s, errno = %d",
559 f_name, errno);
560 tst_exit();
Garrett Cooper53740502010-12-16 00:04:01 -0800561 }
plars865695b2001-08-27 22:15:12 +0000562 exit(sig);
563}
564
subrata_modak56207ce2009-03-23 13:35:39 +0000565long l_seek(int fdesc, long offset, int whence)
plars865695b2001-08-27 22:15:12 +0000566{
567 if (lseek(fdesc, offset, whence) < 0) {
568 perror("lseek");
569 tst_resm(TFAIL, "lseek Failed : errno = %d", errno);
570 fail = 1;
571 }
subrata_modak43337a32009-02-26 11:43:51 +0000572 return 0;
Garrett Cooper2c282152010-12-16 00:55:50 -0800573}