]> mj.ucw.cz Git - libucw.git/commitdiff
added
authorRobert Spalek <robert@ucw.cz>
Fri, 2 Mar 2001 13:36:47 +0000 (13:36 +0000)
committerRobert Spalek <robert@ucw.cz>
Fri, 2 Mar 2001 13:36:47 +0000 (13:36 +0000)
lib/lfs-test.c [new file with mode: 0644]

diff --git a/lib/lfs-test.c b/lib/lfs-test.c
new file mode 100644 (file)
index 0000000..c30f29b
--- /dev/null
@@ -0,0 +1,63 @@
+/* Test for configuration parser */
+
+#include "lib/lib.h"
+#include "lib/fastbuf.h"
+
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define        BLOCK   (1<<10)
+#define        COUNT   (5<<20)
+#define        TESTS   (1<<20)
+
+int main(void)
+{
+       struct fastbuf *b;
+       byte block[BLOCK];
+       uns i;
+
+       srand(time(NULL));
+#if 0
+       b = bopen("/big/robert/large-file", O_CREAT | O_TRUNC | O_RDWR, 1<<20);
+       if (!b)
+               die("Cannot create large-file");
+
+       log(L_DEBUG, "Writing %d blocks of size %d", COUNT, BLOCK);
+       for (i=0; i<COUNT; i++)
+       {
+               memset(block, i & 0xff, BLOCK);
+               bwrite(b, block, BLOCK);
+               if ( i%1024 == 0 )
+               {
+                       printf("\r%10d", i);
+                       fflush(stdout);
+               }
+       }
+#else
+       b = bopen("/big/robert/large-file", O_RDWR, 1<<20);
+       if (!b)
+               die("Cannot create large-file");
+#endif
+       log(L_DEBUG, "Checking the file contents in %d tests", TESTS);
+       for (i=0; i<TESTS; i++)
+       {
+               uns idx = random()%COUNT;
+               sh_off_t ofs = idx*BLOCK;
+               bseek(b, ofs, SEEK_SET);
+               bread(b, block, BLOCK);
+               if (block[17] != (idx & 0xff))
+                       die("Invalid block %d in test %d: %x != %x", idx, i, block[17], idx & 0xff);
+               if ( i%16 == 0 )
+               {
+                       printf("\r%10d", i);
+                       fflush(stdout);
+               }
+       }
+       log(L_DEBUG, "Done");
+
+       bclose(b);
+       return 0;
+}