TInt E32Main()
	{
	//
	// For the tests to work we need SID policing enforced plus the specific
	// capabilities listed below.
	//
	// These are dependent on the capabilities set in the platform security
	// repository test initialisation file 87654321.txt.  If the content
	// of that file changes then the following clauses may need to be
	// updated.
	//
	if(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) ||
			!PlatSec::IsCapabilityEnforced(ECapabilityNetworkServices) ||
			!PlatSec::IsCapabilityEnforced(ECapabilityDRM) ||
			!PlatSec::IsCapabilityEnforced(ECapabilityLocalServices) ||
			!PlatSec::IsCapabilityEnforced(ECapabilityCommDD))
		{
		TheTest.Start(_L("NOTE: Skipping tests due to incompatible PlatSec enforcement settings"));
		TheTest.End();
		TheTest.Close();
		return 0;
		}

	__UHEAP_MARK;
	CTrapCleanup* cleanup = CTrapCleanup::New();
	if(!cleanup)
		return KErrNoMemory;

	TRAPD(err, MainL());
	if (err != KErrNone)
		User::Panic(_L("Testing failed: "), err);

	delete cleanup;
	__UHEAP_MARKEND;

	return 0;
	}
void DoRun()
	{
    RFs fs;
	TInt err = fs.Connect();
	TEST2(err, KErrNone);

	TheTest.Start(_L("  @SYMTestCaseID:SYSLIB-SQL-LEGACY-T_SQLENVDESTROY-0001 Delete secure databases from C: "));

	DoDeleteFile(fs, KDbCFileName1);
	DoDeleteFile(fs, KDbCFileName2);
	DoDeleteFile(fs, KDbCFileName3);
	DoDeleteFile(fs, KDbCFileName4);
	DoDeleteFile(fs, KDbCFileName5);

	DoDeleteFile(fs, KDb1);
	DoDeleteFile(fs, KDb2);
	DoDeleteFile(fs, KDb3);
	DoDeleteFile(fs, KDb4);
	DoDeleteFile(fs, KDb5);
	DoDeleteFile(fs, KDb6);
	DoDeleteFile(fs, KDb7);
	DoDeleteFile(fs, KDb8);

	TheTest.Printf(_L("====================================================\r\n"));
	PrintDiskUsage(fs, _L("c:\\"));
	TheTest.Printf(_L("====================================================\r\n"));
	
	//Remove the created subdir in the private datacage. 
	err = fs.RmDir(KPrivateSubDir);
	if(err != KErrNone && err != KErrNotFound)
		{
		TheTest.Printf(_L("Error %d deleting \"%S\" directory.\n"), err, &KPrivateSubDir);
		}
	
	fs.Close();
	}
void TTestMsBlock::tLastLbaAccessL()
    {
    test.Start(_L("tLastLbaAccess\n"));
    test.Next(_L("tLastLbaAccess\n"));

    TInt driveNumber = msDrive->DriveNumber();

    TVolumeInfo volInfo;
    TInt err = fsSession.Volume(volInfo);
    test(err == KErrNone);

    test.Printf(_L("Memory 'in use' = 0x%lx (0x%x)\n"),
                (volInfo.iSize - volInfo.iFree), (volInfo.iSize - volInfo.iFree)/KBlockSize);
    test.Printf(_L("volInfo.iSize   = 0x%lx (0x%x)\n"),
                volInfo.iSize, volInfo.iSize/KBlockSize);
    test.Printf(_L("volInfo.iFree   = 0x%lx (0x%x)\n"),
                volInfo.iFree, volInfo.iFree/KBlockSize);

    TLba lba = volInfo.iSize/KBlockSize;
    RBlockTargetMedia media(driveNumber);
    media.OpenL();

    TInt writeRes = KErrNone;
    TInt readRes = KErrNone;
    test.Printf(_L("LBA=%x\n"), lba);
    for (;writeRes == KErrNone && readRes == KErrNone; lba++)
        {
        writeRes = media.WriteBlock(lba);
        readRes = media.ReadBlock(lba);
        }

    test.Printf(_L("LBA=%x ERR Write=%d Read=%d\n"), lba, writeRes, readRes);

    media.Close();
    test.End();
    }
TInt E32Main()
	{

	__UHEAP_MARK;
	test.Title();
	test.Start(_L("initialising"));

	CTrapCleanup* c=CTrapCleanup::New();

	// start the loader
	RFs fs;
	test (fs.Connect()==KErrNone);
	fs.Close();

	test (c!=0);
	TRAPD(r,MainL());
	test (r==KErrNone);
	delete c;
	test.End();
	test.Close();
	__UHEAP_MARKEND;

	return KErrNone;
	}
void TestCL(RTest& test, CSdpDatabase *aDb)
	{
	test.Start(_L("Test C -- continuation stress test"));

	gSdpTestDatabase = aDb;
	gSdpTestDatabase->EncodeDbL();

	sdp_debug_level = 1;  // wind the noise down - this works
	test.Printf(_L("SS for KSdpContTestUUID\n"));
	TUint8 requestdata00a[] = {
		0x35, 0x03, 0x19, 0x01, 0x00,	// UUID list
		0xff, 0xff,						// max handles
		0x00							// continuation
		};

	TUint tCount = testSdpContL(test, requestdata00a, sizeof(requestdata00a), KServiceSearchRequest, /*TUint8* aRespData,*/ DUMMTU);
	test.Printf(_L("SS for KSdpContTestUUID %d continuations\n"), tCount);
	test.Getch();

	test.Printf(_L("AR for all attributes\n"));
	TUint8 requestdata01[] = {
		0x00, 0x00, 0x00, 0x00,			// handle
		0x01, 0x00,						// max bytes
		0x35, 0x05,						// DES header attrib list
		0x0a, 0x00, 0x00, 0xff, 0xff,	// attribute ID range 0000 to ffff
		0x00							// continuation
		};
	tCount = testSdpContL(test, requestdata01, sizeof(requestdata01), KAttributeRequest, /*TUint8* aRespData,*/ DUMMTU);
	test.Printf(_L("AR for all attributes, handle 00000000 %d continuations\n"), tCount);
	test.Getch();

	test.Printf(_L("AR for all attributes\n"));
	TUint8 requestdata02[] = {
		0x00, 0x01, 0x00, 0x00,			// handle
		0x01, 0x00,						// max bytes
		0x35, 0x05,						// DES header attrib list
		0x0a, 0x00, 0x00, 0xff, 0xff,	// attribute ID range 0000 to ffff
		0x00							// continuation
		};
	tCount = testSdpContL(test, requestdata02, sizeof(requestdata02), KAttributeRequest, /*TUint8* aRespData,*/ DUMMTU);
	test.Printf(_L("AR for all attributes, handle 00010000 %d continuations\n"), tCount);
	test.Getch();

	test.Printf(_L("AR for attribute 0004\n"));
	TUint8 requestdata03[] = {
		0x00, 0x01, 0x00, 0x00,			// handle
		0x01, 0x00,						// max bytes
		0x35, 0x03,						// DES header attrib list
		0x09, 0x00, 0x04,				// attribute ID 0004
		0x00							// continuation
		};
	tCount = testSdpContL(test, requestdata03, sizeof(requestdata03), KAttributeRequest, /*TUint8* aRespData,*/ DUMMTU);
	test.Printf(_L("AR for attribute 0004, handle 00010000 %d continuations\n"), tCount);
	test.Getch();

	test.Printf(_L("AR for all attributes\n"));
	TUint8 requestdata04[] = {
		0x00, 0x01, 0x00, 0x03e,		// handle
		0x01, 0x00,						// max bytes
		0x35, 0x05,						// DES header attrib list
		0x0a, 0x00, 0x00, 0xff, 0xff,	// attribute ID range 0000 to ffff
		0x00							// continuation
		};
	tCount = testSdpContL(test, requestdata04, sizeof(requestdata04), KAttributeRequest, /*TUint8* aRespData,*/ DUMMTU);
	test.Printf(_L("AR for all attributes, handle 0001003e %d continuations\n"), tCount);
	test.Getch();

	sdp_debug_level = 5;

	test.Printf(_L("SAS for all attributes\n"));
	TUint8 requestdata05[] = {
		0x35, 0x03, 0x19, 0x01, 0x00,	// UUID list
		0x01, 0x00,						// max byte count
		0x35, 0x05,						// DES header attrib list
		0x0a, 0x00, 0x00, 0xff, 0xff,	// attribute ID range 0000 to ffff
		0x00							// continuation
		};
	tCount = testSdpContL(test, requestdata05, sizeof(requestdata05), KServiceAttSearchRequest, /*TUint8* aRespData,*/ DUMMTU);
//	tCount = testSdpCont(test, requestdata05, sizeof(requestdata05), KServiceAttSearchRequest, /*TUint8* aRespData,*/ 102);
	test.Printf(_L("SAS for all attributes, %d continuations\n"), tCount);
	test.Getch();
	
//	CleanupStack::PopAndDestroy(/*CSdpReqHandler*/);
	delete gSdpTestDatabase;
	gSdpTestDatabase = 0;
	test.End();
	}
