1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_open.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,725 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\server\t_open.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <f32file.h>
1.22 +#include <e32test.h>
1.23 +#include "t_server.h"
1.24 +
1.25 +GLDEF_D RTest test(_L("T_OPEN"));
1.26 +
1.27 +LOCAL_D TFileName gBatchFile;
1.28 +LOCAL_D TBool gRunByBatch=EFalse;
1.29 +
1.30 +TFileName filename1=_L("Z:\\TEST\\T_FSRV.CPP");
1.31 +TFileName filename2=_L("Z:\\TEST\\T_FILE.CPP");
1.32 +TFileName dirname1=_L("Z:\\TEST\\*.XDE");
1.33 +
1.34 +
1.35 +LOCAL_C void Test0()
1.36 +//
1.37 +// Scan for open files - no sessions
1.38 +//
1.39 + {
1.40 +
1.41 + test.Next(_L("Scan for open files with no sessions open"));
1.42 + CFileList* list;
1.43 + TOpenFileScan fileScan(TheFs);
1.44 + fileScan.NextL(list);
1.45 + if (list==NULL)
1.46 + return;
1.47 + TInt count=list->Count();
1.48 + if (count==1)
1.49 + {
1.50 + gRunByBatch=ETrue;
1.51 + gBatchFile=(*list)[0].iName;
1.52 + delete list;
1.53 + fileScan.NextL(list);
1.54 + if (list==NULL)
1.55 + return;
1.56 + count=list->Count();
1.57 + }
1.58 + while (count--)
1.59 + {
1.60 + TEntry entry=(*list)[count];
1.61 + test.Printf(_L("%d) EntryName = %S\n"),count,&entry.iName);
1.62 + }
1.63 + test.Printf(_L("Test will fail unless files are closed.\n"));
1.64 + test(0);
1.65 + //test.Printf(_L("Press any key ...\n"));
1.66 + //test.Getch();
1.67 + }
1.68 +
1.69 +LOCAL_C void Test1()
1.70 +//
1.71 +// Test OpenFileScan
1.72 +//
1.73 + {
1.74 +
1.75 + test.Next(_L("Scan for open files - one session only"));
1.76 +
1.77 + RFile file1,file2,file3;
1.78 +
1.79 + TInt r=file1.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
1.80 + test(r==KErrNone);
1.81 +
1.82 + r=file2.Open(TheFs,filename2,EFileRead);
1.83 + test(r==KErrNone);
1.84 +
1.85 + r=file3.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
1.86 + test(r==KErrNone);
1.87 +
1.88 + CFileList* list=NULL;
1.89 + TOpenFileScan fileScan(TheFs);
1.90 + TRAP(r,fileScan.NextL(list));
1.91 + test(r==KErrNone);
1.92 +
1.93 + if (gRunByBatch)
1.94 + {
1.95 + test(list!=NULL);
1.96 + test(list->Count()==1);
1.97 + TEntry entry=(*list)[0];
1.98 + test(entry.iName.FindF(_L(".BAT"))>=0);
1.99 + delete list;
1.100 + fileScan.NextL(list);
1.101 + }
1.102 +
1.103 +
1.104 + test(list!=NULL);
1.105 + TInt count=list->Count();
1.106 + test(count==3);
1.107 + TEntry entry=(*list)[0];
1.108 +
1.109 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.110 + entry=(*list)[1];
1.111 + test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
1.112 + entry=(*list)[2];
1.113 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.114 + TThreadId threadId=fileScan.ThreadId();
1.115 + RThread current;
1.116 + TThreadId currentId=current.Id();
1.117 + test(threadId==currentId);
1.118 + delete list;
1.119 +
1.120 + fileScan.NextL(list);
1.121 + test(list==NULL);
1.122 +
1.123 + file1.Close();
1.124 + file2.Close();
1.125 + file3.Close();
1.126 + }
1.127 +
1.128 +LOCAL_C void Test2()
1.129 +//
1.130 +// Test openfilescan - empty, full, empty.
1.131 +//
1.132 + {
1.133 +
1.134 +
1.135 + test.Next(_L("Scan for open files - empty sessions"));
1.136 +
1.137 + RFs fs1,fs2,fs3,fs4;
1.138 + TInt r=fs1.Connect();
1.139 + test(r==KErrNone);
1.140 + r=fs2.Connect();
1.141 + test(r==KErrNone);
1.142 + r=fs3.Connect();
1.143 + test(r==KErrNone);
1.144 + r=fs4.Connect();
1.145 + test(r==KErrNone);
1.146 +
1.147 + RFile file1,file2,file3;
1.148 +
1.149 + r=file1.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
1.150 + test(r==KErrNone);
1.151 +
1.152 + r=file2.Open(fs2,filename2,EFileRead);
1.153 + test(r==KErrNone);
1.154 +
1.155 + r=file3.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
1.156 + test(r==KErrNone);
1.157 +
1.158 + CFileList* list;
1.159 + TOpenFileScan fileScan(TheFs);
1.160 + fileScan.NextL(list);
1.161 +
1.162 + if (gRunByBatch)
1.163 + {
1.164 + test(list!=NULL);
1.165 + test(list->Count()==1);
1.166 + TEntry entry=(*list)[0];
1.167 + test(entry.iName.FindF(_L(".BAT"))>=0);
1.168 + delete list;
1.169 + fileScan.NextL(list);
1.170 + }
1.171 +
1.172 + test(list!=NULL);
1.173 + TInt count=list->Count();
1.174 + test(count==3);
1.175 + TEntry entry=(*list)[0];
1.176 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.177 + entry=(*list)[1];
1.178 + test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
1.179 + entry=(*list)[2];
1.180 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.181 + TThreadId threadId=fileScan.ThreadId();
1.182 + RThread current;
1.183 + TThreadId currentId=current.Id();
1.184 + test(threadId==currentId);
1.185 + delete list;
1.186 +
1.187 + fileScan.NextL(list);
1.188 + test(list==NULL);
1.189 +
1.190 + file1.Close();
1.191 + file2.Close();
1.192 + file3.Close();
1.193 + fs1.Close();
1.194 + fs2.Close();
1.195 + fs3.Close();
1.196 + fs4.Close();
1.197 + }
1.198 +
1.199 +LOCAL_C void Test3()
1.200 +//
1.201 +// Test openfilescan - empty, full, empty full
1.202 +//
1.203 + {
1.204 +
1.205 + test.Next(_L("Scan for open files - multiple sessions"));
1.206 +
1.207 + RFs fs1,fs2,fs3,fs4;
1.208 + TInt r=fs1.Connect();
1.209 + test(r==KErrNone);
1.210 + r=fs2.Connect();
1.211 + test(r==KErrNone);
1.212 + r=fs3.Connect();
1.213 + test(r==KErrNone);
1.214 + r=fs4.Connect();
1.215 + test(r==KErrNone);
1.216 +
1.217 + RFile file1,file2,file3;
1.218 +
1.219 + r=file1.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
1.220 + test(r==KErrNone);
1.221 +
1.222 + r=file2.Open(fs2,filename2,EFileRead|EFileShareReadersOnly);
1.223 + test(r==KErrNone);
1.224 +
1.225 + r=file3.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
1.226 + test(r==KErrNone);
1.227 +
1.228 + r=file1.Open(fs4,filename1,EFileRead|EFileShareReadersOnly);
1.229 + test(r==KErrNone);
1.230 +
1.231 + r=file2.Open(fs4,filename2,EFileRead|EFileShareReadersOnly);
1.232 + test(r==KErrNone);
1.233 +
1.234 + r=file3.Open(fs4,filename1,EFileRead|EFileShareReadersOnly);
1.235 + test(r==KErrNone);
1.236 +
1.237 + CFileList* list;
1.238 + TOpenFileScan fileScan(TheFs);
1.239 + fileScan.NextL(list);
1.240 +
1.241 + if (gRunByBatch)
1.242 + {
1.243 + test(list!=NULL);
1.244 + test(list->Count()==1);
1.245 + TEntry entry=(*list)[0];
1.246 + test(entry.iName.FindF(_L(".BAT"))>=0);
1.247 + delete list;
1.248 + fileScan.NextL(list);
1.249 + }
1.250 +
1.251 + test(list!=NULL);
1.252 + TInt count=list->Count();
1.253 + test(count==3);
1.254 + TEntry entry=(*list)[0];
1.255 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.256 + entry=(*list)[1];
1.257 + test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
1.258 + entry=(*list)[2];
1.259 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.260 + TThreadId threadId=fileScan.ThreadId();
1.261 + RThread current;
1.262 + TThreadId currentId=current.Id();
1.263 + test(threadId==currentId);
1.264 + delete list;
1.265 +
1.266 + fileScan.NextL(list);
1.267 + test(list!=NULL);
1.268 + count=list->Count();
1.269 + test(count==3);
1.270 + entry=(*list)[0];
1.271 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.272 + entry=(*list)[1];
1.273 + test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
1.274 + entry=(*list)[2];
1.275 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.276 + threadId=fileScan.ThreadId();
1.277 + currentId=current.Id();
1.278 + test(threadId==currentId);
1.279 + delete list;
1.280 +
1.281 + fileScan.NextL(list);
1.282 + test(list==NULL);
1.283 +
1.284 + file1.Close();
1.285 + file2.Close();
1.286 + file3.Close();
1.287 + fs1.Close();
1.288 + fs2.Close();
1.289 + fs3.Close();
1.290 + fs4.Close();
1.291 + }
1.292 +
1.293 +LOCAL_C void Test4()
1.294 +//
1.295 +// Test openfilescan - rdirs, empty, full, empty rdirs.
1.296 +//
1.297 + {
1.298 + test.Next(_L("Scan for open files - check RDir sessions are ignored"));
1.299 +
1.300 + RFs fs1,fs2,fs3,fs4;
1.301 + TInt r=fs1.Connect();
1.302 + test(r==KErrNone);
1.303 + r=fs2.Connect();
1.304 + test(r==KErrNone);
1.305 + r=fs3.Connect();
1.306 + test(r==KErrNone);
1.307 + r=fs4.Connect();
1.308 + test(r==KErrNone);
1.309 +
1.310 + RDir dir1,dir2,dir3,dir4;
1.311 + r=dir1.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.312 + test(r==KErrNone);
1.313 + r=dir2.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.314 + test(r==KErrNone);
1.315 + r=dir3.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.316 + test(r==KErrNone);
1.317 + r=dir4.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.318 + test(r==KErrNone);
1.319 +
1.320 + RFile file1,file2,file3;
1.321 + r=file1.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
1.322 + test(r==KErrNone);
1.323 + r=file2.Open(fs2,filename2,EFileRead);
1.324 + test(r==KErrNone);
1.325 + r=file3.Open(fs2,filename1,EFileRead|EFileShareReadersOnly);
1.326 + test(r==KErrNone);
1.327 +
1.328 + RDir dir5,dir6,dir7,dir8;
1.329 + r=dir5.Open(fs4,dirname1,KEntryAttMaskSupported);
1.330 + test(r==KErrNone);
1.331 + r=dir6.Open(fs4,dirname1,KEntryAttMaskSupported);
1.332 + test(r==KErrNone);
1.333 + r=dir7.Open(fs4,dirname1,KEntryAttMaskSupported);
1.334 + test(r==KErrNone);
1.335 + r=dir8.Open(fs4,dirname1,KEntryAttMaskSupported);
1.336 + test(r==KErrNone);
1.337 +
1.338 + CFileList* list;
1.339 + TOpenFileScan fileScan(TheFs);
1.340 + fileScan.NextL(list);
1.341 +
1.342 + if (gRunByBatch)
1.343 + {
1.344 + test(list!=NULL);
1.345 + test(list->Count()==1);
1.346 + TEntry entry=(*list)[0];
1.347 + test(entry.iName.FindF(_L(".BAT"))>=0);
1.348 + delete list;
1.349 + fileScan.NextL(list);
1.350 + }
1.351 +
1.352 + test(list!=NULL);
1.353 + TInt count=list->Count();
1.354 + test(count==3);
1.355 + TEntry entry=(*list)[0];
1.356 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.357 + entry=(*list)[1];
1.358 + test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
1.359 + entry=(*list)[2];
1.360 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.361 + TThreadId threadId=fileScan.ThreadId();
1.362 + RThread current;
1.363 + TThreadId currentId=current.Id();
1.364 + test(threadId==currentId);
1.365 + delete list;
1.366 +
1.367 + fileScan.NextL(list);
1.368 + test(list==NULL);
1.369 +
1.370 + file1.Close();
1.371 + file2.Close();
1.372 + file3.Close();
1.373 + dir1.Close(); dir2.Close();
1.374 + dir3.Close(); dir4.Close();
1.375 + dir5.Close(); dir6.Close();
1.376 + dir7.Close(); dir8.Close();
1.377 + fs1.Close(); fs2.Close();
1.378 + fs3.Close(); fs4.Close();
1.379 + }
1.380 +
1.381 +LOCAL_C void Test5()
1.382 +//
1.383 +// Test OpenFileScan
1.384 +//
1.385 + {
1.386 +
1.387 + test.Next(_L("Scan for open files - mixed RDirs and RFiles"));
1.388 +
1.389 + RFile file1,file2,file3;
1.390 + TInt r=file1.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
1.391 + test(r==KErrNone);
1.392 + r=file2.Open(TheFs,filename2,EFileRead);
1.393 + test(r==KErrNone);
1.394 + r=file3.Open(TheFs,filename1,EFileRead|EFileShareReadersOnly);
1.395 + test(r==KErrNone);
1.396 +
1.397 + RDir dir1,dir2,dir3,dir4;
1.398 + r=dir1.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.399 + test(r==KErrNone);
1.400 + r=dir2.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.401 + test(r==KErrNone);
1.402 + r=dir3.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.403 + test(r==KErrNone);
1.404 + r=dir4.Open(TheFs,dirname1,KEntryAttMaskSupported);
1.405 + test(r==KErrNone);
1.406 +
1.407 + CFileList* list;
1.408 + TOpenFileScan fileScan(TheFs);
1.409 + fileScan.NextL(list);
1.410 +
1.411 + if (gRunByBatch)
1.412 + {
1.413 + test(list!=NULL);
1.414 + test(list->Count()==1);
1.415 + TEntry entry=(*list)[0];
1.416 + test(entry.iName.FindF(_L(".BAT"))>=0);
1.417 + delete list;
1.418 + fileScan.NextL(list);
1.419 + }
1.420 +
1.421 + test(list!=NULL);
1.422 + TInt count=list->Count();
1.423 + test(count==3);
1.424 + TEntry entry=(*list)[0];
1.425 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.426 + entry=(*list)[1];
1.427 + test(entry.iName.FindF(_L("T_FILE.CPP"))>=0);
1.428 + entry=(*list)[2];
1.429 + test(entry.iName.FindF(_L("T_FSRV.CPP"))>=0);
1.430 + TThreadId threadId=fileScan.ThreadId();
1.431 + RThread current;
1.432 + TThreadId currentId=current.Id();
1.433 + test(threadId==currentId);
1.434 + delete list;
1.435 +
1.436 + fileScan.NextL(list);
1.437 + test(list==NULL);
1.438 +
1.439 + file1.Close();
1.440 + file2.Close();
1.441 + file3.Close();
1.442 + dir1.Close();
1.443 + dir2.Close();
1.444 + dir3.Close();
1.445 + dir4.Close();
1.446 + }
1.447 +
1.448 +
1.449 +NONSHARABLE_STRUCT(TThreadData)
1.450 +//
1.451 +// Encapsulates the data required by the worker thread.
1.452 +//
1.453 + {
1.454 + // Thread identifier for debug output
1.455 + TInt iNumber;
1.456 +
1.457 + // ID of the thread that started the worker thread, and the
1.458 + // worker thread itself
1.459 + TThreadId iMain;
1.460 + TThreadId iWorker;
1.461 +
1.462 + // Request status object of the parent thread, used for signalling
1.463 + TRequestStatus* iStatus;
1.464 +
1.465 + // Name of the file the parent thread requires this thread to open
1.466 + TFileName iFilename;
1.467 +
1.468 + // Number of files opened by the thread;
1.469 + TInt iNumFiles;
1.470 + };
1.471 +
1.472 +
1.473 +LOCAL_C TInt WorkerThread(TAny* aParameter)
1.474 +//
1.475 +// This function is designed to run as a separate thread in order to verify the
1.476 +// fix for DEF062875.
1.477 +//
1.478 +// When the thread is started it opens the file specified in the startup
1.479 +// parameter, signals the main thread and then suspends. Once the main thread
1.480 +// has completed its checking the worker thread is resumed and allowed to run
1.481 +// to completion.
1.482 +//
1.483 +// @param aParameter Thread specific data supplied by the main thread when the
1.484 +// worker thread is started. The data may be accessed by
1.485 +// casting this pointer to a TThreadData*
1.486 +//
1.487 + {
1.488 + // Can't use our global "test" object here
1.489 + RTest myTest(_L("Worker thread"));
1.490 +
1.491 +
1.492 + // Extract the parameters that this thread will need to use
1.493 + TThreadData* threadData = (TThreadData*)aParameter;
1.494 +
1.495 +
1.496 + RThread current;
1.497 + TThreadId currentId = current.Id();
1.498 +
1.499 +
1.500 + myTest.Printf(_L("WORK%d: Worker thread %d started\n"), threadData->iNumber, threadData->iNumber);
1.501 + myTest.Printf(_L("WORK%d: File: %S\n"), threadData->iNumber, &threadData->iFilename);
1.502 + myTest.Printf(_L("WORK%d: Thread: %d\n"), threadData->iNumber, (TUint)currentId);
1.503 + myTest.Printf(_L("WORK%d: Parent: %d\n"), threadData->iNumber, (TUint)threadData->iMain);
1.504 +
1.505 +
1.506 + // Open the file specified by the parameter passed to us from the main
1.507 + // thread
1.508 + RFs myFs;
1.509 + myFs.Connect();
1.510 + RFile file;
1.511 + User::LeaveIfError(file.Open(myFs, threadData->iFilename, EFileRead | EFileShareReadersOnly));
1.512 +
1.513 + // Signal the parent thread to continue then wait
1.514 + myTest.Printf(_L("WORK%d: Signalling parent thread\n"), threadData->iNumber);
1.515 + RThread parent;
1.516 + User::LeaveIfError(parent.Open(threadData->iMain));
1.517 + parent.RequestComplete(threadData->iStatus, KErrNone);
1.518 +
1.519 +
1.520 + myTest.Printf(_L("WORK%d: Waiting for parent thread to restart us\n"), threadData->iNumber);
1.521 + current.Suspend();
1.522 +
1.523 +
1.524 + // Tidy up
1.525 + myTest.Printf(_L("WORK%d: Closing file\n"), threadData->iNumber);
1.526 + file.Close();
1.527 +
1.528 +
1.529 + return KErrNone;
1.530 + }
1.531 +
1.532 +
1.533 +LOCAL_C void TestDEF062875()
1.534 +//
1.535 +// Verify that TOpenFileScan::ThreadId() returns the ID of the thread that
1.536 +// opened the file.
1.537 +//
1.538 +// The object of the exercise here is to create several worker threads, each
1.539 +// one will open a file, signal the main thread and then suspend. Once all
1.540 +// the worker threads have suspended the main thread then uses
1.541 +// TOpenFileScan::NextL() to verify that the thread IDs correspond to the
1.542 +// worker threads that opened each file and not that of the main thread.
1.543 +//
1.544 +// The worker threads are then restarted and allowed to terminate naturally by
1.545 +// running to completion
1.546 +//
1.547 + {
1.548 + test.Start(_L("Test TOpenFileScan::ThreadId()"));
1.549 +
1.550 + const TInt KHeapSize = 32768;
1.551 +
1.552 + RThread thread1;
1.553 + RThread thread2;
1.554 +
1.555 + TRequestStatus status1;
1.556 + TRequestStatus status2;
1.557 +
1.558 + TThreadId id = RThread().Id();
1.559 +
1.560 + TThreadData threadData[3];
1.561 +
1.562 + threadData[0].iNumber = 0;
1.563 + threadData[0].iMain = id;
1.564 + threadData[0].iWorker = id;
1.565 + threadData[0].iStatus = 0;
1.566 + threadData[0].iFilename = filename1;
1.567 + threadData[0].iNumFiles = 2;
1.568 +
1.569 + threadData[1].iNumber = 1;
1.570 + threadData[1].iMain = id;
1.571 + threadData[1].iStatus = &status1;
1.572 + threadData[1].iFilename = filename1;
1.573 + threadData[1].iNumFiles = 1;
1.574 +
1.575 + threadData[2].iNumber = 2;
1.576 + threadData[2].iMain = id;
1.577 + threadData[2].iStatus = &status2;
1.578 + threadData[2].iFilename = filename2;
1.579 + threadData[2].iNumFiles = 1;
1.580 +
1.581 + TInt numThreads = sizeof(threadData)/sizeof(threadData[0]);
1.582 +
1.583 +
1.584 + // Open the files in the MAIN thread.
1.585 + RFile file1;
1.586 + User::LeaveIfError(file1.Open(TheFs, filename1, EFileRead | EFileShareReadersOnly));
1.587 +
1.588 + RFile file2;
1.589 + User::LeaveIfError(file2.Open(TheFs, filename2, EFileRead | EFileShareReadersOnly));
1.590 +
1.591 +
1.592 + // Create the first worker thread
1.593 + test.Printf(_L("MAIN: Creating worker threads\n"));
1.594 + thread1.Create(_L("WorkerThread1"), WorkerThread, KDefaultStackSize, KHeapSize, KHeapSize, &threadData[1]);
1.595 + threadData[1].iWorker = thread1.Id();
1.596 +
1.597 + // Start it and wait for it to suspend
1.598 + thread1.Logon(status1);
1.599 + thread1.Resume();
1.600 + test.Printf(_L("MAIN: Waiting for worker thread 1\n"));
1.601 + User::WaitForRequest(status1);
1.602 +
1.603 +
1.604 + // Create the second worker thread
1.605 + thread2.Create(_L("WorkerThread2"), WorkerThread, KDefaultStackSize, KHeapSize, KHeapSize, &threadData[2]);
1.606 + threadData[2].iWorker = thread2.Id();
1.607 +
1.608 +
1.609 + // Start it and wait for it to suspend
1.610 + thread2.Logon(status2);
1.611 + thread2.Resume();
1.612 + test.Printf(_L("MAIN: Waiting for worker thread 2\n"));
1.613 + User::WaitForRequest(status2);
1.614 +
1.615 +
1.616 + // Obtain a list of open files. At this point we should have a single open
1.617 + // file, as opened by our worker thread. The thread ID reported by
1.618 + // TOpenFileScan should be that of our worker thread rather than the main
1.619 + // thread.
1.620 + test.Printf(_L("MAIN: Verifying thread ID of open file(s)\n"));
1.621 + CFileList* list;
1.622 + TOpenFileScan fileScan(TheFs);
1.623 +
1.624 +
1.625 + TInt count = 0;
1.626 + FOREVER
1.627 + {
1.628 + fileScan.NextL(list);
1.629 +
1.630 +
1.631 + // The NULL list indicates we've run out of sessions.
1.632 + if(!list)
1.633 + {
1.634 + break;
1.635 + }
1.636 +
1.637 +
1.638 + TThreadId threadId=fileScan.ThreadId();
1.639 + TThreadData* data = 0;
1.640 + for (count = 0; count < numThreads; count++)
1.641 + {
1.642 + if (threadId == threadData[count].iWorker)
1.643 + {
1.644 + data = &threadData[count];
1.645 + break;
1.646 + }
1.647 + }
1.648 +
1.649 +
1.650 + if (data)
1.651 + {
1.652 + test.Next(_L("Check number of open files..."));
1.653 + test.Printf(_L("MAIN: Number of open files: %d (expecting %d)\n"), list->Count(), data->iNumFiles);
1.654 + test(list->Count() == threadData[count].iNumFiles);
1.655 +
1.656 +
1.657 + test.Next(_L("Check TThreadIds..."));
1.658 + test.Printf(_L("MAIN: Main thread ID : %d\n"), (TUint)data->iMain);
1.659 + test.Printf(_L("MAIN: Worker thread ID: %d\n"), (TUint)data->iWorker);
1.660 + test.Printf(_L("MAIN: File thread ID : %d\n"), (TUint)threadId);
1.661 +
1.662 +
1.663 + TInt loop = 0;
1.664 + for (loop = 0; loop < list->Count(); loop++)
1.665 + {
1.666 + const TEntry& theEntry = (*list)[loop];
1.667 + test.Printf(_L(" "));
1.668 + test.Printf(theEntry.iName);
1.669 + test.Printf(_L("\n"));
1.670 + }
1.671 + }
1.672 + else
1.673 + {
1.674 + test.Printf(_L("Ignored thread %d\n"), (TUint)threadId);
1.675 + }
1.676 +
1.677 +
1.678 + delete list;
1.679 + list = 0;
1.680 +
1.681 +
1.682 + test.Printf(_L("\n"));
1.683 + }
1.684 +
1.685 +
1.686 + // Signal the two worker threads to tidy up and run to normal termination
1.687 + test.Printf(_L("MAIN: Signalling worker thread 1\n"));
1.688 + thread1.Logon(status1);
1.689 + thread1.Resume();
1.690 + User::WaitForRequest(status1);
1.691 +
1.692 + test.Printf(_L("MAIN: Signalling worker thread 2\n"));
1.693 + thread2.Logon(status2);
1.694 + thread2.Resume();
1.695 + User::WaitForRequest(status2);
1.696 +
1.697 +
1.698 + // Tidy up and finish
1.699 + test.Printf(_L("MAIN: Closing worker thread 1\n"));
1.700 + thread1.Close();
1.701 +
1.702 + test.Printf(_L("MAIN: Closing worker thread 2\n"));
1.703 + thread2.Close();
1.704 +
1.705 + file1.Close();
1.706 + file2.Close();
1.707 +
1.708 + test.End();
1.709 + }
1.710 +
1.711 +
1.712 +GLDEF_C void CallTestsL()
1.713 +//
1.714 +// Call tests that may leave
1.715 +//
1.716 + {
1.717 + filename1[0] = gExeFileName[0];
1.718 + filename2[0] = gExeFileName[0];
1.719 + dirname1[0] = gExeFileName[0];
1.720 + Test0();
1.721 + Test1();
1.722 + Test2();
1.723 + Test3();
1.724 + Test4();
1.725 + Test5();
1.726 +
1.727 + TestDEF062875();
1.728 + }