Changes by: flatcap
Update of /cvsroot/linux-ntfs/ntfs-driver-tng/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv20176/scripts
Modified Files:
Makefile rl.c
Log Message:
make the test cases more useful
Index: Makefile
===================================================================
RCS file: /cvsroot/linux-ntfs/ntfs-driver-tng/scripts/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -U2 -r1.4 -r1.5
--- Makefile 13 Feb 2002 01:42:44 -0000 1.4
+++ Makefile 18 Feb 2002 01:44:17 -0000 1.5
@@ -31,4 +31,6 @@
all: clean rl
+blank:
+ @echo
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
@@ -39,5 +41,6 @@
distclean: clean
$(RM) tags
- $(RM) {c,n}{1,4}
+ $(RM) zero
+ $(RM) pure-{c,n}{s,m}
$(RM) frag[123][123][123]
@@ -45,17 +48,22 @@
ctags -R rl.c ../linux/fs/ntfs
-testrl:
- $(RM) {c,n}{1,4}
- $(CC) $(CFLAGS) -DTESTRL -DCONTIG=1 -DMULTI=0 rl.c -o rl
- rl > c1
- $(CC) $(CFLAGS) -DTESTRL -DCONTIG=1 -DMULTI=1 rl.c -o rl
- rl > c4
- $(CC) $(CFLAGS) -DTESTRL -DCONTIG=0 -DMULTI=0 rl.c -o rl
- rl > n1
- $(CC) $(CFLAGS) -DTESTRL -DCONTIG=0 -DMULTI=1 rl.c -o rl
- rl > n4
+test: rl blank testz testp testf
+
+testz: rl
+ @rl zero > zero
+ @diff -qs {test/,}zero
+ @echo
+ @echo Success
@echo
- @for i in {c,n}{1,4}; do \
- diff -qs $$i test/$$i ; \
+
+testp: rl
+ @for i in contig non-contig; do \
+ for j in single multi; do \
+ L1=`echo $$i | cut -b1`; \
+ L2=`echo $$j | cut -b1`; \
+ FILE=pure-$$L1$$L2; \
+ rl pure $$i $$j > $$FILE; \
+ diff -qs {test/,}$$FILE; \
+ done; \
done
@echo
@@ -63,21 +71,8 @@
@echo
-testf:
- $(RM) frag[123][123][123]
- $(CC) $(CFLAGS) -DTESTF=123 rl.c -o rl
- rl > frag123
- $(CC) $(CFLAGS) -DTESTF=132 rl.c -o rl
- rl > frag132
- $(CC) $(CFLAGS) -DTESTF=213 rl.c -o rl
- rl > frag213
- $(CC) $(CFLAGS) -DTESTF=231 rl.c -o rl
- rl > frag231
- $(CC) $(CFLAGS) -DTESTF=312 rl.c -o rl
- rl > frag312
- $(CC) $(CFLAGS) -DTESTF=321 rl.c -o rl
- rl > frag321
- @echo
- @for i in frag[123][123][123]; do \
- diff -qs $$i test/frag ; \
+testf: rl
+ @for i in 123 132 213 231 312 321; do \
+ rl frag $$i > frag$$i; \
+ diff -qs {test/,}frag$$i; \
done
@echo
Index: rl.c
===================================================================
RCS file: /cvsroot/linux-ntfs/ntfs-driver-tng/scripts/rl.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -U2 -r1.22 -r1.23
--- rl.c 13 Feb 2002 03:05:22 -0000 1.22
+++ rl.c 18 Feb 2002 01:44:17 -0000 1.23
@@ -1,24 +1,4 @@
#include "compat.c"
-/**
- * config
- */
-
-#ifndef CONTIG
-#define CONTIG 1
-#endif
-#ifndef MULTI
-#define MULTI 1
-#endif
-
-#if CONTIG
- int fudge = 0;
-#else
- int fudge = 999;
-#endif
-/*
-}
-*/
-
/* Temporary helper functions -- might become macros */
@@ -64,8 +44,8 @@
run_list *nrl;
- if (old == new)
- return orig;
old = PAGE_ALIGN (old * sizeof (run_list));
new = PAGE_ALIGN (new * sizeof (run_list));
+ if (old == new)
+ return orig;
nrl = ntfs_malloc_nofs (new);
@@ -131,5 +111,4 @@
BUG_ON (!orig || !new);
- ntfs_debug ("ntfs_rl_append\n");
right = ntfs_rl_merge (new + nsize - 1, orig + loc + 1);
@@ -178,5 +157,4 @@
BUG_ON (!orig || !new);
- ntfs_debug ("ntfs_rl_insert\n");
if (loc > 0) {
left = ntfs_rl_merge (orig + loc - 1, new);
@@ -189,6 +167,4 @@
}
- //ntfs_debug("left = %i, disc = %i, hole = %i\n", left, disc, hole);
-
res = ntfs_rl_realloc (orig, osize, osize + nsize - left + disc - hole);
if (IS_ERR (res))
@@ -260,11 +236,8 @@
BUG_ON (!orig || !new);
- ntfs_debug ("ntfs_rl_replace\n");
right = ntfs_rl_merge (new + nsize - 1, orig + loc + 1);
if (loc > 0)
left = ntfs_rl_merge (orig + loc - 1, new);
- //printf("loc = %i, right = %i, left = %i\n", loc, right, left);
-
res = ntfs_rl_realloc (orig, osize, osize + nsize - left - right);
if (IS_ERR (res))
@@ -309,5 +282,4 @@
BUG_ON (!orig || !new);
- ntfs_debug ("ntfs_rl_split\n");
res = ntfs_rl_realloc (orig, osize, osize + nsize + 1);
if (IS_ERR (res))
@@ -809,13 +781,71 @@
-int main (int argc, char *argv[])
+/**
+ * helper
+ */
+#define MKRL(R,V,L,S) \
+ (R)->vcn = V; \
+ (R)->lcn = L; \
+ (R)->length = S;
+/*
+}
+*/
+/**
+ * pure_src
+ */
+run_list *pure_src (BOOL contig, BOOL multi, int vcn, int len)
+{
+ run_list *result;
+ int fudge;
+
+ if (contig)
+ fudge = 0;
+ else
+ fudge = 999;
+
+ result = ntfs_malloc_nofs (PAGE_SIZE);
+ memset (result, -7, PAGE_SIZE);
+ if (multi) {
+ MKRL (result+0, vcn + (0*len/4), fudge + vcn + 1000 + (0*len/4), len / 4)
+ MKRL (result+1, vcn + (1*len/4), fudge + vcn + 1000 + (1*len/4), len / 4)
+ MKRL (result+2, vcn + (2*len/4), fudge + vcn + 1000 + (2*len/4), len / 4)
+ MKRL (result+3, vcn + (3*len/4), fudge + vcn + 1000 + (3*len/4), len / 4)
+ MKRL (result+4, vcn + (4*len/4), LCN_RL_NOT_MAPPED, 0)
+ } else {
+ MKRL (result+0, vcn, fudge + vcn + 1000, len)
+ MKRL (result+1, vcn + len, LCN_RL_NOT_MAPPED, 0)
+ }
+ return result;
+}
+
+/**
+ * pure_test
+ */
+static void pure_test (int test, BOOL contig, BOOL multi,
+ int vcn, int len, run_list *file, int size)
{
-#if 0 || defined(TESTRL)
+ run_list *src;
+ run_list *dst;
+ run_list *res;
+
+ src = pure_src (contig, multi, vcn, len);
+ dst = ntfs_malloc_nofs (PAGE_SIZE);
+
+ memset (dst, -7, PAGE_SIZE);
+ memcpy (dst, file, size);
+
+ ntfs_debug ("Test %2d ----------\n", test);
+ res = merge_run_lists (dst, src);
+
+ ntfs_free (res);
+}
+
/**
- * files
+ * pure
*/
- run_list *res, *page1, *page2;
- run_list file1[] = {
+void pure (char *contig, char *multi)
+{
/* VCN, LCN, len */
+ static run_list file1[] = {
{ 0, -1, 100 }, /* HOLE */
{ 100, 1100, 100 }, /* DATA */
@@ -825,138 +855,62 @@
{ 500, -3, 0 } /* NOENT */
};
-
- run_list file2[] = {
- /* VCN, LCN, len */
+ static run_list file2[] = {
{ 0, 1000, 100 }, /* DATA */
{ 100, -1, 100 }, /* HOLE */
{ 200, -3, 0 } /* NOENT */
};
-
- run_list file3[] = {
- /* VCN, LCN, len */
+ static run_list file3[] = {
{ 0, 1000, 100 }, /* DATA */
{ 100, -3, 0 } /* NOENT */
};
-
- run_list file4[] = {
- /* VCN, LCN, len */
+ static run_list file4[] = {
{ 0, -3, 0 } /* NOENT */
};
-/*
-}
-*/
-/**
- * tests
- */
-#if MULTI
-#define RL_SRC(X,Y,Z) \
- run_list s##X[] = \
- { \
- { Y, fudge + Y + 1000, Z/4 }, \
- { Y+(1*Z/4), fudge + Y + 1000 + (1*Z/4), Z/4 }, \
- { Y+(2*Z/4), fudge + Y + 1000 + (2*Z/4), Z/4 }, \
- { Y+(3*Z/4), fudge + Y + 1000 + (3*Z/4), Z/4 }, \
- { Y+Z, LCN_RL_NOT_MAPPED, 0 } \
- };
-#else
-#define RL_SRC(X,Y,Z) \
- run_list s##X[] = \
- { \
- { Y, fudge + Y + 1000, Z }, \
- { Y+Z, LCN_RL_NOT_MAPPED, 0 } \
- };
-#endif
+ BOOL c, m;
- RL_SRC (1, 0, 40)
- RL_SRC (2, 40, 40)
- RL_SRC (3, 60, 40)
- RL_SRC (4, 0, 100)
- RL_SRC (5, 200, 40)
- RL_SRC (6, 240, 40)
- RL_SRC (7, 260, 40)
- RL_SRC (8, 200, 100)
- RL_SRC (9, 400, 40)
- RL_SRC (10, 440, 40)
- RL_SRC (11, 460, 40)
- RL_SRC (12, 400, 100)
- RL_SRC (13, 160, 100)
- RL_SRC (14, 100, 140)
- RL_SRC (15, 200, 40)
- RL_SRC (16, 240, 40)
- RL_SRC (17, 100, 40)
- RL_SRC (18, 140, 40)
- RL_SRC (19, 0, 40)
- RL_SRC (20, 40, 40)
-/*
+ if (strcmp (contig, "contig") == 0)
+ c = TRUE;
+ else if (strcmp (contig, "non-contig") == 0)
+ c = FALSE;
+ else {
+ printf ("rl pure [contig|non-contig] [single|multi]\n");
+ return;
+ }
+ if (strcmp (multi, "multi") == 0)
+ m = TRUE;
+ else if (strcmp (multi, "single") == 0)
+ m = FALSE;
+ else {
+ printf ("rl pure [contig|non-contig] [single|multi]\n");
+ return;
+ }
+
+ pure_test (1, c, m, 0, 40, file1, sizeof (file1));
+ pure_test (2, c, m, 40, 40, file1, sizeof (file1));
+ pure_test (3, c, m, 60, 40, file1, sizeof (file1));
+ pure_test (4, c, m, 0, 100, file1, sizeof (file1));
+ pure_test (5, c, m, 200, 40, file1, sizeof (file1));
+ pure_test (6, c, m, 240, 40, file1, sizeof (file1));
+ pure_test (7, c, m, 260, 40, file1, sizeof (file1));
+ pure_test (8, c, m, 200, 100, file1, sizeof (file1));
+ pure_test (9, c, m, 400, 40, file1, sizeof (file1));
+ pure_test (10, c, m, 440, 40, file1, sizeof (file1));
+ pure_test (11, c, m, 460, 40, file1, sizeof (file1));
+ pure_test (12, c, m, 400, 100, file1, sizeof (file1));
+ pure_test (13, c, m, 160, 100, file2, sizeof (file2));
+ pure_test (14, c, m, 100, 140, file2, sizeof (file2));
+ pure_test (15, c, m, 200, 40, file2, sizeof (file2));
+ pure_test (16, c, m, 240, 40, file2, sizeof (file2));
+ pure_test (17, c, m, 100, 40, file3, sizeof (file3));
+ pure_test (18, c, m, 140, 40, file3, sizeof (file3));
+ pure_test (19, c, m, 0, 40, file4, sizeof (file4));
+ pure_test (20, c, m, 40, 40, file4, sizeof (file4));
}
-*/
-/**
- * junk
- */
- *file1 = *file1; *file2 = *file2; *file3 = *file3; *file4 = *file4;
- *s1 = *s1; *s2 = *s2; *s3 = *s3; *s4 = *s4; *s5 = *s5; *s6 = *s6;
- *s7 = *s7; *s8 = *s8; *s9 = *s9; *s10 = *s10; *s11 = *s11; *s12 = *s12;
- *s13 = *s13; *s14 = *s14; *s15 = *s15; *s16 = *s16; *s17 = *s17;
- *s18 = *s18; *s19 = *s19; *s20 = *s20;
-
-#define TEST_RL(X,Y) \
- printf ("Test %2d ----------\n", X); \
- page1 = ntfs_malloc_nofs (PAGE_SIZE); \
- page2 = ntfs_malloc_nofs (PAGE_SIZE); \
- memset (page1, -7, PAGE_SIZE); \
- memset (page2, -7, PAGE_SIZE); \
- memcpy (page1, file##Y, sizeof (file##Y)); \
- memcpy (page2, s##X, sizeof (s##X)); \
- res = merge_run_lists (page1, page2); \
- ntfs_free (res);
-/*
-}
-*/
-/**
- * run
- */
-#if 0
-
- TEST_RL(15,2)
-
-#else
-
- TEST_RL(1,1)
- TEST_RL(2,1)
- TEST_RL(3,1)
- TEST_RL(4,1)
- TEST_RL(5,1)
- TEST_RL(6,1)
- TEST_RL(7,1)
- TEST_RL(8,1)
- TEST_RL(9,1)
- TEST_RL(10,1)
- TEST_RL(11,1)
- TEST_RL(12,1)
- TEST_RL(13,2)
- TEST_RL(14,2)
- TEST_RL(15,2)
- TEST_RL(16,2)
- TEST_RL(17,3)
- TEST_RL(18,3)
- TEST_RL(19,4)
- TEST_RL(20,4)
-
-#endif
-/*
-}
-*/
-#endif
-
-#if 0
/**
* zero
*/
-#define MKRL(R,V,L,S) \
- (R)->vcn = V; \
- (R)->lcn = L; \
- (R)->length = S;
-
+void zero (void)
+{
run_list *jim = NULL;
run_list *bob = NULL;
@@ -964,43 +918,50 @@
bob = ntfs_rl_realloc (bob, 0, 3);
if (IS_ERR(bob))
- return 1;
+ return;
- MKRL(bob+0, 10, 99, 5);
- MKRL(bob+1, 0, LCN_RL_NOT_MAPPED, 0);
+ MKRL(bob+0, 10, 99, 5)
+ MKRL(bob+1, 0, LCN_RL_NOT_MAPPED, 0)
jim = merge_run_lists (jim, bob);
if (IS_ERR(jim))
- return 1;
+ return;
ntfs_free (jim);
-/*
}
-*/
-#endif
-#if 1 || defined (TESTF)
/**
- * fragged
+ * frag_combine
*/
-#define MKRL(R,V,L,S) \
- (R)->vcn = V; \
- (R)->lcn = L; \
- (R)->length = S;
+static void frag_combine (ntfs_volume *vol, ATTR_RECORD *attr1, ATTR_RECORD *attr2, ATTR_RECORD *attr3)
+{
+ run_list *run1;
+ run_list *run2;
+ run_list *run3;
+
+ run1 = decompress_mapping_pairs (vol, attr1, NULL);
+ if (IS_ERR (run1))
+ return;
+ run2 = decompress_mapping_pairs (vol, attr2, run1);
+ if (IS_ERR (run2))
+ return;
+ run3 = decompress_mapping_pairs (vol, attr3, run2);
+ if (IS_ERR (run3))
+ return;
+
+ ntfs_free (run3);
+}
- ATTR_RECORD *buf1 = NULL;
- ATTR_RECORD *buf2 = NULL;
- ATTR_RECORD *buf3 = NULL;
- run_list *rl1 = NULL;
- run_list *rl2 = NULL;
- run_list *rl3 = NULL;
+/**
+ * frag
+ */
+static void frag (char *test)
+{
ntfs_volume vol;
+ ATTR_RECORD *attr1 = malloc (1024);
+ ATTR_RECORD *attr2 = malloc (1024);
+ ATTR_RECORD *attr3 = malloc (1024);
- buf1 = malloc (1024);
- buf2 = malloc (1024);
- buf3 = malloc (1024);
- if (!buf1 || !buf2 || !buf3) {
- printf ("memory\n");
- return 1;
- }
+ if (!attr1 || !attr2 || !attr3)
+ goto out;
vol.sb = NULL;
@@ -1010,87 +971,35 @@
vol.major_ver = 3;
- if (!read_buffer ("attr1", (void*) buf1, 1024))
- return 1;
- if (!read_buffer ("attr2", (void*) buf2, 1024))
- return 1;
- if (!read_buffer ("attr3", (void*) buf3, 1024))
- return 1;
-
-#if 0 || (TESTF == 123)
- rl1 = decompress_mapping_pairs (&vol, buf1, NULL);
- if (IS_ERR (rl1))
- return 1;
- rl2 = decompress_mapping_pairs (&vol, buf2, rl1);
- if (IS_ERR (rl2))
- return 1;
- rl3 = decompress_mapping_pairs (&vol, buf3, rl2);
- if (IS_ERR (rl3))
- return 1;
-#endif
-
-#if 0 || (TESTF == 132)
- rl1 = decompress_mapping_pairs (&vol, buf1, NULL);
- if (IS_ERR (rl1))
- return 1;
- rl2 = decompress_mapping_pairs (&vol, buf3, rl1);
- if (IS_ERR (rl2))
- return 1;
- rl3 = decompress_mapping_pairs (&vol, buf2, rl2);
- if (IS_ERR (rl3))
- return 1;
-#endif
-
-#if 1 || (TESTF == 213)
- rl1 = decompress_mapping_pairs (&vol, buf2, NULL);
- if (IS_ERR (rl1))
- return 1;
- rl2 = decompress_mapping_pairs (&vol, buf1, rl1);
- if (IS_ERR (rl2))
- return 1;
- rl3 = decompress_mapping_pairs (&vol, buf3, rl2);
- if (IS_ERR (rl3))
- return 1;
-#endif
-
-#if 0 || (TESTF == 231)
- rl1 = decompress_mapping_pairs (&vol, buf2, NULL);
- if (IS_ERR (rl1))
- return 1;
- rl2 = decompress_mapping_pairs (&vol, buf3, rl1);
- if (IS_ERR (rl2))
- return 1;
- rl3 = decompress_mapping_pairs (&vol, buf1, rl2);
- if (IS_ERR (rl3))
- return 1;
-#endif
+ if (!read_buffer ("attr1", (void*) attr1, 1024))
+ goto out;
+ if (!read_buffer ("attr2", (void*) attr2, 1024))
+ goto out;
+ if (!read_buffer ("attr3", (void*) attr3, 1024))
+ goto out;
+
+ if (strcmp (test, "123") == 0) frag_combine (&vol, attr1, attr2, attr3);
+ else if (strcmp (test, "132") == 0) frag_combine (&vol, attr1, attr3, attr2);
+ else if (strcmp (test, "213") == 0) frag_combine (&vol, attr2, attr1, attr3);
+ else if (strcmp (test, "231") == 0) frag_combine (&vol, attr2, attr3, attr1);
+ else if (strcmp (test, "312") == 0) frag_combine (&vol, attr3, attr1, attr2);
+ else if (strcmp (test, "321") == 0) frag_combine (&vol, attr3, attr2, attr1);
+ else printf ("Frag: No such test '%s'\n", test);
+
+out:
+ free (attr1);
+ free (attr2);
+ free (attr3);
+}
-#if 0 || (TESTF == 312)
- rl1 = decompress_mapping_pairs (&vol, buf3, NULL);
- if (IS_ERR (rl1))
- return 1;
- rl2 = decompress_mapping_pairs (&vol, buf1, rl1);
- if (IS_ERR (rl2))
- return 1;
- rl3 = decompress_mapping_pairs (&vol, buf2, rl2);
- if (IS_ERR (rl3))
- return 1;
-#endif
+/**
+ * main
+ */
+int main (int argc, char *argv[])
+{
+ if ((argc == 2) && (strcmp (argv[1], "zero") == 0)) zero();
+ else if ((argc == 3) && (strcmp (argv[1], "frag") == 0)) frag (argv[2]);
+ else if ((argc == 4) && (strcmp (argv[1], "pure") == 0)) pure (argv[2], argv[3]);
+ else printf ("rl [zero|frag|pure] {args}\n");
-#if 0 || (TESTF == 321)
- rl1 = decompress_mapping_pairs (&vol, buf3, NULL);
- if (IS_ERR (rl1))
- return 1;
- rl2 = decompress_mapping_pairs (&vol, buf2, rl1);
- if (IS_ERR (rl2))
- return 1;
- rl3 = decompress_mapping_pairs (&vol, buf1, rl2);
- if (IS_ERR (rl3))
- return 1;
-#endif
-/*
-}
-*/
- //ntfs_debug_dump_runlist (rl3);
-#endif
//printf ("%d,%d\n", ntfs_a, ntfs_f);
return 0;
|