Пример #1
0
TInt CTestSession::CheckDesPresent(const RMessage2& aMessage, TUint aArgIndex, TBool aExpected, TBool aWrite)
	{
	TRequestStatus clientStat;
	
	if (aExpected)
		{
		RDebug::Printf("  Checking message argument at %d is present", aArgIndex);
		}
	else
		{
		RDebug::Printf("  Checking message argument at %d is not present", aArgIndex);
		// Start watching for client thread death
		RThread clientThread;
		aMessage.Client(clientThread);
		clientThread.Logon(clientStat);
		clientThread.Close();
		}
		
	// Get the length of the descriptor and verify it is as expected.
	TInt length = aMessage.GetDesLength(aArgIndex);
	if (length < KErrNone)
		{
		RDebug::Printf("  Error getting descriptor length %d", length);
		return length;
		}
	if (length < 3)
		{// The incorrect descriptor length.
		RDebug::Printf("  Error - Descriptor length too small %d", length);
		return KErrArgument;
		}
	if (!aWrite)
		{// Now read the descriptor and verify that it is present or not.
		TBuf8<5> des;
		TInt r = aMessage.Read(aArgIndex, des);
		if (r != (aExpected ? KErrNone : KErrBadDescriptor))
			{
			RDebug::Printf("  Unexpected value returned from aMessage.Read:%d", r);
			return KErrGeneral;
			}
		if (r==KErrNone && (des[0] != 'a' || des[1] != 'r' || des[2] != 'g'))
			{// The incorrect descriptor data has been passed.
			RDebug::Printf("  Error in descriptor data is corrupt r %d", r);
			return KErrArgument;
			}
		}
	else
		{// Now write to the maximum length of the descriptor.
		TInt max = aMessage.GetDesMaxLength(aArgIndex);
		if (max < 0)
			{
			RDebug::Printf("  Error getting descriptor max. length %d", max);
			return length;
			}
		HBufC8* argTmp = HBufC8::New(max);
		TPtr8 argPtr = argTmp->Des();
		argPtr.SetLength(max);
		for (TInt i = 0; i < max; i++)
			argPtr[i] = (TUint8)aArgIndex;
		TInt r = aMessage.Write(aArgIndex, argPtr);
		if (r != (aExpected ? KErrNone : KErrBadDescriptor))
			{
			RDebug::Printf("  Unexpected value returned from aMessage.Write:%d", r);
			return KErrGeneral;
			}
		}

	if (!aExpected)
		{// The client should have been killed as the data wasn't present.
		RDebug::Printf("  CheckDesPresent: Waiting for client to die");
		User::WaitForRequest(clientStat);
		iClientDied = ETrue;
		RDebug::Printf("  CheckDesPresent: Client dead");
		}
	return KErrNone;
	}
