[Pvfs2-cvs] commit by sampson in pvfs2/src/client/windows/client-test: Makefile create.c file-ops.c find.c info.c open.c test-io.c test-list.h test-support.c test-support.h thread.c thread.h timer.c

CVS commit program cvs at parl.clemson.edu
Fri Feb 25 18:03:10 EST 2011


Update of /projects/cvsroot/pvfs2/src/client/windows/client-test
In directory parlweb1:/tmp/cvs-serv31397/src/client/windows/client-test

Modified Files:
      Tag: windows-client
	Makefile create.c file-ops.c find.c info.c open.c test-io.c 
	test-list.h test-support.c test-support.h thread.c thread.h 
	timer.c 
Log Message:
Porting Windows client tests


Index: Makefile
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/Makefile,v
diff -p -u -r1.1.2.1 -r1.1.2.2
--- Makefile	24 Feb 2011 22:29:16 -0000	1.1.2.1
+++ Makefile	25 Feb 2011 23:03:10 -0000	1.1.2.2
@@ -3,11 +3,20 @@
 # Use with Linux kernel module to compare
 # results to the Windows client test
 
+CFLAGS=-g
 LDFLAGS=-lpthread
 
-objects=$(patsubst %.c,%.o,$(wildcard *.c))
+objects:=$(patsubst %.c,%.o,$(wildcard *.c))
 
 client-test : $(objects)
 	cc -o client-test $(objects) $(CFLAGS) $(LDFLAGS)
 
-%.o : %.h test-support.h
+# override implicit rule
+%.o: %.c
+
+%.o: %.c %.h test-support.h test-list.h
+	cc -o $@ -c $< $(CFLAGS)
+
+clean:
+	rm -f client-test *.o
+

Index: create.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/create.c,v
diff -p -u -r1.1.2.5 -r1.1.2.6
--- create.c	24 Feb 2011 22:29:16 -0000	1.1.2.5
+++ create.c	25 Feb 2011 23:03:10 -0000	1.1.2.6
@@ -51,15 +51,19 @@ void create_subdir_cleanup(char *root_di
     if (root_dir_int[strlen(root_dir_int)-1] == SLASH_CHAR)
         root_dir_int[strlen(root_dir_int)-1] = '\0';
 
+    if (!_stricmp(root_dir_int, path))
+        return;
+
     /* remove directories back to front */
-    while (_stricmp(root_dir_int, path))
+    do 
     {
+        _rmdir(path);
+
         slash = strrchr(path, SLASH_CHAR);
         if (slash)
             *slash = '\0';
 
-        _rmdir(path);
-    }
+    } while  (_stricmp(root_dir_int, path));
 
     free(root_dir_int);
 

