[Pvfs2-cvs] commit by sampson in pvfs2/src/client/windows/client-test: timer.c timer.h open.c test-io.c test-io.h test-list.h test-support.c test-support.h

CVS commit program cvs at parl.clemson.edu
Tue Feb 8 16:59:57 EST 2011


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

Modified Files:
      Tag: windows-client
	open.c test-io.c test-io.h test-list.h test-support.c 
	test-support.h 
Added Files:
      Tag: windows-client
	timer.c timer.h 
Log Message:
Coding Windows client tests


--- /dev/null	2004-06-24 14:04:38.000000000 -0400
+++ timer.c	2011-02-08 16:59:57.000000000 -0500
@@ -0,0 +1,33 @@
+/* Copyright (C) 2011 Omnibond, LLC
+   Client test -- timer functions */
+
+#include <Windows.h>
+
+#include "timer.h"
+
+/* get the start time for the timer */
+unsigned long long timer_start()
+{
+    LARGE_INTEGER counter;
+
+    if (!QueryPerformanceCounter(&counter))
+        return 0;
+
+    return (unsigned) counter.QuadPart;
+}
+
+/* get the elapsed time for the timer (seconds) */
+double timer_elapsed(unsigned long long start)
+{
+    LARGE_INTEGER counter, freq;
+    unsigned long long elapsed;
+
+    if (!QueryPerformanceCounter(&counter))
+        return 0;
+
+    if (!QueryPerformanceFrequency(&freq))
+        return 0;
+
+    return ((double) counter.QuadPart - (double) start) / (double) freq.QuadPart;
+}
+

--- /dev/null	2004-06-24 14:04:38.000000000 -0400
+++ timer.h	2011-02-08 16:59:57.000000000 -0500
@@ -0,0 +1,9 @@
+/* Copyright (C) 2011 Omnibond, LLC
+   Client test -- timer declarations */
+
+/* get the start time for the timer */
+unsigned long long timer_start();
+
+/* get the elapsed time for the timer (seconds) */
+double timer_elapsed(unsigned long long start);
+

Index: open.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/open.c,v
diff -p -u -r1.1.2.1 -r1.1.2.2
--- open.c	7 Feb 2011 22:36:15 -0000	1.1.2.1
+++ open.c	8 Feb 2011 21:59:57 -0000	1.1.2.2
@@ -7,6 +7,11 @@
 
 #include "open.h"
 
