]> mj.ucw.cz Git - libucw.git/blob - ucw/lfs-test.c
Merge branch 'v3.12.4'
[libucw.git] / ucw / lfs-test.c
1 /* Test of large files */
2
3 #include "ucw/lib.h"
4 #include "ucw/fastbuf.h"
5
6 #include <stdlib.h>
7 #include <time.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11
12 #define BLOCK   (1<<10)
13 #define COUNT   (5<<20)
14 #define TESTS   (1<<20)
15
16 int main(void)
17 {
18         struct fastbuf *b;
19         byte block[BLOCK];
20         uns i;
21
22         srand(time(NULL));
23 #if 0
24         b = bopen("/big/robert/large-file", O_CREAT | O_TRUNC | O_RDWR, 1<<20);
25         if (!b)
26                 die("Cannot create large-file");
27
28         msg(L_DEBUG, "Writing %d blocks of size %d", COUNT, BLOCK);
29         for (i=0; i<COUNT; i++)
30         {
31                 memset(block, i & 0xff, BLOCK);
32                 bwrite(b, block, BLOCK);
33                 if ( i%1024 == 0 )
34                 {
35                         printf("\r%10d", i);
36                         fflush(stdout);
37                 }
38         }
39 #else
40         b = bopen("/big/robert/large-file", O_RDWR, 1<<20);
41         if (!b)
42                 die("Cannot create large-file");
43 #endif
44         msg(L_DEBUG, "Checking the file contents in %d tests", TESTS);
45         for (i=0; i<TESTS; i++)
46         {
47                 uns idx = random()%COUNT;
48                 ucw_off_t ofs = idx*BLOCK;
49                 bseek(b, ofs, SEEK_SET);
50                 bread(b, block, BLOCK);
51                 if (block[17] != (idx & 0xff))
52                         die("Invalid block %d in test %d: %x != %x", idx, i, block[17], idx & 0xff);
53                 if ( i%16 == 0 )
54                 {
55                         printf("\r%10d", i);
56                         fflush(stdout);
57                 }
58         }
59         msg(L_DEBUG, "Done");
60
61         bclose(b);
62         return 0;
63 }