void TCallbackRecord::SelfTest()
	{
	test.Start(_L("SelfTest of TCallbackRecord"));

	test.Next(_L("create default TCallbackRecord record, record2"));
	TCallbackRecord record;
	const TCallbackRecord record2;
	if(gVerboseOutput)
	{
	test.Next(_L("Print record"));
	record.Print();
	}

	test.Next(_L("test (record == record2)"));
	if(!(record == record2))
		{
		if(gVerboseOutput)
			{
			record2.Print();
			}
		TEST_FAULT;
		}

	//A series of callback masks
	//Note these combinations do not necessarily represent
	//possible callback combinations
	TUint callbacks[]  =
		{
		EDmaCallbackDescriptorCompletion,
		EDmaCallbackDescriptorCompletion,
		EDmaCallbackDescriptorCompletion,
		EDmaCallbackDescriptorCompletion,
		EDmaCallbackFrameCompletion_Src,
		EDmaCallbackFrameCompletion_Dst,
		EDmaCallbackDescriptorCompletion_Src | EDmaCallbackDescriptorCompletion_Dst,
		EDmaCallbackDescriptorCompletion_Src | EDmaCallbackFrameCompletion_Src | EDmaCallbackLinkedListPaused_Dst,
		EDmaCallbackRequestCompletion | EDmaCallbackRequestCompletion_Src,
		EDmaCallbackDescriptorCompletion_Dst
		};
	test.Next(_L("Feed a series of callback masks in to record"));
	const TInt length = ARRAY_LENGTH(callbacks);
	for(TInt i = 0; i < length; i++)
		{
		record.ProcessCallback(callbacks[i], EDmaResultOK);
		}
	
	if(gVerboseOutput)
	{
	test.Next(_L("Print record"));
	record.Print();
	}

	test.Next(_L("test GetCount"));
	test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion));
	test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion_Src));
	test_Equal(0, record.GetCount(EDmaCallbackRequestCompletion_Dst));
	test_Equal(4, record.GetCount(EDmaCallbackDescriptorCompletion));
	test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Src));
	test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Dst));
	test_Equal(0, record.GetCount(EDmaCallbackFrameCompletion));
	test_Equal(2, record.GetCount(EDmaCallbackFrameCompletion_Src));
	test_Equal(1, record.GetCount(EDmaCallbackFrameCompletion_Dst));
	test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused));
	test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused_Src));
	test_Equal(1, record.GetCount(EDmaCallbackLinkedListPaused_Dst));

	test.Next(_L("test expected == record"));
	const TCallbackRecord expected(TCallbackRecord::EThread, 1, 1, 0, 4, 2, 2, 0, 2, 1, 0, 0, 1);
	if(!(expected == record))
		{
		if(gVerboseOutput)
			{
			expected.Print();
			}
		TEST_FAULT;
		}

	test.Next(_L("modify record: test expected != record"));
	record.SetCount(EDmaCallbackFrameCompletion, 10);
	if(expected == record)
		{
		if(gVerboseOutput)
			{
			expected.Print();
			}
		TEST_FAULT;
		}

	test.Next(_L("test Reset()"));
	record.Reset();
	test(record == record2);

	test.End();
	}
TInt E32Main()

	{

	test.Title();



	test.Start(_L("Test retrieving 0th ordinal and therefore named symbol export data"));

	

	E32EmulExpSymInfoHdr tmpHdr;

	E32EmulExpSymInfoHdr *readHdr;

	RLibrary library;



	// The values for the header of the dll with a 0th ordinal

	tmpHdr.iSymCount = 0x0;

	tmpHdr.iDllCount = 0x3;

	test(library.Load(_L("t_oedll.dll")) == KErrNone);

	test.Next(_L("Attempt to retrieve named symbol data from t_oedll.dll"));

	readHdr = (E32EmulExpSymInfoHdr*)library.Lookup(0);

	test(readHdr!=NULL);

//#define PRINT_ZEROTH

#ifdef PRINT_ZEROTH

	test.Printf(_L("iSymCount=%08x;iDllCounts=%08x\n"),readHdr->iSymCount,readHdr->iDllCount);

#endif

	test.Next(_L("Verify export data of t_oedll.dll is that expected"));

	VerifyHdr(tmpHdr, *readHdr);

	library.Close();



	test.Next(_L("Verify lookup on dll without oe export data returns NULL"));

	test(library.Load(_L("t_dll1.dll")) == KErrNone);

	readHdr = (E32EmulExpSymInfoHdr*)library.Lookup(0);

	test(readHdr == NULL);

	library.Close();



	// The values for the header of the exe of the current process with a 0th ordinal

	tmpHdr.iSymCount = 0x3;

	tmpHdr.iDllCount = 0x5;

	test.Next(_L("Attempt to retrieve named symbol data from current process"));

	readHdr = (E32EmulExpSymInfoHdr*)(RProcess::ExeExportData());

	test(readHdr!=NULL);

	test.Next(_L("Verify export data 0th ordinal data of this exe is that expected"));

#ifdef PRINT_ZEROTH

	test.Printf(_L("iSymCount=%08x;iDllCounts=%08x;\n"),readHdr->iSymCount,readHdr->iDllCount);

#endif

	VerifyHdr(tmpHdr, *readHdr);



/*

On Emulator can't examine fixups & depdencies via export data as data not included

in E32EmulExpSymInfoHdr.  This is all handled by the MS loader.



*/

	test.End();

	return KErrNone;

	}
static void MainL()
	{
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIBS-LOGENG-LEGACY-T_LOGSECURITY-0001 OOM test "));
	::OOMTest();
	}
GLDEF_C TInt E32Main()
//
// Test NanoWait() delays
//
    {

    
    // To use in command line
    	TBool pause = EFalse;
    TBuf<256> cmdline;
	User::CommandLine(cmdline);
	if( cmdline == _L("-p"))
		{
			pause = ETrue;			
		}

    
	test.Title();

	test.Start(_L("Load D_NanoWait.LDD"));
	TInt r=User::LoadLogicalDevice(KLddFileName);
	TEST(r==KErrNone || r==KErrAlreadyExists);
	
	test.Next(_L("Test NanoWait delay"));
	r=nanowait.Open();
	CHECK(r);

	TInt requested = 100000000;  // nsec = 100 msec
	TUint32 startTick;
	TUint32 endTick;
	
	TInt nanokernel_tick_period;
	HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period );
	nanokernel_tick_period *= 1000; 	// convert from micro sec to nsec

	
	test.Printf(_L("Test parameters: total requested:%d nsec\n"), requested);
	
	startTick = User::NTickCount();
	r=nanowait.StartNanoWait(1, requested);
	endTick = User::NTickCount();
	
	startTick *= nanokernel_tick_period;	// in nsec
	endTick   *= nanokernel_tick_period;	// in nsec
	
	TInt measured  = endTick-startTick;
	TInt diff = measured - requested;
	test.Printf(_L("Requested delay:%10d nsec\n"), requested);
	test.Printf(_L("Measured delay :%10d nsec\n"), measured);
	test.Printf(_L("Difference     :%10d nsec\n"), diff);
	
	
	test.End();
	if( pause )
		{
		test.Printf(_L("Press any key\n"));
		test.Getch();	
		}
	
	return(KErrNone);
    }
