shane           Sun Jan 14 17:52:47 2001 EDT

  Modified files:              
    /php4/sapi/isapi/stresstest notes.txt stresstest.cpp 
  Log:
  test now produce valid OK or FAIL.
  
Index: php4/sapi/isapi/stresstest/notes.txt
diff -u php4/sapi/isapi/stresstest/notes.txt:1.2 
php4/sapi/isapi/stresstest/notes.txt:1.3
--- php4/sapi/isapi/stresstest/notes.txt:1.2    Sun Jan 14 16:29:49 2001
+++ php4/sapi/isapi/stresstest/notes.txt        Sun Jan 14 17:52:47 2001
@@ -37,13 +37,10 @@
 
 TODO:
 
-Make an apropriate test of the output against the EXPECT data for the test files, 
right now it simply doesn't work since I'm burnt (tired that is).
-
 Make more options configurable: number of threads, itterations, etc.
 
 Improve stdout output to make it more usefull
 
-Log totals for each test.
-
 Implement support for SKIPIF
 
+Improve speed of CompareFile function (too slow on big files).
Index: php4/sapi/isapi/stresstest/stresstest.cpp
diff -u php4/sapi/isapi/stresstest/stresstest.cpp:1.8 
php4/sapi/isapi/stresstest/stresstest.cpp:1.9
--- php4/sapi/isapi/stresstest/stresstest.cpp:1.8       Sun Jan 14 17:17:44 2001
+++ php4/sapi/isapi/stresstest/stresstest.cpp   Sun Jan 14 17:52:47 2001
@@ -83,12 +83,11 @@
 int stress_main(const char *filename, 
                                const char *arg, 
                                const char *postfile, 
-                               const char *matchdata,
-                               const char *testname);
+                               const char *matchdata);
 
 
 
-BOOL test = FALSE;
+BOOL bUseTestFiles = FALSE;
 char temppath[MAX_PATH];
 
 void stripcrlf(char *line)
@@ -99,6 +98,37 @@
        if (line[l]==10 || line[l]==13) line[l]=0;
 }
 
+
+BOOL CompareFiles(const char*f1, const char*f2)
+{
+       FILE *fp1 = fopen(f1,"r");
+       if (!fp1) return FALSE;
+       FILE *fp2 = fopen(f2,"r");
+       if (!fp2) {
+               fclose(fp1);
+               return FALSE;
+       }
+
+       CString file1, file2, line;
+       char buf[1024];
+       while (fgets(buf, sizeof(buf), fp1)) {
+               line = buf;
+               line.TrimLeft();
+               line.TrimRight();
+               file1+=line;
+       }
+       fclose(fp1);
+       while (fgets(buf, sizeof(buf), fp2)) {
+               line = buf;
+               line.TrimLeft();
+               line.TrimRight();
+               file2+=line;
+       }
+       fclose(fp2);
+
+       return file1==file2;
+}
+
 BOOL ReadGlobalEnvironment(const char *environment)
 {
        if (environment) {
@@ -154,6 +184,8 @@
 
                i++;
        }
+       Results.SetSize(TestNames.GetSize());
+
        fclose(fp);
        return IsapiFileList.GetSize() > 0;
 }
@@ -371,7 +403,7 @@
                printf("USAGE: stresstest [L|T] filelist [environment]\r\n");
                return 0;
        } else {
-               if (argv[1][0]=='T') test = TRUE;
+               if (argv[1][0]=='T') bUseTestFiles = TRUE;
                if (argc > 1) filelist = argv[2];
                if (argc > 2) environment = argv[3];
        }
@@ -416,7 +448,7 @@
                return -1;
        }
 
-       if (test) {
+       if (bUseTestFiles) {
                char TestPath[MAX_PATH];
                if (filelist != NULL) 
                        _snprintf(TestPath, sizeof(TestPath)-1, "%s\\tests", filelist);
@@ -443,16 +475,24 @@
        for (DWORD j=0; j<ITERATIONS; j++) {
                for (DWORD i=0; i<filecount; i++) {
                        // execute each file
-                       printf("Thread %d File %s\n", GetCurrentThreadId(), 
IsapiFileList.GetAt(i));
-
+                       CString testname = TestNames.GetAt(i);
+                       BOOL ok = FALSE;
                        if (stress_main(IsapiFileList.GetAt(i), 
                                                IsapiGetData.GetAt(i), 
                                                IsapiPostData.GetAt(i),
-                                               IsapiMatchData.GetAt(i),
-                                               TestNames.GetAt(i)))
-                               if (test) InterlockedIncrement(&Results[i].ok);
-                       else
-                               if (test) InterlockedIncrement(&Results[i].bad);
+                                               IsapiMatchData.GetAt(i))) {
+                               InterlockedIncrement(&Results[i].ok);
+                               ok = TRUE;
+                       } else {
+                               InterlockedIncrement(&Results[i].bad);
+                               ok = FALSE;
+                       }
+
+                       if (testname.IsEmpty()) {
+                               printf("Thread %d File %s\n", GetCurrentThreadId(), 
+IsapiFileList.GetAt(i));
+                       } else {
+                               printf("tid %d: %s %s\n", GetCurrentThreadId(), 
+testname, ok?"OK":"FAIL");
+                       }
                        Sleep(10);
                }
        }
@@ -472,8 +512,7 @@
 BOOL stress_main(const char *filename, 
                                const char *arg, 
                                const char *postdata,
-                               const char *matchdata,
-                               const char *testname) 
+                               const char *matchdata) 
 {
 
        EXTENSION_CONTROL_BLOCK ECB;
@@ -485,7 +524,7 @@
        CString fname;
        fname.Format("%08X.out", context.tid);
 
-       context.out = CreateFile(fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 
NULL);
+       context.out = CreateFile(fname, GENERIC_WRITE, FILE_SHARE_READ, NULL, 
+CREATE_ALWAYS, 0, NULL);
        if (context.out==INVALID_HANDLE_VALUE) {
                printf("failed to open output file %s\n", fname);
                return 0;
@@ -538,25 +577,14 @@
 
        BOOL ok = TRUE;
 
+       if (context.out != INVALID_HANDLE_VALUE) CloseHandle(context.out);
+
        // compare the output with the EXPECT section
        if (matchdata && *matchdata != 0) {
-               // wimpy I know, but I'm tired and lazy now
-               HANDLE md = CreateFile(matchdata, GENERIC_READ, FILE_SHARE_READ, NULL, 
OPEN_EXISTING, 0, NULL);
-               if (md) {
-                       DWORD osz = 0, msz = 0;
-                       GetFileSize(md, &msz);
-                       GetFileSize(context.out, &osz);
-                       if (osz == msz && osz != 0) {
-                               printf("%s OK\r\n", testname);
-                       } else {
-                               printf("%s FAILED\r\n", testname);
-                               ok = FALSE;
-                       }
-               }
+               ok = CompareFiles(matchdata, fname);
        }
-
-       if (context.out) CloseHandle(context.out);
 
+       DeleteFile(fname);
        //if (rc == HSE_STATUS_PENDING) // We will exit in ServerSupportFunction
        //      Sleep(INFINITE);
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to