TVerdict CUPSDbManagementStep::doTestStepPreambleL()
/**
 * @return - TVerdict code
 * Override of base class virtual
 */
	{
 	__UHEAP_MARK;
 	
 	INFO_PRINTF2(_L("START CELLS: %d"), User::CountAllocCells());
 	
 	// reads client name and SID
	TParse clientFullName;
	RThread client;
	clientFullName.Set(client.FullName(),NULL, NULL);
	iTEFServerName=clientFullName.Name();
	iExpectedClientSid = client.SecureId() ;
	client.Close();
 	
    // Read how many times the test step needs to be repeated.
    TName fStepRepeat(_L("StepRepeat"));
    TInt  repeats;
    
    if(GetIntFromConfig(ConfigSection(),fStepRepeat,repeats))
    	{
    	iStepRepeat=repeats;
    	}
	else
		{	
		iStepRepeat=1;		
		}
    
    // Read values for test sequence from INI file. (ARRAY of values)
	TInt index=0;
	TName fOperation;
	fOperation.Format(_L("Operation_%d"), index);
	TName fClientSid;
	fClientSid.Format(_L("ClientSid_%d"),index);
	TName fEvaluatorId;
	fEvaluatorId.Format(_L("EvaluatorId_%d"),index);
	TName fServiceId;
	fServiceId.Format(_L("ServiceId_%d"),index);
	TName fServerSid;
	fServerSid.Format(_L("ServerSid_%d"),index);
	TName fFingerprint;
	fFingerprint.Format(_L("Fingerprint_%d"),index);
	TName fClientEntity;
	fClientEntity.Format(_L("ClientEntity_%d"),index);
	TName fDescription;
	fDescription.Format(_L("Description_%d"),index);
	TName fDecisionResult;
	fDecisionResult.Format(_L("DecisionResult_%d"),index);
	TName fMajorPolicyVersion;
	fMajorPolicyVersion.Format(_L("MajorPolicyVersion_%d"),index);
	TName fRecordId;
	fRecordId.Format(_L("RecordId_%d"),index);
	TName fEvaluatorInfo;
	fEvaluatorInfo.Format(_L("EvaluatorInfo_%d"),index);
	TName fExpectedDecisionCount;
	fExpectedDecisionCount.Format(_L("ExpectedDecisionCount_%d"),index);
	
	TPtrC 	operation;
	TInt	clientSid;
	TInt	evaluatorId;
	TInt	serviceId;
	TInt	serverSid;
	TPtrC	fingerprint;
	TPtrC	clientEntity;
	TPtrC	description;
	TPtrC	decisionResult;
	TInt	majorPolicyVersion;
	TInt 	recordId;
	TInt	evaluatorInfo;
	TInt 	expectedDecisionCount;
	
	while (GetStringFromConfig(ConfigSection(),fOperation,operation))
		{
		
		// Create an instance of a new request
		CUpsDbRequest* newRequest = CUpsDbRequest::NewL();
		CleanupStack::PushL(newRequest);
		
		// Set the operation to be performed
	    newRequest->iOperation = operation;
	    
	    if(GetHexFromConfig(ConfigSection(),fClientSid,clientSid))
		    {
		    newRequest->iClientSid = clientSid;
		  	newRequest->iDecisionFilter->SetClientSid(TSecureId(clientSid),EEqual);
		    }
	    
		if(GetHexFromConfig(ConfigSection(),fEvaluatorId,evaluatorId))
			{
			newRequest->iEvaluatorId = evaluatorId;	
			newRequest->iDecisionFilter->SetEvaluatorId(TUid::Uid(evaluatorId),EEqual);
			}
		
		if(GetHexFromConfig(ConfigSection(),fServiceId,serviceId))
			{
			newRequest->iServiceId = serviceId;	
			newRequest->iDecisionFilter->SetServiceId(TUid::Uid(serviceId),EEqual);
			}
	
		if(GetHexFromConfig(ConfigSection(),fServerSid,serverSid))
			{
			newRequest->iServerSid = serverSid;	
			newRequest->iDecisionFilter->SetServerSid(TSecureId(serverSid),EEqual);
			}
			
		if(GetStringFromConfig(ConfigSection(),fFingerprint,fingerprint))
			{
			HBufC8* fingerprintConverter = HBufC8::NewLC(fingerprint.Length());
			TPtr8 fingerprintPtr = fingerprintConverter->Des();
			fingerprintPtr.Copy(fingerprint); 	
             
	       	newRequest->iFingerprint = fingerprintPtr;
	       	
	       	HBufC8* binaryFingerprint = StringToBinaryLC(fingerprintPtr);
	       	
	      	newRequest->iDecisionFilter->SetFingerprintL(*binaryFingerprint,EEqual);	
	       	CleanupStack::PopAndDestroy(binaryFingerprint);
	       	CleanupStack::PopAndDestroy(fingerprintConverter); 
			}

		if(GetStringFromConfig(ConfigSection(),fClientEntity,clientEntity))
			{
			HBufC8* clientEntityConverter = HBufC8::NewLC(clientEntity.Length());
			TPtr8 clientEntityPtr = clientEntityConverter->Des();
			clientEntityPtr.Copy(clientEntity); 	
             
	       	newRequest->iClientEntity = clientEntityPtr;
	       	newRequest->iDecisionFilter->SetClientEntityL(clientEntityPtr,EEqual);		
	       	CleanupStack::PopAndDestroy(clientEntityConverter); 
			}
			
		if(GetStringFromConfig(ConfigSection(),fDescription,description))
			{
		    newRequest->iDescription = description;
			}
			
		if(GetStringFromConfig(ConfigSection(),fDecisionResult,decisionResult))
			{
			if(decisionResult.CompareF(_L("Yes"))==0 || decisionResult.CompareF(_L("No"))==0 || decisionResult.CompareF(_L(""))==0 )
				{
				newRequest->iDecisionResult = decisionResult;	
				}
			else 
				{
				ERR_PRINTF3(_L("%S: Unexpected Decision Result - %S"),&iTEFServerName, &decisionResult);
				}
			}

		if(GetIntFromConfig(ConfigSection(),fMajorPolicyVersion,majorPolicyVersion)) 
			{
			newRequest->iMajorPolicyVersion = majorPolicyVersion;
			newRequest->iDecisionFilter->SetMajorPolicyVersion(majorPolicyVersion,EEqual);		
			}
		
		if(GetIntFromConfig(ConfigSection(),fRecordId,recordId))
			{
			newRequest->iRecordId = recordId;
			newRequest->iDecisionFilter->SetRecordId(recordId,EEqual);		
			}
			
		if(GetIntFromConfig(ConfigSection(),fEvaluatorInfo,evaluatorInfo))
			{
			newRequest->iEvaluatorInfo = evaluatorInfo;		
			}
			
		if(GetIntFromConfig(ConfigSection(),fExpectedDecisionCount,expectedDecisionCount))
			{
			newRequest->iExpectedDecisionCount = expectedDecisionCount;		
			}
	    
	    // Add the new service to be requested to array.
	    iArraySersToRequest.AppendL(newRequest);
	    
	    CleanupStack::Pop(newRequest);
	       
	    index++;
	    fOperation.Format(_L("Operation_%d"), index);
	    fClientSid.Format(_L("ClientSid_%d"),index);
		fEvaluatorId.Format(_L("EvaluatorId_%d"),index);
		fServiceId.Format(_L("ServiceId_%d"),index);
		fServerSid.Format(_L("ServerSid_%d"),index);
		fFingerprint.Format(_L("Fingerprint_%d"),index);
		fClientEntity.Format(_L("ClientEntity_%d"),index);
		fDescription.Format(_L("Description_%d"),index);
		fDecisionResult.Format(_L("DecisionResult_%d"),index);
		fMajorPolicyVersion.Format(_L("MajorPolicyVersion_%d"),index);
		fRecordId.Format(_L("RecordId_%d"),index);
		fEvaluatorInfo.Format(_L("EvaluatorInfo_%d"),index);
		fExpectedDecisionCount.Format(_L("ExpectedDecisionCount_%d"),index);
		}
	
	SetTestStepResult(EPass);
	return TestStepResult();
	}