Exemple #10
0
TInt E32Main()
//
//
//
	{

	CMyActiveScheduler* s=NULL;
	TRAPD(ret,s=CMyActiveScheduler::NewL())
	test(ret==KErrNone);

	CActiveScheduler::Install(s);
	test.Title();
	test.Start(_L("Timer"));
	
	__KHEAP_MARK;

	TTimeIntervalMicroSeconds32 tickPeriod;
	UserHal::TickPeriod(tickPeriod);

	TRAP(ret,theTimer=CDeltaTimer::NewL(100, tickPeriod.Int()));
	test(ret==KErrNone);

	Mem::FillZ(theResults,10*sizeof(TInt));

	TCallBack callBacks[10]=
		{
		/* 0 */ TCallBack(print,(TAny*)0),
		/* 1 */ TCallBack(cancelNext,(TAny*)1),
		/* 2 */ TCallBack(print,(TAny*)2),	// Gets cancelled
		/* 3 */ TCallBack(print,(TAny*)3),		// Runs twice
		/* 4 */ TCallBack(requeuePrevious,(TAny*)4),
		/* 5 */ TCallBack(cancel2ndFollowing,(TAny*)5),
		/* 6 */ TCallBack(print,(TAny*)6),
		/* 7 */ TCallBack(cancelNext,(TAny*)7),	// Gets cancelled
		/* 8 */ TCallBack(requeue,(TAny*)8),	// Runs twice, once on the same RunL as the stop
		/* 9 */ TCallBack(stop,(TAny*)9),
		};

	theCallBacks=callBacks;
	for (TInt i=0;i<10;i++)
		TheTimers[i].Set(theCallBacks[i]);

	const TInt K13Ticks = 13 * tickPeriod.Int();

	theTimer->Queue(K13Ticks,TheTimers[0]);
	theTimer->Queue(2*K13Ticks,TheTimers[1]);
	theTimer->Queue(3*K13Ticks,TheTimers[2]);
	theTimer->Queue(4*K13Ticks,TheTimers[3]);
	theTimer->Queue(5*K13Ticks,TheTimers[4]);
	theTimer->Queue(6*K13Ticks,TheTimers[5]);
	theTimer->Queue(7*K13Ticks,TheTimers[6]);
	theTimer->Queue(8*K13Ticks,TheTimers[7]);
	theTimer->Queue(9*K13Ticks,TheTimers[8]);
	theTimer->Queue(10*K13Ticks,TheTimers[9]);

	CActiveScheduler::Start();

	test(theResults[0]==1);
	test(theResults[1]==1);
	test(theResults[2]==0);
	test(theResults[3]==2);
	test(theResults[4]==1);
	test(theResults[5]==1);
	test(theResults[6]==1);
	test(theResults[7]==0);
	test(theResults[8]==2);
	test(theResults[9]==1);

	delete theTimer;

	__KHEAP_MARKEND;

	test.End();
	return 0;
	}
/**
@SYMTestCaseID 	 SYSLIB-CENTRALREPOSITORY-CT-3342
@SYMTestCaseDesc Restore factory Settings from merged repository.
@SYMTestPriority High
@SYMTestActions  Ensure that the repository file  exists in both the Rom and install
					directories.
				 Open the repository and modify a setting.  Force RFS
				 and check that the repository is restored against the merged repository
@SYMTestExpectedResults The test repository should be reset against the merged repository
@SYMDEF 		 PDEF099108
*/
LOCAL_C void RFSRomAndInstallL()
	{

	//restore all test files - this ensures we have a c: and z: file
	//for the test repository which causes a repository merge
	RestoreRFSTestFilesL(ERomAndInstall);

	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3342 ResetAllRepositoriesTestL "));
	TInt r;
	TReal realVal;
	TBuf<20> strVal;

	TheTest.Next(_L("Open repository to ensure server is running"));
	CRepository* repository = CRepository::NewLC(KUidRfsRepository);

	TheTest.Next(_L("Modify a Setting"));
	r = repository->Set(KReal1, KReal1_UpdatedValue);
	TEST2(r, KErrNone);

	//verify the update
	r = repository->Get(KReal1, realVal);
	TEST2(r, KErrNone);
	TEST(realVal == KReal1_UpdatedValue);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	//Kill the server
	TheTest.Next(_L("Kill the server process"));
	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
	r = KillProcess(KCentralRepositoryServerName);
	TEST2(r,KErrNone);

	User::After(KGeneralDelay);

	//Restart the server in soft reset mode to force a
	//repository reset
	TheTest.Next(_L("Manually start central respository"));
	ReStartServerInSoftResetMode();

	//Open the repository
	repository = CRepository::NewLC(KUidRfsRepository);

	//Verify that the string value, which is only found in the ROM file is
	//present in the merged repository
	r = repository->Get(KString1, strVal);
	TEST2(r, KErrNone);
	TEST(strVal==KString1_InitialValue);

	//verify that the Real value has been reset against the value in the install
	//repository file
	TheTest.Next(_L("Get 'Modified' value"));
	r = repository->Get(KReal1, realVal);
	TEST2(r, KErrNone);
	TEST(realVal == KReal1_InstallValue);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	TheTest.End();
	}
/**
@SYMTestCaseID 	 SYSLIB-CENTRALREPOSITORY-CT-3341
@SYMTestCaseDesc Restore factory Settings from Rom file.
@SYMTestPriority High
@SYMTestActions  Ensure that the repository file only exists on the Rom.
				 Open the repository and modify a setting.  Force RFS
				 and check that the repository is restored against the ROM file
@SYMTestExpectedResults The test repository should be reset against the ROM file
@SYMDEF 		 PDEF099108
*/
LOCAL_C void RFSRomOnlyL()
	{

	//restore all test files - this ensures we have a repository file
	//only on the z:
	RestoreRFSTestFilesL(ERomOnly);

	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3341 ResetAllRepositoriesTestL "));
	TInt r, intVal;
	TReal realVal;

	TheTest.Next(_L("Open repository to ensure server is running"));
	CRepository* repository = CRepository::NewLC(KUidRfsRepository);

	TheTest.Next(_L("Modify a Setting"));
	r = repository->Set(KInt1, KInt1_UpdatedValue);
	TEST2(r, KErrNone);

	//verify the update
	r = repository->Get(KInt1, intVal);
	TEST2(r, KErrNone);
	TEST(intVal == KInt1_UpdatedValue);

	TheTest.Next(_L("Modify a Setting"));
	r = repository->Set(KReal1, KReal1_UpdatedValue);
	TEST2(r, KErrNone);

	//verify the update
	r = repository->Get(KReal1, realVal);
	TEST2(r, KErrNone);
	TEST(realVal == KReal1_UpdatedValue);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	//Kill the server
	TheTest.Next(_L("Kill the server process"));
	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
	r = KillProcess(KCentralRepositoryServerName);
	TEST2(r,KErrNone);

	User::After(KGeneralDelay);

	//Restart the server in soft reset mode to force a
	//repository reset
	TheTest.Next(_L("Manually start central respository"));
	ReStartServerInSoftResetMode();

	//Open the repository
	repository = CRepository::NewLC(KUidRfsRepository);

	//Verify that the real value is reset against the value in the Rom version of
	//the repository file
	TheTest.Next(_L("Get 'Modified' value"));
	r = repository->Get(KReal1, realVal);
	TEST2(r, KErrNone);
	TEST(realVal == KReal1_InitialValue);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	TheTest.End();
	}
LOCAL_C void RestoreFactorySettingsTestL()
	{
	TheTest.Start(_L("ResetAllRepositoriesTestL"));
	TInt r;
	TInt i;
	TBuf<20> str;

	TheTest.Next(_L("Open repository to ensure server is running"));
	CRepository* repository = CRepository::NewLC(KUidRfsRepository);

	TheTest.Next(_L("Add a Setting"));
	const TInt KIntValue = 1234;
	r = repository->Create(KNewInt, KIntValue);
	TEST2(r, KErrNone);

	TheTest.Next(_L("Delete a Setting"));
	r = repository->Delete(KReal1);
	TEST2(r, KErrNone);

	TheTest.Next(_L("Modify a Setting"));
	r = repository->Set(KInt1, KInt1_UpdatedValue);
	TEST2(r, KErrNone);

	TheTest.Next(_L("Modify a String Setting"));
	r = repository->Set(KString1, KString1_UpdatedValue);

	TEST2(r, KErrNone);
	// Close repository
	CleanupStack::PopAndDestroy(repository);

	TheTest.Next(_L("Kill the server process"));
	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
	r = KillProcess(KCentralRepositoryServerName);
	TEST2(r,KErrNone);

	User::After(KGeneralDelay);

	TheTest.Next(_L("Manually start central respository"));
	ReStartServerInSoftResetMode();

	TheTest.Next(_L("Re-create the repository to ensure server is running"));
	repository = CRepository::NewLC(KUidRfsRepository);

	TheTest.Next(_L("Get 'Added' value"));
	r = repository->Get(KNewInt, i);
	TEST2(r, KErrNone);

	TReal real;
	TheTest.Next(_L("Get 'Deleted' value"));
	r = repository->Get(KReal1, real);
	TEST2(r, KErrNone);
	TEST(real == KReal1_InitialValue);

	TheTest.Next(_L("Get 'Modified' value"));
	r = repository->Get(KInt1, i);
	TEST2(r, KErrNone);
	TEST(i == KInt1_UpdatedValue);

	r = repository->Get(KString1, str);
	TEST2(r, KErrNone);
	TEST(str==KString1_InitialValue);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	TheTest.End();
	}
