liyujie
2025-08-28 b3810562527858a3b3d98ffa6e9c9c5b0f4a9a8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/* IBM Corporation */
/* 01/02/2003    Port to LTP avenkat@us.ibm.com */
/* 06/30/2001    Port to Linux    nsharoff@us.ibm.com */
/*
 *   Copyright (c) International Business Machines  Corp., 2003
 *
 *
 *   This program is free software;  you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program;  if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
 
#define _GNU_SOURCE 1
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <limits.h>
/*****  LTP Port        *****/
#include "test.h"
#define FAILED 0
#define PASSED 1
 
int local_flag = PASSED;
char *TCID = "mmapstress01";    //tmnoextend
FILE *temp;
int TST_TOTAL = 1;
 
int anyfail();
void ok_exit();
/*****  **      **      *****/
 
/*
 *  This test stresses mmaps, without dealing with fragments or anything!
 *  It forks a specified number of children,
 *  all of whom mmap the same file, make a given number of accesses
 *  to random pages in the map (reading & writing and comparing data).
 *  Then the child exits and the parent forks another to take its place.
 *  Each time a child is forked, it stats the file and maps the full
 *  length of the file.
 *
 *  This program continues to run until it either receives a SIGINT,
 *  or times out (if a timeout value is specified).  When either of
 *  these things happens, it cleans up its kids, then checks the
 *  file to make sure it has the correct data.
 *
 *  usage:
 *    tmnoextend -p nprocs [-t minutes -f filesize -S sparseoffset
 *                  -r -o -m -l -d]
 *  where:
 *    -p nprocs    - specifies the number of mapping children
 *              to create.  (nprocs + 1 children actually
 *              get created, since one is the writer child)
 *    -t minutes    - specifies minutes to run.  If not specified,
 *              default is to run forever until a SIGINT
 *              is received.
 *    -f filesize    - initial filesize (defaults to FILESIZE)
 *    -S sparseoffset - when non-zero, causes a sparse area to
 *              be left before the data, meaning that the
 *              actual initial file size is sparseoffset +
 *              filesize.  Useful for testing large files.
 *              (default is 0).
 *    -r        - randomize number of pages map children check.
 *              (random % MAXLOOPS).  If not specified, each
 *              child checks MAXLOOPS pages.
 *    -o        - randomize offset of file to map. (default is 0)
 *    -m        - do random msync/fsyncs as well
 *    -l        - if set, the output file is not removed on
 *              program exit.
 *    -d        - enable debug output
 *
 *  Compile with -DLARGE_FILE to enable file sizes > 2 GB.
 */
 
#define MAXLOOPS    500    /* max pages for map children to write */
#define    FILESIZE    4096    /* initial filesize set up by parent */
 
#ifdef roundup
#undef roundup
#endif
#define roundup(x, y)    ((((x)+((y)-1))/(y))*(y))
#define min(x, y)    (((x) < (y)) ? (x) : (y))
 
extern time_t time(time_t *);
extern char *ctime(const time_t *);
extern void *malloc(size_t);
extern long lrand48(void);
extern void srand(unsigned);
extern void srand48(long);
extern int rand(void);
extern int atoi(const char *);
 
char *usage =
    "-p nprocs [-t minutes -f filesize -S sparseoffset -r -o -m -l -d]";
 
typedef unsigned char uchar_t;
#define SIZE_MAX UINT_MAX
 
unsigned int initrand(void);
void finish(int sig);
void child_mapper(char *file, unsigned procno, unsigned nprocs);
int fileokay(char *file, uchar_t * expbuf);
int finished = 0;
int leavefile = 0;
 
int debug = 0;
#ifdef LARGE_FILE
off64_t filesize = FILESIZE;
off64_t sparseoffset = 0;
#else /* LARGE_FILE */
off_t filesize = FILESIZE;
off_t sparseoffset = 0;
#endif /* LARGE_FILE */
unsigned randloops = 0;
unsigned dosync = 0;
unsigned do_offset = 0;
unsigned pattern = 0;
 
