void FragmentMemoryFunc() { ChunkCommitEnd = 0; TInt r; while(KErrNone == (r = Chunk.Commit(ChunkCommitEnd,PageSize)) && !FragThreadStop) { ChunkCommitEnd += PageSize; } if (FragThreadStop) return; test_Equal(KErrNoMemory, r); TUint freeBlocks = 0; for ( TUint offset = 0; (offset + FragData.iSize) < ChunkCommitEnd; offset += FragData.iFrequency, freeBlocks++) { test_KErrNone(Chunk.Decommit(offset, FragData.iSize)); } if (FragData.iDiscard && CacheSizeAdjustable && !FragThreadStop) { TUint minCacheSize = FreeRam(); TUint maxCacheSize = minCacheSize; DPTest::SetCacheSize(minCacheSize, maxCacheSize); if (OrigMinCacheSize <= maxCacheSize) DPTest::SetCacheSize(OrigMinCacheSize, maxCacheSize); } }
// ----------------------------------------------------------------------------- // TMSCallSession::HandleDataXferBufferGetHndlCallL // // ----------------------------------------------------------------------------- // void TMSCallSession::HandleDataXferBufferGetHndlCallL( const RMessage2& aMessage) { TRACE_PRN_FN_ENT; gint status(TMS_RESULT_DOES_NOT_EXIST); RChunk chunk; if (iCallAdpt &&(iActiveCallType == TMS_CALL_IP)) { TMSCliSrvDataXferChunkHndlDataStructBufPckg pckg; aMessage.ReadL(0, pckg); status = static_cast<TMSCallIPAdpt*>(iCallAdpt)->GetDataXferBufferHndl( pckg().CallType, pckg().StreamType, pckg().StreamId, pckg().Key, chunk); } if (status == TMS_RESULT_SUCCESS && chunk.Handle() > 0) { aMessage.Complete(chunk); } else { // TODO: make sure error code is negative or zero aMessage.Complete(0); } TRACE_PRN_FN_EXT; }
TInt CreateChunkAt(TUint32 addr,TInt minsize, TInt maxsize ) { TInt err = g_code_chunk->CreateLocalCode( minsize, maxsize ); if( err ) return err; if ((TUint32)g_code_chunk->Base() != addr) { TUint offset = (TInt)g_code_chunk->Base(); offset = addr-offset; g_code_chunk->Close(); RChunk temp; if( offset > 0x7FFFFFFF ) { //shit, offset too big :( return KErrNoMemory; } TInt chunkoffset = (TInt) offset; err = temp.CreateLocal(0,chunkoffset); if( err ) { temp.Close(); return err; } err = g_code_chunk->CreateLocalCode(minsize,maxsize); temp.Close(); } return err; }
GLDEF_C TInt E32Main() { test.Title(); test.Start(_L("Create chunk")); RChunk c; TInt r=c.CreateDisconnectedLocal(0,0x1000,0x100000); test(r==KErrNone); r=c.Commit(0x10000,0x1000); test(r==KErrNone); TUint8* pBuf1=c.Base(); TUint8* pBuf2=pBuf1+0x10000; TInt s; TInt d; TInt l; for (l=1; l<300; l+=3) { for (s=0; s<=4096-l; s+=227) { test.Printf(_L("\ns=%4d l=%4d: "),s,l); for (d=0; d<=4096-l; d+=229) { DoTest(pBuf1,pBuf2,4096,s,d,l,0); DoTest(pBuf1,pBuf2,4096,s,d,l,1); } } } for (l=1; l<300; l+=3) { for (s=4096-l; s>=0; s-=227) { test.Printf(_L("\ns=%4d l=%4d: "),s,l); for (d=4096-l; d>=0; d-=229) { DoTest(pBuf1,pBuf2,4096,s,d,l,0); DoTest(pBuf1,pBuf2,4096,s,d,l,1); } } } for (l=1; l<400; l+=((l<=64)?1:3) ) { test.Printf(_L("\nOverlap test: l=%4d: "),l); for (s=32; s<=4096-32-l; s+=101) // want s to take all values 0...31 modulo 32 { for (d=s-32; d<=s+32; ++d) { DoOverlapTest(pBuf1,pBuf2,4096,s,d,l); } } } c.Close(); test.End(); return 0; }
// ----------------------------------------------------------------------------- // CLibxml2Tester::TestSetInputFileL // test setting input file // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::TestSetInputFileInfosetL(CStifItemParser& aItem) { TPtrC pType; aItem.GetNextString(pType); TPtrC pDoc; aItem.GetNextString(pDoc); TPtrC pOut; aItem.GetNextString(pOut); iDoc = parser.ParseFileL(pDoc); TBufC<100> chunkName(_L("ChunkContainer") ); TInt size = 2000; TInt maxSize = 10000; TInt offset = 0; TInt binarySize = CID_1().Length(); // TBool isReadOnly = EFalse; RChunk chunk; chunk.CreateGlobal(chunkName, size, maxSize); CleanupClosePushL(chunk); TBuf8<32> contbuff = _L8("binary container some data..."); RFs aRFs; aRFs.Connect(); CleanupClosePushL( aRFs ); RFile fp; User::LeaveIfError( fp.Open(aRFs, _L("c:\\testing\\data\\xmleng\\efute\\input\\containers\\petit.jpg"), EFileRead) ); CleanupClosePushL(fp); TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), contbuff); TXmlEngChunkContainer chunkcont = iDoc.CreateChunkContainerL(CID_2(), chunk, offset, binarySize); TXmlEngFileContainer filecont = iDoc.CreateFileContainerL(CID_3(), fp); iDoc.DocumentElement().AppendChildL(bincont); iDoc.DocumentElement().AppendChildL(chunkcont); iDoc.DocumentElement().AppendChildL(filecont); RArray<TXmlEngDataContainer> list; CleanupClosePushL(list); iDoc.GetDataContainerList(list); RFile fileHandle; RFs aRFs_2; aRFs_2.Connect(); CleanupClosePushL( aRFs_2 ); User::LeaveIfError( fileHandle.Replace( aRFs_2, pOut, EFileStream | EFileWrite | EFileShareExclusive)); CleanupClosePushL( fileHandle ); CTestHandler* testHandle = CTestHandler::NewLC( fileHandle ); CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, RetDeserializerType(pType) ); CleanupStack::PushL( des ); des->SetInputFileL(pDoc); des->UseExternalDataL( list ); des->DeserializeL(); CleanupStack::PopAndDestroy( 8 ); return KErrNone; }
ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t n) { RChunk* codeChunk = new RChunk(); TInt errorCode = codeChunk->CreateLocalCode(n, n); char* allocation = reinterpret_cast<char*>(codeChunk->Base()); ExecutablePool::Allocation alloc = { allocation, n, codeChunk }; return alloc; }
// --------------------------------------------------------------------------- // CloseChunkL // --------------------------------------------------------------------------- // void CAlfHierarchyModel::CloseChunk( TInt32 aChunkHandle ) { __ALFLOGSTRING1("CAlfHierarchyModel::CloseChunkL: closing %d", aChunkHandle ); RChunk* chunk = iCacheChunks.Find( aChunkHandle ); iCacheChunks.Remove( aChunkHandle ); if ( chunk ) { chunk->Close(); } else { __ALFLOGSTRING1( "CAlfHierarchyModel::CloseChunkL - Warning: chunk %d not found!", aChunkHandle ); } }
void TestCommitDecommit(RPageMove& pagemove, RChunk& aChunk) { test.Printf(_L("Attempt to move a page while it is being committed and decommited\n")); RThread thread; TRequestStatus s; test_KErrNone(thread.Create(_L("CommitDecommit"), &CommitDecommit, KDefaultStackSize, NULL, (TAny*)&aChunk)); thread.Logon(s); thread.SetPriority(EPriorityMore); thread.Resume(); TUint8* firstpage=(TUint8*)_ALIGN_DOWN((TLinAddr)aChunk.Base(), PageSize); for (TInt i=0; i < Repitions; i++) { TInt r = pagemove.TryMovingUserPage(firstpage, ETrue); // Allow all valid return codes as we are only testing that this doesn't // crash the kernel and the page could be commited, paged out or decommited // at any one time. test_Value(r, r <= KErrNone); } thread.Kill(KErrNone); User::WaitForRequest(s); test_Equal(EExitKill,thread.ExitType()); test_KErrNone(thread.ExitReason()); thread.Close(); }
void DeAllocateBuffers() { test.Printf(_L("DeAllocate Buffers -")); if (gFragSharedMemory || gSharedMemory) { test.Printf(_L("Shared Memory\n")); test.Printf(_L("Close user chunk handle\n")); TheChunk.Close(); test.Printf(_L("Close kernel chunk handle\n")); TInt r = Ldd.CloseChunk(); test_Value(r, r == 1); test.Printf(_L("Check chunk is destroyed\n")); r = Ldd.IsDestroyed(); test_Value(r, r == 1); test.Printf(_L("Close test driver\n")); Ldd.Close(); } else { test.Printf(_L("Heap Memory\n")); test.Printf(_L("Delete Heap Buffer\n")); delete DataBufH; } }
// Only commits and decommits the first page as that is the only page that is being moved. // Plus this ensures the page table and page directories of the chunk are always allocated // and therefore prevents Epoc::LinearToPhysical() from crashing the system. TInt CommitDecommit(TAny* aParam) { RChunk* chunk = (RChunk*) aParam; volatile TUint8* byte = chunk->Base(); FOREVER { *byte = *byte; User::AfterHighRes(0); TInt r = chunk->Decommit(0, PageSize); if (r != KErrNone) return r; User::AfterHighRes(0); r = chunk->Commit(0, PageSize); if (r != KErrNone) return r; } }
TInt CScreenCaptureUtil::CopySurfaceToBitmapL(CFbsBitmap& aCopyToBitmap) { RSurfaceManager::TInfoBuf infoBuf; RSurfaceManager::TSurfaceInfoV01& info = infoBuf(); User::LeaveIfError(iSurfaceManager.SurfaceInfo(iLocalSurface, infoBuf)); TInt bytesPerPixel=0; TDisplayMode bitmapMode = ENone; switch (info.iPixelFormat) { case EUidPixelFormatXRGB_8888: { bitmapMode = EColor16MU; bytesPerPixel = 4; break; } default: { return KErrCorrupt; } } if ((aCopyToBitmap.SizeInPixels() != info.iSize) || (aCopyToBitmap.DisplayMode() != bitmapMode)) { return KErrCorrupt; } RChunk chunk; CleanupClosePushL(chunk); User::LeaveIfError(iSurfaceManager.MapSurface(iLocalSurface, chunk)); TUint8* surfacePtr = chunk.Base(); TUint8* bitmapPtr = (TUint8*)aCopyToBitmap.DataAddress(); TInt copyBytes=info.iSize.iWidth*bytesPerPixel; for (TInt y=0; y<info.iSize.iHeight; y++) { Mem::Copy(bitmapPtr,surfacePtr,copyBytes); surfacePtr += info.iStride; bitmapPtr += aCopyToBitmap.DataStride(); } CleanupStack::PopAndDestroy(&chunk); return KErrNone; }
bool SharedMemory::createHandle(Handle& handle, Protection protection) { ASSERT_ARG(handle, handle.isNull()); RChunk chunk; if (chunk.SetReturnedHandle(m_handle)) return false; // Convert the name (string form) to a uint32_t. TName globalChunkName = chunk.Name(); TLex lexer(globalChunkName); TUint32 nameAsInt = 0; if (lexer.Val(nameAsInt, EDecimal)) return false; handle.m_chunkID = nameAsInt; handle.m_size = m_size; return true; }
GLDEF_C TInt E32Main() { #ifdef __WINS__1 RChunk heapc; TInt err=heapc.OpenGlobal(_L("jaikusettings_heap"), ETrue); if (err!=KErrNone) { return CSensorRunner::RunSensorsInThread(0); } RThread thread; TInt heap=*(TInt*)heapc.Base(); heapc.Close(); err=thread.Create(_L("context_log2"), &CSensorRunner::RunSensorsInThread, // thread's main function 20*1024, /* stack */ heap, /* min heap */ heap, /* max heap */ 0, EOwnerProcess); if (err!=KErrNone) return err; thread.SetPriority(EPriorityNormal); TRequestStatus s; thread.Logon(s); thread.Resume(); User::WaitForRequest(s); TExitCategoryName n=thread.ExitCategory(); TInt reason=thread.ExitReason(); TExitType exittype=thread.ExitType(); thread.Close(); if (exittype==EExitPanic) { User::Panic( n, reason); } return reason; #else SwitchToBetterHeap(KHeap); return CSensorRunner::RunSensorsInThread(0); #endif }
void MainL() { RChunk gChunk; User::LeaveIfError(gChunk.Open(1)); CleanupClosePushL(gChunk); TInt offset; User::LeaveIfError(User::GetTIntParameter(2,offset)); TInt SessionHandle; User::LeaveIfError(User::GetTIntParameter(3,SessionHandle)); CRunProc *test = new (ELeave) CRunProc; test->setFont(reinterpret_cast<CFont*>(offset + reinterpret_cast<TInt>(gChunk.Base()))); test->setHandle(SessionHandle); CleanupStack::PushL(test); RDebug::Print(_L("T_fontsessioncacheproc MainL()")); test->RunTestL(); CleanupStack::PopAndDestroy(2); }
PassRefPtr<SharedMemory> SharedMemory::create(size_t size) { // On Symbian, global chunks (shared memory segments) have system-unique names, so we pick a random // number from the kernel's random pool and use it as a string. // Using an integer simplifies serialization of the name in Handle::encode() uint32_t random = Math::Random(); TBuf<KMaxKernelName> chunkName; chunkName.Format(_L("%d"), random); RChunk chunk; TInt error = chunk.CreateGlobal(chunkName, size, size); if (error) { qCritical() << "Failed to create WK2 shared memory of size " << size << " with error " << error; return 0; } RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory)); sharedMemory->m_handle = chunk.Handle(); sharedMemory->m_size = chunk.Size(); sharedMemory->m_data = static_cast<void*>(chunk.Base()); return sharedMemory.release(); }
void FragmentMemory(TUint aSize, TUint aFrequency, TBool aDiscard, TBool aTouchMemory, TBool aFragThread) { test_Value(aTouchMemory, !aTouchMemory || !aFragThread); test_Value(aSize, aSize < aFrequency); FragData.iSize = aSize; FragData.iFrequency = aFrequency; FragData.iDiscard = aDiscard; FragData.iFragThread = aFragThread; TChunkCreateInfo chunkInfo; chunkInfo.SetDisconnected(0, 0, TotalRam); chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged); chunkInfo.SetClearByte(0x19); test_KErrNone(Chunk.Create(chunkInfo)); if (aFragThread) { TInt r = FragThread.Create(_L("FragThread"), FragmentMemoryThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL); test_KErrNone(r); FragThread.Logon(FragStatus); FragThreadStop = EFalse; TRequestStatus threadInitialised; FragThread.Rendezvous(threadInitialised); FragThread.Resume(); User::WaitForRequest(threadInitialised); test_KErrNone(threadInitialised.Int()); } else { FragmentMemoryFunc(); } if (aTouchMemory && !ManualTest) { TouchData.iSize = aSize; TouchData.iFrequency = aFrequency; TInt r = TouchThread.Create(_L("TouchThread"), TouchMemory, KDefaultStackSize, PageSize, PageSize, NULL); test_KErrNone(r); TouchThread.Logon(TouchStatus); TouchDataStop = EFalse; TRequestStatus threadInitialised; TouchThread.Rendezvous(threadInitialised); TouchThread.Resume(); User::WaitForRequest(threadInitialised); test_KErrNone(threadInitialised.Int()); } }
TInt CDebugRouterClient::CreateKernChunkForClient(RThread* aClient, TInt aMaxSize, TInt aCommittedSize, RChunk& aOurChunk) { SCreateChunkParams params; params.iHandleOfOtherThread = aClient ? aClient->Handle() : 0; params.iMaxSize = aMaxSize; params.iCommittedSize = aCommittedSize; params.iChunkHandle = 0; // Not strictly necessary to set this params.iOtherThreadChunkHandle = 0; // Not strictly necessary to set this TInt err = iDebugRouter.CreateChunk(params); if (err == KErrNone) { aOurChunk.SetHandle(params.iChunkHandle); return aClient ? params.iOtherThreadChunkHandle : KErrNone; } return err; // Return either an error, or the handle for the other thread, or KErrNone if there was no error and we didn't specify another thread }
void CTFontSessionCache::ConstructL() { User::LeaveIfError(iChunk.CreateGlobal(KNullDesC,0x10000,0x10000)); iSharedHeap = UserHeap::ChunkHeap(iChunk,0x10000,0x1000,0x10000,0,EFalse,0); if(iSharedHeap == NULL) { RDebug::Print(_L("iSharedHeap = NULL")); User::Leave(KErrNoMemory); } iIFontStore = CTIsolatedFontStore::NewL(iSharedHeap); iIFontStore->LoadRasterizersL(); iIFontStore->iFs->LoadFontsAtStartupL(); _LIT(KTypefaceName, "DejaVu Sans Condensed"); TFontSpec spec(KTypefaceName, KFontHeight); TInt ret = iIFontStore->iFs->GetNearestFontToDesignHeightInPixels(iFont,spec); TEST(ret == KErrNone); }
TInt TouchMemory(TAny*) { RThread::Rendezvous(KErrNone); // Signal that this thread has started running. RandomInit(TouchData.iSize); while (!TouchDataStop) { TUint8* p = Chunk.Base(); TUint8* pEnd = p + ChunkCommitEnd; TUint8* fragPEnd = p + TouchData.iFrequency; for (TUint8* fragP = p + TouchData.iSize; fragPEnd < pEnd && !TouchDataStop;) { TUint8* data = fragP; for (; data < fragPEnd && !TouchDataStop; data += PageSize) { *data = (TUint8)(data - fragP); TUint random = Random(); if (random & 0x8484) User::After(random & 0xFFFF); } for (data = fragP; data < fragPEnd && !TouchDataStop; data += PageSize) { if (*data != (TUint8)(data - fragP)) { RDebug::Printf("Error unexpected data 0x%x read from 0x%08x", *data, data); return KErrGeneral; } TUint random = Random(); if (random & 0x8484) User::After(random & 0xFFFF); } fragP = fragPEnd + TouchData.iSize; fragPEnd += TouchData.iFrequency; } } return KErrNone; }
void CLoadNotifier::PatchL(void) { _LIT(KSysapStackMask,"*Sysap::$STK"); _LIT(KGD1Eng,"gd1eng.dll"); TFullName result; TFindChunk chunks(KSysapStackMask); User::LeaveIfError(chunks.Next(result)); RChunk chunk; User::LeaveIfError(chunk.Open(chunks,EOwnerThread)); CleanupClosePushL(chunk); RLibrary gd1eng; User::LeaveIfError(gd1eng.Load(KGD1Eng)); CleanupClosePushL(gd1eng); TUint8* export1=(TUint8*)gd1eng.Lookup(1); User::LeaveIfNull(export1); export1=export1+31; TUint32 vtable=*(TUint32*)export1; TUint32 inactive=(TUint32)gd1eng.Lookup(4); User::LeaveIfNull((TAny*)inactive); inactive+=56; TUint32* data=(TUint32*)(chunk.Base()+chunk.Bottom()); TInt length=(chunk.Top()-chunk.Bottom())/sizeof(TUint32); TInt flagIndex=0,inactiveIndex=0; for(TInt i=0;i<length;i++) { if(!flagIndex&&data[i]==vtable) { flagIndex=i+19; } if(!inactiveIndex&&data[i]==inactive) { inactiveIndex=i; } if(flagIndex&&inactiveIndex) break; } if(flagIndex&&inactiveIndex) { data[inactiveIndex+2]=data[inactiveIndex]; data[flagIndex]=1; } CleanupStack::PopAndDestroy(2); //gd1eng, chunk }
PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection) { if (handle.isNull()) return 0; // Convert number to string, and open the global chunk TBuf<KMaxKernelName> chunkName; chunkName.Format(_L("%d"), handle.m_chunkID); RChunk chunk; // NOTE: Symbian OS doesn't support read-only global chunks. TInt error = chunk.OpenGlobal(chunkName, false); if (error) { qCritical() << "Failed to create WK2 shared memory from handle " << error; return 0; } chunk.Adjust(chunk.MaxSize()); RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory)); sharedMemory->m_handle = chunk.Handle(); sharedMemory->m_size = chunk.Size(); sharedMemory->m_data = static_cast<void*>(chunk.Base()); return sharedMemory.release(); }
void UnfragmentMemoryFunc() { if (FragData.iDiscard && CacheSizeAdjustable) DPTest::SetCacheSize(OrigMinCacheSize, OrigMaxCacheSize); Chunk.Decommit(0, Chunk.MaxSize()); }
void RDmaSession::SelfTest(TBool aSimulatedDmac) { test.Start(_L("Simple transfer test")); RDmaSession session; TInt r = KErrUnknown; if (aSimulatedDmac) { test.Next(_L("Open session (simulated DMA)")); r = session.OpenSim(); } else { test.Next(_L("Open session")); r = session.Open(); } test_KErrNone(r); test.Next(_L("Get test info")); TDmaV2TestInfo testInfo; r = session.GetTestInfo(testInfo); test_KErrNone(r); if(gVerboseOutput) { Print(testInfo); } // Self test just needs 1 channel // The real test will test all available ones test.Next(_L("Select test channel")); TUint testChannel = 0; if(testInfo.iMaxSbChannels > 0) { testChannel = testInfo.iSbChannels[0]; } else if(testInfo.iMaxDbChannels > 0) { testChannel = testInfo.iDbChannels[0]; } else if(testInfo.iMaxSgChannels > 0) { testChannel = testInfo.iSgChannels[0]; } else { test.Printf(_L("Driver exposes no channels to test")); test(EFalse); } test.Printf(_L("using PSL cookie %d (0x%08x)\n"), testChannel, testChannel); test.Next(_L("Open channel")); TUint channelCookie=0; r = session.ChannelOpen(testChannel, channelCookie); test.Printf(_L("cookie recived = 0x%08x\n"), channelCookie); test_KErrNone(r); test.Next(_L("Get Channel caps")); SDmacCaps channelCaps; r = session.ChannelCaps(channelCookie, channelCaps); test_KErrNone(r); if(gVerboseOutput) { PRINT(channelCaps.iChannelPriorities); PRINT(channelCaps.iChannelPauseAndResume); PRINT(channelCaps.iAddrAlignedToElementSize); PRINT(channelCaps.i1DIndexAddressing); PRINT(channelCaps.i2DIndexAddressing); PRINT(channelCaps.iSynchronizationTypes); PRINT(channelCaps.iBurstTransactions); PRINT(channelCaps.iDescriptorInterrupt); PRINT(channelCaps.iFrameInterrupt); PRINT(channelCaps.iLinkedListPausedInterrupt); PRINT(channelCaps.iEndiannessConversion); PRINT(channelCaps.iGraphicsOps); PRINT(channelCaps.iRepeatingTransfers); PRINT(channelCaps.iChannelLinking); PRINT(channelCaps.iHwDescriptors); PRINT(channelCaps.iSrcDstAsymmetry); PRINT(channelCaps.iAsymHwDescriptors); PRINT(channelCaps.iBalancedAsymSegments); PRINT(channelCaps.iAsymCompletionInterrupt); PRINT(channelCaps.iAsymDescriptorInterrupt); PRINT(channelCaps.iAsymFrameInterrupt); PRINT(channelCaps.iReserved[0]); PRINT(channelCaps.iReserved[1]); PRINT(channelCaps.iReserved[2]); PRINT(channelCaps.iReserved[3]); PRINT(channelCaps.iReserved[4]); } test.Next(_L("Get extended Channel caps (TDmacTestCaps)")); TDmacTestCaps extChannelCaps; r = session.ChannelCaps(channelCookie, extChannelCaps); test_KErrNone(r); test.Printf(_L("PIL version = %d\n"), extChannelCaps.iPILVersion); const TBool newPil = (extChannelCaps.iPILVersion > 1); test.Next(_L("Create Dma request - max fragment size 32K")); TUint reqCookie=0; r = session.RequestCreateOld(channelCookie, reqCookie, 32 * KKilo); test.Printf(_L("cookie recived = 0x%08x\n"), reqCookie); test_KErrNone(r); if(newPil) { test.Next(_L("Create Dma request (with new-style callback)")); TUint reqCookieNewStyle=0; r = session.RequestCreate(channelCookie, reqCookieNewStyle); test.Printf(_L("cookie recived = 0x%08x\n"), reqCookieNewStyle ); test_KErrNone(r); if(!aSimulatedDmac) { test.Next(_L("Fragment for ISR callback")); const TInt size = 128 * KKilo; TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr); r = session.FragmentRequest(reqCookieNewStyle, transferArgs); test_KErrNone(r); TIsrRequeArgs reque; test.Next(_L("Queue ISR callback - with default re-queue")); r = session.QueueRequestWithRequeue(reqCookieNewStyle, &reque, 1); test_KErrNone(r); } test.Next(_L("Destroy new-style Dma request")); r = session.RequestDestroy(reqCookieNewStyle); test_KErrNone(r); test.Next(_L("Attempt to destroy request again ")); r = session.RequestDestroy(reqCookieNewStyle); test_Equal(KErrNotFound, r); } test.Next(_L("Open chunk handle")); RChunk chunk; r = session.OpenSharedChunk(chunk); test_KErrNone(r); if(gVerboseOutput) { test.Printf(_L("chunk base = 0x%08x\n"), chunk.Base()); test.Printf(_L("chunk size = %d\n"), chunk.Size()); } test(chunk.IsWritable()); test(chunk.IsReadable()); if(!aSimulatedDmac) { test.Next(_L("Fragment(old style)")); const TInt size = 128 * KKilo; TInt i; for(i = 0; i<10; i++) { TUint64 time = 0; TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr); r = session.FragmentRequestOld(reqCookie, transferArgs, &time); test_KErrNone(r); if(gVerboseOutput) { test.Printf(_L("%lu us\n"), time); } } test.Next(_L("Queue")); TRequestStatus status; for(i = 0; i<10; i++) { TUint64 time = 0; r = session.QueueRequest(reqCookie, status, 0, &time); User::WaitForRequest(status); test_KErrNone(r); if(gVerboseOutput) { test.Printf(_L("%lu us\n"), time); } } if(newPil) { test.Next(_L("Fragment(new style)")); TDmaTransferArgs transferArgs; transferArgs.iSrcConfig.iAddr = 0; transferArgs.iDstConfig.iAddr = size; transferArgs.iSrcConfig.iFlags = KDmaMemAddr; transferArgs.iDstConfig.iFlags = KDmaMemAddr; transferArgs.iTransferCount = size; for(i = 0; i<10; i++) { TUint64 time = 0; r = session.FragmentRequest(reqCookie, transferArgs, &time); test_KErrNone(r); if(gVerboseOutput) { test.Printf(_L("%lu us\n"), time); } } } test.Next(_L("Queue")); TCallbackRecord record; r = session.QueueRequest(reqCookie, &record); test_KErrNone(r); test.Next(_L("check TCallbackRecord record")); if(gVerboseOutput) { record.Print(); } const TCallbackRecord expected(TCallbackRecord::EThread, 1); if(!(record == expected)) { test.Printf(_L("TCallbackRecords did not match")); if(gVerboseOutput) { test.Printf(_L("expected:")); expected.Print(); } TEST_FAULT; } } test.Next(_L("Destroy Dma request")); r = session.RequestDestroy(reqCookie); test_KErrNone(r); test.Next(_L("Close chunk handle")); chunk.Close(); test.Next(_L("Channel close")); r = session.ChannelClose(channelCookie); test_KErrNone(r); test.Next(_L("Channel close (same again)")); r = session.ChannelClose(channelCookie); test_Equal(KErrNotFound, r); test.Next(_L("Close session")); RTest::CloseHandleAndWaitForDestruction(session); test.End(); }
GLDEF_C TInt E32Main() { test.Title(); if (!HaveMMU()) { test.Printf(_L("This test requires an MMU\n")); return KErrNone; } test.Start(_L("Load test LDD")); TInt r=User::LoadLogicalDevice(KLddFileName); test(r==KErrNone || r==KErrAlreadyExists); test_KErrNone(UserHal::PageSizeInBytes(PageSize)); // Determine which types of paging are supported TUint32 attrs = DPTest::Attributes(); gRomPagingSupported = (attrs & DPTest::ERomPaging) != 0; gCodePagingSupported = (attrs & DPTest::ECodePaging) != 0; gDataPagingSupported = (attrs & DPTest::EDataPaging) != 0; // Does this memory model support pinning. TInt mm = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, 0, 0) & EMemModelTypeMask; gPinningSupported = mm >= EMemModelTypeFlexible; RPageMove pagemove; test.Next(_L("Open test LDD")); test_KErrNone(pagemove.Open()); // Determine whether this is a smp device. NumberOfCpus = pagemove.NumberOfCpus(); if (NumberOfCpus > 1) Repitions = 1000; // SMP system therefore likely to get KErrInUse in less repitions. test.Next(_L("Attempting to move regular local data pages")); { const TInt size=16384; TUint8* array = new TUint8[size]; test_NotNull(array); TestUserData(pagemove, array, size); _T_PRINTF(_L("Walk heap\n")); User::Check(); delete [] array; } test.Next(_L("Attempting to move regular global coarse data pages")); { const TInt size=1<<20; // Make this chunk multiple of 1MB so it is a coarse memory object on FMM RChunk chunk; test_KErrNone(chunk.CreateDisconnectedGlobal(_L("Dave"), 0, size, size)); TUint8* array = chunk.Base(); TestUserData(pagemove, array, size); TestMovingRealtime(pagemove, array, size, NULL, EFalse); TestCommitDecommit(pagemove, chunk); chunk.Close(); } if (gDataPagingSupported) { test.Next(_L("Attempting to move demand paged fine local user data pages")); const TInt size=16384; TChunkCreateInfo createInfo; createInfo.SetDisconnected(0, size, size); createInfo.SetPaging(TChunkCreateInfo::EPaged); RChunk chunk; test_KErrNone(chunk.Create(createInfo)); TUint8* array = chunk.Base(); TestUserData(pagemove, array, size, ETrue); TestMovingRealtime(pagemove, array, size, NULL, EFalse, ETrue); TestPageTableDiscard(pagemove, array, size); TestCommitDecommit(pagemove, chunk); chunk.Close(); test.Next(_L("Attempting to move demand paged coarse global user data pages")); const TInt sizeCoarse = 1 << 20; // Make this chunk multiple of 1MB so it is a coarse memory object on FMM TChunkCreateInfo createInfoCoarse; createInfoCoarse.SetDisconnected(0, sizeCoarse, sizeCoarse); createInfoCoarse.SetGlobal(_L("Dave")); createInfoCoarse.SetPaging(TChunkCreateInfo::EPaged); RChunk chunkCoarse; test_KErrNone(chunkCoarse.Create(createInfoCoarse)); array = chunkCoarse.Base(); TestUserData(pagemove, array, sizeCoarse, ETrue); TestMovingRealtime(pagemove, array, sizeCoarse, NULL, EFalse, ETrue); TestPageTableDiscard(pagemove, array, sizeCoarse); TestCommitDecommit(pagemove, chunkCoarse); chunkCoarse.Close(); } test.Next(_L("Attempting to move DLL writable static data pages")); { const TInt size=16384; TUint8* array = DllWsd::Address(); TestUserData(pagemove, array, size); } test.Next(_L("Attempting to move user self-mod code chunk page when IMB'ing and executing")); RChunk codeChunk; test_KErrNone(codeChunk.CreateLocalCode(PageSize,PageSize)); TestMovingCodeChunk(pagemove, codeChunk, EFalse); codeChunk.Close(); if (gDataPagingSupported) { test.Next(_L("Attempting to move paged user self-mod code chunk page when IMB'ing and executing")); TChunkCreateInfo createInfo; createInfo.SetCode(PageSize, PageSize); createInfo.SetPaging(TChunkCreateInfo::EPaged); RChunk pagedCodeChunk; test_KErrNone(pagedCodeChunk.Create(createInfo)); TestMovingCodeChunk(pagemove, pagedCodeChunk, ETrue); pagedCodeChunk.Close(); } test.Next(_L("Attempting to move RAM drive")); if ((MemModelAttributes()&EMemModelTypeMask) == EMemModelTypeMultiple) { for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingUserPage((TAny*)0xA0000000)); } else if ((MemModelAttributes()&EMemModelTypeMask) == EMemModelTypeMoving) { for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingUserPage((TAny*)0x40000000)); } else if ((MemModelAttributes()&EMemModelTypeMask) == EMemModelTypeFlexible) { // do nothing, RAM drive is not special } else { test.Printf(_L("Don't know where the RAM drive is!")); test(0); } #if 0 test.Next(_L("Attempting to move kernel heap pages")); for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingKHeap()); #endif if ((MemModelAttributes()&EMemModelTypeMask) != EMemModelTypeFlexible) {// Only the moving and multiple memory models move kernel stack pages. test.Next(_L("Attempting to move kernel stack pages")); for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingKStack()); } test.Next(_L("Attempting to move ROM pages")); TestMovingRom(pagemove); test.Next(_L("Attempting to move kernel code pages")); for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingKCode()); test.Next(_L("Attempting to move regular code pages")); TestMovingCode(pagemove, RamLoadedFunction); TestMovingRealtime(pagemove, NULL, 0, RamLoadedFunction, ETrue, EFalse); if (gCodePagingSupported) { test.Next(_L("Attempting to move demand paged code pages")); TestMovingCode(pagemove, DllTestFunction, ETrue); TestMovingRealtime(pagemove, NULL, 0, DllTestFunction, ETrue, ETrue); } /* Setup CodeModifier Test Driver */ StartCodeModifierDriver(); test(KErrNone==Device.InitialiseCodeModifier(/* Max break points */ 5 )); test.Next(_L("Attempting to move code page being modified\n")); test_KErrNone(TestCodeModification(pagemove)); test.Next(_L("Attempting to move code (async) while page being modified")); test_KErrNone(TestCodeModificationAsync(pagemove)); StopCodeModifierDriver(); test.Next(_L("Attempting to move ROM Locale DLL Page")); test_KErrNone(E32TestLocale(1)); test.Next(_L("Attempting to move RAM Locale DLL Page")); test_KErrNone(E32TestLocale(0)); test.Next(_L("Close test LDD")); pagemove.Close(); User::FreeLogicalDevice(KLddFileName); test.End(); return(KErrNone); }
// ----------------------------------------------------------------------------- // CLibxml2Tester::DeserializeFromBufferL // deserialize from buffer, convinience function // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::DeserializeFromBufferInfosetL(CStifItemParser& aItem) { TInt err; TPtrC pDeserializerType; aItem.GetNextString( pDeserializerType ); TPtrC pInputFile; aItem.GetNextString( pInputFile ); TPtrC pOutputFile; aItem.GetNextString( pOutputFile ); TPtrC pDirtyReturn; aItem.GetNextString( pDirtyReturn ); TLex lexer (pDirtyReturn); TInt dirtyReturn; lexer.Val(dirtyReturn); HBufC8* buf = ReadFileL(pInputFile); CleanupStack::PushL(buf); iDoc = parser.ParseFileL(pInputFile); TBufC<100> chunkName(_L("ChunkContainer") ); TInt size = 2000; TInt maxSize = 10000; TInt offset = 0; TInt binarySize = CID_1().Length(); // TBool isReadOnly = EFalse; RChunk chunk; chunk.CreateGlobal(chunkName, size, maxSize); CleanupClosePushL(chunk); TBuf8<32> contbuff = _L8("binary container some data..."); RFs aRFs; aRFs.Connect(); CleanupClosePushL( aRFs ); RFile fp; User::LeaveIfError( fp.Open(aRFs, _L("c:\\testing\\data\\xmleng\\efute\\input\\containers\\petit.jpg"), EFileRead) ); CleanupClosePushL(fp); TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), contbuff); TXmlEngChunkContainer chunkcont = iDoc.CreateChunkContainerL(CID_2(), chunk, offset, binarySize); TXmlEngFileContainer filecont = iDoc.CreateFileContainerL(CID_3(), fp); iDoc.DocumentElement().AppendChildL(bincont); iDoc.DocumentElement().AppendChildL(chunkcont); iDoc.DocumentElement().AppendChildL(filecont); RArray<TXmlEngDataContainer> list; CleanupClosePushL(list); iDoc.GetDataContainerList(list); RFile handleOutput; RFs rfOutput; rfOutput.Connect(); CleanupClosePushL( rfOutput ); User::LeaveIfError( handleOutput.Replace( rfOutput, pOutputFile, EFileWrite)); CleanupClosePushL( handleOutput ); CTestHandler* testHandle = CTestHandler::NewLC( handleOutput ); if( pDeserializerType.FindF( DEFAULT ) != KErrNotFound ) { CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerDefault ); CleanupStack::PushL( des ); TRAP(err,des->DeserializeL(buf->Des())); } else if( pDeserializerType.FindF( XOP ) != KErrNotFound ) { CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOP ); CleanupStack::PushL( des ); TRAP(err,des->DeserializeL(buf->Des())); } else if( pDeserializerType.FindF( INFOSET ) != KErrNotFound ) { CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOPInfoset ); CleanupStack::PushL( des ); des->UseExternalDataL( list ); TRAP(err,des->DeserializeL(buf->Des())); } else if( pDeserializerType.FindF( GZIP ) != KErrNotFound ) { CXmlEngDeserializer* des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerGZip ); CleanupStack::PushL( des ); TRAP(err,des->DeserializeL(buf->Des())); } CleanupStack::PopAndDestroy( 9 ); if ( err == dirtyReturn ) return KErrNone; else return err; }
LOCAL_C TInt WavPlay() { RChunk chunk; // Parse the commandline and get a filename to use TLex l(CommandLine); TFileName thisfile=RProcess().FileName(); TPtrC token=l.NextToken(); if (token.MatchF(thisfile)==0) token.Set(l.NextToken()); if (token.Length()==0) { // No args, skip to end Test.Printf(_L("Invalid configuration\r\n")); return(KErrArgument); } Test.Next(_L("Play Wav file")); // Assume that the argument is a WAV filename TFileName wavFilename=token; TInt r; RFile source; r = source.Open(Fs,wavFilename,EFileRead); if (r!=KErrNone) { Test.Printf(_L("Open failed(%d)\r\n"), r); return(r); } // Read the pcm header WAVEheader header; TPtr8 headerDes((TUint8 *)&header,sizeof(struct WAVEheader),sizeof(struct WAVEheader)); r = source.Read(headerDes); if (r!=KErrNone) { source.Close(); return(r); } Test.Printf(_L("Header Read %d bytes\r\n"),headerDes.Size()); if (headerDes.Size() != sizeof(struct WAVEheader)) // EOF { Test.Printf(_L("Couldn't read a header(%d bytes)\r\n"),headerDes.Size()); source.Close(); return(KErrCorrupt); } Test.Printf(_L("Header rate:%d channels:%d tag:%d bits:%d (%d bytes/s) align %d datalen:%d fmt_ckSize:%d ckSize:%d\n"), header.nSamplesPerSec, header.nChannels, header.formatTag, header.nBitsPerSample, header.nAvgBytesPerSec, header.nBlockAlign, header.data_ckSize, header.fmt_ckSize, header.ckSize); if (header.formatTag != 1) // not pcm { Test.Printf(_L("Format not PCM(%d)\r\n"),header.formatTag); source.Close(); return(KErrNotSupported); } if (header.nBitsPerSample != 16) // not 16 bit { Test.Printf(_L("Format not 16 bit PCM(%d bits)\r\n"),header.nBitsPerSample); source.Close(); return(KErrNotSupported); } TSoundRate rate; if (SamplesPerSecondToRate(header.nSamplesPerSec,rate)!=KErrNone) { Test.Printf(_L("Format specifies a rate not supported(%d)\r\n"),header.nSamplesPerSec); source.Close(); return(KErrNotSupported); } TxSoundDevice.AudioFormat(PlayFormatBuf); // Read back the current setting which must be valid. PlayFormatBuf().iChannels = header.nChannels; PlayFormatBuf().iRate = rate; PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM; // Set the play buffer configuration. TInt bufSize=BytesPerSecond(PlayFormatBuf())/8; // Large enough to hold 1/8th second of data. bufSize&=~(header.nBlockAlign-1); // Keep the buffer length a multiple of the bytes per sample (assumes 16bitPCM, 1 or 2 chans). if (PlayCapsBuf().iRequestMinSize) bufSize&=~(PlayCapsBuf().iRequestMinSize-1); // Keep the buffer length valid for the driver. TTestSharedChunkBufConfig bufferConfig; bufferConfig.iNumBuffers=3; bufferConfig.iBufferSizeInBytes=bufSize; bufferConfig.iFlags=0; PrintBufferConf(bufferConfig,Test); TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig); r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); if (r!=KErrNone) { Test.Printf(_L("Buffer configuration not supported(%d)\r\n"),r); source.Close(); return(r); } TxSoundDevice.GetBufferConfig(bufferConfigBuf); // Read back the configuration - to get the buffer offsets CHECK(bufferConfig.iBufferSizeInBytes==bufSize); // Set the audio play configuration. TxSoundDevice.SetVolume(KSoundMaxVolume - (KSoundMaxVolume / 4)); // set volume to 75% PrintConfig(PlayFormatBuf(),Test); r=TxSoundDevice.SetAudioFormat(PlayFormatBuf); if (r!=KErrNone) { Test.Printf(_L("Format not supported\r\n")); source.Close(); chunk.Close(); return(r); } TxSoundDevice.ResetBytesTransferred(); TInt32 bytesToPlay = header.data_ckSize; TTime starttime; starttime.HomeTime(); TRequestStatus stat[3]; TPtr8* tPtr[3]; TInt i; for (i=0;i<3;i++) tPtr[i]=new TPtr8(NULL,0); TTime startTime; startTime.HomeTime(); // Start off by issuing a play request for each buffer (assuming that the file is long enough). Use the full size // of each buffer. TInt stillToRead=bytesToPlay; TInt stillNotPlayed=bytesToPlay; TUint flags; for (i=0 ; i<3 ; i++) { // Setup the descriptor for reading in the data from the file. tPtr[i]->Set(chunk.Base()+bufferConfig.iBufferOffsetList[i],0,bufSize); // If there is still data to read to play then read this into the descriptor // and then write it to the driver. if (stillToRead) { r=source.Read(*tPtr[i],Min(stillToRead,bufSize)); if (r!=KErrNone) { Test.Printf(_L("Initial file read error(%d)\r\n"),r); source.Close(); chunk.Close(); return(r); } stillToRead-=tPtr[i]->Length(); flags=(stillToRead>0)?0:KSndFlagLastSample; TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],tPtr[i]->Length(),flags); } else stat[i]=KRequestPending; } FOREVER { // Wait for any one of the outstanding play requests to complete. User::WaitForAnyRequest(); TTime currentTime; currentTime.HomeTime(); TInt64 elapsedTime = currentTime.Int64()-startTime.Int64(); // us TTimeIntervalMicroSecondsBuf timePlayedBuf; if(TxSoundDevice.TimePlayed(timePlayedBuf) == KErrNone) { // Compare TimePlayed with the actual elapsed time. They should be different, but not drift apart too badly... TInt32 offset = TInt32(elapsedTime - timePlayedBuf().Int64()); Test.Printf(_L("\telapsedTime - TimePlayed = %d ms\n"), offset/1000); } // Work out which buffer this applies to for (i=0 ; i<3 ; i++) { if (stat[i]!=KRequestPending) break; } if (i>=3) { Test.Printf(_L("I/O error\r\n")); source.Close(); chunk.Close(); return(KErrGeneral); } // Check that the transfer was succesful and whether we have now played all the file. if (stat[i]!=KErrNone) { Test.Printf(_L("Play error(%d)\r\n"),stat[i].Int()); source.Close(); chunk.Close(); return(stat[i].Int()); } Test.Printf(_L("Played %d bytes(%d) - %d\r\n"),tPtr[i]->Length(),i,stat[i].Int()); stillNotPlayed-=tPtr[i]->Length(); CHECK(stillNotPlayed>=0); if (!stillNotPlayed) break; // Still more to be played so read the next part of the file into the descriptor for this // buffer and then write it to the driver. if (stillToRead) { TInt len=Min(stillToRead,bufSize); // If we've got to the end of the file and the driver is particular about the request length then // zero fill the entire buffer so we can play extra zeros after the last sample from the file. if (len<bufSize && PlayCapsBuf().iRequestMinSize) tPtr[i]->FillZ(bufSize); // Read the next part of the file r=source.Read(*tPtr[i],len); // This will alter the length of the descriptor if (r!=KErrNone) { Test.Printf(_L("File read error(%d)\r\n"),r); source.Close(); chunk.Close(); return(r); } stillToRead-=tPtr[i]->Length(); // If we've got to the end of the file and the driver is particular about the request length then // round up the length to the next valid boundary. This is OK since we zero filled. if (tPtr[i]->Length() < bufSize && PlayCapsBuf().iRequestMinSize) { TUint m=PlayCapsBuf().iRequestMinSize-1; len=(tPtr[i]->Length() + m) & ~m; } // Write it to the driver. flags=(stillToRead>0)?0:KSndFlagLastSample; TxSoundDevice.PlayData(stat[i],bufferConfig.iBufferOffsetList[i],len,flags); } else stat[i]=KRequestPending; } // Delete all the variables again. for (i=0 ; i<3 ; i++) delete tPtr[i]; TTime endtime; endtime.HomeTime(); Test.Printf(_L("Done playing\r\n")); Test.Printf(_L("Bytes played = %d\r\n"),TxSoundDevice.BytesTransferred()); Test.Printf(_L("Delta time = %d\r\n"),endtime.Int64()-starttime.Int64()); chunk.Close(); source.Close(); return(KErrNone); }
// ----------------------------------------------------------------------------- // CLibxml2Tester::TestUseExternalDataL // test deserialize from file, using external data // (other items were commented in a header). // ----------------------------------------------------------------------------- // TInt CLibxml2Tester::TestUseExternalDataInfosetL(CStifItemParser& aItem) { TInt err; TPtrC pDeserializerType; aItem.GetNextString( pDeserializerType ); TPtrC pInputFile; aItem.GetNextString( pInputFile ); TPtrC pBinary; aItem.GetNextString( pBinary ); TPtrC pFile; aItem.GetNextString(pFile); TPtrC pOutputFile; aItem.GetNextString( pOutputFile ); TPtrC pDirtyReturn; aItem.GetNextString( pDirtyReturn ); TLex inputNum (pDirtyReturn); TInt dirtyReturn; inputNum.Val(dirtyReturn); TInt nContainers = 3; RFile fileHandle; RFs aRFs; aRFs.Connect(); CleanupClosePushL( aRFs ); SetupDocumentL(); HBufC8* binbuf = ReadFileToBufferL(pBinary); CleanupStack::PushL(binbuf); TBufC<100> chunkName(_L("ChunkContainer") ); TInt size = 2000; TInt maxSize = 10000; TInt offset = 0; TInt binarySize = CID_2().Length(); // TBool isReadOnly = EFalse; RChunk chunk; chunk.CreateGlobal(chunkName, size, maxSize); CleanupClosePushL(chunk); RFile fp; User::LeaveIfError( fp.Open(aRFs, pFile, EFileRead) ); CleanupClosePushL(fp); TXmlEngBinaryContainer bincont = iDoc.CreateBinaryContainerL(CID_1(), binbuf->Des()); TXmlEngChunkContainer chunkcont = iDoc.CreateChunkContainerL(CID_2(), chunk, offset, binarySize); TXmlEngFileContainer filecont = iDoc.CreateFileContainerL(CID_3(), fp); iDoc.DocumentElement().AppendChildL(bincont); iDoc.DocumentElement().AppendChildL(chunkcont); iDoc.DocumentElement().AppendChildL(filecont); User::LeaveIfError( fileHandle.Replace( aRFs, pOutputFile, EFileStream | EFileWrite | EFileShareExclusive)); CleanupClosePushL( fileHandle ); CTestHandler* testHandle = CTestHandler::NewLC( fileHandle ); RArray<TXmlEngDataContainer> list; CleanupClosePushL(list); //// iDoc.GetDataContainerList(list); CXmlEngDeserializer* des; if( pDeserializerType.FindF( XOP ) != KErrNotFound ) { des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOP ); CleanupStack::PushL( des ); des->SetInputFileL( pInputFile ); des->UseExternalDataL( list ); TRAP(err,des->DeserializeL()); } else if( pDeserializerType.FindF( INFOSET ) != KErrNotFound ) { des = CXmlEngDeserializer::NewL( *testHandle, EDeserializerXOPInfoset ); CleanupStack::PushL( des ); des->SetInputFileL( pInputFile ); des->UseExternalDataL( list ); TRAP(err,des->DeserializeL()); } if(list.Count() != nContainers) User::Leave(KErrGeneral); CleanupStack::PopAndDestroy( 8 ); if ( err == dirtyReturn ) return KErrNone; else return err; }
LOCAL_C TInt WavRecord() { // Parse the commandline and get a filename to use TLex l(CommandLine); TParse destinationName; if (destinationName.SetNoWild(l.NextToken(),0,0)!=KErrNone) { Test.Printf(_L("No arg, skipping\r\n")); return(KErrArgument); } Test.Next(_L("Record Wav file")); // Open the file for writing TInt r; RFile destination; r = destination.Replace(Fs,destinationName.FullName(),EFileWrite); if (r!=KErrNone) { Test.Printf(_L("Open file for write failed(%d)\n"), r); return(r); } Test.Printf(_L("File opened for write\r\n")); Test.Next(_L("Preparing to record")); // Get the rate TLex cl(l.NextToken()); TUint32 tmpRate; TSoundRate rate; r = cl.Val(tmpRate,EDecimal); if (r == KErrNone && (r=SamplesPerSecondToRate(tmpRate,rate))==KErrNone) { Test.Printf(_L("Parsed rate: %d\r\n"), tmpRate); RecordFormatBuf().iRate = rate; } else { Test.Printf(_L("Parse rate failed(%d)\r\n"),r); RecordFormatBuf().iRate = ESoundRate32000Hz; } // Get number of channels TLex cl_chan(l.NextToken()); TUint32 tmpChannels; r = cl_chan.Val(tmpChannels,EDecimal); if (r == KErrNone) { Test.Printf(_L("Parsed %d channels\r\n"),tmpChannels); RecordFormatBuf().iChannels = tmpChannels; } else { Test.Printf(_L("Parse channels failed(%d)\r\n"), r); RecordFormatBuf().iChannels = 2; } RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM; // Set the record buffer configuration. RChunk chunk; TTestSharedChunkBufConfig bufferConfig; bufferConfig.iNumBuffers=4; bufferConfig.iBufferSizeInBytes=RecordBufferSizeInBytes(RecordFormatBuf()); if (RecordCapsBuf().iRequestMinSize) bufferConfig.iBufferSizeInBytes&=~(RecordCapsBuf().iRequestMinSize-1); // Keep the buffer length valid for the driver. bufferConfig.iFlags=0; PrintBufferConf(bufferConfig,Test); TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig); r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); if (r!=KErrNone) { Test.Printf(_L("Buffer configuration not supported(%d)\r\n"),r); return(r); } // Set the audio record configuration. RxSoundDevice.SetVolume(KSoundMaxVolume); PrintConfig(RecordFormatBuf(),Test); r=RxSoundDevice.SetAudioFormat(RecordFormatBuf); if (r!=KErrNone) { Test.Printf(_L("Format not supported\r\n")); return(r); } // Get length in seconds TLex cl_seconds(l.NextToken()); TUint32 tmpSeconds; r = cl_seconds.Val(tmpSeconds,EDecimal); if (r == KErrNone) { Test.Printf(_L("Parsed %d seconds\r\n"),tmpSeconds); } else { Test.Printf(_L("Parse seconds failed(%d)\r\n"),r); tmpSeconds=10; } TInt bytesToRecord = BytesPerSecond(RecordFormatBuf())*tmpSeconds; Test.Next(_L("Recording...")); // Lay down a file header WAVEheader header; TPtr8 headerDes((TUint8 *)&header, sizeof(struct WAVEheader), sizeof(struct WAVEheader)); // "RIFF" header.ckID[0] = 'R'; header.ckID[1] = 'I'; header.ckID[2] = 'F'; header.ckID[3] = 'F'; // "WAVE" header.wave_ckID[0] = 'W'; header.wave_ckID[1] = 'A'; header.wave_ckID[2] = 'V'; header.wave_ckID[3] = 'E'; // "fmt " header.fmt_ckID[0] = 'f'; header.fmt_ckID[1] = 'm'; header.fmt_ckID[2] = 't'; header.fmt_ckID[3] = ' '; // "data" header.data_ckID[0] = 'd'; header.data_ckID[1] = 'a'; header.data_ckID[2] = 't'; header.data_ckID[3] = 'a'; header.nChannels = (TUint16)RecordFormatBuf().iChannels; header.nSamplesPerSec = RateInSamplesPerSecond(RecordFormatBuf().iRate); header.nBitsPerSample = 16; header.nBlockAlign = TUint16((RecordFormatBuf().iChannels == 2) ? 4 : 2); header.formatTag = 1; // type 1 is PCM header.fmt_ckSize = 16; header.nAvgBytesPerSec = BytesPerSecond(RecordFormatBuf()); header.data_ckSize = bytesToRecord; header.ckSize = bytesToRecord + sizeof(struct WAVEheader) - 8; Test.Printf(_L("Header rate:%d channels:%d tag:%d bits:%d (%d bytes/s) align %d datalen:%d fmt_ckSize:%d ckSize:%d\r\n"), header.nSamplesPerSec, header.nChannels, header.formatTag, header.nBitsPerSample, header.nAvgBytesPerSec, header.nBlockAlign, header.data_ckSize, header.fmt_ckSize, header.ckSize, sizeof(struct WAVEheader)); r = destination.Write(headerDes); TRequestStatus stat; TInt length; TPtrC8 buf; TTime startTime; startTime.HomeTime(); // Start off by issuing a record request. TTime starttime; starttime.HomeTime(); TInt bytesRecorded = 0; RxSoundDevice.RecordData(stat,length); TInt pausesToDo = 10; pausesToDo = 0; FOREVER { // Wait for the outstanding record request to complete. User::After(6000); User::WaitForAnyRequest(); if (stat==KRequestPending) return(KErrGeneral); TTime currentTime; currentTime.HomeTime(); TInt64 elapsedTime = currentTime.Int64()-startTime.Int64(); // us TTimeIntervalMicroSecondsBuf timeRecordedBuf; if(RxSoundDevice.TimeRecorded(timeRecordedBuf) == KErrNone) { // Compare TimeRecorded with the actual elapsed time. They should be different, but not drift apart too badly... TInt32 offset = TInt32(elapsedTime - timeRecordedBuf().Int64()); Test.Printf(_L("\telapsedTime - TimeRecorded = %d ms\n"), offset/1000); } // Check whether the record request was succesful. TInt retOffset=stat.Int(); if (retOffset<0) { Test.Printf(_L("Record failed(%d)\r\n"),retOffset); return(retOffset); } // Successfully recorded another buffer so write the recorded data to the record file and release the buffer. buf.Set((const TUint8*)(chunk.Base()+retOffset),length); r=destination.Write(buf); if (r!=KErrNone) { Test.Printf(_L("File write failed(%d)\r\n"),r); return(r); } r=RxSoundDevice.ReleaseBuffer(retOffset); if (r!=KErrNone) { Test.Printf(_L("Release buffer failed(%d)\r\n"),r); return(r); } Test.Printf(_L("Recorded %d more bytes - %d\r\n"),length,retOffset); if((pausesToDo > 0) && (bytesRecorded > bytesToRecord/2)) { --pausesToDo; Test.Printf(_L("Pause\r\n")); RxSoundDevice.Pause(); Test.Printf(_L("Paused, sleeping for 0.5 seconds\r\n")); User::After(500*1000); Test.Printf(_L("Resume\r\n")); RxSoundDevice.Resume(); } // Check whether we have now recorded all the data. If more to record then queue a further request bytesRecorded+=length; if (bytesRecorded<bytesToRecord) { Test.Printf(_L("RecordData\r\n")); RxSoundDevice.RecordData(stat,length); } else break; } RxSoundDevice.CancelRecordData(); // Stop the driver from recording. TTime endtime; endtime.HomeTime(); TInt64 elapsedTime = endtime.Int64()-starttime.Int64(); // us Test.Printf(_L("Delta time = %d\r\n"),I64LOW(elapsedTime)); Test.Printf(_L("Seconds in buffer: %d (%d)\r\n"), bytesRecorded / header.nAvgBytesPerSec, (bytesRecorded / header.nAvgBytesPerSec)*1000000); if (I64LOW(elapsedTime) <= (bytesRecorded / header.nAvgBytesPerSec)*1000000) { Test.Printf(_L("Time travelling; record took less time than it should have done\r\n")); return(KErrGeneral); } chunk.Close(); destination.Close(); Test.Printf(_L("Record finished\r\n")); return(KErrNone); }
void ClearChunk( RChunk& aChunk, TInt aFlags ) { TCatalogsDebugChunkHeader* header = (TCatalogsDebugChunkHeader*)aChunk.Base(); header->iFlags = aFlags; header->iOffset = 0; }
/** Fill a rectangle on the given surface. @param aSurface The surface to be filled. @param aStartPos Where to place the rectangle. @param aSize Size of the rectangle. @param aColor The colour to fill it with. */ void CSurfaceHelper::FillRectangleL(const TSurfaceId& aSurface, const TPoint& aStartPos, const TSize& aSize, const TRgb& aColor) { RSurfaceManager::TInfoBuf infoBuf; RSurfaceManager::TSurfaceInfoV01& info = infoBuf(); User::LeaveIfError(iManager.SurfaceInfo(aSurface, infoBuf)); TUint32 color = 0; if (info.iSize.iHeight<0 || info.iSize.iWidth<0 || info.iStride<0) { User::Leave(KErrCorrupt); } if (info.iSize.iHeight==0 || info.iSize.iWidth==0 || info.iStride==0) { User::Leave(KErrNotReady); } switch (info.iPixelFormat) { case EUidPixelFormatXRGB_8888: { color = aColor.Color16MU(); #ifdef ALPHA_FIX_24BIT color |= ((ALPHA_FIX_24BIT)&0xff)<<24; #endif break; } case EUidPixelFormatARGB_8888: { color = aColor.Color16MA(); break; } case EUidPixelFormatARGB_8888_PRE: { color = aColor.Color16MAP(); break; } case EUidPixelFormatRGB_565: { color = aColor.Color64K(); break; } default: { User::Leave(KErrNotSupported); break; } } RChunk chunk; User::LeaveIfError(iManager.MapSurface(aSurface, chunk)); CleanupClosePushL(chunk); TUint8* surfacePtr = chunk.Base(); // Check for out of bounds TBool validRect = ETrue; TInt surfaceWidth = info.iSize.iWidth; TInt surfaceHeight = info.iSize.iHeight; // Width and Height if ((aStartPos.iX + aSize.iWidth) > surfaceWidth) { validRect = EFalse; } if ((aStartPos.iY + aSize.iHeight) > surfaceHeight) { validRect = EFalse; } // Starting position if ((aStartPos.iX < 0) || (aStartPos.iY < 0)) { validRect = EFalse; } if (!validRect) { User::Leave(KErrOverflow); } if (info.iPixelFormat == EUidPixelFormatRGB_565) { //2 bytes per pixel if ( info.iSize.iWidth*2>info.iStride) { User::Leave(KErrOverflow); } TInt offset; User::LeaveIfError(iManager.GetBufferOffset(aSurface, 0, offset)); TUint16* ptr = reinterpret_cast<TUint16*>(surfacePtr + offset); // Fill the rectangle TInt yPos = aStartPos.iY; TInt xPos = aStartPos.iX; for (TInt yy = 0; yy < aSize.iHeight; ++yy) { ptr = reinterpret_cast<TUint16*>(surfacePtr + (yPos*info.iStride)); for (TInt xx = 0; xx < aSize.iWidth; ++xx) { ptr[xPos] = color; xPos++; } xPos = aStartPos.iX; yPos++; } } else { if ( info.iSize.iWidth*4>info.iStride) { User::Leave(KErrOverflow); } TInt offset; User::LeaveIfError(iManager.GetBufferOffset(aSurface, 0, offset)); TUint32* ptr = reinterpret_cast<TUint32*>(surfacePtr + offset); // Fill the rectangle TInt yPos = aStartPos.iY; TInt xPos = aStartPos.iX; for (TInt yy = 0; yy < aSize.iHeight; ++yy) { ptr = reinterpret_cast<TUint32*>(surfacePtr+(yPos*info.iStride)); for (TInt xx = 0; xx < aSize.iWidth; ++xx) { ptr[xPos] = color; xPos++; } xPos = aStartPos.iX; yPos++; } } CleanupStack::PopAndDestroy(&chunk); }