void TTestMsBlock::tRawAccessL()
    {
    test.Start(_L("tRawAccess\n"));

    // Head
    const TPos KPos_H = (KBlockSize * 5) + 0x7;
    const TUint KLen_H = 0x123;

    // Head + Tail
    const TPos KPos_HT = (KBlockSize * 7) + 0x180;
    const TUint KLen_HT = 0x100;

    // Head + Body + Tail
    const TPos KPos_HBT = (KBlockSize * 9) + 0x190;
    const TUint KLen_HBT = (KBlockSize * 4) + 0x110;


    test.Next(_L("Create Test drive\n"));
    TInt driveNumber = msDrive->DriveNumber();
    CBlockDeviceTester* blockDeviceTester = CBlockDeviceTester::NewL(driveNumber);

    test.Next(_L("Verify Test area on drive\n"));
    TInt res = blockDeviceTester->VerifyDrive();
    test_KErrNone(res);


    TPos pos = KPos_H;
    TUint len = KLen_H;
    test.Next(_L("Test head access\n"));
    test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len);
    res = blockDeviceTester->Update(pos, len);
    test_KErrNone(res);
    res = blockDeviceTester->Verify(pos, len);
    test_KErrNone(res);
    res = blockDeviceTester->VerifyDrive();
    test_KErrNone(res);

    pos = KPos_HT;
    len = KLen_HT;
    test.Next(_L("Test head + tail access\n"));
    test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len);
    res = blockDeviceTester->Update(pos, len);
    test_KErrNone(res);
    res = blockDeviceTester->Verify(pos, len);
    test_KErrNone(res);
    res = blockDeviceTester->VerifyDrive();
    test_KErrNone(res);

    pos = KPos_HBT;
    len = KLen_HBT;
    test.Next(_L("Test head + body+ tail access\n"));
    test.Printf(_L("Pos=0x%lx Len=0x%x\n"), pos, len);
    res = blockDeviceTester->Update(pos, len);
    test_KErrNone(res);
    res = blockDeviceTester->Verify(pos, len);
    test_KErrNone(res);
    res = blockDeviceTester->VerifyDrive();
    test_KErrNone(res);

    delete blockDeviceTester;
    test.End();
    }
void DoTestsL()
	{
	TheTest.Start(_L("SQL OOM tests - 1"));
	DbOomTestsL(ENonSecureDb);
	}
LOCAL_C void RunTestsL()
	{
	test.Title();

	test.Start(_L("Unziping test xml files"));

	RFs fs;
	User::LeaveIfError(fs.Connect());
	CleanupClosePushL(fs);

	CUnzip* unzip = CUnzip::NewLC(fs, KZipTestFile);
	unzip->ExtractL(KXmlTestDir);
	CleanupStack::PopAndDestroy(unzip);

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3734 Basic XML parsing test "));
	BasicParsingTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3735 DEF056122 descriptors greater than 2048 (Expat internal buffer size) "));
	DEF056122L();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3736 DEF051379 parsing encoded characters "));
	DEF051379L();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-1598 INC073797: Stack crashes sometimes in XML parsing in 3.0 platform "));
	INC073797();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3737 Reset mechanism "));
	ResetTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3738 Leave from callback "));
	CallbackLeaveTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3739 Invalid XML handling "));
	InvalidXmlTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3740 Namespace testing "));
	NamespaceTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3741 Skipped entity test "));
	SkippedEntityTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3742 Parser features test "));
	ParserFeatureTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-1578 INC073582: SS31 Symbian XML Framework - Symbian SAX Plugin is not returned by default "));
	INC073582L();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3743 "));
	ExpatTestL();

	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3744 Out-of-Memory testing "));
	OomTest(CallbackLeaveTestL);
	OomTest(InvalidXmlTestL);
	OomTest(NamespaceTestL);
	OomTest(SkippedEntityTestL);
	test.Next(_L(" @SYMTestCaseID:SYSLIB-XML-CT-3745 Two-parser test "));
	TwoParserTestL();


	test.Next(_L("Finished."));

	test.End();

	test.Close();

	CleanupStack::PopAndDestroy(&fs);

	REComSession::FinalClose();
	}
void DoTestsL()
    {
    TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4108 RFeatureControl platsec test"));
    FeatureControlPlatSecTest();
    }
/**
@SYMTestCaseID			SYSLIB-CENTRALREPOSITORY-CT-3435
@SYMTestCaseDesc		PDEF105203: Start-up Settings: New access point remains after restoring factory setting
@SYMTestPriority		High
@SYMTestActions			Create a new setting inside a range with range meta RFS bit set, create another setting
						outside the range, restart server in RFS mode, check to see the setting created outside
						the range still exists, check to see the setting created inside the range has been deleted.
						Repeat same steps with another repository which has default meta having RFS on and range meta
						having RFS off, check to see the setting created outside the range has been deleted, check to
						see the setting created inside the range still exists.
@SYMTestExpectedResults Test must not fail
@SYMDEF					PDEF105203
*/
LOCAL_C void PDEF105203()
	{
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3435 PDEF105203: Start-up Settings: New access point remains after restoring factory setting "));
	TInt r;
	TInt i;

	TheTest.Next(_L("Open repository to ensure server is running"));
	CRepository* repository = CRepository::NewLC(KUidRfsRepository);

	TheTest.Next(_L("Create a new setting outside RFSable range meta area"));
	const TInt KIntValue = 999;
	r = repository->Create(KNewInt2, KIntValue);
	TEST2(r, KErrNone);

	TheTest.Next(_L("Create a new setting in RFSable range meta area"));
	r = repository->Create(KNewInt3, KIntValue);
	TEST2(r, KErrNone);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	TheTest.Next(_L("Kill the server process"));
	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
	r = KillProcess(KCentralRepositoryServerName);
	TEST2(r,KErrNone);

	User::After(KGeneralDelay);

	TheTest.Next(_L("Manually start central respository"));
	ReStartServerInSoftResetMode();

	TheTest.Next(_L("Re-create the repository to ensure server is running"));
	repository = CRepository::NewLC(KUidRfsRepository);

	TheTest.Next(_L("Get 'created' value outside range meta"));
	r = repository->Get(KNewInt2, i);
	TEST2(r, KErrNone); // should still exist
	TEST(i == KIntValue);

	TheTest.Next(_L("Get 'created' value inside range meta"));
	r = repository->Get(KNewInt3, i);
	TEST2(r, KErrNotFound); // should have been deleted

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	repository = CRepository::NewLC(KUidRfsRepositoryDefaultRfsOn);

	TheTest.Next(_L("Create a new setting in RFSable default meta area"));
	const TInt KIntValue2 = 990;
	r = repository->Create(KNewInt2, KIntValue2);
	TEST2(r, KErrNone);

	TheTest.Next(_L("Create a new setting in non-RFSable range meta area"));
	r = repository->Create(KNewInt3, KIntValue2);
	TEST2(r, KErrNone);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	TheTest.Next(_L("Kill the server process"));
	r = KillProcess(KCentralRepositoryServerName);
	TEST2(r,KErrNone);

	User::After(KGeneralDelay);

	TheTest.Next(_L("Manually start central respository"));
	ReStartServerInSoftResetMode();

	TheTest.Next(_L("Re-create the repository to ensure server is running"));
	repository = CRepository::NewLC(KUidRfsRepositoryDefaultRfsOn);

	TheTest.Next(_L("Get 'created' value outside range meta"));
	r = repository->Get(KNewInt2, i);
	TEST2(r, KErrNotFound); // should have been deleted

	TheTest.Next(_L("Get 'created' value inside range meta"));
	r = repository->Get(KNewInt3, i);
	TEST2(r, KErrNone); // should still exist
	TEST(i == KIntValue2);

	// Close repository
	CleanupStack::PopAndDestroy(repository);

	TheTest.End();
	}