Index: file-ops.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/file-ops.c,v
diff -p -u -r1.1.2.3 -r1.1.2.4
--- file-ops.c	24 Feb 2011 22:29:16 -0000	1.1.2.3
+++ file-ops.c	25 Feb 2011 23:03:10 -0000	1.1.2.4
@@ -374,7 +374,7 @@ int move_file_exist(global_options *opti
 
     /* create new file */    
     new_name = (char *) malloc(strlen(dir_name) + strlen(file_name) + 4);
-    sprintf(new_name, "%s%c%s", dir_name, SLASH_CHAR, strrchr(file_name, '\\')+1);
+    sprintf(new_name, "%s%c%s", dir_name, SLASH_CHAR, strrchr(file_name, SLASH_CHAR)+1);
     if ((code = quick_create(new_name)) != 0)
     {
         free(new_name);

Index: find.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/find.c,v
diff -p -u -r1.1.2.2 -r1.1.2.3
--- find.c	24 Feb 2011 22:29:16 -0000	1.1.2.2
+++ find.c	25 Feb 2011 23:03:10 -0000	1.1.2.3
@@ -6,6 +6,9 @@
 #include <string.h>
 #ifdef WIN32
 #include <io.h>
+#else
+#include <dirent.h>
+#include <fnmatch.h>
 #endif
 #include <errno.h>
 
@@ -215,9 +218,35 @@ int find_files_pattern(global_options *o
     return 0;     
 }
 #else
+/* return first file in dir matching pattern */
+int find_file(DIR *dir, char *pattern, char *path, size_t path_size)
+{
+    struct dirent *entry;
+    int ret = -1;
+
+    path[0] = '\0';
+
+    entry = readdir(dir);
+    while (entry) {
+        ret = fnmatch(pattern, entry->d_name, FNM_PATHNAME);
+        if (ret == 0)
+        {
+            strncpy(path, entry->d_name, path_size);
+            return ret;
+        }
+        if (ret != FNM_NOMATCH)
+            break;
+
+        entry = readdir(dir);
+
+    }
+
+    return ret;
+}
+
 int find_files(global_options *options, int fatal)
 {
-    char *file_names[10];
+    char *file_names[10], match_file[256];
     int code, i, j;
     DIR *dir;
     struct dirent *entry;
@@ -239,15 +268,20 @@ int find_files(global_options *options, 
     }
 
     /* find the files */    
-    for (i = 0, findptr = 0; i < 10 && findptr != -1; i++)
+    dir = opendir(options->root_dir);
+    if (dir != NULL) {
+        for (i = 0; i < 10 && code == 0; i++)
+        {
+            code = find_file(dir, file_names[i], match_file, 256);
+            seekdir(dir, 0);
+        }
+        closedir(dir);
+    }
+    else
     {
-        findptr = _findfirst(file_names[i], &fileinfo);
-        if (findptr != -1)
-            _findclose(findptr);
+        code = errno;
     }
 
-    code = (findptr != -1) ? 0 : errno;
-
     report_result(options,
                   "find-files",
                   "main",
@@ -270,10 +304,9 @@ int find_files(global_options *options, 
 
 int find_files_pattern(global_options *options, int fatal)
 {
-    char *file_names[10], *file_name, *pattern;
+    char *file_names[10], *file_name, *pattern, match_file[256];
     int code = 0, i, j, mark[10], found, ret;
-    struct _finddata_t fileinfo;
-    intptr_t findptr;
+    DIR *dir;
 
     /* create 10 files */
     for (i = 0; i < 10; i++)
@@ -297,111 +330,102 @@ int find_files_pattern(global_options *o
     pattern = (char *) malloc(strlen(options->root_dir) + 5);
     sprintf(pattern, "%sxyz*", options->root_dir);
 
-    ret = findptr = _findfirst(pattern, &fileinfo);   
-    while (ret != -1)
+    dir = opendir(options->root_dir);
+    if (dir != NULL)
     {
-        /* search file list for file */
-        for (i = 0; i < 10; i++)
+        ret = find_file(dir, pattern, match_file, 256);
+        while (ret == 0)
         {
-            file_name = strrchr(file_names[i], SLASH_CHAR) + 1;
-            if (!_stricmp(file_name, fileinfo.name))
-            {
-                mark[i] = 1;
-                break;
+            /* search file list for file */
+            for (i = 0; i < 10; i++)
+            {                
+                if (!_stricmp(file_names[i], match_file))
+                {
+                    mark[i] = 1;
+                    break;
+                }
             }
-        }
-
-        ret = _findnext(findptr, &fileinfo);
-    }
-
-    if (errno == ENOENT)
-    {
-        /* all found? */
-        for (i = 0, found = 1; i < 10 && found; i++)
-            found = found && mark[i];
 
-        code = !found;
+            ret = find_file(dir, pattern, match_file, 256);
+        }
 
-        report_result(options,
-                      "find-files-pattern",
-                      "pattern-*",
-                      RESULT_SUCCESS,
-                      0,
-                      OPER_EQUAL,
-                      code);
+        if (ret != FNM_NOMATCH)
+        {
+            report_error(options, "find-files-pattern: search error (1)\n");
+        }
 
-        _findclose(findptr);
+        closedir(dir);
     }
     else
     {
-        _findclose(findptr);
+        report_error(options, "find-files-pattern: could not open directory (1)\n");
+        return 2;
+    }
 
-        free(pattern);
-        /* technical error */
-        for (i = 0; i < 10; i++)
-        {
-            _unlink(file_names[i]);
-            free(file_names[i]);
-        }
+    /* all found? */
+    for (i = 0, found = 1; i < 10 && found; i++)
+        found = found && mark[i];
 
-        return errno;
-    }
+    code = !found;
+
+    report_result(options,
+                  "find-files-pattern",
+                  "pattern-*",
+                  RESULT_SUCCESS,
+                  0,
+                  OPER_EQUAL,
+                  code);
 
     /* find by ? pattern */
     free(pattern);
     pattern = (char *) malloc(strlen(options->root_dir) + 9);
     sprintf(pattern, "%sxyz?????", options->root_dir);
 
-    ret = findptr = _findfirst(pattern, &fileinfo);   
-    while (ret != -1)
+    dir = opendir(options->root_dir);
+    if (dir != NULL)
     {
-        /* search file list for file */
-        for (i = 0; i < 10; i++)
+        ret = find_file(dir, pattern, match_file, 256);
+        while (ret == 0)
         {
-            file_name = strrchr(file_names[i], SLASH_CHAR) + 1;
-            if (!_stricmp(file_name, fileinfo.name))
-            {
-                mark[i] = 1;
-                break;
+            /* search file list for file */
+            for (i = 0; i < 10; i++)
+            {                
+                if (!_stricmp(file_names[i], match_file))
+                {
+                    mark[i] = 1;
+                    break;
+                }
             }
-        }
 
-        ret = _findnext(findptr, &fileinfo);
-    }
-
-    if (errno == ENOENT)
-    {
-        /* all found? */
-        for (i = 0, found = 1; i < 10 && found; i++)
-            found = found && mark[i];
+            ret = find_file(dir, pattern, match_file, 256);
+        }
 
-        code = !found;
+        closedir(dir);
 
-        report_result(options,
-                      "find-files-pattern",
-                      "pattern-?",
-                      RESULT_SUCCESS,
-                      0,
-                      OPER_EQUAL,
-                      code);
-
-        _findclose(findptr);
+        if (ret != FNM_NOMATCH)
+        {
+            report_error(options, "find-files-pattern: search error (2)\n");
+        }
     }
     else
     {
-        _findclose(findptr);
+        report_error(options, "find-files-pattern: could not open directory (2)\n");
+        return 2;
+    }
 
-        free(pattern);
-        /* technical error */
-        for (i = 0; i < 10; i++)
-        {
-            _unlink(file_names[i]);
-            free(file_names[i]);
-        }
+    /* all found? */
+    for (i = 0, found = 1; i < 10 && found; i++)
+         found = found && mark[i];
 
-        return errno;
-    }
+    code = !found;
 
+    report_result(options,
+                  "find-files-pattern",
+                  "pattern-?",
+                  RESULT_SUCCESS,
+                  0,
+                  OPER_EQUAL,
+                  code);
 
     /* cleanup */
     free(pattern);

Index: info.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/info.c,v
diff -p -u -r1.1.2.3 -r1.1.2.4
--- info.c	24 Feb 2011 22:29:16 -0000	1.1.2.3
+++ info.c	25 Feb 2011 23:03:10 -0000	1.1.2.4
@@ -9,8 +9,11 @@
 #include <time.h>
 #ifdef WIN32
 #include <direct.h>
+#else
+#include <sys/vfs.h>
 #endif
 #include <ctype.h>
+#include <errno.h>
 
 #include "test-support.h"
 #include "info.h"
@@ -66,13 +69,14 @@ int file_time(global_options *options, i
     return 0;
 }
 
+#ifdef WIN32
 int volume_space(global_options *options, int fatal)
 {
     struct _diskfree_t driveinfo;
-    int code;
     __int64 total_clusters, avail_clusters, 
             sectors_per_cluster, bytes_per_sector,
             bytes_free, bytes_total;
+    int code;
     double gb_free, gb_total;
 
     code = _getdiskfree(toupper(options->root_dir[0]) - 'A' + 1, &driveinfo); 
@@ -116,3 +120,34 @@ int volume_space(global_options *options
 
     return 0;
 }
+#else
+int volume_space(global_options *options, int fatal)
+{
+    struct statfs buf;
+    int code;
+    double gb_free, gb_total;
+
+    code = statfs(options->root_dir, &buf);
+    if (code != 0)
+    {
+        return errno;
+    }
+
+    gb_free = (double) (buf.f_bsize * buf.f_bfree) / (double) 1024*1024*1024;
+    gb_total = (double) (buf.f_bsize * buf.f_blocks) / (double) 1024*1024*1024;
+
+    report_perf(options,
+                "volume-space",
+                "free-space",
+                gb_free,
+                "%4.3f GB");
+
+    report_perf(options,
+                "volume-space",
+                "avail-space",
+                gb_total,
+                "%4.3f GB");
+
+    return 0;
+}
+#endif
\ No newline at end of file

Index: open.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/open.c,v
diff -p -u -r1.1.2.2 -r1.1.2.3
--- open.c	8 Feb 2011 21:59:57 -0000	1.1.2.2
+++ open.c	25 Feb 2011 23:03:10 -0000	1.1.2.3
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 #include "open.h"
 

Index: test-io.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/test-io.c,v
diff -p -u -r1.1.2.8 -r1.1.2.9
--- test-io.c	24 Feb 2011 22:29:16 -0000	1.1.2.8
+++ test-io.c	25 Feb 2011 23:03:10 -0000	1.1.2.9
@@ -10,6 +10,7 @@
 #else
 #include <pthread.h>
 #endif
+#include <errno.h>
 
 #include "test-support.h"
 #include "test-io.h"
@@ -58,7 +59,11 @@ int io_file(global_options *options, int
     char *perftests[] = {"io_file_write_4kb", "io_file_read_4kb", "io_file_write_100kb", 
                         "io_file_read_100kb", "io_file_write_1mb", "io_file_read_1mb"};
     char *subtests[] = {"4kb", "100kb", "1mb"};
+#ifdef WIN32
     unsigned __int64 start;
+#else
+    struct timeval start;
+#endif
     double elapsed;
     
     for (i = 0; i < 3; i++)
@@ -74,9 +79,17 @@ int io_file(global_options *options, int
 
         file_name = randfile(options->root_dir);
 
+#ifdef WIN32
         start = timer_start();
+#else
+        timer_start(&start);
+#endif
         code = io_file_int(file_name, "wb", buffer, sizes[i]);
+#ifdef WIN32
         elapsed = timer_elapsed(start);
+#else
+        elapsed = timer_elapsed(&start);
+#endif
 
         if (code != 0)
             goto io_file_exit;
@@ -91,9 +104,18 @@ int io_file(global_options *options, int
         copy = (char *) malloc(sizes[i]);
         memcpy(copy, buffer, sizes[i]);
 
+#ifdef WIN32
         start = timer_start();
+#else
+        timer_start(&start);
+#endif
         code = io_file_int(file_name, "rb", buffer, sizes[i]);
+
+#ifdef WIN32
         elapsed = timer_elapsed(start);
+#else
+        elapsed = timer_elapsed(&start);
+#endif
 
         if (code != 0)
             goto io_file_exit;
@@ -307,7 +329,7 @@ int io_file_mt(global_options *options, 
     uintptr_t *hthreads;
     int threadi, ret, i, code = 0;
     unsigned int counter, total;
-    unsigned __int64 start;
+    unsigned long long start;
     double elapsed;
 
     /* allocate args */
@@ -397,11 +419,14 @@ void *io_file_mt_thread(void *pargs)
     thread_args *args = (thread_args *) pargs;
     char *dir_name, *file_name, buf[4096];
     int i;
-    unsigned __int64 start;
+    struct timeval start;
     double elapsed;
-    unsigned int total = 0;
+    unsigned int *total = 0;
     FILE *f;
 
+    total = (unsigned int *) malloc(sizeof(unsigned int));
+    *total = 0;
+
     /* create directory */
     dir_name = (char *) malloc(strlen(args->options->root_dir) + 16);
     sprintf(dir_name, "%smt%02d", args->options->root_dir, args->threadi);
@@ -415,14 +440,14 @@ void *io_file_mt_thread(void *pargs)
     {
         file_name = (char *) malloc(strlen(dir_name) + 16);
         sprintf(file_name, "%s%cmt%04d.tst", dir_name, SLASH_CHAR, i);
-        start = timer_start();
+        timer_start(&start);
         f = fopen(file_name, "wb");
         if (f)
         {
             fwrite(buf, 1, 4096, f);
             fclose(f);
         }
-        elapsed = timer_elapsed(start);
+        elapsed = timer_elapsed(&start);
         total += (unsigned int) (elapsed * 1000000.0);
 
         free(file_name);
@@ -430,7 +455,7 @@ void *io_file_mt_thread(void *pargs)
 
     free(dir_name);
 
-    return &total;
+    return total;
 }
 
 int io_file_mt(global_options *options, int fatal)
@@ -439,16 +464,14 @@ int io_file_mt(global_options *options, 
     pthread_t *hthreads;
     int threadi, ret, i, code = 0;
     unsigned int *counter, total;
-    time_t start;
+    struct timeval start;
     double elapsed;
 
     /* allocate args */
     args = (thread_args *) malloc(sizeof(thread_args) * THREAD_COUNT);
 
     /* allocate thread array */
-    hthreads = (pthread_t *) malloc(sizeof(uintptr_t) * THREAD_COUNT);
-
-    counter = (unsigned int *) malloc(sizeof(unsigned int));
+    hthreads = (pthread_t *) malloc(sizeof(pthread_t) * THREAD_COUNT);
 
     /* spawn threads */    
     timer_start(&start);
@@ -467,12 +490,16 @@ int io_file_mt(global_options *options, 
     {
         for (i = 0; i < THREAD_COUNT && code == 0; i++)
         {
+            counter = (unsigned int *) malloc(sizeof(unsigned int));
+
             /* return value is time in microseconds */
             code = pthread_join(hthreads[threadi], &counter);
             total += *counter;
+
+            free(counter);
         }
 
-        elapsed = timer_elapsed(start);
+        elapsed = timer_elapsed(&start);
     }
 
     if (code == 0)

Index: test-list.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/test-list.h,v
diff -p -u -r1.1.2.8 -r1.1.2.9
--- test-list.h	22 Feb 2011 22:11:50 -0000	1.1.2.8
+++ test-list.h	25 Feb 2011 23:03:10 -0000	1.1.2.9
@@ -43,7 +43,9 @@ test_operation op_table[] =
     {"move-file-baddir", move_file_baddir, FALSE},
     {"move-file-exist", move_file_exist, FALSE},
     {"file-time", file_time, FALSE},
+#ifdef WIN32
     {"volume-space", volume_space, FALSE},
+#endif
     {"find-files", find_files, FALSE},
     {"find-files-pattern", find_files_pattern, FALSE},
     {"io-file-mt", io_file_mt, FALSE},

Index: test-support.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/test-support.c,v
diff -p -u -r1.1.2.9 -r1.1.2.10
--- test-support.c	24 Feb 2011 22:29:16 -0000	1.1.2.9
+++ test-support.c	25 Feb 2011 23:03:10 -0000	1.1.2.10
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 #include "test-support.h"
 #include "timer.h"

Index: test-support.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/test-support.h,v
diff -p -u -r1.1.2.7 -r1.1.2.8
--- test-support.h	24 Feb 2011 22:29:16 -0000	1.1.2.7
+++ test-support.h	25 Feb 2011 23:03:10 -0000	1.1.2.8
@@ -20,6 +20,7 @@
 #define _unlink unlink
 #define _stricmp strcasecmp
 #define _stat stat
+#define _snprintf snprintf
 
 #endif
 

Index: thread.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/thread.c,v
diff -p -u -r1.1.2.2 -r1.1.2.3
--- thread.c	18 Feb 2011 22:59:30 -0000	1.1.2.2
+++ thread.c	25 Feb 2011 23:03:10 -0000	1.1.2.3
@@ -2,17 +2,16 @@
    Windows client tests -- thread functions */
 
 #ifdef WIN32
+
 #include <Windows.h>
 #include <process.h>
-#else
-#include <pthread.h>
-#endif
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "thread.h"
 
+
 /*
 #ifdef WIN32
 int thread_create(void *handle, void *(*start_routine)(void *), void *arg)
@@ -67,3 +66,5 @@ int get_thread_exit_code(uintptr_t handl
 {
     return GetExitCodeThread((HANDLE) handle, (LPDWORD) code);
 }
+
+#endif
\ No newline at end of file

Index: thread.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/thread.h,v
diff -p -u -r1.1.2.2 -r1.1.2.3
--- thread.h	18 Feb 2011 22:59:30 -0000	1.1.2.2
+++ thread.h	25 Feb 2011 23:03:10 -0000	1.1.2.3
@@ -4,6 +4,8 @@
 #ifndef __THREAD_H
 #define __THREAD_H
 
+#ifdef WIN32
+
 #define THREAD_WAIT_SIGNALED           0
 #define THREAD_WAIT_TIMEOUT       0x102L
 #define THREAD_WAIT_INFINITE 0xFFFFFFFFL
@@ -16,5 +18,7 @@ int thread_wait_multiple(unsigned int co
                                   int wait_all, unsigned int timeout);
 
 int get_thread_exit_code(uintptr_t handle, unsigned int *code);
+
+#endif
 
 #endif

Index: timer.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/timer.c,v
diff -p -u -r1.1.2.3 -r1.1.2.4
--- timer.c	18 Feb 2011 22:59:30 -0000	1.1.2.3
+++ timer.c	25 Feb 2011 23:03:10 -0000	1.1.2.4
@@ -6,6 +6,7 @@
 #else
 #include <sys/time.h>
 #endif
+#include <stdlib.h>
 
 #include "timer.h"
 



More information about the Pvfs2-cvs mailing list