Пример #3
0
TInt E32Main()
	{
	StaticMain();
	
	RBuf cmd;
	test_KErrNone(cmd.Create(User::CommandLineLength()));
	User::CommandLine(cmd);

	TLex lex(cmd);
	TTestType type;
	test_KErrNone(lex.Val((TInt&)type));
	GlobalObjectWithDestructor.iTestType = type;

	RMsgQueue<TMessage> messageQueue;
	test_KErrNone(messageQueue.OpenGlobal(KMessageQueueName));

	// Dynamically load DLL with global data
	RLibrary library;
	test_KErrNone(library.Load(KDynamicDll));
	
	switch(type)
		{
		case ETestMainThreadReturn:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			return type;

		case ETestMainThreadExit:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			User::Exit(type);
			break;

		case ETestChildThreadReturn:
			{
			// Start child thread passing this thread's id
			MainThreadId = RThread().Id();
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), ChildThread, 4096, NULL, (TAny*)type));
			TRequestStatus status;
			childThread.Rendezvous(status);
			childThread.Resume();

			User::After(1);

			// Wait for child to open handle on this thread
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();

			// Set this thread non-critical and exit
			User::SetCritical(User::ENotCritical);
			}
			break;

		case ETestOtherThreadExit:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), ExitThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			TRequestStatus status;
			childThread.Logon(status);
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			}
			return type;

		case ETestOtherThreadPanic:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), PanicThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			TRequestStatus status;
			childThread.Logon(status);
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			}
			return type;
			
		case ETestOtherThreadRunning:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), LoopThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			childThread.Close();
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			}
			return type;
			
		case ETestPermanentThreadExit:
			{
			RThread childThread;
			test_KErrNone(childThread.Create(_L("ChildThread"), PermanentThread, 4096, NULL, (TAny*)type));
			childThread.Resume();
			TRequestStatus status;
			childThread.Logon(status);
			User::WaitForRequest(status);
			test_KErrNone(status.Int());
			childThread.Close();
			}
			break;
			
		case ETestRecursive:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			break;

		case ETestDestructorExits:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			break;

		case ETestLastThreadPanic:
			test_KErrNone(messageQueue.Send(EMessagePreDestruct));
			Panic(type);
			break;
			
		default:
			test(EFalse);
		}
	return KErrNone;
	}
Пример #4
0
/**
 * This function unlocks the mutex, making it available again. If other
 * threads are waiting for the lock, the first thread in the FIFO queue
 * will be given the lock.
 */