GLDEF_C TInt E32Main()

    {
	__UHEAP_MARK;

	Test.Title();

	TInt r;
	Test.Start(_L("Load sound PDD"));
	r=User::LoadPhysicalDevice(KSndPddFileName);
	if (r==KErrNotFound)
		{
		Test.Printf(_L("Shared chunk sound driver not supported - test skipped\r\n"));
		Test.End();
		Test.Close();
		__UHEAP_MARKEND;
		return(KErrNone);
		}
	Test(r==KErrNone || r==KErrAlreadyExists);
	
	Test.Next(_L("Load sound LDD"));
	r=User::LoadLogicalDevice(KSndLddFileName);
	Test(r==KErrNone || r==KErrAlreadyExists);
	
	/**	@SYMTestCaseID 		PBASE-T_SOUNDMCHAN-224
	@SYMTestCaseDesc 		Opening the channel - more than one channel
	@SYMTestPriority 		Critical
	@SYMTestActions			1)	With the LDD and PDD installed and with all channels closed on the device, 
								open a channel for playback on the device. 
							2)	Without closing the first playback channel, attempt to open a second channel 
								for playback on the same device. 
	@SYMTestExpectedResults	1)	KErrNone - Channel opens successfully. 
							2)	Should fail with KErrInUse.
	@SYMREQ					PREQ1073.4 */	
	
	__KHEAP_MARK;

	Test.Next(_L("Open a channel on the play device"));
	RSoundSc snddev;
	r=snddev.Open(KSoundScTxUnit0);
	Test(r==KErrNone);
	
	Test.Next(_L("Try opening the same unit a second time."));
	RSoundSc snddev2;
	r=snddev2.Open(KSoundScTxUnit0);
	Test(r==KErrInUse);
	
	Test.Next(_L("Query play formats supported"));
	TSoundFormatsSupportedV02Buf capsBuf;
	snddev.Caps(capsBuf);
	TSoundFormatsSupportedV02& caps=capsBuf();
	PrintCaps(caps,Test);
	
	Test.Next(_L("Try playing without setting the buffer config"));
	TRequestStatus pStat;
	snddev.PlayData(pStat,0,0x2000);	// 8K
	User::WaitForRequest(pStat);
	Test(pStat.Int()==KErrNotReady);

	Test.Next(_L("Configure the channel from a 2nd thread"));
	RThread thread;
	TRequestStatus tStat;
	SSecondaryThreadInfo sti;
	
	sti.iTestId=ESecThreadConfigPlayback;
	sti.iThreadId=RThread().Id();	// Get the ID of this thread
	sti.iDrvHandle=snddev.Handle();	// Pass the channel handle
	
	/**	@SYMTestCaseID 		PBASE-T_SOUNDMCHAN-225
	@SYMTestCaseDesc 		Opening the channel - sharing the handle between threads
	@SYMTestPriority 		Critical
	@SYMTestActions			1)	With the LDD and PDD installed and with all channels closed on the device, open a 
								channel for playback on the device. Now create a second thread. Resume this 
								thread - passing the handle to the playback channel to it. Wait for the second 
								thread to terminate.
							2)	In the second thread, duplicate the playback channel handle.
							3)	In the second thread, using the duplicated handle, issue a request to set the audio configuration. 
							4)	In the second thread, using the duplicated handle, issue a request to set the volume. 
							5)	In the second thread, close the handle and exit the thread.
							6)	In the first thread, read back the audio configuration.
							7)	In the first thread, set the buffer configuration, and then issue a request to play 
								audio data. 
							8)	In the first thread, close the channel. 
	@SYMTestExpectedResults	1)	KErrNone - Channel opens successfully. 
							2)	KErrNone - Duplication of the handle succeeds.
							3)	KErrNone - Audio configured successfully.
							4)	KErrNone - Volume set successfully.
							5)	No errors occur closing the channel and exiting the thread.
							6)	The audio configuration should correspond to that set by the second thread.
							7)	KErrNone - Setting the buffer configuration and issuing a play request.
							8)	No errors occur closing the channel.
	@SYMREQ					PREQ1073.4 */	
	
	r=thread.Create(_L("Thread"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
	Test(r==KErrNone);
	thread.Logon(tStat);
	thread.Resume();
	User::WaitForRequest(tStat);
	Test(tStat.Int()==KErrNone);
//	Test.Printf(_L("Thread exit info: Cat:%S, Reason:%x, Type:%d\r\n"),&thread.ExitCategory(),thread.ExitReason(),thread.ExitType());
	Test(thread.ExitType()==EExitKill);
	thread.Close();
	User::After(10000);	// Wait 10ms
	
	Test.Next(_L("Read back the play configuration"));
	TCurrentSoundFormatV02Buf formatBuf;
	snddev.AudioFormat(formatBuf);
	TCurrentSoundFormatV02& format=formatBuf();
	PrintConfig(format,Test);
	
	Test.Next(_L("Set the buffer configuration"));
	RChunk chunk;
	TInt bufSize=BytesPerSecond(formatBuf()); 	 							// Large enough to hold 1 second of data.
	bufSize=ValidBufferSize(bufSize,caps.iRequestMinSize,formatBuf());		// Keep the buffer length valid for driver.
	TTestSharedChunkBufConfig bufferConfig;
	bufferConfig.iNumBuffers=1;
	bufferConfig.iBufferSizeInBytes=bufSize;
	bufferConfig.iFlags=0;	
	TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
	r=snddev.SetBufferChunkCreate(bufferConfigBuf,chunk);
	Test(r==KErrNone);
	snddev.GetBufferConfig(bufferConfigBuf);
	PrintBufferConf(bufferConfig,Test);
	Test(bufferConfig.iBufferSizeInBytes==bufSize);
	
	Test.Next(_L("Start playing"));
	r=MakeSineTable(format);
	Test(r==KErrNone);
	r=SetToneFrequency(660,format);
	Test(r==KErrNone); 
	TPtr8 ptr(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize);
	WriteTone(ptr,format);
	snddev.PlayData(pStat,bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
	User::WaitForRequest(pStat);
	Test(tStat.Int()==KErrNone);
	
	Test.Next(_L("Close the drivers and the chunk"));
	chunk.Close();
	snddev.Close();
	
	__KHEAP_MARKEND;

	Test.Next(_L("Unload the drivers"));
	
	r=User::FreeLogicalDevice(KDevSoundScName);
	Test.Printf(_L("Unloading %S.LDD - %d\r\n"),&KDevSoundScName,r);
	Test(r==KErrNone);
	
	TName pddName(KDevSoundScName);
	_LIT(KPddWildcardExtension,".*");
	pddName.Append(KPddWildcardExtension);
	TFindPhysicalDevice findPD(pddName);
	TFullName findResult;
	r=findPD.Next(findResult);
	while (r==KErrNone)
		{
		r=User::FreePhysicalDevice(findResult);
		Test.Printf(_L("Unloading %S.PDD - %d\r\n"),&findResult,r);
		Test(r==KErrNone);
		findPD.Find(pddName); // Reset the find handle now that we have deleted something from the container.
		r=findPD.Next(findResult);
		} 
	
	Test.End();
	Test.Close();
	
	Cleanup();
	
	__UHEAP_MARKEND;

	return(KErrNone);
    }
Exemple #20
0
void MeasureByNOPs()
{
    test.Start(_L("Create thread"));
    RThread t;
    TInt r=t.Create(KLitThreadName,CountNops,0x1000,NULL,NULL);
    test(r==KErrNone);
    t.SetPriority(EPriorityAbsoluteVeryLow);
    t.Resume();

    test.Next(_L("Get processor clock frequency"));
    TMachineInfoV2Buf buf;
    TMachineInfoV2& info=buf();
    r=UserHal::MachineInfo(buf);
    test(r==KErrNone);
    MaxCycles=info.iProcessorClockInKHz*1000;
    test.Printf(_L("Clock frequency %dHz\n"),MaxCycles);
    TRequestStatus s;
    CConsoleBase* console=test.Console();
    console->Read(s);
#ifdef __WINS__
    TInt timerperiod = 5;
    UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"TimerResolution",&timerperiod);
#endif

    FOREVER
    {
        TUint32 init_count=NopCount;
        TUint32 init_ms=User::NTickCount();
        User::After(1000000);
        TUint32 final_count=NopCount;
        TUint32 final_ms=User::NTickCount();
        TUint32 cycles=final_count-init_count;
        TUint32 ms=final_ms-init_ms;
#ifdef __WINS__
        ms*=timerperiod;
#endif
        while (s!=KRequestPending)
        {
            User::WaitForRequest(s);
            TKeyCode k=console->KeyCode();
            if (k==EKeyTab)
            {
                // calibrate
                TInt64 inst64 = MAKE_TINT64(0, cycles);
                inst64*=1000;
                inst64/=MAKE_TINT64(0,ms);
                MaxCycles=I64LOW(inst64);
                test.Printf(_L("NOPs per second %u\n"),MaxCycles);
            }
            else if (k==EKeyEscape)
                return;
            console->Read(s);
        }
        TInt64 used64=MAKE_TINT64(0, MaxCycles);

        used64-=MAKE_TINT64(0,cycles);
        used64*=1000000;
        used64/=MAKE_TINT64(0,ms);
        used64/=MAKE_TINT64(0, MaxCycles);
        test.Printf(_L("%4d\n"),I64INT(used64));
    }
}
TInt E32Main()
	{
	TInt r;
	test.Title();
	test.Start(_L("Starting T_DENYCLAMP ..."));
	test(TheFs.Connect()==KErrNone);

	GetDriveLetters();
	TBuf<256> pathName;	

	//************************************************************************
	//
	// Test on FAT (writable file system)
	//
	//************************************************************************
	if(NandFatDrv!='?')
		{
		pathName=_L("?:\\CLAMP-TST\\");	// FAT on NAND
		pathName[0]=(TText)NandFatDrv;
		r=TheFs.MkDirAll(pathName);
		test(r==KErrNone || r== KErrAlreadyExists);
		TheFs.SetSessionPath(pathName);
		test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv);

		Test1();		// Basic clamp operation
		Test2();		// Invalid clamp requests
//		Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP

		r=TheFs.RmDir(pathName);
		test(r==KErrNone);
		}
	else
		test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n"));

	//************************************************************************
	//
	// Test on ROFS (non-writable file system) 
	//
	//************************************************************************
	if(RofsDrv!='?')
		{
		pathName=_L("?:\\");
		pathName[0]=(TText)RofsDrv;
		TheFs.SetSessionPath(pathName);
		test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv);

		Test4(pathName);	// Clamp tests for non-writable file system
		}
	else
		test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n"));

	//************************************************************************
	//
	// Test on Z: - Composite File System, or ROMFS (non-writable file system)
	//
	//************************************************************************
	if(CompDrv!='?')
		{
		pathName=_L("?:\\TEST\\");
		pathName[0]=(TText)CompDrv;
		TheFs.SetSessionPath(pathName);
		test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv);

		Test4(pathName);	// Clamp tests for non-writable file system
		}
	else
		test.Printf( _L("T_DENYCLAMP: Z drive not tested\n"));

	//************************************************************************
	//
	// Test on LFFS (non-clampable file system)
	//
	//************************************************************************
	if(LffsDrv!='?')
		{
		TBuf<256> unsuppPath;	
		unsuppPath=_L("?:\\CLAMP-TST\\");
		unsuppPath[0]=(TText)LffsDrv;
		r=TheFs.MkDirAll(unsuppPath);
		test(r==KErrNone || r== KErrAlreadyExists);
		TheFs.SetSessionPath(unsuppPath);
		test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv);

		Test5();		// Clamp requests on non-clamping file systems
		}
	else
		test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n"));

	test.End();
	return 0;
	}
