diff -r 0659d0e1a03c -r 94f2adf59133 kerneltest/e32test/rm_debug/crashmonitor/t_crashmonitor.cpp --- a/kerneltest/e32test/rm_debug/crashmonitor/t_crashmonitor.cpp Wed Oct 20 13:58:28 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1066 +0,0 @@ -// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). -// All rights reserved. -// This component and the accompanying materials are made available -// under the terms of the License "Eclipse Public License v1.0" -// which accompanies this distribution, and is available -// at the URL "http://www.eclipse.org/legal/epl-v10.html". -// -// Initial Contributors: -// Nokia Corporation - initial contribution. -// -// Contributors: -// -// Description: -// Tests the functionality of the SCM Libraries -// -// - -#include "t_crashmonitor.h" - -#include - -using namespace Debug; - -/** - * Test suite version - */ -const TVersion testVersion(1,1,0); - - -/** - * Constructor - */ -CSCMLibraryClient::CSCMLibraryClient(): - iNonCachedWriter(iBuffer, EFalse), - iCachedWriter(iBuffer, EFalse), - iWriter(NULL), - iReader(iBuffer) - { - } - -/** - * First phase constructor - */ -CSCMLibraryClient* CSCMLibraryClient::NewL() - { - CSCMLibraryClient* self = new(ELeave) CSCMLibraryClient(); - self->ConstructL(); - return self; - } - -/** - * Destructor - */ -CSCMLibraryClient::~CSCMLibraryClient() - { - } - -/** - * ConstructL - */ -void CSCMLibraryClient::ConstructL() - {} - - - -/** - * Prints usage of this test suite - */ -void CSCMLibraryClient::PrintUsage() - { - test.Printf(_L("Invoke with arguments:\n")); - test.Printf(_L("-r: run specified tests in reverse order\n")); - test.Printf(_L("-h: display usage information\n")); - test.Printf(_L("-v: display version\n")); - test.Printf(_L(": test number to run, can specify more than one from the following list:\n")); - test.Printf(_L("Press any key for list...\n")); - test.Getch(); - // if there are too many of these they won't fit on the screen! Stick another Getch() in if there get too many - for(TInt i=0; i& aTests) - { - // get the length of the command line arguments - TInt argc = User::CommandLineLength(); - - // allocate a buffer for the command line arguments and extract the data to it - HBufC* commandLine = HBufC::NewLC(argc); - TPtr commandLineBuffer = commandLine->Des(); - User::CommandLine(commandLineBuffer); - - // reset mode - aMode = (TTestMode)0; - - // create a lexer and read through the command line - TLex lex(*commandLine); - while (!lex.Eos()) - { - // expecting the first character to be a '-' - if (lex.Get() == '-') - { - TChar arg = lex.Get(); - switch (arg) - { - case 'v': - //print out the help - aMode |= EModeVersion; - break; - case 'h': - //print out the help - aMode |= EModeHelp; - break; - case 'r': - //store the fact that we want to run in reverse - aMode |= EModeReverse; - break; - default: - // unknown argument so leave - User::Leave(KErrArgument); - } - } - else - { - lex.UnGet(); - TInt testNumber; - User::LeaveIfError(lex.Val(testNumber)); - if( (testNumber<0) || (testNumber>=KMaxTests) ) - { - User::Leave(KErrArgument); - } - aTests.AppendL(testNumber); - } - lex.SkipSpace(); - } - // if no tests specified then run them all - if(aTests.Count() == 0) - { - aMode |= EModeAll; - } - - // do clean up - CleanupStack::PopAndDestroy(commandLine); - } - -/** - * This will run all tests in the suite - */ -void CSCMLibraryClient::ClientAppL() - { - - FillArray(); - - test.Start(_L("ClientAppL")); - - RArray testsToRun; - TUint32 testMode = 0; - ParseCommandLineL(testMode, testsToRun); - - //if help or version mode specified then just print out the relevant stuff and quit - if((testMode & EModeHelp) || (testMode & EModeVersion)) - { - if(testMode & EModeHelp) - { - PrintUsage(); - } - if(testMode & EModeVersion) - { - PrintVersion(); - } - test.End(); - return; - } - - if(testMode & EModeAll) - { - for(TInt i=0; i>1); i++) - { - TInt temp = testsToRun[i]; - testsToRun[i] = testsToRun[numberOfTests - (i+1)]; - testsToRun[numberOfTests - (i+1)] = temp; - } - } - - HelpStartTestTimer(); - - // first run al tests with non cached writer - iWriter = &iNonCachedWriter; - for(TInt i=0; iClientAppL()); - __UHEAP_MARKEND; - - delete tester; - } - - delete trap; - return ret; - } - -/** - * Runs a given test identified by argument - * @param aTestNumber Test to run - */ -void CSCMLibraryClient::RunTest(TInt aTestNumber) - { - if( (aTestNumber<0) || (aTestNumber>=KMaxTests) ) - { - User::Panic(_L("Test number out of range"), aTestNumber); - } - __UHEAP_MARK; - - if(iTestArray[aTestNumber].iFunctionPtr) - { - test.Printf(_L("pre-run test %d"), aTestNumber); - (this->*(iTestArray[aTestNumber].iFunctionPtr))(); - test.Printf(_L("post-run test %d"), aTestNumber); - } - - __UHEAP_MARKEND; - } - -/** - * Prints the version of this test suite - */ -void CSCMLibraryClient::PrintVersion() - { - test.Printf(_L("\nt_crashmonitor_lib.exe\nVersion: %S\n"), &(testVersion.Name())); - test.Printf(_L("Press any key...\n")); - test.Getch(); - } -/** - * Reports performance metrics from all the tests - */ -void CSCMLibraryClient::ReportPerformance(void) - { - test.Printf(_L("\nPerformance\n")); - test.Printf(_L("========================\n")); - - - // Runtime - TInt ticks = HelpGetTestTicks(); -#ifndef __WINS__ - test (ticks != 0); -#endif - TInt nkTicksPerSecond = HelpTicksPerSecond(); - -#ifndef __WINS__ - test (nkTicksPerSecond != 0); -#endif - - test.Printf(_L("Total test runtime: %d seconds\n"),ticks/nkTicksPerSecond); - - test.Printf(_L("\n")); - } - -/** - * Returns the number of nanokernel ticks in one second - * @return Number of nanokernel ticks. 0 if unsuccesful - */ -TInt CSCMLibraryClient::HelpTicksPerSecond(void) - { - TInt nanokernel_tick_period; - HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); - - ASSERT(nanokernel_tick_period != 0); - - static const TInt KOneMillion = 1000000; - - return KOneMillion/nanokernel_tick_period; - } - -void CSCMLibraryClient::DoWrite(MByteStreamSerializable& aObjectToWrite, TInt aPosition) - { - if(iWriter == &iCachedWriter) - { - iCachedWriter.SetPosition(aPosition); - test(aObjectToWrite.Serialize(iCachedWriter) == KErrNone); - iCachedWriter.FlushCache(); - } - else if(iWriter == &iNonCachedWriter) - { - iNonCachedWriter.SetPosition(aPosition); - test(aObjectToWrite.Serialize(iNonCachedWriter) == KErrNone); - } - else - { - // no writer - test(EFalse); - } - } - -// BASE granted test id's 2364 to 2394 - -//--------------------------------------------- -// !@SYMTestCaseID KBASE-T_SCMLIB-2364 -//! @SYMTestType -//! @SYMPREQ PREQ1700 -//! @SYMTestCaseDesc Ensures we can serialise and deserialise the TScmChecksum structure -//! @SYMTestActions TScmChecksum serialized & then deserialized -//! @SYMTestExpectedResults TScmChecksum structure serialized / deserialized ok -//! @SYMTestPriority High -//! @SYMTestStatus Implemented -//--------------------------------------------- -void CSCMLibraryClient::TestCheckSum() - { - test.Next(_L("TestCheckSum\n")); - - TScmChecksum chksm1; - chksm1.Reset(); - - TInt blocksize1 = 123; - TInt blocksize2 = 166; - - TScmChecksum chksm2; - chksm2.Reset(); - - test(ChecksumHelper(chksm1, blocksize1, iBuffer, KBufLen)); - test(ChecksumHelper(chksm2, blocksize2, iBuffer, KBufLen)); - - test(chksm1 == chksm2); - - } - -TBool CSCMLibraryClient::ChecksumHelper(TScmChecksum& aChecksum, TUint aBlocksize, TUint8* aBuffer, TUint aBufferLen) - { - if( aBlocksize == 0 || aBufferLen == 0 ) - { - return EFalse; - } - - TInt remaining = aBufferLen; - TInt pos = 0; - - while(remaining > aBlocksize) - { - aChecksum.ChecksumBlock(aBuffer + pos, aBlocksize); - pos += aBlocksize; - remaining -= aBlocksize; - } - - aChecksum.ChecksumBlock(aBuffer + pos, remaining); - pos += remaining; - - return (pos == aBufferLen); - } - -//--------------------------------------------- -//! @SYMTestCaseID KBASE-T_SCMLIB-2365 -//! @SYMTestType -//! @SYMPREQ PREQ1700 -//! @SYMTestCaseDesc Ensures we can serialise and deserialise the TSCMLockData structure -//! @SYMTestActions TSCMLockData serialized & then deserialized -//! @SYMTestExpectedResults TSCMLockData structure serialized / deserialized ok -//! @SYMTestPriority High -//! @SYMTestStatus Implemented -//--------------------------------------------- -void CSCMLibraryClient::TestLockDataSerialization() - { - test.Next(_L("TestLockDataSerialization\n")); - - TSCMLockData lockData1; - - //Arbitrary values - lockData1.SetLockCount(10); - lockData1.SetMutexHoldCount(17); - lockData1.SetMutexThreadWaitCount(36); - - DoWrite(lockData1); - - iReader.SetPosition(0); - //Test deserialisation works - TSCMLockData lockData2; - test(lockData2.Deserialize(iReader) == KErrNone); - - //Test we got back the correct object - test(lockData1 == lockData2); - } - -//--------------------------------------------- -//! //! @SYMTestCaseID KBASE-T_SCMLIB-2366 -//! @SYMTestType -//! @SYMPREQ PREQ1700 -//! @SYMTestCaseDesc Ensures we can serialise and deserialise the TCrashOffsetsHeader structure -//! @SYMTestActions TCrashOffsetsHeader serialized & then deserialized -//! @SYMTestExpectedResults TCrashOffsetsHeader structure serialized / deserialized ok -//! @SYMTestPriority High -//! @SYMTestStatus Implemented -//--------------------------------------------- -void CSCMLibraryClient::TestOffsetsHeaderSerialization() - { - test.Next(_L("TestOffsetsHeaderSer ialization\n")); - - TCrashOffsetsHeader header1; - header1.iCTFullRegOffset = 123; - header1.iCTUsrStkOffset = 456; - header1.iCTSvrStkOffset = 789; - header1.iCPMetaOffset = 1001; - header1.iCTMetaOffset = 99; - header1.iCPCodeSegOffset = 1234; - header1.iSysUsrStkOffset = 3456; - header1.iSysSvrStkOffset = 255; - header1.iSysUsrRegOffset = 999; - header1.iSysSvrRegOffset = 2002; - header1.iTLstOffset = 3003; - header1.iPLstOffset = 4004; - header1.iSysCodeSegOffset = 5005; - header1.iExcStkOffset = 6006; - header1.iTraceOffset = 1233; - header1.iScmLocksOffset = 3421; - header1.iKernelHeapOffset = 89; - header1.iVarSpecInfOffset = 0; - header1.iRomInfoOffset = 123; - - DoWrite(header1); - - iReader.SetPosition(0); - TCrashOffsetsHeader header2; - - test(header2.Deserialize(iReader) == KErrNone); - - test(header2 == header1); - - } - -//--------------------------------------------- -//! @SYMTestCaseID KBASE-T_SCMLIB-2367 -//! @SYMTestType -//! @SYMPREQ PREQ1700 -//! @SYMTestCaseDesc Ensures we can serialise and deserialise the TCrashInfoHeader structure -//! @SYMTestActions TCrashInfoHeader serialized & then deserialized -//! @SYMTestExpectedResults TCrashInfoHeader structure serialized / deserialized ok -//! @SYMTestPriority High -//! @SYMTestStatus Implemented -//--------------------------------------------- -void CSCMLibraryClient::TestInfoHeaderSerialization() - { - test.Next(_L("TestInfoHeaderSerialization\n")); - - TCrashInfoHeader infoHeader1; - infoHeader1.iLogSize = 5000; - infoHeader1.iFlashAlign = 4; - infoHeader1.iCachedWriterSize = 16; - infoHeader1.iPid = 1001; - infoHeader1.iTid = 2002; - infoHeader1.iExitType = 90; - infoHeader1.iExitReason = 23; - infoHeader1.iExcCode = 8899; - infoHeader1.iCrashTime = 12345; - infoHeader1.iCrashId = 23; - infoHeader1.iFlashBlockSize = 256 * 1024; - infoHeader1.iFlashPartitionSize = 1024 * 1024; - - TVersion ver(21,43,54); - - infoHeader1.iSCMDataTypesVersion = ver; - - DoWrite(infoHeader1); - - iReader.SetPosition(0); - TCrashInfoHeader infoHeader2; - - test(infoHeader2.Deserialize(iReader) == KErrNone); - - test(infoHeader2 == infoHeader1); - - } - -//--------------------------------------------- -//! @SYMTestCaseID KBASE-T_SCMLIB-2368 -//! @SYMTestType -//! @SYMPREQ PREQ1700 -//! @SYMTestCaseDesc Ensures we can serialise and deserialise the TRawData structure -//! @SYMTestActions TRawData serialized & then deserialized -//! @SYMTestExpectedResults TRawData structure serialized / deserialized ok -//! @SYMTestPriority High -//! @SYMTestStatus Implemented -//--------------------------------------------- -void CSCMLibraryClient::TestRawData() - { - test.Next(_L("TestRawData\n")); - - const TInt KLen = 256; - - TUint8 data[KLen]; - - for(TInt i=0;i(data), KLen, KLen);; - - DoWrite(rawData1); - - TPtr8 p(iBuffer, KBufLen, KBufLen); - TCrashLogWalker walker(p); - TInt pos = 0; - TInt len = 0; - TRawData* rawData2 = walker.GetRawDataTypeL(pos, len, p, 0); - - CleanupStack::PushL(rawData2); - - test(rawData1.iLength == rawData2->iLength); - test(rawData1.iData.Compare(rawData2->iData) == 0); - - CleanupStack::PopAndDestroy(rawData2); - } - -//--------------------------------------------- -//! @SYMTestCaseID KBASE-T_SCMLIB-2369 -//! @SYMTestType -//! @SYMPREQ PREQ1700 -//! @SYMTestCaseDesc Ensures we can serialise and deserialise the TProcessData structure -//! @SYMTestActions TProcessData serialized & then deserialized -//! @SYMTestExpectedResults TProcessData structure serialized / deserialized ok -//! @SYMTestPriority High -//! @SYMTestStatus Implemented -//--------------------------------------------- -void CSCMLibraryClient::TestProcessData() - { - test.Next(_L("TestProcessData\n")); - - TProcessData procData1; - - procData1.iPriority = 99; - procData1.iPid = MAKE_TINT64(34567,12345); - - - procData1.iName.Zero(); - for(TInt i=0;i structure serialized / deserialized ok -//! @SYMTestPriority High -//! @SYMTestStatus Implemented -//--------------------------------------------- -void CSCMLibraryClient::TestSCMLockData() - { - - test.Next(_L("TestSCMLockData\n")); - - TSCMLockData ld1; - ld1.SetMutexHoldCount(3); - ld1.SetLockCount(4); - ld1.SetMutexThreadWaitCount(5); - - DoWrite(ld1); - - iReader.SetPosition(0); - TSCMLockData ld2; - test(ld2.Deserialize(iReader) == KErrNone); - - test(ld1.MutexHoldCount() == ld2.MutexHoldCount()); - test(ld1.MutexThreadWaitCount() == ld2.MutexThreadWaitCount()); - test(ld1.LockCount() == ld2.LockCount()); - test(ld1 == ld2); - test(!(ld1 != ld2)); - } - -//eof -