示例#1
0
LOCAL_C void DoTests()
//
//  multiple threads
//
    {

	TInt r=KErrNone;
	test.Next(_L("Start continuous file Write/Read/Verify operation"));
	RThread t[KMaxNumberThreads];
	TRequestStatus tStat[KMaxNumberThreads];

	TInt i=0;

	TName threadName;
	TRequestStatus kStat=KRequestPending;
	test.Console()->Read(kStat);
	for (i=0;i<KMaxNumberThreads;i++)
		{
		ThreadTestInfo[i].iCycles=0;
		ThreadTestInfo[i].iErrors=0;
		ThreadTestInfo[i].iSizeArrayPos=(i%KMaxSizeArray);
		ThreadTestInfo[i].iErrorInfo=0;
		if (i<(KMaxNumberThreads-1))
			{
			threadName.Format(_L("MakeAndDeleteFiles%d"),i);
	    	r=t[i].Create(threadName,MakeAndDeleteFilesThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)i);
			}
		else
			{
			// Last thread fills/empties disk
			threadName.Format(_L("FillAndEmptyDisk%d"),i);
	    	r=t[i].Create(threadName,FillAndEmptyDiskThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)i);
			}
		if (r!=KErrNone)
   			test.Printf(_L("Error(%d) creating thread(%d)\r\n"),r,i);
	    test(r==KErrNone);
	    t[i].Logon(tStat[i]);
		t[i].Resume();
		}
	CurrentlyFillingDisk=ETrue;
	FillDiskCount=0;

    TInt totalTime = 0;
    TTime cycleTime;
    TTime startTime;
    TTime time;
    startTime.UniversalTime();
    cycleTime.UniversalTime();
    
	TVolumeInfo v;
	r=TheFs.Volume(v,gDriveNumber);
	test(r==KErrNone);
//	TInt initialFreeSpace = I64LOW(v.iFree / 1024);

#ifdef __LIMIT_EXECUTION_TIME__
	RTimer timer;
	timer.CreateLocal();
	TRequestStatus reqStat;
	timer.After(reqStat,60000000); // After 60 secs
#endif

#ifdef REUSE_THREAD
	RTimer displayTimer;
	displayTimer.CreateLocal();
	TRequestStatus displayStat;
	displayTimer.After(displayStat, KNotificationInterval); // after 10 secs
#endif

	TInt ypos=test.Console()->WhereY();
	FOREVER
		{
		User::WaitForAnyRequest();
		if (kStat!=KRequestPending)
			{
			// user requested to end - let threads die
#ifdef REUSE_THREAD				
			gRequestEnd = ETrue;
#endif			
			for (i=0;i<KMaxNumberThreads;i++)
				{
				User::WaitForRequest(tStat[i]);
				}
			break;
			}
#ifdef __LIMIT_EXECUTION_TIME__
		else if (reqStat != KRequestPending)
			{
			// max execution exceeded - wait for threads to die
			TInt totalCycles = 0;
			for (i=0;i<KMaxNumberThreads;i++)
				{
				totalCycles+= ThreadTestInfo[i].iCycles;
				}
			test.Printf(_L("Total cycles = %d\r\n"), totalCycles);
			test.Printf(_L("Waiting for thread death...\r\n"));
			for (i=0;i<KMaxNumberThreads;i++)
				{
				User::WaitForRequest(tStat[i]);
				}
			break;
			}
#endif
		else
			{
			// other notification
			TBool threadFinished=EFalse;
			for (i=0;i<KMaxNumberThreads;i++)
				{
				if (tStat[i]!=KRequestPending && !threadFinished)
					{
					t[i].Close();
					(ThreadTestInfo[i].iCycles)++;
					if (tStat[i]!=KErrNone)
						(ThreadTestInfo[i].iErrors)++;
					threadFinished=ETrue;

					// Launch another thread
					TInt threadNameId=((ThreadTestInfo[i].iCycles)%2)?(i+KMaxNumberThreads):i; // Alternate thread name
					if (i<(KMaxNumberThreads-1))
						{
						threadName.Format(_L("MakeAndDeleteFiles%d"),threadNameId);
	    				r=t[i].Create(threadName,MakeAndDeleteFilesThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)i);
						}
					else
						{
						// Last thread fills/empties disk
						threadName.Format(_L("FillAndEmptyDisk%d"),threadNameId);
	    				r=t[i].Create(threadName,FillAndEmptyDiskThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)i);
						}
					if (r!=KErrNone)
   						test.Printf(_L("Error(%d) creating thread(%d)\r\n"),r,i);
	    			test(r==KErrNone);
	    			t[i].Logon(tStat[i]);
					t[i].Resume();
					}
				test.Console()->SetPos(0,(ypos+i));
   				test.Printf(_L("Thread(%d): % 4d errors in % 4d cycles (%d)\r\n"),i,ThreadTestInfo[i].iErrors,ThreadTestInfo[i].iCycles,ThreadTestInfo[i].iErrorInfo);
				}
				