GLDEF_C TInt E32Main()
{
    RLibrary l, l2;

    // Turn off evil lazy dll unloading
    RLoader ldr;
    test(ldr.Connect()==KErrNone);
    test(ldr.CancelLazyDllUnload()==KErrNone);
    ldr.Close();

    test.Title();
    test.Start(_L("Test SMP safe binary flag"));

    test.Next(_L("Get number of CPUs"));
    TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
    test_Compare(cpus, >, 0);
    SMPPlatform = cpus > 1;
    if (!SMPPlatform)
    {
        CompatMode = EFalse;
        test.Printf(_L("*****************************************************\n"));
        test.Printf(_L("Uniprocessor system, not actually testing compat mode\n"));
        test.Printf(_L("*****************************************************\n"));
    }
    else
    {
        test.Next(_L("Get compatibility mode setting"));
        TInt flags = UserSvr::HalFunction(EHalGroupKernel, EKernelHalConfigFlags, 0, 0);
        test_Compare(flags, >=, 0);
        CompatMode = flags & (EKernelConfigSMPUnsafeCompat | EKernelConfigSMPUnsafeCPU0);
        if (!CompatMode)
        {
            test.Printf(_L("*************************************************\n"));
            test.Printf(_L("Compatibility mode is not enabled, not testing it\n"));
            test.Printf(_L("*************************************************\n"));
        }
    }

    test.Next(_L("Load test LDD"));
    TInt r = User::LoadLogicalDevice(_L("d_ldrtst.ldd"));
    test(r==KErrNone || r==KErrAlreadyExists);
    test_KErrNone(ldd.Open());

    test.Next(_L("Check we are safe ourselves"));
    CheckSelf(0);

    test.Next(_L("Check safe exe"));
    StartExe(_L("smpsafe0.exe"), 0);
    test.Next(_L("Load already loaded safe exe (self)"));
    TryExe(_L("smpsafe0.exe"), 0);
    StopExe(0);

    test.Next(_L("Check safe XIP exe"));
    StartExe(_L("smpsafex0.exe"), 0);
    test.Next(_L("Load already loaded safe XIP exe (self)"));
    TryExe(_L("smpsafex0.exe"), 0);
    StopExe(0);

    test.Next(_L("Load unsafe exe"));
    StartExe(_L("smpsafe1.exe"), 1);
    test.Next(_L("Load already loaded unsafe exe"));
    TryExe(_L("smpsafe1.exe"), 1);
    StopExe(1);

    test.Next(_L("Load safe exe directly linked to unsafe dll"));
    TryExe(_L("smpsafe2.exe"), 1);

    test.Next(_L("Dynamically load unsafe dll"));
    test_KErrNone(l.Load(_L("smpsafea.dll")));
    CheckSelf(1);
    test.Next(_L("Load safe exe directly linked to loaded unsafe dll"));
    TryExe(_L("smpsafe2.exe"), 1);
    test.Next(_L("Dynamically unload unsafe dll"));
    l.Close();
    CheckSelf(0);

    test.Next(_L("Load safe XIP exe directly linked to unsafe XIP dll"));
    TryExe(_L("smpsafex2.exe"), 1);

    test.Next(_L("Dynamically load unsafe XIP dll"));
    test_KErrNone(l.Load(_L("smpsafexa.dll")));
    CheckSelf(1);
    test.Next(_L("Load safe XIP exe directly linked to loaded unsafe XIP dll"));
    TryExe(_L("smpsafex2.exe"), 1);
    test.Next(_L("Dynamically unload unsafe XIP dll"));
    l.Close();
    CheckSelf(0);

    test.Next(_L("Load safe exe indirectly linked to unsafe dll"));
    TryExe(_L("smpsafe3.exe"), 1);

    test.Next(_L("Dynamically load unsafe dll"));
    test_KErrNone(l.Load(_L("smpsafea.dll")));
    CheckSelf(1);
    test.Next(_L("Load safe exe indirectly linked to loaded unsafe dll"));
    TryExe(_L("smpsafe3.exe"), 1);
    test.Next(_L("Dynamically unload unsafe dll"));
    l.Close();
    CheckSelf(0);

    test.Next(_L("Dynamically load safe dll linked to unsafe dll"));
    test_KErrNone(l.Load(_L("smpsafeb.dll")));
    CheckSelf(1);
    test.Next(_L("Load safe exe indirectly linked to unsafe dll, inbetween loaded"));
    TryExe(_L("smpsafe3.exe"), 1);
    test.Next(_L("Dynamically load unsafe dll as well"));
    test_KErrNone(l2.Load(_L("smpsafea.dll")));
    CheckSelf(2);
    test.Next(_L("Dynamically unload safe dll linked to unsafe dll"));
    l.Close();
    CheckSelf(1);
    test.Next(_L("Dynamically unload unsafe dll as well"));
    l2.Close();
    CheckSelf(0);

    test.Next(_L("Load safe exe directly linked to unsafe XIP dll"));
    TryExe(_L("smpsafe4.exe"), 1);

    test.Next(_L("Dynamically load unsafe XIP dll"));
    test_KErrNone(l.Load(_L("smpsafexa.dll")));
    CheckSelf(1);
    test.Next(_L("Load safe exe directly linked to loaded unsafe XIP dll"));
    TryExe(_L("smpsafe4.exe"), 1);
    test.Next(_L("Dynamically unload unsafe XIP dll"));
    l.Close();
    CheckSelf(0);

    test.Next(_L("Dynamically load figure-eight dll cycle"));
    test_KErrNone(l.Load(_L("smpsafec.dll")));
    CheckSelf(1);
    test.Next(_L("Load figure-eight from a different point"));
    test_KErrNone(l2.Load(_L("smpsafed.dll")));
    CheckSelf(2);
    test.Next(_L("Unload original point"));
    l.Close();
    CheckSelf(1);
    test.Next(_L("Unload second point"));
    l2.Close();
    CheckSelf(0);

    test.Next(_L("Close test LDD"));
    ldd.Close();
    test_KErrNone(User::FreeLogicalDevice(KLdrTestLddName));

    test.End();
    return KErrNone;
}
TInt E32Main()
	{
	TInt r;

	__UHEAP_MARK;

	Test.Title();

	Test.Start(_L("Load"));
	if (Load()==KErrNotFound)
		{
		Test.Printf(_L("Shared chunk sound driver not supported - test skipped\r\n"));
		Test.End();
		Test.Close();
		__UHEAP_MARKEND;
		return(KErrNone);
		}

	__KHEAP_MARK;

	Test.Next(_L("Open playback channel"));
	r = TxSoundDevice.Open(KSoundScTxUnit0);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Open playback channel error(%d)\r\n"),r);
		Test(0);
		}
	
	Test.Next(_L("Open record channel"));
	r = RxSoundDevice.Open(KSoundScRxUnit0);
	if (r!=KErrNone)
		{
		Test.Printf(_L("Open record channel error(%d)\r\n"),r);
		Test(0);
		}
	
	Test.Next(_L("Query play formats supported"));
	TxSoundDevice.Caps(PlayCapsBuf);
	TSoundFormatsSupportedV02 playCaps=PlayCapsBuf();
	PrintCaps(playCaps,Test);

	Test.Next(_L("Query record formats supported"));
	RxSoundDevice.Caps(RecordCapsBuf);
	TSoundFormatsSupportedV02 recordCaps=RecordCapsBuf();
	PrintCaps(recordCaps,Test);
	
	Test.Next(_L("Connect to the file server"));
	r = Fs.Connect();
	if (r!=KErrNone)
		{
		Test.Printf(_L("Connect to the file server error(%d)\r\n"),r);
		Test(0);
		}
		
	if (User::CommandLineLength())
		{
		User::CommandLine(CommandLine);
		TLex l(CommandLine);
		TPtrC token=l.NextToken();

		TInt count=0;
		while (token.Length()!=0)
			{
			++count;
			token.Set(l.NextToken());
			}
		Test.Printf(_L("Command line %d parameters\r\n"),count);

		if (count==1)		// If 1 parameter try playing a file
			r=WavPlay();
		else if (count)		// If there is more than 1 parameter, try recording
			r=WavRecord();
		
		//TestWaveformGenerator();
			
		}
	
	Fs.Close();
	
	Test.Next(_L("Close channels"));
	RxSoundDevice.Close();
	TxSoundDevice.Close();
	
	__KHEAP_MARKEND;

	// Now that both the channels are closed, unload the LDD and the PDDs.
	TestUnloadDrivers();

	Test(r==KErrNone);

	Test.End();
	Test.Close();

	Cleanup();
	
	__UHEAP_MARKEND;

	return(KErrNone);
	}
