[Pvfs2-cvs] commit by sampson in pvfs2/test/posix: open.c

CVS commit program cvs at parl.clemson.edu
Thu Mar 3 17:58:33 EST 2011


Update of /projects/cvsroot/pvfs2/test/posix
In directory parlweb1:/tmp/cvs-serv1777/test/posix

Modified Files:
      Tag: windows-client
	open.c 
Log Message:
Windows testing


Index: open.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/test/posix/open.c,v
diff -p -u -r1.3 -r1.3.64.1
--- open.c	20 Sep 2006 20:49:57 -0000	1.3
+++ open.c	3 Mar 2011 22:58:33 -0000	1.3.64.1
@@ -4,32 +4,61 @@
  * system call!
  */
 #include <stdio.h>
+#ifdef WIN32
+#include <Windows.h>
+#include <io.h>
+#else
 #include <sys/time.h>
+#endif
 #include <string.h>
 #include <errno.h>
+#ifndef WIN32
 #include <unistd.h>
+#endif
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <time.h>
+#ifndef WIN32
 #include <linux/unistd.h>
 #include "sha1.h"
 #include "crc32c.h"
+#endif
 #include "mpi.h"
 
+#ifdef WIN32
+#define open(f, o, p)    _open(f, o, p)
+#define close(f)         _close(f)
+#define unlink(f)        _unlink(f)
+#endif
+
+#if 0
 static inline double msec_diff(double *end, double *begin)
 {
 	return (*end - *begin);
 }
+#endif
 
+#ifdef WIN32
+static double Wtime(void)
+{
+    LARGE_INTEGER counter;
+
+    QueryPerformanceCounter(&counter);
+
+    return (double) counter.QuadPart;
+}
+#else
 static double Wtime(void)
 {
     struct timeval t;
     gettimeofday(&t, NULL);
     return((double)t.tv_sec * 1e03 + (double)(t.tv_usec) * 1e-03);
 }
+#endif
 
+#if 0
 struct file_handle_generic {
 	/* Filled by VFS */
 	int32_t   fhg_magic; /* magic number */
@@ -38,6 +67,7 @@ struct file_handle_generic {
 	int32_t   fhg_crc_csum; /* crc32c check sum of the blob */
 	unsigned char fhg_hmac_sha1[24]; /* hmac-sha1 message authentication code */
 };
+#endif
 
 int main(int argc, char *argv[])
 {
@@ -47,11 +77,20 @@ int main(int argc, char *argv[])
 	double begin, end, tdiff = 0.0, max_diff;
 	int open_flags = 0;
 	int i, rank, np;
+#ifdef WIN32
+        LARGE_INTEGER freq;
+        HANDLE hFile;
+#endif
 
 	MPI_Init(&argc, &argv);
 	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 	MPI_Comm_size(MPI_COMM_WORLD, &np);
-
+#ifdef WIN32
+        /* just use one option for now */
+        fname = argv[1];
+        open_flags |= O_CREAT;
+        do_create = 1;
+#else
 	while ((c = getopt(argc, argv, opt)) != EOF) {
 		switch (c) {
 			case 'u':
@@ -75,6 +114,7 @@ int main(int argc, char *argv[])
 				exit(1);
 		}
 	}
+#endif
 	if (fname == NULL)
 	{
 		fprintf(stderr, "Usage: %s -f <fname> -c {create} -u {unlink} -n <num iterations>\n", argv[0]);
@@ -88,18 +128,43 @@ int main(int argc, char *argv[])
 			open_flags |= O_RDONLY;
 
 			begin = Wtime();
+#ifdef WIN32
+                        hFile = CreateFile(fname,
+                                           GENERIC_READ | GENERIC_WRITE,
+                                           FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                                           NULL,
+                                           CREATE_ALWAYS,
+                                           FILE_ATTRIBUTE_NORMAL,
+                                           NULL);
+                        if (hFile == INVALID_HANDLE_VALUE)
+                        {
+                            fprintf(stderr, "CreateFile: %d\n", GetLastError());
+                            MPI_Finalize();
+                            exit(1);
+                        }
+#else
 			fd = open(fname, open_flags, 0775);
 			if (fd < 0) {
 				perror("open(2) error:");
 				MPI_Finalize();
 				exit(1);
 			}
+#endif
 			end = Wtime();
 			tdiff += (end - begin);
+#ifdef WIN32
+                        CloseHandle(hFile);
+#else
 			close(fd);
+#endif
 			if (rank == 0 && i < (niters - 1))
 				unlink(fname);
 	}
+        
+#ifdef WIN32
+        QueryPerformanceFrequency(&freq);
+        tdiff = tdiff / (double) freq.QuadPart * 1000.0;
+#endif
 	tdiff = tdiff / niters;
 	MPI_Allreduce(&tdiff, &max_diff, 1, 
 			MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);



More information about the Pvfs2-cvs mailing list