#ifdef REUSE_THREAD
			if(displayStat != KRequestPending)
				{
				// re-request notification
				displayTimer.After(displayStat, KNotificationInterval);
				}
			else if (!threadFinished)
				{
				test.Printf(_L("Semaphore death"));
				break;
				}
#else 
			if (!threadFinished)
				{
				test.Printf(_L("Semaphore death"));
				break;
				}
#endif					
				
			r=TheFs.Volume(v,gDriveNumber);
			test(r==KErrNone);
			test.Console()->SetPos(0,(ypos+KMaxNumberThreads));
			
			TInt  freeSpace;
			TInt8 freeSpaceUnit;
			TInt  totalSpace;
			TInt8 totalSpaceUnit;
			
			// switch t
			if(v.iFree > KDiskUnitThreshold)
				{
				// display in MB
				freeSpace = I64LOW(v.iFree / (1024 * 1024));
				freeSpaceUnit = 'M';
				}
			else
				{
				// display in KB
				freeSpace = I64LOW(v.iFree/1024);
				freeSpaceUnit = 'K';
				}
			
			if(v.iSize > KDiskUnitThreshold)
				{
				// display in MB
				totalSpace = I64LOW(v.iSize / (1024 * 1024));
				totalSpaceUnit = 'M';
				}
			else
				{
				// display in KB
				totalSpace = I64LOW(v.iSize/1024);
				totalSpaceUnit = 'K';
				}
			
			test.Printf(_L("Free space on disk: %u %cB (of %u %cB)\r\n"), 
						freeSpace, freeSpaceUnit, totalSpace, totalSpaceUnit);

            TTimeIntervalSeconds timeTaken;
            time.UniversalTime();            
            r=time.SecondsFrom(startTime,timeTaken);
            test(r==KErrNone);
            totalTime=timeTaken.Int();

            TInt seconds = totalTime % 60;
            TInt minutes = (totalTime / 60) % 60;
            TInt hours   = (totalTime / 3600) % 24;
            TInt days    = totalTime / (60 * 60 * 24);
            test.Printf(_L("Elapsed Time (%d): %d d %02d:%02d:%02d\r\n"), FillDiskCycle, days, hours, minutes, seconds);
            
            if(CurrentlyFillingDisk)
            	{
            	// work out ETA to full disk
	            r = time.SecondsFrom(cycleTime, timeTaken);
    	        if((r == KErrNone) && (v.iSize > v.iFree))
    	        	{
		            	totalTime = (TInt) ((v.iFree/1024 * (TInt64) timeTaken.Int()) / (v.iSize/1024 - v.iFree/1024));
		    	        seconds = totalTime % 60;
    		    	    minutes = (totalTime / 60) % 60;
        		    	hours   = (totalTime / 3600) % 24;
	            		days    = totalTime / (60 * 60 * 24);
            	
    	        		test.Printf(_L("ETA to full disk: %d d %02d:%02d:%02d\r\n"), days, hours, minutes, seconds);
        	    	}
            	}
            else 
            	{
            	// currently emptying disk, update time metrics
            	cycleTime.UniversalTime();
            	}            	
           	
			}
						
			test.Printf(_L("\n"));
		}
    }
