Whamcloud - gitweb
ChangeLog, random_exercise.c:
authorTheodore Ts'o <tytso@mit.edu>
Wed, 18 Oct 2000 19:06:13 +0000 (19:06 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 18 Oct 2000 19:06:13 +0000 (19:06 +0000)
  random_exercise.c: Add support for making the test files have a
   certain size, and also add directories as test inodes as well.

tests/progs/ChangeLog
tests/progs/random_exercise.c

index cfbd719..286af8b 100644 (file)
@@ -1,3 +1,9 @@
+2000-10-18    <tytso@valinux.com>
+
+       * random_exercise.c: Add support for making the test files have a
+               certain size, and also add directories as test inodes as
+               well. 
+
 2000-08-20    <tytso@valinux.com>
 
        * random_exercise.c: New file which feeds a lot of file creations
index 8d55709..e9e86bc 100644 (file)
@@ -24,6 +24,7 @@
 struct state {
        char    name[16];
        int     state;
+       int     isdir;
 };
 
 #define STATE_CLEAR    0
@@ -32,6 +33,8 @@ struct state {
 
 struct state state_array[MAXFDS];
 
+char data_buffer[4096];
+
 void clear_state_array()
 {
        int     i;
@@ -55,12 +58,23 @@ void create_random_file()
 {
        char template[16] = "EX.XXXXXX";
        int     fd;
+       int     isdir = 0;
        
        mktemp(template);
-       fd = open(template, O_CREAT|O_RDWR, 0600);
+       isdir = random() & 1;
+       if (isdir) {
+               if (mkdir(template, 0700) < 0)
+                       return;
+               fd = open(template, O_RDONLY, 0600);
+       } else {
+               fd = open(template, O_CREAT|O_RDWR, 0600);
+               write(fd, data_buffer, sizeof(data_buffer));
+       }
        if (fd < 0)
                return;
-       printf("Created temp file %s, fd = %d\n", template, fd);
+       printf("Created temp %s %s, fd = %d\n",
+              isdir ? "directory" : "file", template, fd);
+       state_array[fd].isdir = isdir;
        state_array[fd].state = STATE_CREATED;
        strcpy(state_array[fd].name, template);
 }
@@ -69,9 +83,12 @@ void unlink_file(int fd)
 {
        char *filename = state_array[fd].name;
        
-       printf("Unlinking %s, fd = %d\n", filename, fd);
-       
-       unlink(filename);
+       printf("Deleting %s, fd = %d\n", filename, fd);
+
+       if (state_array[fd].isdir)
+               rmdir(filename);
+       else
+               unlink(filename);
        state_array[fd].state = STATE_DELETED;
 }
 
@@ -89,7 +106,10 @@ void close_file(int fd)
 main(int argc, char **argv)
 {
        int     i, fd;
-       
+
+       memset(data_buffer, 0, sizeof(data_buffer));
+       sprintf(data_buffer, "This is a test file created by the "
+               "random_exerciser program\n");
        
        for (i=0; i < 100000; i++) {
                fd = get_random_fd();