Touched up testing functions
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 19 Aug 2010 23:56:01 +0000 (16:56 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:52 +0000 (17:35 -0700)
The test_random_fs() is just a dumping ground for interactive tests that
I had sitting around in init.c.  Feel free to turn these into real
tests, or ones that panic on failure but are otherwise quiet and
side-effect free.

kern/include/testing.h
kern/src/testing.c
tests/file_test.c

index ba567f6..3da5092 100644 (file)
@@ -30,6 +30,7 @@ void test_hashtable(void);
 void test_bcq(void);
 void test_vm_regions(void);
 void test_radix_tree(void);
+void test_random_fs(void);
 
 struct trapframe_t;
 
index 230b550..a89af80 100644 (file)
@@ -1114,3 +1114,67 @@ void test_radix_tree(void)
        //print_radix_tree(tree);
        printk("Finished radix tree tests!\n");
 }
+
+/* Assorted FS tests, which were hanging around in init.c */
+void test_random_fs(void)
+{
+       int retval = do_symlink("/dir1/sym", "/bin/hello", S_IRWXU);
+       if (retval)
+               printk("symlink1 creation failed\n");
+       retval = do_symlink("/symdir", "/dir1/dir1-1", S_IRWXU);
+       if (retval)
+               printk("symlink1 creation failed\n");
+       retval = do_symlink("/dir1/test.txt", "/dir2/test2.txt", S_IRWXU);
+       if (retval)
+               printk("symlink2 creation failed\n");
+       retval = do_symlink("/dir1/dir1-1/up", "../../", S_IRWXU);
+       if (retval)
+               printk("symlink3 creation failed\n");
+       retval = do_symlink("/bin/hello-sym", "hello", S_IRWXU);
+       if (retval)
+               printk("symlink4 creation failed\n");
+       
+       struct dentry *dentry;
+       struct nameidata nd_r = {0}, *nd = &nd_r;
+       retval = path_lookup("/dir1/sym", 0, nd);
+       if (retval)
+               printk("symlink lookup failed: %d\n", retval);
+       char *symname = nd->dentry->d_inode->i_op->readlink(nd->dentry);
+       printk("Pathlookup got %s (sym)\n", nd->dentry->d_name.name);
+       if (!symname)
+               printk("symlink reading failed\n");
+       else
+               printk("Symname: %s (/bin/hello)\n", symname);
+       path_release(nd);
+       /* try with follow */
+       memset(nd, 0, sizeof(struct nameidata));
+       retval = path_lookup("/dir1/sym", LOOKUP_FOLLOW, nd);
+       if (retval)
+               printk("symlink lookup failed: %d\n", retval);
+       printk("Pathlookup got %s (hello)\n", nd->dentry->d_name.name);
+       path_release(nd);
+       
+       /* try with a directory */
+       memset(nd, 0, sizeof(struct nameidata));
+       retval = path_lookup("/symdir/f1-1.txt", 0, nd);
+       if (retval)
+               printk("symlink lookup failed: %d\n", retval);
+       printk("Pathlookup got %s (f1-1.txt)\n", nd->dentry->d_name.name);
+       path_release(nd);
+       
+       /* try with a rel path */
+       printk("Try with a rel path\n");
+       memset(nd, 0, sizeof(struct nameidata));
+       retval = path_lookup("/symdir/up/hello.txt", 0, nd);
+       if (retval)
+               printk("symlink lookup failed: %d\n", retval);
+       printk("Pathlookup got %s (hello.txt)\n", nd->dentry->d_name.name);
+       path_release(nd);
+       
+       printk("Try for an ELOOP\n");
+       memset(nd, 0, sizeof(struct nameidata));
+       retval = path_lookup("/symdir/up/symdir/up/symdir/up/symdir/up/hello.txt", 0, nd);
+       if (retval)
+               printk("Symlink lookup failed (it should): %d (-40)\n", retval);
+       path_release(nd);
+}
index da9917f..24ccf97 100644 (file)
@@ -111,12 +111,8 @@ int main()
        retval = link("/bin/hello", "/bin/hardhello2");
        if (retval < 0)
                printf("WARNING! Link failed!\n");
-       printf("Now unlinking symlink /dir1/test.txt\n");
-       retval = unlink("/dir1/test.txt");
-       if (retval < 0)
-               printf("WARNING! Unlink failed!\n");
-       printf("Now unlinking /dir2/test2.txt\n");
-       retval = unlink("/dir2/test2.txt");
+       printf("Now unlinking symlink /dir2/sym-test\n");
+       retval = unlink("/dir2/sym-test");
        if (retval < 0)
                printf("WARNING! Unlink failed!\n");