blob: 134c1525f85cb48c3b7408fcee039ba8a0f18c86 [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;
131extern int Tst_count;
132
robbiew7d5c5172003-03-27 22:54:57 +0000133int main(int argc, char **argv)
plars865695b2001-08-27 22:15:12 +0000134{
135 int nbytes, ret;
136
subrata_modak56207ce2009-03-23 13:35:39 +0000137 int lc; /* loop counter */
138 char *msg; /* message returned from parse_opts */
plars865695b2001-08-27 22:15:12 +0000139
140 /* parse standard options */
subrata_modak56207ce2009-03-23 13:35:39 +0000141 if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) !=
142 (char *)NULL) {
plars865695b2001-08-27 22:15:12 +0000143 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000144 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +0000145
146 /* set "tstdir", and "testfile" vars */
147 setup();
148
149 /* The following loop checks looping state if -i option given */
150 for (lc = 0; TEST_LOOPING(lc); lc++) {
151
plars865695b2001-08-27 22:15:12 +0000152 /* reset Tst_count in case we are looping */
153 Tst_count = 0;
154
155 buf_list[0] = buf1;
156 buf_list[1] = buf2;
157 buf_list[2] = buf3;
158 buf_list[3] = (char *)NULL;
159
subrata_modak56207ce2009-03-23 13:35:39 +0000160 fd[1] = -1; /* Invalid file descriptor */
plars865695b2001-08-27 22:15:12 +0000161
robbiew4644c7e2002-04-26 14:33:32 +0000162 if (signal(SIGTERM, sighandler) == SIG_ERR) {
163 perror("signal: SIGTERM");
plars865695b2001-08-27 22:15:12 +0000164 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000165 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +0000166
robbiew4644c7e2002-04-26 14:33:32 +0000167 if (signal(SIGPIPE, sighandler) == SIG_ERR) {
168 perror("signal: SIGPIPE");
plars865695b2001-08-27 22:15:12 +0000169 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000170 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +0000171
172 init_buffs(buf_list);
173
174 if ((fd[0] = open(f_name, O_WRONLY | O_CREAT, 0666)) < 0) {
175 tst_resm(TFAIL, "open failed: fname = %s, errno = %d",
176 f_name, errno);
177 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000178 /*NOTREACHED*/} else
179 if ((nbytes = write(fd[0], buf_list[2], K_1)) != K_1) {
180 tst_resm(TFAIL,
181 "write failed: nbytes = %d, " "errno = %d",
182 nbytes, errno);
plars865695b2001-08-27 22:15:12 +0000183 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000184 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +0000185
186 if (close(fd[0]) < 0) {
187 tst_resm(TFAIL, "close failed: errno: %d", errno);
188 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000189 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +0000190
191 if ((fd[0] = open(f_name, O_RDWR, 0666)) < 0) {
192 tst_resm(TFAIL, "open failed: fname = %s, errno = %d",
193 f_name, errno);
194 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000195 /*NOTREACHED*/}
robbiew7d5c5172003-03-27 22:54:57 +0000196//block1: /* given vector length -1, writev() return EINVAL. */
plars865695b2001-08-27 22:15:12 +0000197 tst_resm(TINFO, "Enter Block 1");
198 fail = 0;
199
200 TEST(writev(fd[0], wr_iovec, 1));
201 if (TEST_RETURN < 0) {
202 TEST_ERROR_LOG(TEST_ERRNO);
203 if (TEST_ERRNO == EINVAL) {
204 tst_resm(TINFO, "Received EINVAL as expected");
205 } else {
206 tst_resm(TFAIL, "Expected errno = EINVAL, "
207 "got %d", TEST_ERRNO);
208 fail = 1;
209 }
210 } else {
211 tst_resm(TFAIL, "writev() failed to fail");
212 fail = 1;
213 }
214 if (fail) {
215 tst_resm(TINFO, "block 1 FAILED");
216 } else {
217 tst_resm(TINFO, "block 1 PASSED");
218 }
219 tst_resm(TINFO, "Exit block 1");
220
robbiew7d5c5172003-03-27 22:54:57 +0000221//block2:
subrata_modak56207ce2009-03-23 13:35:39 +0000222 /* This testcases doesn't look like what it intent to do
223 * 1. it is not using the wr_iovec initialized
224 * 2. read() and following message is not consistent
225 */
plars865695b2001-08-27 22:15:12 +0000226 tst_resm(TINFO, "Enter block 2");
227 fail = 0;
228
229 if (l_seek(fd[0], CHUNK * 6, 0) < 0) {
230 TEST_ERROR_LOG(errno);
231 tst_resm(TBROK, "block2: 1st lseek failed");
232 fail = 1;
233 }
234
235 if ((ret = writev(fd[0], (wr_iovec + 6), 3)) == CHUNK) {
236 if (l_seek(fd[0], CHUNK * 6, 0) < 0) {
237 TEST_ERROR_LOG(errno);
238 tst_resm(TFAIL, "block2: 2nd lseek failed");
239 fail = 1;
240 }
subrata_modak56207ce2009-03-23 13:35:39 +0000241 if ((nbytes = read(fd[0], buf_list[0], CHUNK)) != CHUNK) {
plars865695b2001-08-27 22:15:12 +0000242 perror("read error");
243 tst_resm(TFAIL, "expected nbytes = 1024, "
244 "got = %d", nbytes);
245 fail = 1;
246 } else if (memcmp((buf_list[0] + CHUNK * 6),
247 (buf_list[2] + CHUNK * 6),
248 CHUNK) != 0) {
249 tst_resm(TFAIL, "Error: writev() over "
250 "wrote %s", f_name);
251 fail = 1;
252 }
253 } else {
254 tst_resm(TFAIL, "writev() failed unexpectedly");
255 fail = 1;
256 }
257 if (fail) {
258 tst_resm(TINFO, "block 2 FAILED");
259 } else {
260 tst_resm(TINFO, "block 2 PASSED");
261 }
262 tst_resm(TINFO, "Exit block 2");
263
robbiew7d5c5172003-03-27 22:54:57 +0000264//block3: /* given 1 bad vector buffer with good ones, writev() success */
plars865695b2001-08-27 22:15:12 +0000265 tst_resm(TINFO, "Enter block 3");
266 fail = 0;
267
268 if (lseek(fd[0], CHUNK * 6, 0) < 0) {
269 TEST_ERROR_LOG(errno);
270 tst_resm(TFAIL, "block3: 1st lseek failed");
271 fail = 1;
272 }
273 if ((nbytes = writev(fd[0], (wr_iovec + 6), 3)) < 0) {
274 TEST_ERROR_LOG(errno);
275 if (errno == EFAULT) {
276 tst_resm(TFAIL, "Got EFAULT");
277 fail = 1;
278 }
279 }
280 if (l_seek(fd[0], 0, 0) < 0) {
281 TEST_ERROR_LOG(errno);
282 tst_resm(TFAIL, "block3: 2nd lseek failed");
283 fail = 1;
284 }
285 if ((nbytes = read(fd[0], buf_list[0], K_1)) != K_1) {
286 perror("read error");
287 tst_resm(TFAIL, "expected nbytes = 1024, got = %d",
288 nbytes);
289 fail = 1;
subrata_modak56207ce2009-03-23 13:35:39 +0000290 } else if (memcmp((buf_list[0] + CHUNK * 6),
291 (buf_list[2] + CHUNK * 6), CHUNK * 3) != 0) {
plars865695b2001-08-27 22:15:12 +0000292 tst_resm(TFAIL, "Error: writev() over wrote %s",
293 f_name);
294 fail = 1;
295 }
296
297 if (fail) {
298 tst_resm(TINFO, "block 3 FAILED");
299 } else {
300 tst_resm(TINFO, "block 3 PASSED");
301 }
302 tst_resm(TINFO, "Exit block 3");
303
robbiew7d5c5172003-03-27 22:54:57 +0000304//block4: /* given bad file discriptor, writev() return EBADF. */
plars865695b2001-08-27 22:15:12 +0000305 tst_resm(TINFO, "Enter block 4");
306 fail = 0;
307
308 TEST(writev(fd[1], (wr_iovec + 9), 1));
309 if (TEST_RETURN < 0) {
310 TEST_ERROR_LOG(TEST_ERRNO);
311 if (TEST_ERRNO == EBADF) {
312 tst_resm(TINFO, "Received EBADF as expected");
313 } else {
314 tst_resm(TFAIL, "expected errno = EBADF, "
315 "got %d", TEST_ERRNO);
316 fail = 1;
317 }
318 } else {
319 tst_resm(TFAIL, "Error: writev() returned a "
320 "positive value");
321 fail = 1;
322 }
323
324 if (fail) {
325 tst_resm(TINFO, "block 4 FAILED");
326 } else {
327 tst_resm(TINFO, "block 4 PASSED");
328 }
329 tst_resm(TINFO, "Exit block 4");
330
robbiew7d5c5172003-03-27 22:54:57 +0000331//block5: /* given invalid vector count, writev() return EINVAL */
plars865695b2001-08-27 22:15:12 +0000332 tst_resm(TINFO, "Enter block 5");
333 fail = 0;
334
335 TEST(writev(fd[0], (wr_iovec + 10), -1));
336 if (TEST_RETURN < 0) {
337 TEST_ERROR_LOG(TEST_ERRNO);
338 if (TEST_ERRNO == EINVAL) {
339 tst_resm(TINFO, "Received EINVAL as expected");
340 } else {
341 tst_resm(TFAIL, "expected errno = EINVAL, "
342 "got %d", TEST_ERRNO);
343 fail = 1;
344 }
345 } else {
346 tst_resm(TFAIL, "Error: writev() returned a "
347 "positive value");
348 fail = 1;
349 }
350
351 if (fail) {
352 tst_resm(TINFO, "block 5 FAILED");
353 } else {
354 tst_resm(TINFO, "block 5 PASSED");
355 }
356 tst_resm(TINFO, "Exit block 5");
357
robbiew7d5c5172003-03-27 22:54:57 +0000358//block6: /* given no buffer vector, writev() success */
plars865695b2001-08-27 22:15:12 +0000359 tst_resm(TINFO, "Enter block 6");
360 fail = 0;
361
362 TEST(writev(fd[0], (wr_iovec + 11), 0));
plars20bc5f22002-10-10 17:37:56 +0000363 if (TEST_RETURN < 0) {
364 TEST_ERROR_LOG(TEST_ERRNO);
365 tst_resm(TFAIL, "writev() failed with unexpected errno "
366 "%d", TEST_ERRNO);
plars29bcde82002-10-07 17:21:48 +0000367 fail = 1;
plars20bc5f22002-10-10 17:37:56 +0000368 } else {
369 tst_resm(TPASS, "writev() wrote 0 iovectors");
plars865695b2001-08-27 22:15:12 +0000370 }
371
372 if (fail) {
373 tst_resm(TINFO, "block 6 FAILED");
374 } else {
375 tst_resm(TINFO, "block 6 PASSED");
376 }
377 tst_resm(TINFO, "Exit block 6");
378
robbiew7d5c5172003-03-27 22:54:57 +0000379//block7:
subrata_modak56207ce2009-03-23 13:35:39 +0000380 /* given 4 vectors, 2 are NULL, 1 with 0 length and 1 with fixed length,
381 * writev() success writing fixed length.
382 */
plars865695b2001-08-27 22:15:12 +0000383 tst_resm(TINFO, "Enter block 7");
384 fail = 0;
385
386 l_seek(fd[0], CHUNK * 12, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000387 if ((ret = writev(fd[0], (wr_iovec + 12), 4)) != CHUNK) {
plars865695b2001-08-27 22:15:12 +0000388 tst_resm(TFAIL, "writev() failed writing %d bytes, "
389 "followed by two NULL vectors", CHUNK);
390 fail = 1;
391 } else {
392 tst_resm(TPASS, "writev passed writing %d bytes, "
393 "followed by two NULL vectors", CHUNK);
394 }
395
396 if (fail) {
397 tst_resm(TINFO, "block 7 FAILED");
398 } else {
399 tst_resm(TINFO, "block 7 PASSED");
400 }
401 tst_resm(TINFO, "Exit block 7");
402
robbiew7d5c5172003-03-27 22:54:57 +0000403//block8: /* try to write to a closed pipe, writev() return EPIPE. */
plars865695b2001-08-27 22:15:12 +0000404 tst_resm(TINFO, "Enter block 8");
405 fail = 0;
406
407 if (pipe(pfd) < 0) {
408 TEST_ERROR_LOG(errno);
409 perror("pipe");
410 tst_resm(TFAIL, "pipe failed: errno = %d", errno);
411 fail = 1;
412 } else {
413 if (close(pfd[0]) < 0) {
414 TEST_ERROR_LOG(errno);
415 perror("close");
416 tst_resm(TFAIL, "close failed: errno = %d",
417 errno);
418 fail = 1;
419 } else if ((writev(pfd[1], (wr_iovec + 12), 1)
subrata_modak56207ce2009-03-23 13:35:39 +0000420 < 0) && in_sighandler) {
plars865695b2001-08-27 22:15:12 +0000421 TEST_ERROR_LOG(errno);
422 if (errno == EPIPE) {
423 tst_resm(TINFO, "Received EPIPE as "
subrata_modak56207ce2009-03-23 13:35:39 +0000424 "expected");
plars865695b2001-08-27 22:15:12 +0000425 } else {
426 tst_resm(TFAIL, "expected errno = "
427 "EPIPE, got %d", errno);
428 fail = 1;
429 }
430 } else {
431 tst_resm(TFAIL, "Error: writev() returned a "
432 "positive value");
433 fail = 1;
434 }
435 }
436 if (fail) {
437 tst_resm(TINFO, "block 8 FAILED");
438 } else {
439 tst_resm(TINFO, "block 8 PASSED");
440 }
441 tst_resm(TINFO, "Exit block 8");
442 }
subrata_modakdad6e1a2007-10-30 10:46:58 +0000443 close(fd[0]);
444 close(fd[1]);
plars865695b2001-08-27 22:15:12 +0000445 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000446 /*NOTREACHED*/ return 0;
plars865695b2001-08-27 22:15:12 +0000447}
448
449/*
450 * setup()
451 * performs all ONE TIME setup for this test
452 */
subrata_modak56207ce2009-03-23 13:35:39 +0000453void setup(void)
plars865695b2001-08-27 22:15:12 +0000454{
455 /* capture signals */
456 tst_sig(FORK, DEF_HANDLER, cleanup);
457
458 /* Set up the expected error numbers for -e option */
459 TEST_EXP_ENOS(exp_enos);
460
461 /* Pause if that option was specified.
462 * TEST_PAUSE contains the code to fork the test with the -i option.
463 * You want to make sure you do this before you create your temporary
464 * directory.
465 */
466 TEST_PAUSE;
467
468 /* Create a unique temporary directory and chdir() to it. */
469 tst_tmpdir();
470
471 strcpy(name, DATA_FILE);
472 sprintf(f_name, "%s.%d", name, getpid());
robbiewb73a6b72003-11-17 15:21:18 +0000473
subrata_modak56207ce2009-03-23 13:35:39 +0000474 bad_addr = mmap(0, 1, PROT_NONE,
475 MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
476 if (bad_addr == MAP_FAILED) {
477 printf("mmap failed\n");
478 }
479 wr_iovec[7].iov_base = bad_addr;
robbiewb73a6b72003-11-17 15:21:18 +0000480
plars865695b2001-08-27 22:15:12 +0000481}
482
483/*
484 * cleanup()
485 * performs all ONE TIME cleanup for this test at
486 * completion or premature exit
487 */
subrata_modak56207ce2009-03-23 13:35:39 +0000488void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000489{
490 /*
491 * print timing stats if that option was specified.
492 * print errno log if that option was specified.
493 */
494 TEST_CLEANUP;
495
496 if (unlink(f_name) < 0) {
497 tst_resm(TFAIL, "unlink Failed--file = %s, errno = %d",
498 f_name, errno);
499 }
500 tst_rmdir();
501
502 tst_exit();
503}
504
subrata_modak56207ce2009-03-23 13:35:39 +0000505int init_buffs(char *pbufs[])
plars865695b2001-08-27 22:15:12 +0000506{
507 int i;
508
509 for (i = 0; pbufs[i] != (char *)NULL; i++) {
510 switch (i) {
511 case 0:
subrata_modak56207ce2009-03-23 13:35:39 +0000512
513 case 1:
514 fill_mem(pbufs[i], 0, 1);
plars865695b2001-08-27 22:15:12 +0000515 break;
516
subrata_modak56207ce2009-03-23 13:35:39 +0000517 case 2:
518 fill_mem(pbufs[i], 1, 0);
519 break;
520
521 default:
522 tst_resm(TFAIL, "Error detected: init_buffs()");
523 cleanup();
524 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +0000525 }
subrata_modak43337a32009-02-26 11:43:51 +0000526 return 0;
plars865695b2001-08-27 22:15:12 +0000527}
528
subrata_modak56207ce2009-03-23 13:35:39 +0000529int fill_mem(char *c_ptr, int c1, int c2)
plars865695b2001-08-27 22:15:12 +0000530{
531 int count;
532
533 for (count = 1; count <= K_1 / CHUNK; count++) {
subrata_modak56207ce2009-03-23 13:35:39 +0000534 if (count & 0x01) { /* if odd */
plars865695b2001-08-27 22:15:12 +0000535 memset(c_ptr, c1, CHUNK);
subrata_modak56207ce2009-03-23 13:35:39 +0000536 } else { /* if even */
plars865695b2001-08-27 22:15:12 +0000537 memset(c_ptr, c2, CHUNK);
538 }
539 }
subrata_modak43337a32009-02-26 11:43:51 +0000540 return 0;
plars865695b2001-08-27 22:15:12 +0000541}
542
subrata_modak56207ce2009-03-23 13:35:39 +0000543void sighandler(int sig)
plars865695b2001-08-27 22:15:12 +0000544{
545 switch (sig) {
subrata_modak56207ce2009-03-23 13:35:39 +0000546 case SIGTERM:
547 break;
plars865695b2001-08-27 22:15:12 +0000548
subrata_modak56207ce2009-03-23 13:35:39 +0000549 case SIGPIPE:
550 ++in_sighandler;
551 return;
plars865695b2001-08-27 22:15:12 +0000552
subrata_modak56207ce2009-03-23 13:35:39 +0000553 default:
554 tst_resm(TFAIL, "sighandler() received invalid "
555 "signal:%d", sig);
556 break;
plars865695b2001-08-27 22:15:12 +0000557 }
558
559 if (unlink(f_name) < 0) {
560 tst_resm(TFAIL, "unlink Failed--file = %s, errno = %d",
561 f_name, errno);
562 tst_exit();
subrata_modak56207ce2009-03-23 13:35:39 +0000563 /*NOTREACHED*/}
plars865695b2001-08-27 22:15:12 +0000564 exit(sig);
565}
566
subrata_modak56207ce2009-03-23 13:35:39 +0000567long l_seek(int fdesc, long offset, int whence)
plars865695b2001-08-27 22:15:12 +0000568{
569 if (lseek(fdesc, offset, whence) < 0) {
570 perror("lseek");
571 tst_resm(TFAIL, "lseek Failed : errno = %d", errno);
572 fail = 1;
573 }
subrata_modak43337a32009-02-26 11:43:51 +0000574 return 0;
plars865695b2001-08-27 22:15:12 +0000575}