void SHVMutexBase::Unlock()
{
#ifdef __SHIVA_WIN32
	SHVVERIFY(WaitForSingleObject(Locker, INFINITE) == WAIT_OBJECT_0);
	if (Queue.GetCount()) // somebody is waiting
	{
	SHVListPos pos;
	LONG prevCount;
		NewOwner = Queue.GetFirst(pos);
		ReleaseSemaphore(NewOwner,1,&prevCount);
	}
	else
	{
		Mutex = 0;
	}
	ReleaseMutex(Locker);
#elif defined(__SHIVA_EPOC)
	Locker.Wait();
	if (Queue.GetCount()) // somebody is waiting
	{
	SHVListPos pos;
	SHVQueuedThread queue = Queue.GetFirst(pos);

		if (queue.Timer)
		{
		RTimer timer( *queue.Timer );
		RThread thread;

			thread.Open(queue.Owner);

			timer.Duplicate(thread);
			timer.Cancel();

			timer.Close();
			thread.Close();
			NewOwner = queue.Timer;
		}
		if (queue.Mutex)
		{
			queue.Mutex->Signal();
			NewOwner = queue.Mutex;
		}
	}
	else
	{
		Mutex = 0;
	}
	Locker.Signal();
#else
	pthread_mutex_lock(&Locker);
	if (Queue.GetCount()) // somebody is waiting
	{
	SHVListPos pos;
		NewOwner = Queue.GetFirst(pos);
        pthread_cond_signal(NewOwner);
	}
	else
	{
		Mutex = 0;
	}
	pthread_mutex_unlock(&Locker);
#endif
}
/**
Unfound TStringTable in Bafl StringPool not treated correctly.
Check that the function panics when the specified table is not present.

@SYMTestCaseID          SYSLIB-BAFL-CT-0492
@SYMTestCaseDesc        Tests for the functionality of RStringPool
@SYMTestPriority        High
@SYMTestActions         Tests for panic when the specified table is not present
@SYMTestExpectedResults Tests must not fail
@SYMREQ                 REQ0000
*/
void RStringPoolPanicTest::DEF043985L()
	{
	test.Next(_L("DEF043985L"));
	
#ifdef _DEBUG
	__UHEAP_MARK;

	TRequestStatus threadStatus;
	RThread thread;
	TInt rc;
	TBool jit;
	jit = User::JustInTime();
	User::SetJustInTime(EFalse);
	
	// Test the Panics for this defect
	
	// RString Test
	rc = thread.Create(_L("DEF043985_StringTest_Thread Panic Test"), 
					   RStringPoolPanicTest::DEF043985_StringTest_ThreadL,
					   KDefaultStackSize, KMinHeapSize, KMinHeapSize<<2, this);
	test(KErrNone == rc);
	thread.Logon(threadStatus);
	thread.Resume();
	User::WaitForRequest(threadStatus);
	test (thread.ExitType() == EExitPanic);
	test (thread.ExitReason() == StringPoolPanic::EStringTableNotFound);
	thread.Close();

	// RStringF Test
	rc = thread.Create(_L("DEF043985_StringFTest_Thread Panic Test"), 
					   RStringPoolPanicTest::DEF043985_StringFTest_ThreadL,
					   KDefaultStackSize, KMinHeapSize, KMinHeapSize<<2, this);
	test(KErrNone == rc);
	thread.Logon(threadStatus);
	thread.Resume();
	User::WaitForRequest(threadStatus);
	test (thread.ExitType() == EExitPanic);
	test (thread.ExitReason() == StringPoolPanic::EStringTableNotFound);
	thread.Close();

	// Index Test
	rc = thread.Create(_L("DEF043985_IndexTest_Thread Panic Test"), 
					   RStringPoolPanicTest::DEF043985_IndexTest_Thread,
					   KDefaultStackSize, KMinHeapSize, KMinHeapSize<<2, this);
	test(KErrNone == rc);
	thread.Logon(threadStatus);
	thread.Resume();
	User::WaitForRequest(threadStatus);
	test (thread.ExitType() == EExitPanic);
	test (thread.ExitReason() == StringPoolPanic::EStringTableNotFound);
	thread.Close();


	User::SetJustInTime(jit);

	__UHEAP_MARKEND;
	
#else
	test.Printf(_L("This test is valid for debug builds only, behaviour for release builds is undefined (DEF050908)\n"));
#endif
	}