void CSmilTranslatorTestUtils::RunTestL()
	{
	TRequestStatus *s = &iStatus;

	// used to generate a leave if an out of memory error was encountered, specifically
	// during the memory test loop in E32Main().  This is necessary because leaves in
	// the .dll Active Object RunL() functions do not return to this application, so
	// have to be Trapped in the Active objects and translated into an error code.
	TBool memoryError = EFalse;

	switch(iState)
		{
	case KInit:
		{
		// Utility class for file manipulation
		iFileFinder = new TFindFile(iSession);

		TPtrC errorFileName(KErrorFileName);

		// create err dir if doesn't exist - this api ignores the file name (ignores everything after final '/')
		fileSystem.MkDirAll(KErrorFileName);

		// overwrite any existing file of this name
		iErr = iErrorFile.Replace(iSession, errorFileName, EFileWrite | EFileStreamText);

		if(iErr == KErrNone)
			{
			TBuf<1> bom;
			bom.Append(CEditableText::EByteOrderMark);
			iErrorFile.Write(DES_AS_8_BIT(bom));
			// will search multiple directories, but halt after completing current directory
			// if at least one match is made.  Remembers which directories have been searched
			// in order to continue search using .FindWild() function later
			iErr = iFileFinder->FindWildByPath(KWildName, &KInputPathList, iFileList);
			iIndex = 0;
			}

		if(iErr == KErrNone)
			{
			iState = KParseFile;
			}
		else
			{
			iState = KEnd;
			}
		User::RequestComplete(s, KErrNone);
		SetActive();
		}
		break;

	case KParseFile:
		{
		++iFilesProcessed;
		iErr = KErrNone;

		TParse fullEntry;
		fullEntry.Set((*iFileList)[iIndex++].iName,& iFileFinder->File(),NULL);
		iInputFileName = fullEntry.FullName(); // extract individual path + name from list
		SetOutputFileName(); // output name is based on input one

		iOutputMsg = KStartFile;
		iOutputMsg.Append(iInputFileName);		// display full path
		test.Start(iOutputMsg);				// print to console

		// test console automatically places output on a new line, for output
		// to error file we need to add white space ready for next line
		iOutputMsg.Append(KOutputNewLine);
		iErrorFile.Write(DES_AS_8_BIT(iOutputMsg));	// print to error file

		// schedule Parser active object for call to it's RunL function
		if (testConfig->DataMode() == CTestConfig::EBufferData)
			{
			// We're testing the buffering API...
			// Create a data supplier object and pass it in to the parser
			delete iDataSupplier;
			iDataSupplier = NULL;
			iDataSupplier = CTestDataSupplier::NewL(iSession, iInputFileName);
			iParser->ParseSource(iDataSupplier);
			}
		else
			{
			if( iUseFileHandle )
				{
				RFile file;
				User::LeaveIfError(file.Open(iSession, iInputFileName, EFileRead | EFileShareReadersOnly));
			// 	No function declaration of ParseFile() that take RFile Object parameter
			//	iParser->ParseFile(file);
				iParser->ParseFile(iSession, iInputFileName);
				}
			else
				{
				// We're testing the file mode so parse the file.
				iParser->ParseFile(iSession, iInputFileName);
				}
			}

		iState = KCheckResults;
		iStatus = KRequestPending;
		SetActive();
		}
		break;

	case KCheckResults:
		{
		// when execution begins again one parse followed by a compose would have
		// completed for the current file, handle any error messages generated here
		iErr = iParser->Error();
		TInt severity = iParser->ErrorSeverity();
		if(iErr != KErrNone)
			{
			iOutputMsg = KParseError;
			AppendErrorStr(iErr, iOutputMsg);
			AppendSeverityStr(severity, iOutputMsg);
			iOutputMsg.Append(KOutputNewLine);
			
			// IF there are no more errors for this file bung in an
			// extra line to make output more prominent
			if(iComposer->Error() == KErrNone)
				{
				iOutputMsg.Append(KOutputNewLine);
				}
			test.Printf(iOutputMsg);						// print to console
			iErrorFile.Write(DES_AS_8_BIT(iOutputMsg));	// print to error file
			
			if(iErr == KErrNoMemory)
				{
				memoryError = ETrue;
				}
			}

		iErr = iComposer->Error();
		severity = iComposer->ErrorSeverity();
		if(iErr != KErrNone)
			{
			iOutputMsg = KComposeError;
			AppendErrorStr(iErr, iOutputMsg);
			AppendSeverityStr(severity, iOutputMsg);
			iOutputMsg.Append(KOutputNewLine);
			iOutputMsg.Append(KOutputNewLine);								
			test.Printf(iOutputMsg);
			iErrorFile.Write(DES_AS_8_BIT(iOutputMsg));
			
			if(iErr == KErrNoMemory)
				{
				memoryError = ETrue;
				}
			}

		test.End();

		// if the OOM condition occured during Parsing or Composing
		if(memoryError)
			{
			User::Leave(KErrNoMemory);
			}

		iState = KParseFile;

		if(iIndex >= iFileList->Count())
			{
			// fileList must be deleted after each loop prior to being passed
			// back to fileFinder (unnecessary after KErrNotFound)
			delete iFileList;
			iFileList = 0; // Just in case it doesn't get set in the FindWild

			// continue wildcard search for next directory in list
			iErr = iFileFinder->FindWild(iFileList);
			iIndex = 0;
			if(iErr != KErrNone)
				iState = KEnd;
			}

		SetActive();
		User::RequestComplete(s, KErrNone);
		}
		break;

	default:
	case KEnd:
		{
		TTime endTime;
		TTimeIntervalSeconds interval;
		endTime.UniversalTime();
		endTime.SecondsFrom(iStartTime, interval);

		TBuf<100> time;
		_LIT(KComposeTime, "Total time for composing: %d microseconds\n");
		time.Format(KComposeTime, iComposeTime);
		iErrorFile.Write(DES_AS_8_BIT(time));

		_LIT(KTimeTaken, "Total time for tests: %d seconds");
		time.Format(KTimeTaken, interval.Int());
		iErrorFile.Write(DES_AS_8_BIT(time));


		delete iFileFinder;
		delete iDataSupplier;
		CActiveScheduler::Stop();
		}
		break;
		}
	}
