MsgQueueConnection::EReceiveStatus MsgQueueConnection::Receive() { TRequestStatus dataStatus; GetInQueue().NotifyDataAvailable(dataStatus); TRequestStatus timerStatus; RTimer timer; timer.CreateLocal(); timer.After(timerStatus, 1000000); User::WaitForRequest(dataStatus, timerStatus); if (dataStatus == KRequestPending) { GetInQueue().CancelDataAvailable(); User::WaitForRequest(dataStatus); timer.Close(); return RS_TIME_OUT; } else { timer.Cancel(); User::WaitForRequest(timerStatus); timer.Close(); } if (KErrNone == GetInQueue().Receive(*(reinterpret_cast<message_buf*>(&m_cBuffer)))) { return RS_OK; } else return RS_ERROR; }
// ----------------------------------------------------------------------------- // CContextEnginePluginTest::CreateContextEngine2L // ----------------------------------------------------------------------------- // TInt CContextEnginePluginTest::CreateContextEngine2L( CStifItemParser& /* aItem */ ) { _LIT( KMsg1, "Enter CreateContextEngine" ); iLog->Log( KMsg1 ); RDebug::Print( KMsg1 ); iContextEngine = NULL; iContextEngine = CContextEngine::GetInstanceL(); // 4 seconds TTimeIntervalMicroSeconds32 timeout(4000000); RTimer timer; TRequestStatus status; timer.CreateLocal(); timer.After( status,timeout ); User::WaitForAnyRequest(); timer.Close(); if( !iContextEngine ) { User::Leave( KErrUnknown ); } _LIT( KMsg2, "Exit CreateContextEngine" ); iLog->Log( KMsg2 ); RDebug::Print( KMsg2 ); return KErrNone; }
LOCAL_C TInt SendSerialData(RBusDevComm& aSerial,const TDesC8& aData) { TRequestStatus serStat; TRequestStatus timStat; RTimer timer; TInt error=timer.CreateLocal(); if (!error) { timer.After(timStat,KSerialLogTransmitTimeout); aSerial.Write(serStat,aData); User::WaitForRequest(serStat,timStat); if (timStat.Int()==KErrNone) { aSerial.WriteCancel(); error=KErrTimedOut; } else if (serStat.Int()!=KErrNone) { timer.Cancel(); error=serStat.Int(); } else timer.Cancel(); timer.Close(); } return(error); }
static inline void PhoneClose(RMobilePhone& /*aPhone*/) { if (selectedPhone != -1) { timer.Close(); selectedPhone = -1; } }
void CTestCalInterimApiSuiteStepBase::WaitForAgendaServerShutdown() { // the name of the agenda server process includes its uid like this [10003a5b] _LIT(KAgendaServerUIDMatch, "*[10003a5b]*"); TFindProcess findProcess(KAgendaServerUIDMatch); TFullName fullName; TInt findProcessResult(KErrNone); findProcessResult = findProcess.Next(fullName); if (findProcessResult == KErrNone) { // find the latest agenda server process while (findProcessResult == KErrNone) { findProcessResult = findProcess.Next(fullName); } // The agenda server process is running so wait RProcess process; if (process.Open(fullName) == KErrNone) { TRequestStatus processStatus; process.Logon(processStatus); // ask for a callback when the process ends // Don't wait for the server to close for longer than 7 seconds RTimer timeOutTimer; timeOutTimer.CreateLocal(); TRequestStatus timeOutStatus; timeOutTimer.After(timeOutStatus, 7000000); // Wait for either the agenda server to close // or the time out timer to time out. User::WaitForRequest(processStatus, timeOutStatus); if (timeOutStatus.Int() == KRequestPending) { timeOutTimer.Cancel(); User::WaitForRequest(timeOutStatus); } else { if (timeOutStatus.Int() == KErrNone) { // Agenda server shutdown request has timed out ERR_PRINTF1(KErrAgendaServerShutdownTimedOut); SetTestStepResult(EFail); } } timeOutTimer.Close(); process.LogonCancel(processStatus); process.Close(); } } }
void TestNotify() // // Test Notify by launching a simple notifier. Gets closed // using timer and simulated keypress. // { TInt r; test.Start(_L("Connect to notifier server")); RNotifier n; r = n.Connect(); test(r==KErrNone); TInt button=0; TRequestStatus status; TRequestStatus timerStatus; RTimer timer; timer.CreateLocal(); test.Next(_L("Launching simple notifier")); _LIT(KLine1,"Line1 - Select Button2"); _LIT(KLine2,"Line2 - or press enter"); _LIT(KButton1,"Button1"); _LIT(KButton2,"Button2"); n.Notify(KLine1,KLine2,KButton1,KButton2,button,status); timer.After(timerStatus,KTimeOut); // launch timer for getting control back after timeout User::WaitForRequest(status, timerStatus); if (status==KRequestPending) { test.Printf(_L("Timeout in waiting for keypress, continuing\n")); // make the notifier to disappear TRawEvent eventDown; eventDown.Set(TRawEvent::EKeyDown,EStdKeyEnter); TRawEvent eventUp; eventUp.Set(TRawEvent::EKeyUp,EStdKeyEnter); UserSvr::AddEvent(eventDown); UserSvr::AddEvent(eventUp); User::WaitForRequest(status); // wait again } else { timer.Cancel(); } timer.Close(); test(status.Int()==KErrNone); test.Next(_L("Close connection to notifier server")); n.Close(); test.End(); }
/** Test cancelling asynchronous requests. This function cancels a pending asynchronous receive request. @pre TestLoadDriver(), channel opened */ void TestExDriver::TestCancelRequests() { TInt r; // Cancel Asynchronous Receive Request iTest.Printf(_L("Test Cancelling Asynchronous Receive Request\n")); // Create the iTimer that is relative to the thread r = iTimer.CreateLocal(); iTest(r==KErrNone); // Create a buffer that has to be filled and returned by the driver TBuf8<KTestRxSize> rxBuf; // Request status object for receive. This object will be used to read the // status of asynchronous requests after the notification of request completion // TRequestStatus rxStatus; // Trigger iTimer expiry after KTimeOutTxRx. The status should be pending iTimer.After(iTimeStatus,KTimeOutTxRx); iTest(iTimeStatus==KRequestPending); // Call ldd interface ReceiveData() API to get data to RxBuf r = iLdd.ReceiveData(rxStatus, rxBuf); iTest(r==KErrNone); // Cancel the Receive Request, This invokes a DoCancel() iLdd.CancelReceive(); // Wait till the request is complete on rxStatus. User thread is blocked // with this call, till it is notified about the request completion. // User::WaitForRequest(rxStatus,iTimeStatus); // If receive has occured correctly, the iTimeStatus will not be KErrNone, // else no receive complete has occured and iTimer has expired iTest (iTimeStatus!=KErrNone); // rxStatus holds the request completion. TRequestStatus::Int() returns // the completion code. It should be KErrCancel in case of successful // cancellation of request // r=rxStatus.Int(); iTest(r==KErrCancel); // Cancel the iTimer iTimer.Cancel(); // Close the handle to the iTimer iTimer.Close(); }
/** Test access from a different thread @pre TestLoadDriver() called */ void TestExDriver::TestMultipleThreadAccess() { TInt r; RThread thrd; TRequestStatus tS; _LIT(KTestThreadName,"TestThread"); iTest.Printf(_L("Test multiple thread access\n")); // Create the iTimer that is relative to the thread r = iTimer.CreateLocal(); iTest(r==KErrNone); // Open the channel r=iLdd.Open(KUnit1); iTest(r==KErrNone); // Create a new thread, where we can test access to the driver iTest (thrd.Create(KTestThreadName,&ThreadFunc,KDefaultStackSize,NULL,&iLdd)==KErrNone); // Logon() will request asynchronous notification on thread termination thrd.Logon(tS); // Trigger iTimer expiry after KTimeOut. The status should be pending iTimer.After(iTimeStatus,KTimeOut); iTest(iTimeStatus==KRequestPending); // Resume() schedules the thread created thrd.Resume(); // Wait for the thread termination notification //User::WaitForRequest(tS,iTimeStatus); User::WaitForRequest(tS); // Incase thread is not scheduled and timeout occurs if ((iTimeStatus==KErrNone)) { iTest.Printf(_L("Timeout for TestThread schedule and exit\n")); } // Cancel the timer and close iTimer.Cancel(); iTimer.Close(); // Close the thread created thrd.Close(); // Close the channel opened iLdd.Close(); }
/** Transmits data over the device @pre TestLoadDriver(), channel opened */ void TestExDriver::TestTransmit() { TInt r; // Transmit data to the device (uart) iTest.Printf(_L("Test Transmit Asynchronous Request\n")); // Request status object for transmit. This object will be used to read the // status of asynchronous requests after the notification of request completion // TRequestStatus txStatus; // Create the iTimer that is relative to the thread r = iTimer.CreateLocal(); iTest(r==KErrNone); // Trigger iTimer expiry after KTimeOut. The status should be pending iTimer.After(iTimeStatus,KTimeOutTxRx); iTest(iTimeStatus==KRequestPending); // Call ldd interface TransmitData() API test data descriptor as parameter r = iLdd.TransmitData(txStatus, KTestTxDataMedium); iTest(r==KErrNone); // Wait till the request is complete on txStatus or iTimeStatus. User thread is // blocked with this call, till it is notified about the request completion or // iTimer expiry // User::WaitForRequest(txStatus, iTimeStatus); // if transmit has occured correctly, the iTimeStatus will not be KErrNone, else // no transmit complete has occured and iTimer has expired iTest (iTimeStatus!=KErrNone); // Cancel the iTimer request iTimer.Cancel(); // txStatus holds the request completion. TRequestStatus::Int() returns the // completion code. It will be KErrNone in case of successful completion // r = txStatus.Int(); iTest(r==KErrNone); // Cancel the iTimer request iTimer.Cancel(); // Close the handle to the iTimer iTimer.Close(); }
// Called by the UI framework when a command has been issued. // In this example, a command can originate through a // hot-key press or by selection of a menu item. // The command Ids are defined in the .hrh file // and are 'connected' to the hot-key and menu item in the // resource file. // Note that the EEikCmdExit is defined by the UI // framework and is pulled in by including eikon.hrh // void CExampleAppUi::HandleCommandL(TInt aCommand) { switch (aCommand) { // Just issue simple info messages to show that // the menu items have been selected case EExampleItem0: iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM0); break; case EExampleItem1: iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM1); break; case EExampleItem2: iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ITEM2); break; // Exit the application. The call is // implemented by the UI framework. case EEikCmdExit: TInt timerDuration(KDefaultTimeout); CCommandLineArguments* cmdLine = CCommandLineArguments::NewL(); TInt argTotal=cmdLine->Count(); for (TInt loop=1 ; loop < argTotal ; ++loop) { TPtrC arg(cmdLine->Arg(loop)); if (arg==KSetShutDownTimeOption && loop++ < (argTotal-1)) { TLex timeoutLex(cmdLine->Arg(loop)); timeoutLex.Val(timerDuration); } } delete cmdLine; if(timerDuration > 0) { RTimer timer; TRequestStatus timerStatus; timer.CreateLocal(); timer.After(timerStatus, timerDuration); User::WaitForRequest(timerStatus); timer.Close(); } Exit(); break; } }
/** * Timeout function */ void CTestMmfAclntStep::WaitWithTimeout(TRequestStatus& aStatus, TInt aNumberOfMicroSeconds) { TRequestStatus timerStatus; RTimer timer ; timer.CreateLocal() ; timer.After(timerStatus,aNumberOfMicroSeconds); User::WaitForRequest(aStatus, timerStatus); if (timerStatus == KRequestPending) { timer.Cancel(); User::WaitForRequest(timerStatus); } else { INFO_PRINTF1(_L("Time is over!!!")) ; } timer.Close() ; }
void CRunProc::RunTestL() { TTime theTime; theTime.UniversalTime(); TInt64 randSeed(theTime.Int64()); TInt random(Math::Rand(randSeed) % (1000 * 1000)); User::After(random); RTimer timer; timer.CreateLocal(); TRequestStatus timerStatus = KRequestPending; TTimeIntervalMicroSeconds32 timeout(KTimeOut); timer.After(timerStatus, timeout); TText ch; const TUint8 *bitmap = NULL; TSize bitmapsize; TOpenFontCharMetrics Metrics; do { TInt hitcount = 0; for (ch = 'A'; ch <= 'z'; ch++) { if(iFont->GetCharacterData(iSessionHandle, (TInt)ch, Metrics,bitmap)) { //RDebug::Print(_L("%c hit bitmap[0]=%x"),ch,bitmap[0]); TUint8 testbyte = bitmap[0]; testbyte += testbyte; __ASSERT_ALWAYS((testbyte & 0x01) == 0, User::Panic(KTCacheDeletionProcess, KErrGeneral)); hitcount++; } else { //RDebug::Print(_L("%c missed"),ch); } } __ASSERT_ALWAYS(hitcount > 0, User::Panic(KTCacheDeletionProcess, KErrNotFound)); } while (timerStatus == KRequestPending); timer.Cancel(); timer.Close(); }
// ----------------------------------------------------------------------------- // CContextEnginePluginTest::ActiveWait // ----------------------------------------------------------------------------- // void CContextEnginePluginTest::ActiveWait( TInt aTimeout ) { _LIT( KMsg1, "Enter ActiveWait" ); iLog->Log( KMsg1 ); RDebug::Print( KMsg1 ); TTimeIntervalMicroSeconds32 timeout( aTimeout ); RTimer timer; TRequestStatus status; timer.CreateLocal(); timer.After(status,timeout); User::WaitForAnyRequest(); timer.Close(); _LIT( KMsg2, "Exit ActiveWait" ); iLog->Log( KMsg2 ); RDebug::Print( KMsg2 ); }
enum TVerdict CTS_Delay::doTestStepL(void) { TInt aDelay = 0; RTimer aTimer; aTimer.CreateLocal(); GetIntFromConfig(KDelay, KDelayInMs, aDelay); TTimeIntervalMicroSeconds32 aInterval = aDelay * 1000; TRequestStatus aStatus; aTimer.After(aStatus, aInterval); User::WaitForRequest(aStatus); aTimer.Cancel(); aTimer.Close(); return EPass; }
static void TestFileSeek() // // Benchmark file seek method // { ClearSessionDirectory(); test.Next(_L("RFile::Seek method")); TInt increment=1789; // random number > cluster size TInt count=0; TInt pos=0; // Create test file TBuf8<1024> testdata(1024); RFile f; TInt r=f.Create(TheFs,_L("SEEKTEST"),EFileStream); test_KErrNone(r); count=64; while (count--) f.Write(testdata); TInt fileSize=count*testdata.MaxLength(); pos=0; count=0; RTimer timer; timer.CreateLocal(); TRequestStatus reqStat; timer.After(reqStat,10000000); // After 10 secs while(reqStat==KRequestPending) { TInt dum=(pos+=increment)%fileSize; f.Seek(ESeekStart,dum); count++; } test.Printf(_L("RFile::Seek operations in 10 secs == %d\n"),count); timer.Close(); f.Close(); TheFs.Delete(_L("SEEKTEST")); }
void CPhBkAndPacketTestsTestStepBase::WaitWithTimeout(TRequestStatus& aStatus, TInt aNumberOfMicroSeconds) /** * Timeout function */ { TRequestStatus timerStatus; RTimer timer ; timer.CreateLocal() ; timer.After(timerStatus,aNumberOfMicroSeconds); User::WaitForRequest(aStatus, timerStatus); if (timerStatus == KRequestPending) { timer.Cancel(); User::WaitForRequest(timerStatus); } else { INFO_PRINTF1(_L("Time is over!!!")) ; } timer.Close() ; }
// Member for thread function TInt CSMPSoakThread::DoSMPStressDeviceThread() { RTest test(_L("SMPStressDeviceThread")); test.Start(_L("SMPStressDeviceThread")); RTimer timer; RFs session; TFileName sessionPath; test_KErrNone(timer.CreateLocal()); TRequestStatus s; TDesC** ptrDevices = (TDesC**) (iThreadData.listPtr); PRINT ((_L("Devices Number %d [%s]\n"), ptrDevices[0]->Length(), ptrDevices[0]->Ptr())); for (TInt i = 1; ptrDevices[i] ; i++) PRINT ((_L("LDD%d=%s "),i,ptrDevices[i]->Ptr())); PRINT (_L("\n")); FOREVER { for (TInt i = 0; i < ptrDevices[0]->Length(); i++) { TText driveLetter = (*ptrDevices[0])[i]; PRINT ((_L("Device %c\n"),driveLetter)); test_KErrNone(session.Connect()); sessionPath=(_L("?:\\SESSION_TEST\\")); sessionPath[0]=driveLetter; test_KErrNone(session.SetSessionPath(sessionPath)); TInt driveNumber; test_KErrNone(session.CharToDrive(driveLetter, driveNumber)); TBuf<64> fileSystemName; test_KErrNone(session.FileSystemName(fileSystemName,driveNumber)); PRINT ((_L("File System Name %s\n"),fileSystemName.PtrZ())); TDriveInfo driveInfo; test_KErrNone(session.Drive(driveInfo, driveNumber)); TVolumeInfo volumeInfo; test_KErrNone(session.Volume(volumeInfo, driveNumber)); session.Close(); } for (TInt i = 1; ptrDevices[i] ; i += 2) { RDevice device; TInt r = User::LoadLogicalDevice(*ptrDevices[i]); if (r != KErrNone && r != KErrAlreadyExists) { test.Printf(_L("LDD %S not present\n"), ptrDevices[i]); continue; } test_KErrNone(device.Open(*ptrDevices[i+1])); TBuf8<64> deviceCaps; device.GetCaps(deviceCaps); TVersion deviceVersion; device.QueryVersionSupported(deviceVersion); device.Close(); } SetThreadPriority(); timer.After(s, iThreadData.delayTime*1000); User::WaitForRequest(s); test (s == KErrNone); if (gAbort) break; User::After(gPeriod); } timer.Close(); PRINT((_L("SMPStressDeviceThread MyTimer.Cancel() called\n"))); test.End(); test.Close(); return 0x00; }
TVerdict CSmsCapsSmsIoctlReadFailedSms::doTestStepL() { TInt ret; // // Set TSY to the test case that has read message // #TestSimpleRxL in tsmsprt-config.txt // TInt testNo=6; RProperty testNumberProperty; User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); CleanupClosePushL(testNumberProperty); TRequestStatus status; testNumberProperty.Subscribe(status); User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo)); User::WaitForRequest(status); TEST(status.Int() == KErrNone); TInt testNumberCheck; User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); if (testNo != testNumberCheck) User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&testNumberProperty); // RSocket socket; ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); if(ret!=KErrNone) User::Leave(ret); CleanupClosePushL(socket); TSmsAddr smsaddr; smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny); ret=socket.Bind(smsaddr); if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData)) { TESTL(ret != KErrPermissionDenied); } else { // skip this one CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; } // CSmsBuffer* buffer=CSmsBuffer::NewL(); CSmsMessage* smsMessage=CSmsMessage::NewL(iFs, CSmsPDU::ESmsSubmit,buffer); CleanupStack::PushL(smsMessage); RSmsSocketReadStream readstream(socket); TRequestStatus timerStatus; RTimer timer; timer.CreateLocal(); timer.After(timerStatus, TTimeIntervalMicroSeconds32(20000000)); TPckgBuf<TUint> sbuf; sbuf()=KSockSelectRead; socket.Ioctl(KIOctlSelect, status, &sbuf, KSOLSocket); User::WaitForRequest(timerStatus, status); if(status.Int() != KErrNone) { socket.CancelIoctl(); User::WaitForRequest(status); ret = EFalse; } else { timer.Cancel(); User::WaitForRequest(timerStatus); ret = ETrue; } timer.Close(); if(ret) { TRAP(ret,readstream >> *smsMessage); User::LeaveIfError(ret); socket.Ioctl(KIoctlReadMessageFailed, status, NULL, KSolSmsProv); User::WaitForRequest(status); if(RProcess().HasCapability(ECapabilityReadUserData)) { TEST(status.Int() != KErrPermissionDenied); } else { TEST(status.Int() == KErrPermissionDenied); } } CleanupStack::PopAndDestroy(smsMessage); CleanupStack::PopAndDestroy(&socket); return TestStepResult() ; }
void PowerTests() { test.Next(_L("test PowerDown()")); TInt r = Power::PowerDown(); test (r == KErrNotReady); for (int i = 0; i < 4; ++i) { test.Printf(_L(" %d "), i); // Arm an absolute timer wakeup event after 5 sec TRequestStatus absstatus; RTimer abstimer; r = abstimer.CreateLocal(); test (r == KErrNone); SetAbsoluteTimeout(abstimer, 5000000, absstatus); // 5 sec // Go to standby r = Power::EnableWakeupEvents(EPwStandby); test (r == KErrNone); r = Power::PowerDown(); test (r == KErrNone); User::WaitForRequest(absstatus); abstimer.Close(); } test.Printf(_L(" OK\n")); test.Next(_L("test RequestWakeupEventNotification()")); { TInt r = Power::EnableWakeupEvents(EPwActive); test (r == KErrArgument); // Request wakup event notification and enable wakeup events TRequestStatus status; Power::RequestWakeupEventNotification(status); test(status.Int() == KRequestPending); r = Power::EnableWakeupEvents(EPwStandby); test (r == KErrNone); // Arm an absolute timer wakeup event TRequestStatus absstatus; RTimer abstimer; r = abstimer.CreateLocal(); test (r == KErrNone); SetAbsoluteTimeout(abstimer, 100000, absstatus); // 100ms // Wait for the timer User::WaitForRequest(absstatus); test(absstatus.Int() == KErrNone); // Wakup event has to be already notified test(status.Int() == KErrNone); User::WaitForRequest(status); // collect it // Issue another notification request Power::RequestWakeupEventNotification(status); test(status.Int() == KRequestPending); // Disable wakeup events Power::DisableWakeupEvents(); // Arm another absolute timer wakeup event SetAbsoluteTimeout(abstimer, 100000, absstatus); // 100ms // Wait for the timer User::WaitForRequest(absstatus); test(absstatus.Int() == KErrNone); // Wakeup event has not to be notified test(status.Int() == KRequestPending); // Cancel the notification request Power::CancelWakeupEventNotification(); test(status.Int() == KErrCancel); User::WaitForRequest(status); // collect it // Cancel again just for fun ... Power::CancelWakeupEventNotification(); test(status.Int() == KErrCancel); abstimer.Close(); } }
LOCAL_C TInt testAsyncAccess(TChar dc1, TChar dc2) // // Test one drive against the other. // { TFileOps f1; TFileOps f2; f1.Open(dc1, 1); if (dc1 != dc2) f2.Open(dc2, 2); TInt op1 = 0; TInt op2 = 0; RTimer timer; TRequestStatus tstat; TTime startTime; TTime endTime; TTimeIntervalMicroSeconds timeTaken; timer.CreateLocal(); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { TInt num = f1.Write(); num += f2.Write(); if (num == 0) User::WaitForAnyRequest(); } op1 = f1.End(); op2 = f2.End(); endTime.HomeTime(); timeTaken=endTime.MicroSecondsFrom(startTime); TInt64 dtime = timeTaken.Int64(); TTest::Printf(_L("%c: %8d writes in %6d mS = %8d bytes per second\n"), (TUint)dc1, op1, I64LOW(dtime)/1000, GetSpeed(op1, dtime)); if (dc1 != dc2) TTest::Printf(_L("%c: %8d writes in %6d mS = %8d bytes per second\n"), (TUint)dc2, op2, I64LOW(dtime)/1000, GetSpeed(op2, dtime)); AddStats(gWrStats, MAKE_TINT64(0, op1 + op2) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond), dtime); // now the reads! f1.Reset(); f2.Reset(); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { f1.Read(); f2.Read(); User::WaitForAnyRequest(); } op1 = f1.End(); op2 = f2.End(); endTime.HomeTime(); timeTaken=endTime.MicroSecondsFrom(startTime); dtime = timeTaken.Int64(); TTest::Printf(_L("%c: %8d reads in %6d mS = %8d bytes per second\n"), (TUint)dc1, op1, I64LOW(dtime)/1000, GetSpeed(op1, dtime)); if (dc1 != dc2) TTest::Printf(_L("%c: %8d reads in %6d mS = %8d bytes per second\n"), (TUint)dc2, op2, I64LOW(dtime)/1000, GetSpeed(op2, dtime)); AddStats(gRdStats, MAKE_TINT64(0, op1 + op2) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond), dtime); test.Printf(_L("\n")); test.Printf(_L("average write throughput = %d bytes/sec\n"), GetSpeed(gWrStats)); test.Printf(_L("average read throughput = %d bytes/sec\n"), GetSpeed(gRdStats)); test.Printf(_L("\n")); gWrStats.Init(); gRdStats.Init(); timer.Cancel(); timer.Close(); f1.Close(); f2.Close(); // delay for a second to allow the close to complete before dismounting. User::After(1000000); return KErrNone; }
TInt CAnvltestListener::ThreadFunction(TAny* anArg) { RTimer timer; int loop = FALSE; while (loop != TRUE) { AnvlGlob *anvlglob; CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack CAnvltestListener *listener; #if 0 // create active scehuler for the thread CActiveScheduler *pA = new CActiveScheduler; __ASSERT_ALWAYS( pA != NULL, PanicServer( EMainSchedulerError ) ); CActiveScheduler::Install( pA ); CShutDown* shut_down = NULL; TRAP( r,shut_down = new (ELeave) CShutDown ); if ( r != KErrNone ) return Fault( EStServerCreate ); CActiveScheduler::Add( shut_down ); // activate shutdown object shut_down->Start(); CActiveScheduler::Start(); #endif listener = (CAnvltestListener*)anArg; anvlglob = AnvlCreateGlobalsL(); //anvlglob->printObj = listener->iControl; anvlglob->printObj = listener; CAnvlSockMain *sockMain; sockMain = new (ELeave) CAnvlSockMain; anvlglob->anvl_main_blk = sockMain; sockMain->InitL(); loop = mntcpapp_main(0,listener->ipVersion); sockMain->Close(); AnvlDeleteGlobals(); delete cleanup; TRequestStatus delayStatus; timer.CreateLocal(); timer.After(delayStatus,60000000); User::WaitForRequest(delayStatus); timer.Close(); } return( KErrNone ); };
/** * Function called after the CActivePanConn completes and the IAP has started. */ void CPanConnections::IapStarted() { TInt rerr; if (!iIapLoading) { } iIapLoading = EFalse; iIapStarted = ETrue; // Open TCP socket with interface to existing RConnection if (iUseTcpTransport) { rerr = iSocket.Open(iSockSvr, KAfInet, KSockStream, KProtocolInetTcp, iConnection); } else { // User wants a UDP socket rerr = iSocket.Open(iSockSvr, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection); } if (rerr != KErrNone) { return; } // Start TCP connection sequence if (iListening && iUseTcpTransport) { TcpIpBindAndListen(); AcceptNewSocket(); } // If we are a UDP socket then bind, a wait is required if (!iUseTcpTransport) { TInt duration; if (iLocalRole == KPanGnUUID) { duration = 4000000; } else { duration = 6000000; } RTimer timer; TRequestStatus status; timer.CreateLocal(); timer.After(status, duration); User::WaitForRequest(status); timer.Close(); rerr = UdpBind(); if (iLocalRole == KPanGnUUID) { ReceiveRemoteName(); } else { TPckgBuf<TInt> buff = 1; TRequestStatus status; TInetAddr addr(KDealerIpAddr,KGenericPort); iSocket.SendTo(buff, addr, 0, status); User::WaitForRequest(status); iConsole.Printf(_L("\nJoined the PAN, press ENTER to continue...")); } } }
LOCAL_C TInt testAsyncAccess(TAny* aData) // /// Test read file handling. /// /// @param aData pointer to the thread data area { TThreadData& data = *(TThreadData*)aData; TFileName fileName = data.iFile; TBool dowrite = (data.iData != NULL); TBuf8<KBufLen>* buffer = gBufferArr[data.iNum]; TRequestStatus* status = gStatusArr[data.iNum]; RFs myFs; TInt r = myFs.Connect(); TEST(r==KErrNone); r = myFs.SetSessionPath(gSessionPath); if (r != KErrNone) TTest::Fail(HERE, _L("SetSessionPath returned %d"), r); TVolumeInfo vol; TInt drv; r = myFs.CharToDrive(fileName[0], drv); if (r != KErrNone) TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), fileName[0], r); r = myFs.Volume(vol, drv); if (r != KErrNone) TTest::Fail(HERE, _L("Volume() returned %d"), r); TInt64 maxwrite = vol.iFree / 2 - KBufLen; if (maxwrite < KBufLen*2) TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"), TInt(vol.iFree/1024)); RFile f; RTimer timer; TRequestStatus tstat; TTime startTime; TTime endTime; TTimeIntervalMicroSeconds timeTaken; TInt wrnum = 0; TInt rdnum = 0; TInt opnum = 0; TInt opfin = 0; TInt i; timer.CreateLocal(); if (dowrite) { r = f.Replace(myFs, fileName, EFileStreamText | EFileWrite); TEST(r==KErrNone); // wait for both tasks to have a chance to complete opening the files User::After(1000); for (i = 0; i < KNumBuf; i++) buffer[i].Fill('_', KBufLen); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { TInt pos = TInt((wrnum * KBufLen) % maxwrite); TInt bnum = opnum++ % KNumBuf; f.Write(pos, buffer[bnum], status[bnum]); if (opnum - opfin > KMaxLag) { while (status[opfin % KNumBuf] == KRequestPending) User::WaitForRequest(status[opfin % KNumBuf]); opfin++; } ++wrnum; } while (opfin < opnum) { while (status[opfin % KNumBuf] == KRequestPending) User::WaitForRequest(status[opfin % KNumBuf]); opfin++; } endTime.HomeTime(); TTimeIntervalMicroSeconds timeTaken=endTime.MicroSecondsFrom(startTime); TInt64 dtime = timeTaken.Int64(); TInt64 dsize = wrnum * KBufLen * TInt64(KSecond); TInt32 speed = TInt32((dsize + dtime/2) / dtime); AddStats(gWrStats, dsize, dtime); TTest::Printf(_L("%8d writes in %6d mS = %8d bytes per second\n"), wrnum, TInt32(dtime)/1000, speed); } else { r = f.Open(myFs, fileName, EFileStreamText); TEST(r==KErrNone); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { TInt pos = TInt((rdnum * KBufLen) % maxwrite); TInt bnum = opnum++ % KNumBuf; f.Read(pos, buffer[bnum], status[bnum]); if (opnum - opfin > KMaxLag) { User::WaitForRequest(status[opfin++ % KNumBuf]); } ++rdnum; } while (opfin < opnum) { if (status[opfin % KNumBuf] == KRequestPending) User::WaitForRequest(status[opfin % KNumBuf]); opfin++; } endTime.HomeTime(); timeTaken=endTime.MicroSecondsFrom(startTime); TInt64 dtime = timeTaken.Int64(); TInt64 dsize = rdnum * KBufLen * TInt64(KSecond); TInt32 speed = TInt32((dsize + dtime/2) / dtime); AddStats(gRdStats, dsize, dtime); // wait to allow the dust to settle User::After(KSecond); TTest::Printf(_L("%8d reads in %6d mS = %8d bytes per second\n"), rdnum, TInt32(dtime)/1000, speed); myFs.Delete(fileName); } timer.Cancel(); timer.Close(); f.Close(); myFs.Close(); return r; }
static void DoTestFileRead(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aReRead = EFalse) // // Do Read Test // { // Create test data // test.Printf(_L("Creating test file...")); TInt writeBlockLen = aFileSize > DataBuf.MaxSize() ? DataBuf.MaxSize() : aFileSize; DataBuf.SetLength(writeBlockLen); #if defined(_DEBUG) for (TInt m = 0; m < DataBuf.Length(); m++) DataBuf[m] = TText8(m % 256); #endif // To allow this test to run on a non-preq914 branch : enum {EFileWriteDirectIO = 0x00001000}; TInt r = File.Create(TheFs, _L("READTEST"), EFileStream | EFileWriteDirectIO); test_KErrNone(r); TInt count = aFileSize / DataBuf.Length(); while (count--) File.Write(DataBuf); // test.Printf(_L("done\n")); File.Close(); enum {EFileReadBuffered = 0x00002000, EFileReadDirectIO = 0x00004000}; r = File.Open(TheFs, _L("READTEST"), EFileStream | (gReadCachingOn ? EFileReadBuffered : EFileReadDirectIO)); test_KErrNone(r); // const TInt maxReadCount = aFileSize / aBlockSize; TUint functionCalls = 0; #if defined SYMBIAN_TEST_COPY // To allow this test to run on a non-preq914 branch : enum {EFileWriteDirectIO = 0x00001000}; TInt r = File2.Replace(TheFs, _L("WRITETEST"), EFileStream | EFileWriteDirectIO); test_KErrNone(r); #endif TTime startTime(0); TTime endTime(0); // we stop after the entire file has been read or after 10 seconds, whichever happens sooner RTimer timer; timer.CreateLocal(); TRequestStatus reqStat; TUint initTicks = 0; TUint finalTicks = 0; // if aReRead file is set, then read file twice for (TInt n=0; n<(aReRead?2:1); n++) { functionCalls = 0; const TInt readLen = (aReRead && n == 0) ? writeBlockLen : aBlockSize; const TInt maxReadCount = aFileSize / readLen; TInt pos = 0; File.Seek(ESeekStart, pos); timer.After(reqStat, 10000000); // After 10 secs startTime.HomeTime(); initTicks = User::FastCounter(); for (TInt i = 0; i<maxReadCount && reqStat==KRequestPending; i++) { // test.Printf(_L("Read %d\n"),i); // for (TInt a = 0; a < 512; a++) // test.Printf(_L("%d"),DataBuf[a]); TInt r = File.Read(DataBuf, readLen); test_KErrNone(r); if (DataBuf.Length() == 0) break; #if defined SYMBIAN_TEST_COPY r = File2.Write(DataBuf, readLen); test_KErrNone(r); #endif functionCalls++; #if defined(_DEBUG) // for (TInt a = 0; a < 512; a++) // test.Printf(_L("%d"),DataBuf[a]); for (TInt j = 0; j < DataBuf.Size(); j++) test(DataBuf[j] == (j + i * readLen) % 256); #endif } finalTicks = User::FastCounter(); endTime.HomeTime(); timer.Cancel(); } TInt dataTransferred = functionCalls * aBlockSize; // TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime); TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ; TReal transferRate = TReal32(dataTransferred) / TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"), dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64()); timer.Close(); #if defined SYMBIAN_TEST_COPY File2.Close(); #endif File.Close(); r = TheFs.Delete(_L("READTEST")); test_KErrNone(r); return; }
static void DoTestFileReadCPU(TInt aBlockSize) // // Benchmark CPU utilisation for Read method // // Read operations are performed for 10 seconds whilst a second thread executes floating point calculations // The higher the number of calculations the less amount of CPU time has been used by the Read method. // { enum {EFileReadBuffered = 0x00002000, EFileReadDirectIO = 0x00004000}; TInt r = File.Open(TheFs, _L("READCPUTEST"), EFileStream | (gReadCachingOn ? EFileReadBuffered : EFileReadDirectIO)); test_KErrNone(r); TInt pos = 0; TUint functionCalls = 0; TUint fltPntCalls = 0; RThread fltPntThrd; TBuf<6> buf = _L("Floaty"); fltPntThrd.Create(buf, FloatingPointLoop, KDefaultStackSize, KHeapSize, KHeapSize, (TAny*) &fltPntCalls); RTimer timer; timer.CreateLocal(); TRequestStatus reqStat; TUint initTicks = 0; TUint finalTicks = 0; timer.After(reqStat, KFloatingPointTestTime); // After 10 secs initTicks = User::FastCounter(); // up the priority of this thread so that we only run the floating point thread when this thread is idle RThread thisThread; thisThread.SetPriority(EPriorityMuchMore); TRequestStatus req; fltPntThrd.Logon(req); fltPntThrd.Resume(); for (TInt i = 0; reqStat==KRequestPending; i++) { TInt r = File.Read(pos, DataBuf, aBlockSize); test_KErrNone(r); pos += aBlockSize; if (pos > KMaxFileSize-aBlockSize) pos = 0; functionCalls++; } TUint fltPntCallsFinal = fltPntCalls; fltPntThrd.Kill(KErrNone); finalTicks = User::FastCounter(); fltPntThrd.Close(); User::WaitForRequest(req); TInt dataTransferred = functionCalls * aBlockSize; TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ; TReal transferRate = TReal32(dataTransferred) / TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s; %d Flt Calcs\n"), dataTransferred, aBlockSize, transferRate, fltPntCallsFinal); timer.Close(); File.Close(); return; }
/* ??? LOCAL_C void PrintBuf(TDes8 &aBuf) // // Print the contents of a buffer // { TInt len=aBuf.Length(); for (TInt i=0;i<=len/8;i++) { test.Printf(_L("%4d: "),i*8); for (TInt j=0;j<8;j++) { if ((i*8)+j>=len) break; TInt v=aBuf[(i*8)+j]; test.Printf(_L("%02x "),v); } test.Printf(_L("\n\r")); } } */ LOCAL_C void testLoopBack(TLineRate aLineRate,TBps aBaudRate) // // Perform an analogue loopback test at the specified linerate // { TInt err; TBuf<64> b; TPtrC bd=BaudRateInText(aBaudRate); b.Format(_L("Loopback test(%S)"),&bd); test.Start(b); TBuf8<KBlockSize> txBuf; theSerialPort->ResetBuffers(); txBuf.Format(_L8("AT&F+MS=%d,0,%d,%d\\N0&K3&D2M0\r"),LineModeData[aLineRate],LineRateData[aLineRate],LineRateData[aLineRate]); test(theSerialPort->WriteS(txBuf)==KErrNone); TBuf8<KBlockSize> rxBuf; User::After(2000000); // 2Secs err=theSerialPort->QueryReceiveBuffer(); test(err>0); rxBuf.SetLength(err); TRequestStatus rxStat; theSerialPort->ReadOneOrMore(rxStat,rxBuf); User::WaitForRequest(rxStat); // test.Printf(_L(" Rx(%d):"),rxStat); // ??? test(rxStat==KErrNone); txBuf.Append(_L("\r\nOK\r\n")); err=rxBuf.Compare(txBuf); // test(TranslateCrLf(rxBuf)==KErrNone); // ??? // test.Printf(_L(" %S\r\n"),&rxBuf); // ??? test(err==0); test.Next(_L("Get loopback")); txBuf.Format(_L8("AT&T1\r")); test(theSerialPort->WriteS(txBuf)==KErrNone); User::After(5000000); // 5Secs err=theSerialPort->QueryReceiveBuffer(); test(err>0); rxBuf.SetLength(err); theSerialPort->ReadOneOrMore(rxStat,rxBuf); User::WaitForRequest(rxStat); test.Printf(_L(" Rx(%d):"),rxStat); test(rxStat==KErrNone); txBuf.AppendFormat(_L8("\r\nCONNECT %d\r\n"),LineConnectData[aLineRate]); err=rxBuf.Compare(txBuf); test(TranslateCrLf(rxBuf)==KErrNone); test.Printf(_L(" %S\r\n"),&rxBuf); // Print what we got back (without CR/LF etc). // Sometimes get extra character as modem goes on-line so just look for command echo + connect test(err>=0); User::After(2000000); // 2Secs TInt totalBlocksToTransfer; if (aBaudRate<EBps1200||aLineRate<EV22_1200) totalBlocksToTransfer=KBlocksShort; else if (aBaudRate<EBps4800||aLineRate<EV32_4800) totalBlocksToTransfer=KBlocksMedium; else if (aLineRate<EV34_28800) totalBlocksToTransfer=KBlocksLong; else totalBlocksToTransfer=KBlocksVeryLong; b.Format(_L("Transfering data(%dK)"),(totalBlocksToTransfer*KBlockSize)/1024); test.Next(b); TInt loopBackFail=KErrGeneral; TRequestStatus txStat; txBuf.SetLength(KBlockSize); TInt i; for (i=0; i<KBlockSize; i++) txBuf[i]=(TUint8)i; theSerialPort->Write(txStat,txBuf,KBlockSize); TInt txBlks=(totalBlocksToTransfer-1); rxBuf.Fill(0,KBlockSize); theSerialPort->Read(rxStat,rxBuf,KBlockSize); TInt rxBlks=0; TRequestStatus tStat; RTimer tim; test(tim.CreateLocal()==KErrNone); tim.After(tStat,40000000); // 40Secs test.Printf(_L(">")); FOREVER { User::WaitForAnyRequest(); if (tStat!=KRequestPending) { // test.Printf(_L("t")); // Timed out theSerialPort->ReadCancel(); // Cancel serial read User::WaitForRequest(rxStat); if (txBlks>0) { theSerialPort->WriteCancel(); // Cancel serial write User::WaitForRequest(txStat); } loopBackFail=KErrTimedOut; // Test failed break; } else if (rxStat!=KRequestPending) { // test.Printf(_L("r")); // Serial rx request complete if (rxStat!=0) { loopBackFail=rxStat.Int(); // Test failed goto endSerial; } for (i=0; i<KBlockSize; i++) { if (rxBuf[i]!=i) { loopBackFail=KErrCorrupt; // Test failed rxBuf[KBlockSize-1]=0; // PrintBuf(rxBuf); // ??? // goto endSerial; // !!!Ignore compare fails for now!!! } } test.Printf(_L("<")); if (++rxBlks<totalBlocksToTransfer) { rxBuf.Fill(0,KBlockSize); theSerialPort->Read(rxStat,rxBuf,KBlockSize); } else { loopBackFail=KErrNone; endSerial: tim.Cancel(); // Cancel timer request. User::WaitForRequest(tStat); if (txBlks>0) { theSerialPort->WriteCancel(); // Cancel serial write User::WaitForRequest(txStat); } break; } } else if (txStat!=KRequestPending) { // test.Printf(_L("s")); // Serial tx request complete if (txBlks>0) { theSerialPort->Write(txStat,txBuf,KBlockSize); test.Printf(_L(">")); txBlks--; } } else { // test.Printf(_L("?")); // Stray signal - cancel everything theSerialPort->ReadCancel(); // Cancel serial read User::WaitForRequest(rxStat); tim.Cancel(); // Cancel timer request. User::WaitForRequest(tStat); if (txBlks>0) { theSerialPort->WriteCancel(); // Cancel serial write User::WaitForRequest(txStat); } loopBackFail=KErrDied; break; } } test.Printf(_L(" (%d)\r\n"),loopBackFail); // !!! At this point RTS may or may not be asserted following the write cancel. The // following seems necessary to make sure RTS is asserted so any remaining Rx data // can be received.and thrown away User::After(2000000); theSerialPort->ResetBuffers(); User::After(1000000); // Wait 1Secs for any remaining Rx data tim.Close(); test.Next(_L("Disconnect")); theSerialPort->ResetBuffers(); // Through away any remaining Rx data. txBuf.Format(_L8("+++")); test(theSerialPort->WriteS(txBuf)==KErrNone); User::After(2000000); // 2Secs err=theSerialPort->QueryReceiveBuffer(); test(err>0); rxBuf.SetLength(err); theSerialPort->ReadOneOrMore(rxStat,rxBuf); User::WaitForRequest(rxStat); test(rxStat==KErrNone); txBuf.Append(_L("\r\nOK\r\n")); err=rxBuf.Compare(txBuf); // test(TranslateCrLf(rxBuf)==KErrNone); // ??? // test.Printf(_L(" %S\r\n"),&rxBuf); // ??? test(err==0); txBuf.Format(_L8("ATH0\r")); test(theSerialPort->WriteS(txBuf)==KErrNone); User::After(4000000); // 4Secs err=theSerialPort->QueryReceiveBuffer(); test(err>0); rxBuf.SetLength(err); theSerialPort->ReadOneOrMore(rxStat,rxBuf); User::WaitForRequest(rxStat); test(rxStat==KErrNone); txBuf.Append(_L("\r\nOK\r\n")); err=rxBuf.Compare(txBuf); // test(TranslateCrLf(rxBuf)==KErrNone); // ??? // test.Printf(_L(" %S\r\n"),&rxBuf); // ??? test(err==0); test.Next(_L("Check result")); test(loopBackFail==KErrNone || loopBackFail==KErrCorrupt); // !!!Ignore compare fails for now!!! // test(loopBackFail==KErrNone); test.End(); }
static void DoTestFileWrite(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aUpdate = EFalse) // // Do Write benchmark // { DataBuf.SetLength(aBlockSize); const TInt maxWriteCount = aFileSize / aBlockSize; TFileName testDir(_L("?:\\F32-TST\\")); testDir[0] = (TText) gDriveToTest; TInt r = TheFs.MkDir(testDir); test_Value(r, r == KErrNone || r == KErrAlreadyExists); TFileName fileName; r = File.Temp(TheFs, testDir, fileName, EFileWrite | (gFileSequentialModeOn ? EFileSequential : 0) | (gWriteCachingOn ? EFileWriteBuffered : EFileWriteDirectIO)); test_KErrNone(r); if (aUpdate) { TInt r = File.SetSize(aFileSize); test_KErrNone(r); } TUint functionCalls = 0; TTime startTime; TTime endTime; TUint initTicks = 0; TUint finalTicks = 0; // we stop after the entire file has been written or after 10 seconds, whichever happens sooner RTimer timer; timer.CreateLocal(); TRequestStatus reqStat; TInt pos = 0; File.Seek(ESeekStart, pos); timer.After(reqStat, 10000000); // After 10 secs startTime.HomeTime(); initTicks = User::FastCounter(); for (TInt i = 0 ; i<maxWriteCount && reqStat==KRequestPending; i++) { File.Write(pos, DataBuf, aBlockSize); pos += aBlockSize; if (pos > KMaxFileSize-aBlockSize) pos = 0; functionCalls++; } if (gFlushAfterWrite) { r = File.Flush(); test_KErrNone(r) } // write file once only finalTicks = User::FastCounter(); endTime.HomeTime(); // TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime); TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ; TInt dataTransferred = functionCalls * aBlockSize; TReal transferRate = TReal32(dataTransferred) / TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"), dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64()); timer.Close(); File.Close(); r = TheFs.Delete(fileName); test_KErrNone(r) return; }
static void DoTestFileWriteCPU(TInt aBlockSize) // // Benchmark CPU utilisation for Write method // // Write operations are performed for 10 seconds whilst a second thread executes floating point calculations // The higher the number of calculations the less amount of CPU time has been used by the Write method. // { DataBuf.SetLength(aBlockSize); TFileName testDir(_L("?:\\F32-TST\\")); testDir[0] = (TText) gDriveToTest; TInt r = TheFs.MkDir(testDir); test_Value(r, r == KErrNone || r == KErrAlreadyExists); TFileName fileName; r = File.Temp(TheFs, testDir, fileName, EFileWrite | (gFileSequentialModeOn ? EFileSequential : 0) | (gWriteCachingOn ? EFileWriteBuffered : EFileWriteDirectIO)); test_KErrNone(r); TUint functionCalls = 0; TUint fltPntCalls = 0; RThread fltPntThrd; TBuf<6> buf = _L("Floaty"); fltPntThrd.Create(buf, FloatingPointLoop, KDefaultStackSize, KHeapSize, KHeapSize, (TAny*) &fltPntCalls); TUint initTicks = 0; TUint finalTicks = 0; // up the priority of this thread so that we only run the floating point thread when this thread is idle RThread thisThread; thisThread.SetPriority(EPriorityMuchMore); TRequestStatus req; fltPntThrd.Logon(req); RTimer timer; timer.CreateLocal(); TRequestStatus reqStat; TInt pos = 0; File.Seek(ESeekStart, pos); timer.After(reqStat, KFloatingPointTestTime); initTicks = User::FastCounter(); fltPntThrd.Resume(); for (TInt i = 0 ; reqStat==KRequestPending; i++) { File.Write(DataBuf, aBlockSize); functionCalls++; } TUint fltPntCallsFinal = fltPntCalls; fltPntThrd.Kill(KErrNone); finalTicks = User::FastCounter(); fltPntThrd.Close(); User::WaitForRequest(req); TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ; TInt dataTransferred = functionCalls * aBlockSize; TReal transferRate = TReal32(dataTransferred) / TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s; %d Flt Calcs\n"), dataTransferred, aBlockSize, transferRate, fltPntCallsFinal); timer.Close(); File.Close(); r = TheFs.Delete(fileName); test_KErrNone(r) return; }
TInt CNcmCommunicationInterface::WriteInterruptData(TInt aEndPoint, TDesC8& aDes, TInt aLength) { OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_ENTRY, this ); TInt ret; RTimer timer; ret = timer.CreateLocal(); if ( ret ) { OstTrace1( TRACE_FATAL, CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA, "\ttimer.CreateLocal = %d- returning", ret); OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT, this ); return ret; } TRequestStatus status; TRequestStatus timerStatus; TEndpointBuffer epBuffer; ret = iPort.OpenEndpoint(epBuffer, aEndPoint); if (ret != KErrNone) { timer.Close(); OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP1, this ); return ret; } TAny *buf; TUint size; ret = epBuffer.GetInBufferRange(buf, size); if (ret != KErrNone) { timer.Close(); OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP2, this ); return ret; } else if (size < aLength) { timer.Close(); OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP3, this ); return KErrArgument; } TPtr8 writeBuf((TUint8 *)buf, size); writeBuf.Copy(aDes.Ptr(), aLength); ret = epBuffer.WriteBuffer(buf, writeBuf.Size(), ETrue, status); if (ret != KErrNone) { timer.Close(); OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP4, this ); return ret; } const TInt KWriteDataTimeout = 1000000; timer.After(timerStatus, KWriteDataTimeout); User::WaitForRequest(status, timerStatus); if ( timerStatus != KRequestPending ) { // Timeout occurred, silently ignore error condition. // Assuming that the line has been disconnected OstTrace0( TRACE_ERROR, CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA1, "CNcmCommunicationInterface::WriteInterruptData() - Timeout occurred"); iPort.WriteCancel(epBuffer.BufferNumber()); User::WaitForRequest(status); ret = timerStatus.Int(); } else { OstTrace0( TRACE_ERROR, CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA2, "CNcmCommunicationInterface::WriteInterruptData() - Write completed"); timer.Cancel(); User::WaitForRequest(timerStatus); ret = status.Int(); } epBuffer.Close(); timer.Close(); OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP5, this ); return ret; }
virtual ~CTwoPhaser() { delete iOnePhaser; // just destroy anything we point to iTimer.Close(); // close timer }