Exemple #24
0
TInt E32Main()
	{
	TInt err;
	
	Test.Start(_L("Comm Driver Tests"));
	CommStart();
    Test.Printf(_L("Insert plug in then press a key\r\n"));
	Test.Getch();

	TEST(CTrapCleanup::New()!=NULL);
	CActiveScheduler* Scheduler = new CActiveScheduler;
	TEST(Scheduler!=NULL);
	CActiveScheduler::Install(Scheduler);
/*
	CTestSignals* testsignals = NULL;
	TRAP(err, testsignals = CTestSignals::NewL(0));
	TEST(err==KErrNone);
	testsignals->Start();
	Scheduler->Start();
	delete testsignals;
	
	CTestRandTerm* testrandterm = NULL;
	TRAP(err, testrandterm = CTestRandTerm::NewL(0));
	TEST(err==KErrNone);
	testrandterm->Start();
	Scheduler->Start();
	delete testrandterm;

	CTestPerf* testperf = NULL;
	TRAP(err, testperf = CTestPerf::NewL(0));
	TEST(err==KErrNone);
	testperf->Start();
	Scheduler->Start();
	delete testperf;
*/

	CTestXonXoff* testx = NULL;
	TRAP(err, testx = CTestXonXoff::NewL(0));
	TEST(err==KErrNone);
	testx->Start();
	Scheduler->Start();
	delete testx;

/*
	CTestXonXoff* testx1 = NULL;
	TRAP(err, testx1 = CTestXonXoff::NewL(0));
	TEST(err==KErrNone);
	testx1->Start();

	CTestXonXoff* testx2 = NULL;
	TRAP(err, testx2 = CTestXonXoff::NewL(1));
	TEST(err==KErrNone);
	testx2->Start();

	Scheduler->Start();

	delete testx1;
	delete testx2;
*/
	Test.End();
	return KErrNone;
	}
void CallTestsL()
	{
    TInt drive;
	TInt err=RFs::CharToDrive(gDriveToTest,drive);
	test.Start(_L("Starting Test - T_PROXYDRIVE1"));
	test(err==KErrNone);

    PrintDrvInfo(TheFs, drive);


	_LIT(KBitProxyDriveName, "t_bitproxydrive.pxy");
	_LIT(KBitProxyDrive, "bitproxydrive");

	TInt r;

	TInt localDriveNumber = GetRemovableDrive(drive); //-- local _physical_ drive number
	if (localDriveNumber < 0)
		{
		test.Printf(_L("Not a removable drive, skipping test\n"));
		return;
		}


	test.Next(_L("Adding and then removing a proxy drive with an open subsession"));
	r = TheFs.AddProxyDrive(KBitProxyDriveName);
	test.Printf(_L("AddProxyDrive(%S) r %d\n"), &KBitProxyDriveName, r);
	test(r == KErrNone || r == KErrAlreadyExists);

	TPckgBuf<TInt> p1; p1() = localDriveNumber;
	TBuf<1> p2;
	TInt driveNumber = EDriveM;

    //-- this is a hack - mount the proxy drive to the existing one with alive file system just to check
    //-- that it works.

	r = TheFs.MountProxyDrive(driveNumber, KBitProxyDrive, &p1, &p2);
	test.Printf(_L("MountProxyDrive(%d, %S) r %d\n"), driveNumber, &KBitProxyDrive, r);
	test (r >= 0);

    //-- query existing file system name on the drive that we are be parasiting on.
    TFSName fsName;
    r = TheFs.FileSystemName(fsName, drive);
    test(r == KErrNone);


	r = TheFs.MountFileSystem(fsName, driveNumber);
	test.Printf(_L("MountFileSystem(%S) r %d\n"), &fsName, r);
	test(r == KErrNone);



	RFs fs;
	r = fs.Connect();
	test(r == KErrNone);


	TPath dirPath = _L("?:\\*");
	dirPath[0] = (TUint8) ('A' + driveNumber);
	RDir dir;
	r = dir.Open(fs, dirPath, KEntryAttNormal);
	test.Printf(_L("RDir::Open(%S) r %d\n"), &dirPath, r);


	r = TheFs.DismountFileSystem(fsName, driveNumber);
	test.Printf(_L("DismountFileSystem(%S) r %d\n"), &fsName, r);
	test (r == KErrInUse);

	// dismount failed - attempt a forced dismount
	TRequestStatus stat;
	TheFs.NotifyDismount(driveNumber, stat, EFsDismountForceDismount);
	User::WaitForRequest(stat);
	r = stat.Int();
	test.Printf(_L("DismountFileSystem(%S, EFsDismountForceDismount) r %d\n"), &fsName, r);
	test (r == KErrNone);

	r = TheFs.DismountProxyDrive(driveNumber);
	test.Printf(_L("DismountProxyDrive(%d) r %d\n"), driveNumber, r);
	test (r == KErrNone);

	test.Printf(_L("Calling RemoveProxyDrive()...\n"));
	r = TheFs.RemoveProxyDrive(KBitProxyDrive);
	test.Printf(_L("RemoveProxyDrive() r %d\n"), r);
	test (r == KErrNone);
	User::After(1000000);

	test.Printf(_L("closing dir (%S)....\n"), &dirPath, r);
	dir.Close();

	test.Printf(_L("closing file session()....\n"));
	fs.Close();


	test.End();
	test.Close();
	}
void EnsureSystemIdle()
	{
	// This test assumes 100% cpu resource is available, so it can fail on
	// windows builds if something else is running in the background.  This
	// function attempts to wait for the system to become idle.
	
#ifdef __WINS__

	const TInt KMaxWait = 60 * 1000000;
	const TInt KSampleTime = 1 * 1000000;
	const TInt KWaitTime = 5 * 1000000;
	
	test.Start(_L("Waiting for system to become idle"));
	TInt totalTime = 0;
	TBool idle;
	do
		{
		test(totalTime < KMaxWait);
		
		TThreadParam threadParam;
		FailIfError((threadParam.iSem).CreateLocal(0));
		threadParam.iCpu = 1;

		RThread thread;
		FailIfError(thread.Create(_L("Thread"), ThreadFunction, 1024, NULL, &threadParam));		
		thread.SetPriority(EPriorityLess);
		thread.Resume();

		User::After(KShortWait); // Pause to allow thread setup

		(threadParam.iSem).Signal();		
		User::After(KSampleTime);
		thread.Suspend();

		TTimeIntervalMicroSeconds time;
		FailIfError(thread.GetCpuTime(time));
		TReal error = (100.0 * Abs(time.Int64() - KSampleTime)) / KSampleTime;
		test.Printf(_L("    time == %ld, error == %f%%\n"), time, error);

		idle = error < 2.0;		
		
		thread.Kill(KErrNone);
		TRequestStatus status;
		thread.Logon(status);
		User::WaitForRequest(status);
		test(status == KErrNone);
		CLOSE_AND_WAIT(thread);
		
		(threadParam.iSem).Close();

		if (!idle)
			User::After(KWaitTime);		// Allow system to finish whatever it's doing

		totalTime += KShortWait + KSampleTime + KWaitTime;
		}
	while(!idle);
	
	test.End();
	
#endif
	}
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();
	}