示例#3
0
LOCAL_C void DoTests()
//
//  single thread
//
    {

	TInt r=KErrNone;
	test.Next(_L("Start continuous file Write/Read/Verify operation"));
	RThread t[KMaxNumberThreads];
	TRequestStatus tStat[KMaxNumberThreads];

	TInt i=0;

	TName threadName;
	TRequestStatus kStat=KRequestPending;
	test.Console()->Read(kStat);
	ThreadTestInfo[i].iCycles=0;
	ThreadTestInfo[i].iErrors=0;
	ThreadTestInfo[i].iSizeArrayPos=(i%KMaxSizeArray);
	ThreadTestInfo[i].iErrorInfo=0;
	if (i<(KMaxNumberThreads-1))
		{
		threadName.Format(_L("MakeAndDeleteFiles%d"),i);
    	r=t[i].Create(threadName,MakeAndDeleteFilesThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)i);
		}
	else
		{
		// Last thread fills/empties disk
		threadName.Format(_L("FillAndEmptyDisk%d"),i);
    	r=t[i].Create(threadName,FillAndEmptyDiskThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)i);
		}
	if (r!=KErrNone)
		test.Printf(_L("Error(%d) creating thread(%d)\r\n"),r,i);
	test(r==KErrNone);
	t[i].Logon(tStat[i]);
	t[i].Resume();
	CurrentlyFillingDisk=ETrue;
	FillDiskCount=0;

    TInt totalTime=0;
    TTime startTime;
    TTime time;
    startTime.UniversalTime();

	TInt ypos=test.Console()->WhereY();
	FOREVER
		{
		User::WaitForAnyRequest();
		if (kStat!=KRequestPending)
			{
    		t[i].LogonCancel(tStat[i]);
			User::WaitForRequest(tStat[i]);
			break;
			}
		else
			{
			TBool threadFinished=EFalse;
			if (tStat[i]!=KRequestPending && !threadFinished)
				{
				t[i].Close();
				(ThreadTestInfo[i].iCycles)++;
				if (tStat[i]!=KErrNone)
					(ThreadTestInfo[i].iErrors)++;
				threadFinished=ETrue;

				// Launch another thread
				TInt threadNameId=((ThreadTestInfo[i].iCycles)%2)?(i+KMaxNumberThreads):i; // Alternate thread name
				threadName.Format(_L("FillAndEmptyDisk%d"),threadNameId);
   				r=t[i].Create(threadName,FillAndEmptyDiskThread,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)i);
				if (r!=KErrNone)
					test.Printf(_L("Error(%d) creating thread(%d)\r\n"),r,i);
    			test(r==KErrNone);
    			t[i].Logon(tStat[i]);
				t[i].Resume();
				}
				
			test.Console()->SetPos(0,(ypos+i));
			test.Printf(_L("Thread(%d): % 4d errors in % 4d cycles (%d)\r\n"),i,ThreadTestInfo[i].iErrors,ThreadTestInfo[i].iCycles,ThreadTestInfo[i].iErrorInfo);
			if (!threadFinished)
				{
				test.Printf(_L("Semaphore death"));
				break;
				}
			TVolumeInfo v;
			r=TheFs.Volume(v,gDriveNumber);
			test(r==KErrNone);
			test.Console()->SetPos(0,(ypos+KMaxNumberThreads));
			test.Printf(_L("Free space on disk: %u K(of %u K)\r\n"),(v.iFree/1024).Low(),(v.iSize/1024).Low());

            TTimeIntervalSeconds timeTaken;
            time.UniversalTime();
            r=time.SecondsFrom(startTime,timeTaken);
            test(r==KErrNone);
            totalTime=timeTaken.Int();

            TInt seconds = totalTime % 60;
            TInt minutes = (totalTime / 60) % 60;
            TInt hours   = (totalTime / 3600) % 24;
            TInt days    = totalTime / (60 * 60 * 24);
            test.Printf(_L("Elapsed Time: %d d %02d:%02d:%02d\r\n"), days, hours, minutes, seconds);
			}
		}
    }