void CMemoryMonitorSession::ServiceL(const RMessage2& aMessage)
    {
    FUNC_LOG;
    
    iFunction = aMessage.Function();
    RThread t;
    aMessage.Client(t);
    
    iClientId = t.SecureId();
    t.Close();
    
    TRACES1("NEW REQUEST from client %x", iClientId);
    switch (aMessage.Function())
        {
        case EGOomMonitorRequestFreeMemory:

            //Do not take any more requests from the same client if previous request being served
            if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(iClientId))
                {
                TRACES1("CANNOT PROCESS NEW REQUEST from %x", iClientId);
                aMessage.Complete(KErrInUse);
                return;
                }
            
            Server().Monitor().SetActiveClient(iClientId);
            // message will be completed when CloseAppsFinished() is called.
            if (aMessage.Int1() == 0)
                {
                iRequestFreeRam = aMessage;

                Server().Monitor().SessionInCriticalAllocation(1, iClientId);
                
                TRAPD(err, Monitor().RequestFreeMemoryL(aMessage.Int0()));
                if(err == KErrCompletion) 
                    {
                    TRACES("There is already enough memory - nothing to do");
                    Server().Monitor().SessionInCriticalAllocation(0, iClientId);
                    }
                else if (err != KErrNone )
                    {
                    // completes the message if that was left to pending
                    TRACES1("Error in RequestFreeMemory %d", err);
                    CloseAppsFinished(0, EFalse);
                    }
                }
            else
                {
                TInt appUid = aMessage.Int1();
                // if no new memory was needed, the message is completed synchronously
                iRequestFreeRam = aMessage;
                TRAP_IGNORE(Monitor().HandleFocusedWgChangeL(appUid));
                }
            break;
            
        case EGOomMonitorMemoryAllocationsComplete:
            TRACES1("ServiceL : Memory Allocations complete from %x", iClientId);
            Server().Monitor().SessionInCriticalAllocation(0, iClientId);
            aMessage.Complete(KErrNone);
            break;

        case EGOomMonitorCancelRequestFreeMemory:
            if (!iRequestFreeRam.IsNull())
                {
                iRequestFreeRam.Complete(KErrCancel);
                }
            Server().Monitor().SessionInCriticalAllocation(0, iClientId);
            aMessage.Complete(KErrNone);
            break;

        case EGOomMonitorThisAppIsNotExiting:
            Monitor().AppNotExiting(aMessage.Int0());
            aMessage.Complete(KErrNone);
            break;

        case EGOomMonitorRequestOptionalRam:
            if (!iRequestFreeRam.IsNull() && !Server().Monitor().IsSafeToProcessNewRequest(iClientId))
                {
                aMessage.Complete(KErrInUse);
                }
            Server().Monitor().SetActiveClient(iClientId);
            // message will be completed when CloseAppsFinished() is called.
            iRequestFreeRam = aMessage;
            iMinimumMemoryRequested = aMessage.Int1();
            Monitor().FreeOptionalRamL(aMessage.Int0(), aMessage.Int2());
            break;
            
        case EGOomMonitorSetPriorityBusy:
            Monitor().SetPriorityBusy(aMessage.Int0());
            aMessage.Complete(KErrNone);
            break;
            
        case EGOomMonitorSetPriorityNormal:
            Monitor().SetPriorityNormal(aMessage.Int0());
            aMessage.Complete(KErrNone);
            break;

        case EGOomMonitorSetPriorityHigh:
            Monitor().SetPriorityHigh(aMessage.Int0());
            aMessage.Complete(KErrNone);
            break;

        case EGoomMonitorAppAboutToStart:
            {
            TInt appUid = aMessage.Int0();
            aMessage.Complete(KErrNone);  
            TRAP_IGNORE(Monitor().HandleFocusedWgChangeL(appUid))
            break;
            }
           
        case EGoomMonitorAppUsesAbsoluteMemTargets:
            {
            iUseAbsoluteTargets = aMessage.Int0();
/*            TRACES2("EGoomMonitorAppUsesAbsoluteMemTargets this: 0x%x, use abs targets %d", this, iUseAbsoluteTargets);
            Server().Monitor().SessionInCriticalAllocation(iUseAbsoluteTargets);
*/          aMessage.Complete(KErrNone);     
            break;
            }    
        case EGOomMonitorRequestHWRendering:
            {
            RDebug::Printf("RAN_DEBUG : GOOM EGOomMonitorRequestHWRendering");
            if(Server().Monitor().SwitchRenderingToHW())
                aMessage.Complete(KErrNone);
            else
                aMessage.Complete(KErrNoMemory);
            
            break;
            }
        default:
            PanicClient(aMessage, EPanicIllegalFunction);
            break;
        }
    }