]> Zhao Yanbai Git Server - minix.git/commitdiff
test 55 for statvfs. fix formatting bug in test54.
authorBen Gras <ben@minix3.org>
Thu, 24 Jun 2010 00:06:40 +0000 (00:06 +0000)
committerBen Gras <ben@minix3.org>
Thu, 24 Jun 2010 00:06:40 +0000 (00:06 +0000)
test/Makefile
test/run
test/test54.c
test/test55.c [new file with mode: 0644]

index 13a423a628ea2b3eeb52a81be90ef9a165bf2e52..734feab3686c34b7c2cad0805e126f4ef1a3e461 100644 (file)
@@ -12,7 +12,7 @@ OBJ=  test1  test2  test3  test4  test5  test6  test7  test8  test9  \
        test30 test31 test32        test34 test35 test36 test37 test38 \
        test39 t10a t11a t11b test40 t40a t40b t40c t40d t40e t40f test41 \
        test42 test44 test45 test47 test48 test49 test50 test51 test52 test53 \
-       test54
+       test54 test55
 
 BIGOBJ=  test20 test24
 ROOTOBJ= test11 test33 test43 test46
@@ -110,3 +110,4 @@ test51-gcc: test51.c
 test52: test52.c
 test52-gcc: test52.c
 test54: test54.c
+test55: test55.c
index 6b0d9bd4d914183e537f6416f89e46514a8d8ce9..f272806a512d79a01843882711813c24e3c739fa 100755 (executable)
--- a/test/run
+++ b/test/run
@@ -14,7 +14,7 @@ badones=                      # list of tests that failed
 tests="   1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 \
          21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
          41 42 43 44 45 45-gcc 46 47 48 49 49-gcc 50 \
-         51 51-gcc 52 52-gcc 53 \
+         51 51-gcc 52 52-gcc 53 54 55 \
         sh1.sh sh2.sh"
 tests_no=`expr 0`
 
index 08468d0afbcd9d9a93a93c3aaa77e462b85bd55c..f3fc904c1d68e0e1dc936c1be5d9078952a7451d 100644 (file)
@@ -55,7 +55,7 @@ int main(void)
                err(1, "Test failed.\n");
        }
 
-       printf(" ok\n");
+       printf("ok\n");
 
        close(fd);
        free(wbuf);
diff --git a/test/test55.c b/test/test55.c
new file mode 100644 (file)
index 0000000..165e2c4
--- /dev/null
@@ -0,0 +1,110 @@
+#include <sys/statvfs.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <err.h>
+#include <unistd.h>
+#define TRIALS 10
+#define SIZE   65536
+
+void create_file(void)
+{
+       char buf[SIZE]={0};
+       char *p;
+       int fd;
+       char *filename;
+       ssize_t ntowrite, nwritten;
+
+       if((filename = mktemp("/tmp/statvfs_test_XXXXXXX")) == NULL) {
+               err(1, "mktemp failed");
+       }
+
+       if((fd = open(filename, O_CREAT|O_WRONLY)) < 0) {
+               err(1, "open failed");
+       }
+
+       ntowrite = SIZE;
+       p = &buf[0];
+       while(ntowrite > 0) {
+               if((nwritten = write(fd, p, ntowrite)) < 0) {
+                       err(1, "write failed");
+               }
+               p += nwritten;
+               ntowrite -= nwritten;
+       }
+}
+
+int main(int argc, char *argv[])
+{
+       struct statvfs stats;
+       unsigned long f_bsize,   f_bsize_new;   
+       unsigned long f_frsize,  f_frsize_new;  
+       fsblkcnt_t    f_blocks,  f_blocks_new;  
+       fsblkcnt_t    f_bfree,   f_bfree_new;   
+       fsblkcnt_t    f_bavail,  f_bavail_new;  
+       fsfilcnt_t    f_files,   f_files_new;   
+       fsfilcnt_t    f_ffree,   f_ffree_new;   
+       fsfilcnt_t    f_favail,  f_favail_new;  
+       unsigned long f_fsid,    f_fsid_new;    
+       unsigned long f_flag,    f_flag_new;    
+       unsigned long f_namemax, f_namemax_new; 
+       int i;
+
+       printf("Test 55 ");
+       
+       for(i = 0; i < TRIALS; i++) {
+               if(statvfs("/tmp", &stats) < 0) {
+                       perror("statvfs failed");
+                       return 1;
+               }
+
+               f_bsize   = stats.f_bsize  ;
+               f_frsize  = stats.f_frsize ;
+               f_blocks  = stats.f_blocks ;
+               f_bfree   = stats.f_bfree  ;
+               f_bavail  = stats.f_bavail ;
+               f_files   = stats.f_files  ;
+               f_ffree   = stats.f_ffree  ;
+               f_favail  = stats.f_favail ;
+               f_fsid    = stats.f_fsid   ;
+               f_flag    = stats.f_flag   ;
+               f_namemax = stats.f_namemax;
+               
+               create_file();
+
+               if(statvfs("/tmp", &stats) < 0) {
+                       perror("statvfs failed");
+                       return 1;
+               }
+
+               f_bsize_new   = stats.f_bsize  ;
+        f_frsize_new  = stats.f_frsize ;
+        f_blocks_new  = stats.f_blocks ;
+        f_bfree_new   = stats.f_bfree  ;
+        f_bavail_new  = stats.f_bavail ;
+        f_files_new   = stats.f_files  ;
+        f_ffree_new   = stats.f_ffree  ;
+        f_favail_new  = stats.f_favail ;
+        f_fsid_new    = stats.f_fsid   ;
+        f_flag_new    = stats.f_flag   ;
+        f_namemax_new = stats.f_namemax;
+
+               if ((f_bsize   == f_bsize_new) && 
+               (f_frsize  == f_frsize_new) && 
+               (f_blocks  == f_blocks_new) && 
+               (f_bfree   > f_bfree_new) && 
+               (f_bavail  > f_bavail_new) && 
+               (f_files   == f_files_new) && 
+               (f_ffree   == f_ffree_new + 1) && 
+               (f_favail  == f_favail_new + 1) && 
+               (f_fsid    == f_fsid_new) && 
+               (f_flag    == f_flag_new) && 
+               (f_namemax == f_namemax_new) ) {
+                               printf("ok\n");
+                               return 0;
+               }
+       }
+
+       return 1;
+}