//! @SYMTestCaseID t_cputime_1
//! @SYMTestType CT
//! @SYMTestCaseDesc Thread CPU time tests
//! @SYMREQ CR RFID-66JJKX
//! @SYMTestActions Tests cpu time when a thread is put through the various states
//! @SYMTestExpectedResults Reported cpu time increses only when the thread is running
//! @SYMTestPriority High
//! @SYMTestStatus Defined
void TestThreadCpuTime()
	{
	test.Start(_L("CPU thread time unit tests"));

	TThreadParam threadParam;
	FailIfError((threadParam.iSem).CreateLocal(0));
	threadParam.iCpu = 0;				// Later tests will exercise other CPUs

	RThread thread;
	RUndertaker u;
	TInt h;
	TRequestStatus s;
	FailIfError(thread.Create(_L("Thread"), ThreadFunction, 1024, NULL, &threadParam));
	thread.SetPriority(EPriorityLess);
	FailIfError(u.Create());
	FailIfError(u.Logon(s,h));
	test(s==KRequestPending);

	TTimeIntervalMicroSeconds time, time2;
	TInt64 us;

	// Test cpu time is initially zero
	FailIfError(thread.GetCpuTime(time));
	test(time == 0);

	// Test cpu time is not increased while thread is waiting on semaphore
	thread.Resume();
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time2));
	us = time2.Int64();
	test.Printf(_L("Time %dus\n"), us);
	test(us < KTolerance); // wait should happen in less than 1ms

	// Test cpu time increases when thread allowed to run
	// We want to allow 2% tolerance for the thread's CPU time, as there could be
	// something else running on the system during that time which would result lower CPU time than the
	// actual KShortPeriod or KLongPeriod wait time.
	// Also User::After(t) might return within the range of <t, t + 1000000/64 + 2*NanoKarnelTickPeriod>.
	// Given all that - we expect that the the cpu time should be within the range of:
	// <t - 0.02*t, t + 15625 + 2*NanoKernelTickPeriod>
	// or <0.98*t, t + 15625 + 2*NanoKernelTickPeriod>
	TInt user_after_tolerance = 0;
	HAL::Get(HAL::ENanoTickPeriod, user_after_tolerance);
	user_after_tolerance += user_after_tolerance + 15625;

	(threadParam.iSem).Signal();
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time));
	us = time.Int64() - time2.Int64();
	test.Printf(_L("Time %dus\n"), us);
	test(100*us >= 98*KShortWait); // left limit
	test(us - KShortWait <= user_after_tolerance); // right limit

	FailIfError(thread.GetCpuTime(time));
	User::After(KLongWait);
	FailIfError(thread.GetCpuTime(time2));
	us = time2.Int64() - time.Int64();
	test.Printf(_L("Time %dus\n"), us);
	test(100*us >= 98*KLongWait); // left limit
	test(us - KLongWait <= user_after_tolerance); // right limit

	// Test not increased while suspended
	thread.Suspend();
	FailIfError(thread.GetCpuTime(time));
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time2));
	test(time == time2);
	thread.Resume();

	// Test not increased while dead
	thread.Kill(KErrNone);
	User::WaitForRequest(s);	// wait on undertaker since that completes in supervisor thread
	FailIfError(thread.GetCpuTime(time));
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time2));
	test(time == time2);

	RThread t;
	t.SetHandle(h);
	test(t.Id()==thread.Id());
	t.Close();
	u.Close();
	thread.Close();
	(threadParam.iSem).Close();
	test.End();
	}
void TIsrRequeArgsSet::SelfTest()
	{
	test.Start(_L("Selftest of TIsrRequeArgsSet"));

	TUint size = 0x1000;
	TDmaTransferArgs tferArgs(0, 1*size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);

	TIsrRequeArgs requeArgArray[] = {
		TIsrRequeArgs(),									// Repeat
		TIsrRequeArgs(KPhysAddrInvalidUser, 2*size, 0),		// Change destination
		TIsrRequeArgs(),									// Repeat
		TIsrRequeArgs(3*size, KPhysAddrInvalidUser, 0),		// Change source
		TIsrRequeArgs(),									// Repeat
	};
	TIsrRequeArgsSet argSet(requeArgArray, ARRAY_LENGTH(requeArgArray));

	test.Next(_L("Test that Substitute updates transfer args in order"));
	argSet.Substitute(tferArgs);

	TAddressParms expectedFinal(3*size, 2*size, size);
	if(!(expectedFinal == argSet.iRequeArgs[4]))
		{
		TBuf<0x100> out;

		out += _L("substitue: ");
		GetAddrParms(tferArgs).AppendString(out);
		test.Printf(out);

		out.Zero();
		out += _L("\nexpected final: ");
		expectedFinal.AppendString(out);
		test.Printf(out);

		out.Zero();
		out += _L("\nactual: ");
		argSet.iRequeArgs[4].AppendString(out);
		test.Printf(out);

		test(EFalse);
		}

	TIsrRequeArgs requeArgArray2[] = {
		TIsrRequeArgs(),									// Repeat
		TIsrRequeArgs(KPhysAddrInvalidUser, 2*size, 0),		// Change destination
		TIsrRequeArgs(KPhysAddrInvalidUser, 1*size, 0),		// Change destination back
	};
	argSet = TIsrRequeArgsSet(requeArgArray2, ARRAY_LENGTH(requeArgArray2));

	test.Next(_L("CheckRange(), negative"));

	test(!argSet.CheckRange(0, (2 * size) - 1, tferArgs));
	test(!argSet.CheckRange(0, (2 * size) + 1, tferArgs));
	test(!argSet.CheckRange(0, (2 * size), tferArgs));

	test(!argSet.CheckRange(1 ,(3 * size), tferArgs));
	test(!argSet.CheckRange(1 ,(3 * size) + 1, tferArgs));

	test(!argSet.CheckRange(1 * size , 2 * size, tferArgs));

	test.Next(_L("CheckRange(), positive"));
	test(argSet.CheckRange(0, 3 * size, tferArgs));
	test(argSet.CheckRange(0, 3 * size+1, tferArgs));
	test(argSet.CheckRange(0, 4 * size, tferArgs));


	test.End();
	}
TBool DoTestThreadCpuTime2()  // Returns ETrue if test passed
	{
	test.Start(_L("Testing time shared between threads"));

	if (numCpus > 1)
		{
		test.Printf(_L("** SMP system detected - not testing time shared between threads until load balancing optimized **\n"));
		return ETrue;
		}

	const TInt KMaxThreads = 4;

	TThreadParam threadParam;
			
	RThread* threads = NULL;
	threads = new(ELeave) RThread[numCpus*KMaxThreads];
	FailIfError((threadParam.iSem).CreateLocal(0));

	TBool pass = ETrue;
	for (TInt numThreads = 1 ; pass && numThreads <= KMaxThreads ; ++numThreads)
		{
		test.Printf(_L("  testing with %d threads on each of %d CPUs:\n"), numThreads, numCpus);

		TInt i, j, k;
		for (i = 0 ; i < numThreads ; ++i)
			{
			for (j = 0 ; j < numCpus ; ++j)
				{
				TBuf<16> name;
				name.AppendFormat(_L("Thread%d%d"), i, j);
				threadParam.iCpu = j;
				k = i+j*KMaxThreads;
				FailIfError(threads[k].Create(name, ThreadFunction, 1024, NULL, &threadParam));
				threads[k].SetPriority(EPriorityLess);
				threads[k].Resume();
				}
			}

		User::After(KShortWait); // Pause to allow thread setup

		(threadParam.iSem).Signal(numThreads*numCpus);		
		User::After(KLongWait);
		for (i = 0 ; i < numThreads ; ++i)
			for (j = 0 ; j < numCpus ; ++j)
				threads[i+j*KMaxThreads].Suspend();

		TInt expected = KLongWait / numThreads;
		for (i = 0 ; i < numThreads ; ++i)
			{
			for (j = 0 ; j < numCpus ; ++j)
				{
				k = i+j*KMaxThreads;
				TTimeIntervalMicroSeconds time;
				FailIfError(threads[k].GetCpuTime(time));

				TReal error = (100.0 * Abs(time.Int64() - expected)) / expected;
			
				test.Printf(_L("    %d%d: time == %ld, error == %d%%\n"), i, j, time.Int64(), TInt(error));

				if (error >= 5.0)
					pass = EFalse;

				threads[k].Kill(KErrNone);
				TRequestStatus status;
				threads[k].Logon(status);
				User::WaitForRequest(status);
				test(status == KErrNone);
				CLOSE_AND_WAIT(threads[k]);
				}
			}
		}

	(threadParam.iSem).Close();
	test.End();

	return pass;
	}