int main(int argc, char *argv[])
{
   char *progname;
   int fd;
   int c;
   extern char *optarg;
   unsigned nprocs = 0;
   unsigned procno;
   pid_t *pidarray = NULL;
   pid_t pid;
   uchar_t *buf = NULL;
   unsigned int seed;
   int pagesize = sysconf(_SC_PAGE_SIZE);
   float alarmtime = 0;
   struct sigaction sa;
   unsigned i;
   int write_cnt;
   uchar_t data;
   int no_prob = 0;
   int wait_stat;
   time_t t;
#ifdef LARGE_FILE
   off64_t bytes_left;
#else /* LARGE_FILE */
   off_t bytes_left;
#endif /* LARGE_FILE */
   const char *filename = "mmapstress01.out";
 
   progname = *argv;
   tst_tmpdir();
   if (argc < 2) {
       tst_brkm(TBROK, NULL, "usage: %s %s\n", progname, usage);
   }
 
   while ((c = getopt(argc, argv, "S:omdlrf:p:t:")) != -1) {
       switch (c) {
       case 'd':
           debug = 1;
           break;
       case 't':
           alarmtime = atof(optarg) * 60;
           break;
       case 'p':
           nprocs = atoi(optarg);
           break;
       case 'l':
           leavefile = 1;
           break;
       case 'f':
#ifdef LARGE_FILE
           filesize = atoll(optarg);
#else /* LARGE_FILE */
           filesize = atoi(optarg);
#endif /* LARGE_FILE */
           if (filesize < 0) {
               (void)fprintf(stderr, "error: negative "
                         "filesize\n");
               anyfail();
           }
           break;
       case 'r':
           randloops = 1;
           break;
       case 'm':
           dosync = 1;
           break;
       case 'o':
           do_offset = 1;
           break;
       case 'S':
#ifdef LARGE_FILE
           sparseoffset = atoll(optarg);
#else /* LARGE_FILE */
           sparseoffset = atoi(optarg);
#endif /* LARGE_FILE */
           if (sparseoffset % pagesize != 0) {
               fprintf(stderr,
                   "sparseoffset must be pagesize multiple\n");
               anyfail();
           }
           break;
       default:
           (void)fprintf(stderr, "usage: %s %s\n", progname,
                     usage);
           tst_exit();
       }
   }
 
   /* nprocs is >= 0 since it's unsigned */
   if (nprocs > 255) {
       (void)fprintf(stderr, "invalid nprocs %d - (range 0-255)\n",
                 nprocs);
       anyfail();
   }
 
   (void)time(&t);
 
   seed = initrand();
   pattern = seed & 0xff;
 
   if (debug) {
#ifdef LARGE_FILE
       (void)printf("creating file <%s> with %Ld bytes, pattern %d\n",
                filename, filesize, pattern);
#else /* LARGE_FILE */
       (void)printf("creating file <%s> with %ld bytes, pattern %d\n",
                filename, filesize, pattern);
#endif /* LARGE_FILE */
       if (alarmtime)
           (void)printf("running for %f minutes\n",
                    alarmtime / 60);
       else
           (void)printf("running with no time limit\n");
   }
 
   /*
    *  Plan for death by signal.  User may have specified
    *  a time limit, in which set an alarm and catch SIGALRM.
    *  Also catch and cleanup with SIGINT.
    */
   sa.sa_handler = finish;
   sa.sa_flags = 0;
   if (sigemptyset(&sa.sa_mask)) {
       perror("sigemptyset error");
       goto cleanup;
   }
 
   if (sigaction(SIGINT, &sa, 0) == -1) {
       perror("sigaction error SIGINT");
       goto cleanup;
   }
   if (sigaction(SIGQUIT, &sa, 0) == -1) {
       perror("sigaction error SIGQUIT");
       goto cleanup;
   }
   if (sigaction(SIGTERM, &sa, 0) == -1) {
       perror("sigaction error SIGTERM");
       goto cleanup;
   }
 
   if (alarmtime) {
       if (sigaction(SIGALRM, &sa, 0) == -1) {
           perror("sigaction error");
           goto cleanup;
       }
       (void)alarm(alarmtime);
   }
#ifdef LARGE_FILE
   if ((fd = open64(filename, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) {
#else /* LARGE_FILE */
   if ((fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) {
#endif /* LARGE_FILE */
       perror("open error");
       anyfail();
   }
 
   if ((buf = malloc(pagesize)) == NULL
       || (pidarray = malloc(nprocs * sizeof(pid_t))) == NULL) {
       perror("malloc error");
       anyfail();
   }
 
   for (i = 0; i < nprocs; i++)
       *(pidarray + i) = 0;
 
   for (i = 0, data = 0; i < pagesize; i++) {
       *(buf + i) = (data + pattern) & 0xff;
       if (++data == nprocs)
           data = 0;
   }
#ifdef LARGE_FILE
   if (lseek64(fd, sparseoffset, SEEK_SET) < 0) {
#else /* LARGE_FILE */
   if (lseek(fd, sparseoffset, SEEK_SET) < 0) {
#endif /* LARGE_FILE */
       perror("lseek");
       anyfail();
   }
   for (bytes_left = filesize; bytes_left; bytes_left -= c) {
       write_cnt = min(pagesize, bytes_left);
       if ((c = write(fd, buf, write_cnt)) != write_cnt) {
           if (c == -1) {
               perror("write error");
           } else {
               (void)fprintf(stderr, "write: wrote %d of %d "
                         "bytes\n", c, write_cnt);
           }
           (void)close(fd);
           (void)unlink(filename);
           anyfail();
       }
   }
 
   (void)close(fd);
 
   /*
    *  Fork off mmap children.
    */
   for (procno = 0; procno < nprocs; procno++) {
       switch (pid = fork()) {
 
       case -1:
           perror("fork error");
           goto cleanup;
 
       case 0:
           child_mapper(filename, procno, nprocs);
           exit(0);
 
       default:
           pidarray[procno] = pid;
       }
   }
 
   /*
    *  Now wait for children and refork them as needed.
    */
 
   while (!finished) {
       pid = wait(&wait_stat);
       /*
        *  Block signals while processing child exit.
        */
 
       if (sighold(SIGALRM) || sighold(SIGINT)) {
           perror("sighold error");
           goto cleanup;
       }
 
       if (pid != -1) {
           /*
            *  Check exit status, then refork with the
            *  appropriate procno.
            */
           if (!WIFEXITED(wait_stat)
               || WEXITSTATUS(wait_stat) != 0) {
               (void)fprintf(stderr, "child exit with err "
                         "<x%x>\n", wait_stat);
               goto cleanup;
           }
           for (i = 0; i < nprocs; i++)
               if (pid == pidarray[i])
                   break;
           if (i == nprocs) {
               (void)fprintf(stderr, "unknown child pid %d, "
                         "<x%x>\n", pid, wait_stat);
               goto cleanup;
           }
 
           if ((pid = fork()) == -1) {
               perror("fork error");
               pidarray[i] = 0;
               goto cleanup;
           } else if (pid == 0) {    /* child */
               child_mapper(filename, i, nprocs);
               exit(0);
           } else
               pidarray[i] = pid;
       } else {
           /*
            *  wait returned an error.  If EINTR, then
            *  normal finish, else it's an unexpected
            *  error...
            */
           if (errno != EINTR || !finished) {
               perror("unexpected wait error");
               goto cleanup;
           }
       }
       if (sigrelse(SIGALRM) || sigrelse(SIGINT)) {
           perror("sigrelse error");
           goto cleanup;
       }
   }
 
   /*
    *  Finished!  Check the file for sanity, then kill all
    *  the children and done!.
    */
 
   if (sighold(SIGALRM)) {
       perror("sighold error");
       goto cleanup;
   }
   (void)alarm(0);
   no_prob = 1;
 
cleanup:
   for (i = 0; i < nprocs; i++)
       (void)kill(pidarray[i], SIGKILL);
 
   while (wait(&wait_stat) != -1 || errno != ECHILD)
       continue;
 
   if (no_prob) {        /* only check file if no errors */
       if (!fileokay(filename, buf)) {
           (void)fprintf(stderr, "file data incorrect!\n");
           (void)printf("  leaving file <%s>\n", filename);
           /***** LTP Port *****/
           local_flag = FAILED;
           anyfail();
           /*****    **    *****/
       } else {
           (void)printf("file data okay\n");
           if (!leavefile)
               (void)unlink(filename);
       }
   } else
       (void)printf("  leaving file <%s>\n", filename);
 
   (void)time(&t);
   //(void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port
   ok_exit();
   tst_exit();
}
 
/*
 *  Child process that reads/writes map.  The child stats the file
 *  to determine the size, maps the size of the file, then reads/writes
 *  its own locations on random pages of the map (its locations being
 *  determined based on nprocs & procno).  After a specific number of
 *  iterations, it exits.
 */
void child_mapper(char *file, unsigned procno, unsigned nprocs)
{
#ifdef LARGE_FILE
   struct stat64 statbuf;
   off64_t filesize;
   off64_t offset;
#else /* LARGE_FILE */
   struct stat statbuf;
   off_t filesize;
   off_t offset;
#endif /* LARGE_FILE */
   size_t validsize;
   size_t mapsize;
   char *maddr = NULL, *paddr;
   int fd;
   size_t pagesize = sysconf(_SC_PAGE_SIZE);
   unsigned randpage;
   unsigned int seed;
   unsigned loopcnt;
   unsigned nloops;
   unsigned mappages;
   unsigned i;
 
   seed = initrand();    /* initialize random seed */
 
#ifdef LARGE_FILE
   if (stat64(file, &statbuf) == -1) {
#else /* LARGE_FILE */
   if (stat(file, &statbuf) == -1) {
#endif /* LARGE_FILE */
       perror("stat error");
       anyfail();
   }
   filesize = statbuf.st_size;
 
#ifdef LARGE_FILE
   if ((fd = open64(file, O_RDWR)) == -1) {
#else /* LARGE_FILE */
   if ((fd = open(file, O_RDWR)) == -1) {
#endif /* LARGE_FILE */
       perror("open error");
       anyfail();
   }
 
   if (statbuf.st_size - sparseoffset > SIZE_MAX) {
       fprintf(stderr, "size_t overflow when setting up map\n");
       anyfail();
   }
   mapsize = (size_t) (statbuf.st_size - sparseoffset);
   mappages = roundup(mapsize, pagesize) / pagesize;
   offset = sparseoffset;
   if (do_offset) {
       int pageoffset = lrand48() % mappages;
       int byteoffset = pageoffset * pagesize;
       offset += byteoffset;
       mapsize -= byteoffset;
       mappages -= pageoffset;
   }
   nloops = (randloops) ? (lrand48() % MAXLOOPS) : MAXLOOPS;
 
   if (debug) {
#ifdef LARGE_FILE
       (void)printf("child %d (pid %ld): seed %d, fsize %Ld, "
                "mapsize %d, off %Ld, loop %d\n",
                procno, getpid(), seed, filesize, mapsize,
                offset / pagesize, nloops);
#else /* LARGE_FILE */
       (void)printf("child %d (pid %d): seed %d, fsize %ld, "
                "mapsize %ld, off %ld, loop %d\n",
                procno, getpid(), seed, filesize, (long)mapsize,
                offset / pagesize, nloops);
#endif /* LARGE_FILE */
   }
#ifdef LARGE_FILE
   if ((maddr = mmap64(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED,
               fd, offset)) == (caddr_t) - 1) {
#else /* LARGE_FILE */
   if ((maddr = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED,
             fd, offset)) == (caddr_t) - 1) {
#endif /* LARGE_FILE */
       perror("mmap error");
       anyfail();
   }
 
   (void)close(fd);
 
   /*
    *  Now loop read/writing random pages.
    */
   for (loopcnt = 0; loopcnt < nloops; loopcnt++) {
       randpage = lrand48() % mappages;
       paddr = maddr + (randpage * pagesize);    /* page address */
 
       if (randpage < mappages - 1 || !(mapsize % pagesize))
           validsize = pagesize;
       else
           validsize = mapsize % pagesize;
 
       for (i = procno; i < validsize; i += nprocs) {
           if (*((unsigned char *)(paddr + i))
               != ((procno + pattern) & 0xff)) {
               (void)fprintf(stderr, "child %d: invalid data "
                         "<x%x>", procno,
                         *((unsigned char *)(paddr + i)));
               (void)fprintf(stderr, " at pg %d off %d, exp "
                         "<x%x>\n", randpage, i,
                         (procno + pattern) & 0xff);
               anyfail();
           }
 
           /*
            *  Now write it.
            */
           *(paddr + i) = (procno + pattern) & 0xff;
       }
   }
   if (dosync) {
       /*
        * Exercise msync() as well!
        */
       randpage = lrand48() % mappages;
       paddr = maddr + (randpage * pagesize);    /* page address */
       if (msync(paddr, (mappages - randpage) * pagesize,
             MS_SYNC) == -1) {
           anyfail();
       }
   }
   if (munmap(maddr, mapsize) == -1) {
       perror("munmap failed");
       local_flag = FAILED;
       anyfail();
   }
   exit(0);
}
 
/*
 *  Make sure file has all the correct data.
 */
int fileokay(char *file, uchar_t * expbuf)
{
#ifdef LARGE_FILE
   struct stat64 statbuf;
#else /* LARGE_FILE */
   struct stat statbuf;
#endif /* LARGE_FILE */
   size_t mapsize;
   unsigned mappages;
   unsigned pagesize = sysconf(_SC_PAGE_SIZE);
   uchar_t readbuf[pagesize];
   int fd;
   int cnt;
   unsigned i, j;
 
#ifdef LARGE_FILE
   if ((fd = open64(file, O_RDONLY)) == -1) {
#else /* LARGE_FILE */
   if ((fd = open(file, O_RDONLY)) == -1) {
#endif /* LARGE_FILE */
       perror("open error");
       /***** LTP Port *****/
       local_flag = FAILED;
       anyfail();
       /*****    **    *****/
       return 0;
   }
#ifdef LARGE_FILE
   if (fstat64(fd, &statbuf) == -1) {
#else /* LARGE_FILE */
   if (fstat(fd, &statbuf) == -1) {
#endif /* LARGE_FILE */
       perror("stat error");
       /***** LTP Port *****/
       local_flag = FAILED;
       anyfail();
       /*****    **    *****/
       return 0;
   }
#ifdef LARGE_FILE
   if (lseek64(fd, sparseoffset, SEEK_SET) < 0) {
#else /* LARGE_FILE */
   if (lseek(fd, sparseoffset, SEEK_SET) < 0) {
#endif /* LARGE_FILE */
       perror("lseek");
       anyfail();
   }
 
   if (statbuf.st_size - sparseoffset > SIZE_MAX) {
       fprintf(stderr, "size_t overflow when setting up map\n");
       anyfail();
   }
   mapsize = (size_t) (statbuf.st_size - sparseoffset);
 
   mappages = roundup(mapsize, pagesize) / pagesize;
 
   for (i = 0; i < mappages; i++) {
       cnt = read(fd, readbuf, pagesize);
       if (cnt == -1) {
           perror("read error");
           /***** LTP Port *****/
           local_flag = FAILED;
           anyfail();
           /*****    **    *****/
           return 0;
       } else if (cnt != pagesize) {
           /*
            *  Okay if at last page in file...
            */
           if ((i * pagesize) + cnt != mapsize) {
               (void)fprintf(stderr, "read %d of %ld bytes\n",
                         (i * pagesize) + cnt,
                         (long)mapsize);
               close(fd);
               return 0;
           }
       }
       /*
        *  Compare read bytes of data.
        */
       for (j = 0; j < cnt; j++) {
           if (expbuf[j] != readbuf[j]) {
               (void)fprintf(stderr,
                         "read bad data: exp %c got %c)",
                         expbuf[j], readbuf[j]);
#ifdef LARGE_FILE
               (void)fprintf(stderr, ", pg %d off %d, "
                         "(fsize %Ld)\n", i, j,
                         statbuf.st_size);
#else /* LARGE_FILE */
               (void)fprintf(stderr, ", pg %d off %d, "
                         "(fsize %ld)\n", i, j,
                         statbuf.st_size);
#endif /* LARGE_FILE */
               close(fd);
               return 0;
           }
       }
   }
   close(fd);
 
   return 1;
}
 
 /*ARGSUSED*/ void finish(int sig)
{
   finished++;
   return;
}
 
unsigned int initrand(void)
{
   unsigned int seed;
 
   /*
    *  Initialize random seed...  Got this from a test written
    *  by scooter:
    *      Use srand/rand to diffuse the information from the
    *      time and pid.  If you start several processes, then
    *      the time and pid information don't provide much
    *      variation.
    */
   srand((unsigned int)getpid());
   seed = rand();
   srand((unsigned int)time(NULL));
   seed = (seed ^ rand()) % 100000;
   srand48((long int)seed);
   return (seed);
}
 
/*****  LTP Port        *****/
void ok_exit(void)
{
   tst_resm(TPASS, "Test passed");
   tst_rmdir();
   tst_exit();
}
 
int anyfail(void)
{
   tst_brkm(TFAIL, tst_rmdir, "Test failed");
}
 
/*****  **      **      *****/