3 TCHAR test_dir[MAX_PATH] = _T("");
4 TCHAR fn_base[MAX_PATH] = _T("");
5 TCHAR fn_aux[MAX_PATH] = _T("");
7 HANDLE h_file_base = NULL;
8 HANDLE h_file_aux = NULL;
10 void log_last_error(void)
12 logfile << "GetLastError() == " << GetLastError() << "\n";
17 TCHAR file_name[MAX_PATH];
20 logfile << "-------Starting tests-----------------------------\n";
22 StringCbCopy(file_name, sizeof(file_name), test_dir);
23 StringCbCat(file_name, sizeof(file_name), _T("FLTST000"));
24 StringCbCopy(fn_base, sizeof(fn_base), file_name);
26 logfile << "h_file_base = CreateFile(" << file_name << ") shared\n";
28 h_file_base = CreateFile(
30 GENERIC_READ | GENERIC_WRITE,
31 FILE_SHARE_READ | FILE_SHARE_WRITE,
37 if(h_file_base == INVALID_HANDLE_VALUE) {
42 StringCbCopy(file_name, sizeof(file_name), test_dir);
43 StringCbCat(file_name, sizeof(file_name), _T("FLTST001"));
44 StringCbCopy(fn_aux, sizeof(fn_aux), file_name);
48 logfile << "h_file_aux = CreateFile(" << file_name << ") exclusive\n";
50 h_file_aux = CreateFile(
52 GENERIC_READ | GENERIC_WRITE,
59 if(h_file_aux == INVALID_HANDLE_VALUE) {
69 - Requesting a sharing mode that conflicts with the access mode specified in a previous
70 open reqeuest whose handle is still open should be an error (should return ERROR_SHARING_VIOLATION)
71 - If sharing mode is 0, the file cannot be opened again until the handle is closed.
72 - Sharing modes should be tested:
82 logfile << "----Begin CreateFile tests ----\n";
85 "TEST:CREATE:001 Requesting a sharing mode that conflicts with the access mode "
86 "specified in a previous open requestion whose handle is still open should be an error.\n";
89 "TEST:CREATE:001:01 Attempt exclusive open of a file which is already opened exclusively\n";
91 logfile << "CreateFile(" << fn_aux << ")... exclusive\n";
94 GENERIC_READ | GENERIC_WRITE,
101 if(h != INVALID_HANDLE_VALUE) {
102 logfile << "BAD : CreateFile(" << fn_aux << ") should have failed but didn't\n";
103 cerr << "TEST:CREATE:001:01 ***FAILED***\n";
106 logfile << "good: CreateFile(" << fn_aux << ") failed\n";
107 cerr << "TEST:CREATE:001:01 PASS (LastError=" << GetLastError() << ")\n";
108 if(GetLastError() != ERROR_SHARING_VIOLATION)
109 cerr << "TEST:CREATE:001:01 **WARN** LastError != ERROR_SHARING_VIOLATION\n";
113 "TEST:CREATE:001:02 Attempt to open a file with shared read which is already opened exclusively\n";
115 logfile << "CreateFile(" << fn_aux << ")... share read\n";
119 GENERIC_READ | GENERIC_WRITE,
126 if(h != INVALID_HANDLE_VALUE) {
127 logfile << "BAD : CreateFile(" << fn_aux << ") should have failed but didn't\n";
128 cerr << "TEST:CREATE:001:02 ***FAILED***\n";
132 cerr << "TEST:CREATE:001:02 PASS (LastError=" << GetLastError() << ")\n";
133 if(GetLastError() != ERROR_SHARING_VIOLATION)
134 cerr << "TEST:CREATE:001:02 **WARN** LastError != ERROR_SHARING_VIOLATION\n";
138 "TEST:CREATE:001:03 Attempt to open a file exclusively which is already opened shared\n";
140 logfile << "CreateFile(" << fn_base << ")... exclusive\n";
144 GENERIC_READ | GENERIC_WRITE,
151 if(h != INVALID_HANDLE_VALUE) {
152 logfile << "BAD : CreateFile(" << fn_base << ") should have failed but didn't\n";
153 cerr << "TEST:CREATE:001:03 ***FAILED***\n";
157 cerr << "TEST:CREATE:001:03 PASS (LastError=" << GetLastError() << ")\n";
158 if(GetLastError() != ERROR_SHARING_VIOLATION)
159 cerr << "TEST:CREATE:001:03 **WARN** LastError != ERROR_SHARING_VIOLATION\n";
163 "TEST:CREATE:001:04 Attempt to open a file shared write which is already opened shared r/w\n";
165 logfile << "CreateFile(" << fn_base << ")... share write\n";
169 GENERIC_READ | GENERIC_WRITE,
176 if(h != INVALID_HANDLE_VALUE) {
177 logfile << "BAD : CreateFile(" << fn_base << ") should have failed but didn't\n";
178 cerr << "TEST:CREATE:001:04 ***FAILED***\n";
182 cerr << "TEST:CREATE:001:04 PASS (LastError=" << GetLastError() << ")\n";
183 if(GetLastError() != ERROR_SHARING_VIOLATION)
184 cerr << "TEST:CREATE:001:04 **WARN** LastError != ERROR_SHARING_VIOLATION\n";
188 "TEST:CREATE:001:05 Attempt to open a file shared r/w which is already opened shared r/w\n";
190 logfile << "CreateFile(" << fn_base << ")... share r/w\n";
194 GENERIC_READ | GENERIC_WRITE,
195 FILE_SHARE_WRITE | FILE_SHARE_READ,
201 if(h != INVALID_HANDLE_VALUE) {
203 cerr << "TEST:CREATE:001:05 PASS\n";
206 logfile << "BAD : CreateFile(" << fn_base << ") failed!\n";
207 cerr << "TEST:CREATE:001:05 ***FAILED*** (LastError=" << GetLastError() << ")\n";
210 logfile << "----End CreateFile tests ----\n";
216 /* prepare the test file by filling it in with the test pattern */
217 int test_lock_prep(void)
223 logfile << "----Preparing test file----\n";
225 buffer = (DWORD *) malloc(sizeof(DWORD) * 1024);
227 assert(buffer != NULL);
228 logfile << "SetFilePointer(h_file_base, 0, NULL, FILE_BEGIN)\n";
229 SetFilePointer(h_file_base, 0, NULL, FILE_BEGIN);
230 for(j=0; j<256; j++) {
231 for(i=0; i<1024; i++) {
235 logfile << "WriteFile(h_file_base, (LPCVOID) buffer, sizeof(DWORD) * 1024, &nb, NULL)\n";
237 if(!WriteFile(h_file_base, (LPCVOID) buffer, sizeof(DWORD) * 1024, &nb, NULL)) {
238 logfile << "WARNING**: WriteFile error=" << GetLastError() << "\n";
239 } else if(nb != sizeof(DWORD) * 1024) {
240 logfile << "WARNING**: WriteFile underrun (j=" << j << ",nb=" << nb << ")\n";
246 SetEndOfFile(h_file_base);
247 FlushFileBuffers(h_file_base);
249 logfile << "----End Preparing test file---\n";
255 /* Test exclusive locks below EOF
257 testint_* functions manage their own cross process synchronization
259 int testint_lock_excl_beof(void)
261 /* at this point, test_lock_prep() has already run, and the length
262 of h_file_base is set at 1M */
264 logfile << "----Begin Lock Test Exclusive BEOF----\n";
266 cerr << "TEST:LOCK:001 Exclusive byte-range locks below EOF\n";
268 /* parent takes three non-overlapping locks */
269 logfile << "LockFile(h_file_base, PAGE_BEGIN(10), 0, PAGE_LEN(10), 0)\n";
270 if(!LockFile(h_file_base, PAGE_BEGIN(10), 0, PAGE_LEN(10), 0)) {
271 logfile << "ERROR**: LockFile Failed (last error=" << GetLastError() << ")\n";
272 cerr << "TEST:LOCK:001 ***ERROR*** Setup failed!\n";
275 logfile << "LockFile(h_file_base, 4096 * 30, 0, 4096 * 10, 0)\n";
276 if(!LockFile(h_file_base, PAGE_BEGIN(30), 0, PAGE_LEN(10), 0)) {
277 logfile << "ERROR**: LockFile Failed (last error=" << GetLastError() << ")\n";
278 cerr << "TEST:LOCK:001 ***ERROR*** Setup failed!\n";
281 logfile << "LockFile(h_file_base, 4096 * 62, 0, 4096 * 1, 0)\n";
282 if(!LockFile(h_file_base, PAGE_BEGIN(62), 0, PAGE_LEN(1), 0)) {
283 logfile << "ERROR**: LockFile Failed (last error=" << GetLastError() << ")\n";
284 cerr << "TEST:LOCK:001 ***ERROR*** Setup failed!\n";
289 logfile << "--Test using same handle, same process--\n";
291 "TEST:LOCK:001:01 Test overlapping locks within same process (complete overlap)\n";
293 if(!LockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(3), 0)) {
294 cerr << "TEST:LOCK:001:01 PASS (LastError=" << GetLastError() << ")\n";
296 cerr << "TEST:LOCK:001:01 ***FAILED***\n";
297 if(!UnlockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(3), 0))
298 cerr << "TEST:LOCK:001:01 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
302 "TEST:LOCK:001:02 Test overlapping locks within same process (partial overlap A)\n";
304 if(!LockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(10), 0)) {
305 cerr << "TEST:LOCK:001:02 PASS (LastError=" << GetLastError() << ")\n";
307 cerr << "TEST:LOCK:001:02 ***FAILED***\n";
308 if(!UnlockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(10), 0))
309 cerr << "TEST:LOCK:001:02 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
313 "TEST:LOCK:001:03 Test overlapping locks within same process (partial overlap B)\n";
315 if(!LockFile(h_file_base, PAGE_BEGIN(25), 0, PAGE_LEN(10), 0)) {
316 cerr << "TEST:LOCK:001:03 PASS (LastError=" << GetLastError() << ")\n";
318 cerr << "TEST:LOCK:001:03 ***FAILED***\n";
319 if(!UnlockFile(h_file_base, PAGE_BEGIN(25), 0, PAGE_LEN(10), 0))
320 cerr << "TEST:LOCK:001:03 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
324 "TEST:LOCK:001:04 Test non-overlapping locks with same process\n";
326 "TEST:LOCK:001:04 PASS (iff Setup succeeded)\n";
331 logfile << "--Test using child process--\n";
333 "TEST:LOCK:001:05 Test overlapping locks with different process (complete overlap)\n";
335 if(!LockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(3), 0)) {
336 cerr << "TEST:LOCK:001:05 PASS (LastError=" << GetLastError() << ")\n";
338 cerr << "TEST:LOCK:001:05 ***FAILED***\n";
339 if(!UnlockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(3), 0))
340 cerr << "TEST:LOCK:001:05 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
344 "TEST:LOCK:001:06 Test overlapping locks with different process (partial overlap A)\n";
346 if(!LockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(10), 0)) {
347 cerr << "TEST:LOCK:001:06 PASS (LastError=" << GetLastError() << ")\n";
349 cerr << "TEST:LOCK:001:06 ***FAILED***\n";
350 if(!UnlockFile(h_file_base, PAGE_BEGIN(15), 0, PAGE_LEN(10), 0))
351 cerr << "TEST:LOCK:001:06 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
355 "TEST:LOCK:001:07 Test overlapping locks with different process (partial overlap B)\n";
357 if(!LockFile(h_file_base, PAGE_BEGIN(25), 0, PAGE_LEN(10), 0)) {
358 cerr << "TEST:LOCK:001:07 PASS (LastError=" << GetLastError() << ")\n";
360 cerr << "TEST:LOCK:001:07 ***FAILED***\n";
361 if(!UnlockFile(h_file_base, PAGE_BEGIN(25), 0, PAGE_LEN(10), 0))
362 cerr << "TEST:LOCK:001:07 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
366 "TEST:LOCK:001:08 Test non-overlapping lock with different process\n";
368 if(!LockFile(h_file_base, PAGE_BEGIN(50), 0, PAGE_LEN(10), 0)) {
369 cerr << "TEST:LOCK:001:08 ***FAILED*** (LastError=" << GetLastError() << ")\n";
371 cerr << "TEST:LOCK:001:08 PASS\n";
372 /* leave lock held */
379 /* by now we have the following exclusive locks:
381 pages 10-19 : exclusive by parent
382 pages 30-39 : exclusive by parent
383 pages 50-59 : exclusive by child
384 pages 0-9 : free-for-all
385 pages 20-29 : free-for-all
386 pages 40-49 : free-for-all
387 pages 60-61 : free-for-all
388 page 62 : exclusive by parent
389 pages 63-255: free-for-all
390 pages 256- : non-existent
394 int testint_lock_excl_rw_beof(void)
400 /* each of read_buf and write_buf are 10 pages long */
401 read_buf = (DWORD *) malloc(sizeof(DWORD) * 10240);
402 assert(read_buf != NULL);
404 write_buf = (DWORD *) malloc(sizeof(DWORD) * 10240);
405 assert(write_buf != NULL);
408 logfile << "----Test writes and reads on exclusive locks----\n";
409 logfile << "--Read tests--\n";
411 cerr << "TEST:LOCK:002 Read tests in the presence of locks\n";
413 cerr << "TEST:LOCK:002:01 Read in unlocked area\n";
415 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(42), NULL, FILE_BEGIN)\n";
416 if(SetFilePointer(h_file_base, PAGE_BEGIN(42), NULL, FILE_BEGIN) != PAGE_BEGIN(42)) {
417 cerr << "TEST:LOCK:002:01 ERROR** Setup Failed!\n";
418 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
420 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
421 cerr << "TEST:LOCK:002:01 ***FAILED*** (LastError=" << GetLastError() << ")\n";
423 cerr << "TEST:LOCK:002:01 PASS\n";
426 cerr << "TEST:LOCK:002:02 Read in partially locked area (A)\n";
428 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(27), NULL, FILE_BEGIN)\n";
429 if(SetFilePointer(h_file_base, PAGE_BEGIN(27), NULL, FILE_BEGIN) != PAGE_BEGIN(27)) {
430 cerr << "TEST:LOCK:002:02 ERROR** Setup Failed!\n";
431 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
433 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
434 cerr << "TEST:LOCK:002:02 ***FAILED*** (LastError=" << GetLastError() << ")\n";
436 cerr << "TEST:LOCK:002:02 PASS\n";
439 cerr << "TEST:LOCK:002:03 Read in locked area\n";
441 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(32), NULL, FILE_BEGIN)\n";
442 if(SetFilePointer(h_file_base, PAGE_BEGIN(32), NULL, FILE_BEGIN) != PAGE_BEGIN(32)) {
443 cerr << "TEST:LOCK:002:03 ERROR** Setup Failed!\n";
444 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
446 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
447 cerr << "TEST:LOCK:002:03 ***FAILED*** (LastError=" << GetLastError() << ")\n";
449 cerr << "TEST:LOCK:002:03 PASS\n";
452 cerr << "TEST:LOCK:002:04 Read in partially locked area (B)\n";
454 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(37), NULL, FILE_BEGIN)\n";
455 if(SetFilePointer(h_file_base, PAGE_BEGIN(37), NULL, FILE_BEGIN) != PAGE_BEGIN(37)) {
456 cerr << "TEST:LOCK:002:04 ERROR** Setup Failed!\n";
457 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
459 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
460 cerr << "TEST:LOCK:002:04 ***FAILED*** (LastError=" << GetLastError() << ")\n";
462 cerr << "TEST:LOCK:002:04 PASS\n";
465 cerr << "TEST:LOCK:002:05 Read in partially unowned area (A)\n";
467 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(47), NULL, FILE_BEGIN)\n";
468 if(SetFilePointer(h_file_base, PAGE_BEGIN(47), NULL, FILE_BEGIN) != PAGE_BEGIN(47)) {
469 cerr << "TEST:LOCK:002:05 ERROR** Setup Failed!\n";
470 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
472 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
473 cerr << "TEST:LOCK:002:05 PASS (LastError=" << GetLastError() << ")\n";
475 cerr << "TEST:LOCK:002:05 ***FAILED***\n";
478 cerr << "TEST:LOCK:002:06 Read in fully unowned area\n";
480 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(52), NULL, FILE_BEGIN)\n";
481 if(SetFilePointer(h_file_base, PAGE_BEGIN(52), NULL, FILE_BEGIN) != PAGE_BEGIN(52)) {
482 cerr << "TEST:LOCK:002:06 ERROR** Setup Failed!\n";
483 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
485 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
486 cerr << "TEST:LOCK:002:06 PASS (LastError=" << GetLastError() << ")\n";
488 cerr << "TEST:LOCK:002:06 ***FAILED***\n";
491 cerr << "TEST:LOCK:002:07 Read in partially unowned area (B)\n";
493 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(56), NULL, FILE_BEGIN)\n";
494 if(SetFilePointer(h_file_base, PAGE_BEGIN(56), NULL, FILE_BEGIN) != PAGE_BEGIN(56)) {
495 cerr << "TEST:LOCK:002:07 ERROR** Setup Failed!\n";
496 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
498 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
499 cerr << "TEST:LOCK:002:07 PASS (LastError=" << GetLastError() << ")\n";
501 cerr << "TEST:LOCK:002:07 ***FAILED***\n";
504 cerr << "TEST:LOCK:002:08 Read in partially unowned area (C)\n";
506 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(59), NULL, FILE_BEGIN)\n";
507 if(SetFilePointer(h_file_base, PAGE_BEGIN(59), NULL, FILE_BEGIN) != PAGE_BEGIN(59)) {
508 cerr << "TEST:LOCK:002:08 ERROR** Setup Failed!\n";
509 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
511 if(!ReadFile(h_file_base, (LPVOID) read_buf, PAGE_LEN(5), &nbytes, NULL)) {
512 cerr << "TEST:LOCK:002:08 PASS (LastError=" << GetLastError() << ")\n";
514 cerr << "TEST:LOCK:002:08 ***FAILED***\n";
522 for(j=0; j<10; j++) {
523 for(i=0; i<1024; i++) {
524 write_buf[j*1024 + i] = 0x0d0d0d0d;
528 cerr << "TEST:LOCK:003 Write tests in the presence of locks\n";
529 logfile << "--Write tests--\n";
531 cerr << "TEST:LOCK:003:01 Write in unlocked area\n";
533 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(42), NULL, FILE_BEGIN)\n";
534 if(SetFilePointer(h_file_base, PAGE_BEGIN(42), NULL, FILE_BEGIN) != PAGE_BEGIN(42)) {
535 cerr << "TEST:LOCK:003:01 ERROR** Setup Failed!\n";
536 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
538 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
539 cerr << "TEST:LOCK:003:01 ***FAILED*** (LastError=" << GetLastError() << ")\n";
541 cerr << "TEST:LOCK:003:01 PASS\n";
544 cerr << "TEST:LOCK:003:02 Write in partially owned area (A)\n";
546 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(47), NULL, FILE_BEGIN)\n";
547 if(SetFilePointer(h_file_base, PAGE_BEGIN(47), NULL, FILE_BEGIN) != PAGE_BEGIN(47)) {
548 cerr << "TEST:LOCK:003:02 ERROR** Setup Failed!\n";
549 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
551 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
552 cerr << "TEST:LOCK:003:02 ***FAILED*** (LastError=" << GetLastError() << ")\n";
554 cerr << "TEST:LOCK:003:02 PASS\n";
557 cerr << "TEST:LOCK:003:03 Write in fully owned area\n";
559 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(52), NULL, FILE_BEGIN)\n";
560 if(SetFilePointer(h_file_base, PAGE_BEGIN(52), NULL, FILE_BEGIN) != PAGE_BEGIN(52)) {
561 cerr << "TEST:LOCK:003:03 ERROR** Setup Failed!\n";
562 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
564 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
565 cerr << "TEST:LOCK:003:03 ***FAILED*** (LastError=" << GetLastError() << ")\n";
567 cerr << "TEST:LOCK:003:03 PASS\n";
570 cerr << "TEST:LOCK:003:04 Write in partially owned area (B)\n";
572 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(56), NULL, FILE_BEGIN)\n";
573 if(SetFilePointer(h_file_base, PAGE_BEGIN(56), NULL, FILE_BEGIN) != PAGE_BEGIN(56)) {
574 cerr << "TEST:LOCK:003:04 ERROR** Setup Failed!\n";
575 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
577 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
578 cerr << "TEST:LOCK:003:04 ***FAILED*** (LastError=" << GetLastError() << ")\n";
580 cerr << "TEST:LOCK:003:04 PASS\n";
583 cerr << "TEST:LOCK:003:05 Write in partially unowned area (A)\n";
585 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(27), NULL, FILE_BEGIN)\n";
586 if(SetFilePointer(h_file_base, PAGE_BEGIN(27), NULL, FILE_BEGIN) != PAGE_BEGIN(27)) {
587 cerr << "TEST:LOCK:003:05 ERROR** Setup Failed!\n";
588 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
590 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
591 cerr << "TEST:LOCK:003:05 PASS (LastError=" << GetLastError() << ")\n";
593 cerr << "TEST:LOCK:003:05 ***FAILED***\n";
596 cerr << "TEST:LOCK:003:06 Write in fully unowned area\n";
598 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(32), NULL, FILE_BEGIN)\n";
599 if(SetFilePointer(h_file_base, PAGE_BEGIN(32), NULL, FILE_BEGIN) != PAGE_BEGIN(32)) {
600 cerr << "TEST:LOCK:003:06 ERROR** Setup Failed!\n";
601 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
603 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
604 cerr << "TEST:LOCK:003:06 PASS (LastError=" << GetLastError() << ")\n";
606 cerr << "TEST:LOCK:003:06 ***FAILED***\n";
609 cerr << "TEST:LOCK:003:07 Write in partially unowned area (B)\n";
611 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(37), NULL, FILE_BEGIN)\n";
612 if(SetFilePointer(h_file_base, PAGE_BEGIN(37), NULL, FILE_BEGIN) != PAGE_BEGIN(37)) {
613 cerr << "TEST:LOCK:003:07 ERROR** Setup Failed!\n";
614 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
616 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
617 cerr << "TEST:LOCK:003:07 PASS (LastError=" << GetLastError() << ")\n";
619 cerr << "TEST:LOCK:003:07 ***FAILED***\n";
622 cerr << "TEST:LOCK:003:08 Write in partially unowned area (C)\n";
624 logfile << "SetFilePointer(h_file_base, PAGE_BEGIN(59), NULL, FILE_BEGIN)\n";
625 if(SetFilePointer(h_file_base, PAGE_BEGIN(59), NULL, FILE_BEGIN) != PAGE_BEGIN(59)) {
626 cerr << "TEST:LOCK:003:08 ERROR** Setup Failed!\n";
627 logfile << "**ERROR** Last error=" << GetLastError() << "\n";
629 if(!WriteFile(h_file_base, (LPCVOID) write_buf, PAGE_LEN(5), &nbytes, NULL)) {
630 cerr << "TEST:LOCK:003:08 PASS (LastError=" << GetLastError() << ")\n";
632 cerr << "TEST:LOCK:003:08 ***FAILED***\n";
635 FlushFileBuffers(h_file_base);
645 int testint_lock_excl_eeof(void)
647 /* at this point, test_lock_prep() has already run, and the length
648 of h_file_base is set at 1M */
650 logfile << "----Begin Lock Test Exclusive EEOF----\n";
652 cerr << "TEST:LOCK:004 Exclusive byte-range locks above EOF\n";
654 /* parent takes three non-overlapping locks */
655 logfile << "LockFile(h_file_base, PAGE_BEGIN(256+10), 0, PAGE_LEN(10), 0)\n";
656 if(!LockFile(h_file_base, PAGE_BEGIN(256+10), 0, PAGE_LEN(10), 0)) {
657 logfile << "ERROR**: LockFile Failed (last error=" << GetLastError() << ")\n";
658 cerr << "TEST:LOCK:004 ***ERROR*** Setup failed!\n";
661 logfile << "LockFile(h_file_base, PAGE_BEGIN(256+30), 0, 4096 * 10, 0)\n";
662 if(!LockFile(h_file_base, PAGE_BEGIN(256+30), 0, PAGE_LEN(10), 0)) {
663 logfile << "ERROR**: LockFile Failed (last error=" << GetLastError() << ")\n";
664 cerr << "TEST:LOCK:004 ***ERROR*** Setup failed!\n";
667 logfile << "LockFile(h_file_base, PAGE_BEGIN(256+62), 0, 4096 * 1, 0)\n";
668 if(!LockFile(h_file_base, PAGE_BEGIN(256+62), 0, PAGE_LEN(1), 0)) {
669 logfile << "ERROR**: LockFile Failed (last error=" << GetLastError() << ")\n";
670 cerr << "TEST:LOCK:004 ***ERROR*** Setup failed!\n";
675 logfile << "--Test using same handle, same process--\n";
677 "TEST:LOCK:004:01 Test overlapping locks within same process (complete overlap)\n";
679 if(!LockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(3), 0)) {
680 cerr << "TEST:LOCK:004:01 PASS (LastError=" << GetLastError() << ")\n";
682 cerr << "TEST:LOCK:004:01 ***FAILED***\n";
683 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(3), 0))
684 cerr << "TEST:LOCK:004:01 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
688 "TEST:LOCK:004:02 Test overlapping locks within same process (partial overlap A)\n";
690 if(!LockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(10), 0)) {
691 cerr << "TEST:LOCK:004:02 PASS (LastError=" << GetLastError() << ")\n";
693 cerr << "TEST:LOCK:004:02 ***FAILED***\n";
694 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(10), 0))
695 cerr << "TEST:LOCK:004:02 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
699 "TEST:LOCK:004:03 Test overlapping locks within same process (partial overlap B)\n";
701 if(!LockFile(h_file_base, PAGE_BEGIN(256+25), 0, PAGE_LEN(10), 0)) {
702 cerr << "TEST:LOCK:004:03 PASS (LastError=" << GetLastError() << ")\n";
704 cerr << "TEST:LOCK:004:03 ***FAILED***\n";
705 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+25), 0, PAGE_LEN(10), 0))
706 cerr << "TEST:LOCK:004:03 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
710 "TEST:LOCK:004:04 Test non-overlapping locks with same process\n";
712 "TEST:LOCK:004:04 PASS (iff Setup succeeded)\n";
717 logfile << "--Test using child process--\n";
719 "TEST:LOCK:004:05 Test overlapping locks with different process (complete overlap)\n";
721 if(!LockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(3), 0)) {
722 cerr << "TEST:LOCK:004:05 PASS (LastError=" << GetLastError() << ")\n";
724 cerr << "TEST:LOCK:004:05 ***FAILED***\n";
725 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(3), 0))
726 cerr << "TEST:LOCK:004:05 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
730 "TEST:LOCK:004:06 Test overlapping locks with different process (partial overlap A)\n";
732 if(!LockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(10), 0)) {
733 cerr << "TEST:LOCK:004:06 PASS (LastError=" << GetLastError() << ")\n";
735 cerr << "TEST:LOCK:004:06 ***FAILED***\n";
736 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+15), 0, PAGE_LEN(10), 0))
737 cerr << "TEST:LOCK:004:06 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
741 "TEST:LOCK:004:07 Test overlapping locks with different process (partial overlap B)\n";
743 if(!LockFile(h_file_base, PAGE_BEGIN(256+25), 0, PAGE_LEN(10), 0)) {
744 cerr << "TEST:LOCK:004:07 PASS (LastError=" << GetLastError() << ")\n";
746 cerr << "TEST:LOCK:004:07 ***FAILED***\n";
747 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+25), 0, PAGE_LEN(10), 0))
748 cerr << "TEST:LOCK:004:07 ****BADNESS**** UnlockFile failed with " << GetLastError() << "\n";
752 "TEST:LOCK:004:08 Test non-overlapping lock with different process\n";
754 if(!LockFile(h_file_base, PAGE_BEGIN(256+50), 0, PAGE_LEN(10), 0)) {
755 cerr << "TEST:LOCK:004:08 ***FAILED*** (LastError=" << GetLastError() << ")\n";
757 cerr << "TEST:LOCK:004:08 PASS\n";
758 /* leave lock held */
765 int testint_waitlock(void)
768 _TCHAR filename[MAX_PATH];
775 ZeroMemory(&ov, sizeof(ov));
776 ov.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
777 ZeroMemory(&ovx, sizeof(ovx));
778 ovx.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
780 StringCbCopy(filename, sizeof(filename), test_dir);
781 StringCbCat(filename, sizeof(filename), _T("asyncft.dat"));
784 logfile << "----Begin Wait Lock tests (single)----\n";
785 cerr << "TEST:WLCS Waiting Lock (single node, 2 process)\n";
787 hFile = CreateFile(filename, GENERIC_READ|GENERIC_WRITE,
788 FILE_SHARE_READ | FILE_SHARE_WRITE,
791 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
793 logfile << "CreateFile(\"" << filename << "\") returns "
794 << ((DWORD_PTR) hFile) << "\n";
797 cerr << "TEST:WLCS *** ERROR *** CreateFile failed for temporary file. See log\n";
798 logfile << " Failed!! GetLastError()==" << GetLastError()
806 hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
807 FILE_SHARE_READ | FILE_SHARE_WRITE,
810 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
812 logfile << "CreateFile(\"" << filename << "\") returns "
813 << ((DWORD_PTR) hFile) << "\n";
816 cerr << "TEST:WLCS *** ERROR *** CreateFile failed for temporary file. See log\n";
817 logfile << " Failed!! GetLastError() ==" << GetLastError()
825 cerr << "TEST:WLCS:001 Simple conflicting wait lock test\n";
827 ov.Offset = PAGE_BEGIN(1);
829 b = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK,
830 0, PAGE_LEN(1), 0, &ov);
832 logfile << "LockFileEx() returns " << b << "\n";
834 cerr << "TEST:WLCS:001:01 PASS Initial Lock (no wait)\n";
838 if (e == ERROR_IO_PENDING) {
839 logfile << "LockFileEx() is pending.\n";
840 cerr << "TEST:WLCS:001:01 Lock pending...";
841 WaitForSingleObject(ov.hEvent, INFINITE);
843 << "TEST:WLCS:001:01 PASS\n";
845 logfile << "LockFileEx() failed!! LastError=" << e
847 cerr << "TEST:WLCS:001:01 FAIL!! LockFileEx() Failed! GetLastERror="
854 ov.Offset = PAGE_BEGIN(1);
856 b = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK,
857 0, PAGE_LEN(2), 0, &ov);
859 logfile << "LockFileEx() returns " << b << "\n";
861 if (!b && GetLastError() == ERROR_IO_PENDING) {
862 cerr << "TEST:WLCS:001:02 PASS Conflicting lock placed in pending\n";
864 cerr << "TEST:WLCS:001:02 FAILED! Conflicting lock not pending!\n";
871 ov.Offset = PAGE_BEGIN(1);
874 b = UnlockFileEx(hFile, 0,
875 PAGE_LEN(1), 0, &ov);
877 logfile << "UnlockFileEx() returns " << b << "\n";
879 logfile << "Unlock completed.\n";
880 cerr << "TEST:WLCS:001:03 PASS Unlock (no wait)\n";
884 if (e == ERROR_IO_PENDING) {
885 logfile << "Waiting for unlock ..";
886 cerr << "TEST:WLCS:001:03 Unlock pending ...";
887 WaitForSingleObject(ov.hEvent, INFINITE);
890 << "TEST:WLCS:001:03 PASS\n";
892 logfile << "UnlockFileEx() failed. Last error = "
894 cerr << "TEST:WLCS:001:03 FAILED! UnlockFileEx() failed\n";
901 logfile << "Child waiting for lock ..";
902 cerr << "TEST:WLCS:001:04 Lock pending...";
903 WaitForSingleObject(ov.hEvent, INFINITE);
904 logfile << "Done.\n";
906 << "TEST:WLCS:001:04 PASS\n";
910 cerr << "TEST:WLCS:002 Multiple queued wait lock test\n";
912 // lock region B (should be pending) (B intersects A)
913 ov.Offset = PAGE_BEGIN(2);
916 b = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK,
917 0, PAGE_LEN(2), 0, &ov);
918 logfile << "LockFileEx() returns " << b << "\n";
919 if (!b && GetLastError() == ERROR_IO_PENDING) {
920 cerr << "TEST:WLCS:002:01 PASS Conflicting lock placed in pending\n";
921 logfile << "Lock pending.\n";
923 logfile << "Lock is not pending. (it should be). Last erorr="
924 << GetLastError() << "\n";
925 cerr << "TEST:WLCS:002:01 FAILED! Conflicting lock is not pending.\n";
932 // lock region C (where C intersects B but not A) (should be granted)
933 ovx.Offset = PAGE_BEGIN(3);
935 b = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK,
938 logfile << "LockFileEx() returns" << b << "\n";
940 if (!b && GetLastError() == ERROR_IO_PENDING) {
941 logfile << "Lock pending.\n";
942 cerr << "TEST:WLCS:002:02 Pending ...";
943 WaitForSingleObject(ovx.hEvent, INFINITE);
945 cerr << "TEST:WLCS:002:02 PASS\n";
947 cerr << "TEST:WLCS:002:02 PASS (no wait)\n";
949 logfile << "** error ** LockFile failed. last error="
951 cerr << "TEST:WLCS:002:02 FAILED!! (see log)\n";
955 b = UnlockFileEx(hFile, 0,
956 PAGE_LEN(2), 0, &ov);
957 logfile << "UnlockFileEx() returns" << b << "\n";
960 cerr << "TEST:WLCS:002:03 PASS Unlock (no wait)\n";
961 logfile << "Unlock succeeded without wait\n";
965 if (e == ERROR_IO_PENDING) {
966 logfile << "Waiting for unlock...";
967 cerr << "TEST:WLCS:002:03 Pending ...";
968 WaitForSingleObject(ov.hEvent, INFINITE);
971 << "TEST:WLCS:002:03 PASS\n";
973 logfile << " Unlock failed! last error ="
975 cerr << "TEST:WLCS:002:03 FAILED! Unlock failed! see log\n";
981 b = UnlockFileEx(hFile, 0,
982 PAGE_LEN(2), 0, &ovx);
983 logfile << "UnlockFileEx() returns" << b << "\n";
986 cerr << "TEST:WLCS:002:04 PASS Unlock (no wait)\n";
987 logfile << "Unlock succeeded without wait\n";
991 if (e == ERROR_IO_PENDING) {
992 logfile << "Waiting for unlock...";
993 cerr << "TEST:WLCS:002:04 Pending ...";
994 WaitForSingleObject(ov.hEvent, INFINITE);
997 << "TEST:WLCS:002:04 PASS\n";
999 logfile << " Unlock failed! last error ="
1001 cerr << "TEST:WLCS:002:04 FAILED! Unlock failed! see log\n";
1009 logfile << "Waiting for lock ...";
1010 cerr << "TEST:WLCS:002:05 Waiting for lock...";
1011 WaitForSingleObject(ov.hEvent, INFINITE);
1012 logfile << "done\n";
1014 cerr << "TEST:WLCS:002:06 PASS\n";
1017 b = UnlockFileEx(hFile, 0,
1021 logfile << "Unlock succeeded without wait\n";
1022 cerr << "TEST:WLCS:002:06 PASS Unlock (no wait)\n";
1026 if (e == ERROR_IO_PENDING) {
1027 logfile << "Waiting for unlock ...";
1028 cerr << "TEST:WLCS:002:06 Pending...";
1029 WaitForSingleObject(ov.hEvent, INFINITE);
1030 logfile << "done\n";
1032 << "TEST:WLCS:002:06 PASS\n";
1034 logfile << "Unlock failed! last error = "
1036 cerr << "TEST:WLCS:002:06 FAILED! Unlock failed! see log\n";
1043 cerr << "TEST:WLCS:002 Done.\n";
1048 CloseHandle(ov.hEvent);
1049 CloseHandle(ovx.hEvent);
1055 int test_waitlock_parent(void)
1060 int test_waitlock_child(void)
1066 int testint_lock_excl_rw_eeof(void)
1071 /* unlock all the remaining locks */
1072 int testint_unlock(void)
1075 logfile << "----Begin Unlock test----\n";
1077 cerr << "TEST:LOCK:005 Unlocks\n";
1079 cerr << "TEST:LOCK:005:01 Unlock parent locks\n";
1081 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(10), 0, PAGE_LEN(10), 0)\n";
1082 if(!UnlockFile(h_file_base, PAGE_BEGIN(10), 0, PAGE_LEN(10), 0)) {
1083 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1084 cerr << "TEST:LOCK:005:01 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1086 cerr << "TEST:LOCK:005:01 PASS\n";
1088 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(30), 0, PAGE_LEN(10), 0)\n";
1089 if(!UnlockFile(h_file_base, PAGE_BEGIN(30), 0, PAGE_LEN(10), 0)) {
1090 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1091 cerr << "TEST:LOCK:005:02 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1093 cerr << "TEST:LOCK:005:02 PASS\n";
1096 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(62), 0, PAGE_LEN(1), 0)\n";
1097 if(!UnlockFile(h_file_base, PAGE_BEGIN(62), 0, PAGE_LEN(1), 0)) {
1098 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1099 cerr << "TEST:LOCK:005:03 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1101 cerr << "TEST:LOCK:005:03 PASS\n";
1104 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(256+10), 0, PAGE_LEN(10), 0)\n";
1105 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+10), 0, PAGE_LEN(10), 0)) {
1106 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1107 cerr << "TEST:LOCK:005:04 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1109 cerr << "TEST:LOCK:005:04 PASS\n";
1111 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(256+30), 0, PAGE_LEN(10), 0)\n";
1112 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+30), 0, PAGE_LEN(10), 0)) {
1113 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1114 cerr << "TEST:LOCK:005:05 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1116 cerr << "TEST:LOCK:005:05 PASS\n";
1119 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(256+62), 0, PAGE_LEN(1), 0)\n";
1120 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+62), 0, PAGE_LEN(1), 0)) {
1121 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1122 cerr << "TEST:LOCK:005:06 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1124 cerr << "TEST:LOCK:005:06 PASS\n";
1129 cerr << "TEST:LOCK:005:02 Unlock parent locks\n";
1131 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(50), 0, PAGE_LEN(10), 0)\n";
1132 if(!UnlockFile(h_file_base, PAGE_BEGIN(50), 0, PAGE_LEN(10), 0)) {
1133 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1134 cerr << "TEST:LOCK:005:07 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1136 cerr << "TEST:LOCK:005:07 PASS\n";
1139 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(256+50), 0, PAGE_LEN(10), 0)\n";
1140 if(!UnlockFile(h_file_base, PAGE_BEGIN(256+50), 0, PAGE_LEN(10), 0)) {
1141 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1142 cerr << "TEST:LOCK:005:08 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1144 cerr << "TEST:LOCK:005:08 PASS\n";
1149 cerr << "TEST:LOCK:006 Check if unlocked really worked\n";
1151 logfile << "LockFile(h_file_base, PAGE_BEGIN(0), 0, PAGE_LEN(256+60), 0)\n";
1152 if(!LockFile(h_file_base, PAGE_BEGIN(0), 0, PAGE_LEN(256+60), 0)) {
1153 logfile << "ERROR**: LockFile Failed (last error=" << GetLastError() << ")\n";
1154 cerr << "TEST:LOCK:006:01 ***ERROR*** Lock Failed! Error=" << GetLastError() << "\n";
1156 cerr << "TEST:LOCK:006:01 PASS\n";
1158 logfile << "UnlockFile(h_file_base, PAGE_BEGIN(0), 0, PAGE_LEN(256+60), 0)\n";
1159 if(!UnlockFile(h_file_base, PAGE_BEGIN(0), 0, PAGE_LEN(256+60), 0)) {
1160 logfile << "ERROR**: UnockFile Failed (last error=" << GetLastError() << ")\n";
1161 cerr << "TEST:LOCK:005:08 ***ERROR*** Unlock Failed! Error=" << GetLastError() << "\n";
1163 cerr << "TEST:LOCK:005:08 PASS\n";
1169 int testint_lock_escalation(void)
1173 ZeroMemory(&ov, sizeof(ov));
1176 cerr << "TEST:LOCK:006 Lock Escalation\n";
1177 logfile << "-----------Lock escalation------\n";
1179 ov.Offset = PAGE_BEGIN(10);
1181 if(!LockFileEx(h_file_base, LOCKFILE_FAIL_IMMEDIATELY, 0, PAGE_LEN(10), 0, &ov)) {
1182 logfile << "ERROR**: Last error = " << GetLastError() << "\n";
1183 cerr << "TEST:LOCK:006:01 ***FAILED*** Error=" << GetLastError() << "\n";
1185 cerr << "TEST:LOCK:006:01 PASS\n";
1188 ov.Offset = PAGE_BEGIN(30);
1190 if(!LockFileEx(h_file_base, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY, 0, PAGE_LEN(10), 0, &ov)) {
1191 logfile << "ERROR**: Last error = " << GetLastError() << "\n";
1192 cerr << "TEST:LOCK:006:02 ***FAILED*** Error=" << GetLastError() << "\n";
1194 cerr << "TEST:LOCK:006:02 PASS\n";
1197 ov.Offset = PAGE_BEGIN(50);
1199 if(!LockFileEx(h_file_base, LOCKFILE_FAIL_IMMEDIATELY, 0, PAGE_LEN(10), 0, &ov)) {
1200 logfile << "ERROR**: Last error = " << GetLastError() << "\n";
1201 cerr << "TEST:LOCK:006:03 ***FAILED*** Error=" << GetLastError() << "\n";
1203 cerr << "TEST:LOCK:006:03 PASS\n";
1206 ov.Offset = PAGE_BEGIN(50);
1208 if(!UnlockFileEx(h_file_base, 0, PAGE_LEN(10), 0, &ov)) {
1209 logfile << "ERROR**: Last error = " << GetLastError() << "\n";
1210 cerr << "TEST:LOCK:006:04 ***FAILED*** Error=" << GetLastError() << "\n";
1212 cerr << "TEST:LOCK:006:04 PASS\n";
1215 ov.Offset = PAGE_BEGIN(30);
1217 if(!UnlockFileEx(h_file_base, 0, PAGE_LEN(10), 0, &ov)) {
1218 logfile << "ERROR**: Last error = " << GetLastError() << "\n";
1219 cerr << "TEST:LOCK:006:05 ***FAILED*** Error=" << GetLastError() << "\n";
1221 cerr << "TEST:LOCK:006:05 PASS\n";
1224 ov.Offset = PAGE_BEGIN(10);
1226 if(!UnlockFileEx(h_file_base, 0, PAGE_LEN(10), 0, &ov)) {
1227 logfile << "ERROR**: Last error = " << GetLastError() << "\n";
1228 cerr << "TEST:LOCK:006:06 ***FAILED*** Error=" << GetLastError() << "\n";
1230 cerr << "TEST:LOCK:006:06 PASS\n";
1240 if(h_file_base != NULL) {
1241 logfile << "Closing h_file_base\n";
1242 CloseHandle(h_file_base);
1244 if(h_file_aux != NULL) {
1245 logfile << "Closing h_file_aux\n";
1246 CloseHandle(h_file_aux);
1249 logfile << "--------Ending tests\n";