+void open_file_cleanup(char *file_name)
+{
+    _unlink(file_name);
+}
+
 /* open file w/specified mode */
 int open_file_int(char *file_name, char *mode)
 {
@@ -43,6 +48,7 @@ int open_file(global_options *options, i
 
     if (code != 0 && fatal)
     {
+        open_file_cleanup(file_name);
         free(file_name);
         return CODE_FATAL;
     }
@@ -60,6 +66,7 @@ int open_file(global_options *options, i
 
     if (code != 0 && fatal)
     {
+        open_file_cleanup(file_name);
         free(file_name);
         return CODE_FATAL;
     }
@@ -77,6 +84,7 @@ int open_file(global_options *options, i
 
     if (code != 0 && fatal)
     {
+        open_file_cleanup(file_name);
         free(file_name);
         return CODE_FATAL;
     }
@@ -94,9 +102,12 @@ int open_file(global_options *options, i
 
     if (code != 0 && fatal)
     {
+        open_file_cleanup(file_name);
         free(file_name);
         return CODE_FATAL;
     }
+
+    open_file_cleanup(file_name);
 
     free(file_name);
 

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.1 -r1.1.2.2
--- test-io.c	7 Feb 2011 22:36:15 -0000	1.1.2.1
+++ test-io.c	8 Feb 2011 21:59:57 -0000	1.1.2.2
@@ -1,3 +1,122 @@
 /* Copyright (C) 2011 Omnibond, LLC
    Client test - IO functions */
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "test-support.h"
+#include "test-io.h"
+#include "timer.h"
+
+int io_file_int(char *file_name, char *mode, char *buffer, size_t size)
+{
+    FILE *f;
+    int real_size, code = 0;
+
+    f = fopen(file_name, mode);
+    if (!f)
+        return errno;
+
+    if (!strcmp(mode, "r"))
+        real_size = fread(buffer, 1, size, f);
+    else /* "w" or "a" */
+        real_size = fwrite(buffer, 1, size, f);
+
+    if (size != real_size)
+        code = errno;
+
+    fclose(f);
+
+    return code;
+}
+
+int io_file(global_options *options, int fatal)
+{
+    char *file_name, *buffer = NULL, *copy = NULL;
+    int i, j, code, code_flag;
+    size_t sizes[] = {4*1024, 100*1024, 1024*1024};
+    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"};
+    unsigned long long start;
+    double elapsed;
+    
+    for (i = 0; i < 3; i++)
+    {
+        code_flag = 0;
+
+        /* allocate buffer */
+        buffer = (char *) malloc(sizes[i]);
+
+        /* fill buffer */
+        for (j = 0; j < sizes[i]; j++)
+            buffer[j] = (char) j % 256;
+
+        file_name = randfile(options->root_dir);
+
+        start = timer_start();
+        code = io_file_int(file_name, "w", buffer, sizes[i]);
+        elapsed = timer_elapsed(start);
+
+        if (code != 0)
+            goto io_file_exit;
+
+        report_perf(options,
+                    "io_file",
+                    perftests[i*2],
+                    elapsed,
+                    "%3.3fs");
+
+        /* copy the buffer */
+        copy = (char *) malloc(sizes[i]);
+        memcpy(copy, buffer, sizes[i]);
+
+        start = timer_start();
+        code = io_file_int(file_name, "r", buffer, sizes[i]);
+        elapsed = timer_elapsed(start);
+
+        if (code != 0)
+            goto io_file_exit;
+
+        report_perf(options,
+                    "io_file",
+                    perftests[i*2+1],
+                    elapsed,
+                    "%3.3fs");
+
+        /* compare buffers */
+        code = memcmp(copy, buffer, sizes[i]);
+        code_flag = 1;
+
+        report_result(options,
+                      "io_file",
+                      subtests[i],
+                      RESULT_SUCCESS,
+                      0,
+                      OPER_EQUAL,
+                      code);
+
+        free(file_name); file_name = NULL;
+        free(buffer); buffer = NULL;
+        free(copy); copy = NULL;
+
+    }
+
+io_file_exit:
+
+    if (file_name)
+        free(file_name);
+    if (buffer)
+        free(buffer);
+    if (copy)
+        free(copy);
+
+    if (!code_flag)
+    {
+        /* todo: report_error */
+        return code;
+    }
+
+    return 0;
+}
\ No newline at end of file

Index: test-io.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-test/Attic/test-io.h,v
diff -p -u -r1.1.2.1 -r1.1.2.2
--- test-io.h	7 Feb 2011 22:36:15 -0000	1.1.2.1
+++ test-io.h	8 Feb 2011 21:59:57 -0000	1.1.2.2
@@ -4,5 +4,8 @@
 #ifndef __TEST_IO_H
 #define __TEST_IO_H
 
+#include "test-support.h"
+
+int io_file(global_options *options, int fatal);
 
 #endif

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.2 -r1.1.2.3
--- test-list.h	7 Feb 2011 22:36:15 -0000	1.1.2.2
+++ test-list.h	8 Feb 2011 21:59:57 -0000	1.1.2.3
@@ -8,6 +8,7 @@
 
 #include "create.h"
 #include "open.h"
+#include "test-io.h"
 
 typedef struct 
 {
@@ -27,6 +28,7 @@ test_operation op_table[] =
     {"create-file-toolong", create_file_toolong, FALSE},
     {"create-files-many", create_files_many, FALSE},
     {"open-file", open_file, TRUE},
+    {"io-file", io_file, FALSE},
     {NULL, NULL, 0}
 };
 

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.5 -r1.1.2.6
--- test-support.c	4 Feb 2011 22:54:51 -0000	1.1.2.5
+++ test-support.c	8 Feb 2011 21:59:57 -0000	1.1.2.6
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include "test-support.h"
+#include "timer.h"
 
 const char *ops[] = {"=", "<>", "<", ">", "=<", ">="};
 
@@ -154,3 +155,26 @@ void report_result(global_options *optio
     free(line);
 }
 
+void report_perf(global_options *options,
+                 const char *test_name,
+                 const char *sub_test,
+                 double value,
+                 char *format)
+{
+    char valstr[32];
+
+    /* get the string for the value in the specified format */
+    sprintf(valstr, format, value);
+
+    /* report to console and/or file */
+    if (options->report_flags & REPORT_CONSOLE)
+        printf("%s %s PERF %s\n", test_name, sub_test, valstr);
+
+    if (options->report_flags & REPORT_FILE)
+    {
+        fprintf(options->freport, "%s %s PERF %s\n", test_name, sub_test, valstr);
+        fflush(options->freport);
+    }
+
+}
+                   
\ No newline at end of file

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.4 -r1.1.2.5
--- test-support.h	4 Feb 2011 22:54:51 -0000	1.1.2.4
+++ test-support.h	8 Feb 2011 21:59:57 -0000	1.1.2.5
@@ -47,4 +47,10 @@ void report_result(global_options *optio
                    int code_operation,
                    int actual_code);
 
+void report_perf(global_options *options,
+                 const char *test_name,
+                 const char *sub_test,
+                 double value,
+                 char *format);
+
 #endif



More information about the Pvfs2-cvs mailing list