Ejemplo n.º 1
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
static TInt StartLockServer()
    {
    TInt result;

    TFindServer findTimeServer(KCrashServerName);
    TFullName name;

	result = findTimeServer.Next(name);
	if (result == KErrNone)
        {
		// Server already running
		return KErrNone;
	    }

	RSemaphore semaphore;		
	result = semaphore.CreateGlobal(KCrashServerSemaphoreName, 0);
    if (result != KErrNone)
        {
        return  result;
        }

    result = CreateLockServerProcess();
    if (result != KErrNone)
        {
        return  result;
        }

	semaphore.Wait();
	semaphore.Close();       

    return  KErrNone;
    }
Ejemplo n.º 2
0
// ---------------------------------------------------------------------------
// StartServerL()  
//  Starts Fota Downlaod Interrupt Monitory server
// ---------------------------------------------------------------------------
TInt StartServerL()
    {
    FLOG(_L("StartServerLt Started"));
    TInt res = KErrNone;
    
    RProcess server;
    RSemaphore sem;
    res = sem.CreateGlobal(KFotaServerScem, EOwnerProcess);

    res=server.Create(KFotaServerName,KNullDesC);
    FLOG(_L("StartServerL-- create server error as %d"),res);
    if (res!=KErrNone)
        {       
        return res;
        }

    server.Resume();    // logon OK - start the server
    
    sem.Wait();
    sem.Close();
    server.Close();
    
    FLOG(_L("StartServerL-- server.ExitType() returns %d"),res);

    return res;
    }
Ejemplo n.º 3
0
GLDEF_C TInt E32Main()
	{     
	CTrapCleanup::New();

	RWin32Stream::StartServer();	// arrange for access to Win32 stdin/stdout/stderr
	SpawnPosixServerThread();	// arrange for multi-threaded operation

	int argc=0;
	wchar_t** wargv=0;
	wchar_t** wenvp=0;


	__crt0(argc,wargv,wenvp);			// get args & environment from somewhere

#ifndef EKA2
	// Cause the graphical Window Server to come into existence
	RSemaphore sem;
	sem.CreateGlobal(_L("WsExeSem"),0);
	RegisterWsExe(sem.FullName());
#endif

	int ret=wmain(argc, wargv, wenvp);		// go

	// no need to explicitly delete the cleanup stack here as all memory used by
	// the process will be released by RProcess::Terminate(), called from inside exit().

	exit(ret);	// to get atexit processing, eventually terminates this process

	return(KErrNone);
	}
Ejemplo n.º 4
0
void CConcurrentDatabaseAccessBase::OpenSemaphore()
	{
	TInt success = KErrNone;

	success = iSemaphoreSignal.OpenGlobal( KSemaphoreNameOne );
	if ( success == KErrNotFound )
		{
		iSemaphoreSignal.CreateGlobal( KSemaphoreNameOne, 0 );
		success = KErrNone;
		}


	success = iSemaphoreWait.OpenGlobal( KSemaphoreNameTwo );
	if ( success == KErrNotFound )
		{
		iSemaphoreWait.CreateGlobal( KSemaphoreNameTwo, 0 );
		}

	iSemaphoreOpen = ETrue;
	}
void CMultiThreadTestApp::ConstructL(CAppActive* aAO)
	{
	TInt error = iSyncSemaphoreOne.CreateGlobal(KSyncSemaphoreOne(), 0);
	if (error == KErrAlreadyExists || error == KErrNone)
		{
		iSyncSemaphoreOne.OpenGlobal(KSyncSemaphoreOne());
		}
	else
		{
		User::Leave(error);
		}
		
	error = iSyncSemaphoreTwo.CreateGlobal(KSyncSemaphoreTwo(), 0);
	if (error == KErrAlreadyExists || error == KErrNone)
		{
		iSyncSemaphoreTwo.OpenGlobal(KSyncSemaphoreTwo());
		}
	else
		{
		User::Leave(error);
		}		
	iActive = aAO;
	}
Ejemplo n.º 6
0
TInt StartThread() {
	TInt result;

	TFindServer findSoundServer(KSoundStreamServerName);
	TFullName name;

	result = findSoundServer.Next(name);
	if (result == KErrNone) {
		// Server already running
		return KErrNone;
	}

	RSemaphore semaphore;
	result = semaphore.CreateGlobal(KSoundStreamServerSemaphoreName, 0);

	if (result != KErrNone) {
		return result;
	}

	RThread thread;

	result=thread.Create(
		KSoundStreamServerName,   // create new server thread
		CSoundStreamServer::ThreadFunction, // thread's main function
		KDefaultStackSize,
		NULL, // share heap with current thread
		&semaphore // passed as TAny* argument to thread function
		);

	if (result != KErrNone) {
		return result;
	}

    thread.SetPriority(EPriorityRealTime); // set thread priority to realtime

	thread.Resume(); // start it going
	thread.Close(); // we're no longer interested in the other thread

	// notify the kernel that a server has started.
	#if defined (__WINS__)
	UserSvr::ServerStarted();
	#endif
	
	// wait for signal from other thread
    semaphore.Wait();
	semaphore.Close();

	return KErrNone;
}
void StartAlmSettingsServerL(void)
{
  TFindServer find(KSettingsServerName);
  TFullName name;
  if(find.Next(name)==KErrNone) User::Leave(KErrGeneral);
  RSemaphore semaphore;
  User::LeaveIfError(semaphore.CreateGlobal(KSettingsServerSemaphoreName,0));
  CleanupClosePushL(semaphore);
  RThread thread;
  User::LeaveIfError(thread.Create(KSettingsServerName,CAlmSettingsServer::ThreadFunction,KDefaultStackSize,KMinHeapSize*16,KMinHeapSize*16,NULL));
  CleanupClosePushL(thread);
  thread.Resume();
  semaphore.Wait();
  CleanupStack::PopAndDestroy(2); //thread,semaphore
}
Ejemplo n.º 8
0
// -----------------------------------------------------------------------------
// RDosServer::StartServer
// Creates the server thread/process
// -----------------------------------------------------------------------------
EXPORT_C TInt RDosServer::StartServer() const
{
    API_TRACE_( "[DOSSERVER] RDosServer::StartServer()" );

    TInt ret(KErrNone);
	TRequestStatus status;
    // IPCv2: TSignal no longer used, but still passed to threadfunction as 
	// otherwise API change would be required.
	CDosServer::TSignal signal( status );

	// Create startup semaphore
	RSemaphore startupSemaphore;
	ret = startupSemaphore.CreateGlobal( KServerStartupSemaphoreName, 0 );

	if ( ret == KErrAlreadyExists )
		{
		// The server is starting up, but has not yet started 
		startupSemaphore.OpenGlobal( KServerStartupSemaphoreName );
		startupSemaphore.Wait(); // wait until the server has started up.
		startupSemaphore.Close();
		return ret;
		}

	// launch server thread (emulator) or process (Target platform)

	RProcess server;

	ret = server.Create( KDosServerExe, signal.Get(),
                       TUidType( KNullUid, KNullUid, KDosServerUid ),
                       EOwnerThread );

	if ( ret )
	{
		startupSemaphore.Close();
		return ret;
	}

	server.SetPriority(EPriorityHigh);

	server.Resume();
	server.Close();

	startupSemaphore.Wait();
	startupSemaphore.Close();

	return KErrNone;
}
Ejemplo n.º 9
0
GLDEF_C TInt E32Main()
	{     
	CTrapCleanup* TheTrapCleanup=CTrapCleanup::New();

#ifdef USE_FULL_GRAPHICAL_ENVIRONMENT
	// Cause the Eikon environment to come into existence
	RSemaphore sem;
	sem.CreateGlobal(_L("WsExeSem"),0);
	RegisterWsExe(sem.FullName());

	DoTest();
	User::InfoPrint(_L("Test passed"));

	sem.Wait();	// continue running Eikon until that exits as well
#else
	DoTest();
	User::InfoPrint(_L("Test passed"));
#endif

	return(KErrNone);
	}
Ejemplo n.º 10
0
TInt CCapabilityTestStep::StartServer()
	{
	TInt err = KErrNone;

    RMutex mutex;
    err = mutex.CreateGlobal(KSipServerStarterMutex);
    if (err != KErrNone)
        {
        err = mutex.OpenGlobal(KSipServerStarterMutex);
        if (err != KErrNone)
            {
            return err;
            }
        }
    mutex.Wait();
        {
        // Protected with a mutex
        TFindServer findServer(KSipServerName);
        TFullName name;
	    if (findServer.Next(name) == KErrNone)
            {
            mutex.Signal();
            mutex.Close();
            return KErrNone; // Server already running
            }

	    RSemaphore semaphore;
	    err = semaphore.CreateGlobal(KSipServerSemaphoreName,0);
	    if (err == KErrNone)
		    {
	        err = CreateServerProcess(semaphore);
	        semaphore.Close();
		    }
        }
    mutex.Signal();
    mutex.Close();

    return err;
	}
// ---------------------------------------------------------------------------
// Start server if it isn't running already
// ---------------------------------------------------------------------------
//
TInt RCatalogsPCConnectivityClient::StartServer()
    {
    // Check if the server is already running
    TFindServer findServer( KCatalogsPCConnectivityServerName );
    TFullName name;

    TInt result = findServer.Next( name );
    if ( result == KErrNone )
        {
        // Server is running
        return KErrNone;
        }

    // Create a semaphore so we can wait while the server starts
    RSemaphore semaphore;
    result = semaphore.CreateGlobal( 
    	KCatalogsPCConnectivityServerSemaphoreName, 0 );
    if ( result != KErrNone )
        {
        return result;
        }

    // Create new Engine service process 
    result = CreateServerProcess();
    if ( result != KErrNone )
        {
        semaphore.Close();
        return result;
        }

    // Wait while the server starts
    semaphore.Wait();

    // Semaphore has been signaled, close and return
    semaphore.Close();

    return KErrNone;
    }
Ejemplo n.º 12
0
TInt CCapabilityTestStep::StartServer()
{
	TInt err = KErrNone;

    TFindServer findServer(KSipClientResolverServerName);
    TFullName name;
	if (findServer.Next(name) == KErrNone)
        {
        return KErrNone; // Server already running
        }

	RSemaphore semaphore;
	err = semaphore.CreateGlobal(KSipClientResolverServerSemaphoreName,0);
	if (err != KErrNone)
		{
		return err;
		}

	err = CreateServerProcess(semaphore);
	semaphore.Close ();

    return err;
}
Ejemplo n.º 13
0
// -----------------------------------------------------------------------------
// MceServerStarter::Start
// -----------------------------------------------------------------------------
//
TInt MceServerStarter::Start ()
	{
	TInt err = KErrNone;

    TFindServer findServer( KMceServerName );
    TFullName name;
	if ( findServer.Next( name ) == KErrNone) 
        {
        return KErrNone; // Server already running
        }
		
	RSemaphore semaphore;
	err = semaphore.CreateGlobal( KMceServerSemaphoreName , 0 );
	if ( err != KErrNone )
		{
		return err;
		}

	err = CreateServerProcess( semaphore );
	semaphore.Close ();

    return err;
    
	}
Ejemplo n.º 14
0
GLDEF_C TInt E32Main()
//
// Test server & session cleanup.
//
    {
	RSemaphore svrSem;
	RSemaphore svrSem2;
	RSemaphore clientSem;
	RTest test(_L("T_SVR2"));
	test.Title();

	__KHEAP_MARK;

	test.Start(_L("Creating server semaphore"));
	TInt r=svrSem.CreateGlobal(KSvrSemName, 0);
	test(r==KErrNone);
	test.Next(_L("Creating server semaphore 2"));
	r=svrSem2.CreateGlobal(KSvrSem2Name, 0);
	test(r==KErrNone);
	test.Next(_L("Creating client semaphore"));
	r=clientSem.CreateGlobal(KClientSemName, 0);
	test(r==KErrNone);

	test.Next(_L("Creating server"));
	RThread server;
	r=server.Create(_L("MyServer"),serverThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)1);
	test(r==KErrNone);
	server.Resume();
	svrSem2.Wait(); // server up & running

	test.Next(_L("Forcing granularity expansion"));
	const TInt KNumberOfSessions=10;
	TInt i;
	RMySessionBase ts[KNumberOfSessions];
	for (i=0; i<KNumberOfSessions; i++)
		ts[i].Open();
	for (i=0; i<KNumberOfSessions; i++)
		ts[i].Close(); 

	test.Next(_L("Opening a session and closing it"));
	RMySessionBase t;
	r=t.Open();
	test(r==KErrNone);
	t.Close();
	RThread clientx;
	r=clientx.Create(_L("MyClientx"),clientThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)1);
	test(r==KErrNone);
	clientx.Resume();
	clientSem.Wait(); // client connected

	test.Next(_L("Creating client & killing it"));

	RThread client;
	r=client.Create(_L("MyClient"),clientThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)1);
	test(r==KErrNone);
	client.Resume();
	clientSem.Wait(); // client connected
	User::After(1000000);
	client.Kill(666); // kill the client

	clientx.Kill(666); // kill the client
	CLOSE_AND_WAIT(clientx);
	CLOSE_AND_WAIT(client);

	test.Next(_L("Creating client and killing server"));
	server.Kill(0);	// first kill the existing server 
	CLOSE_AND_WAIT(server);
	RThread client2;	// and create the client so the heap is in a good state for the mark
	r=client2.Create(_L("MyClient"),clientThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)2);
	test(r==KErrNone);
	client2.Resume();
	clientSem.Wait(); // client running but not connected

	RThread server2;
	r=server2.Create(_L("MyServer"),serverThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)2);
	test(r==KErrNone);
	server2.Resume();
	svrSem.Wait(); // client has request outstanding to server
	server2.Kill(666); // kill the server
	clientSem.Wait(); // client's request has completed & client has closed session
	User::After(1000000);
	client2.Kill(666);
	CLOSE_AND_WAIT(client2);
	CLOSE_AND_WAIT(server2);

	svrSem.Close();
	svrSem2.Close();
	clientSem.Close();

	__KHEAP_MARKEND; // and check the kernel's heap is OK

	test.End();
 	return(KErrNone);
    }
Ejemplo n.º 15
0
/**
 * Read command line parameters and control the launching of targets. 
 * Create global launch semaphore KLaunchSemaphoreName
 */
void MainL()
    {

    TInt numApps = KNumApps;
    TInt numLaunches = KNumLaunches;
    TInt launchControl = 0;

    TInt argc = User::CommandLineLength();
    HBufC* commandLine = NULL;
    RDebug::Printf( ">Launcher Process() argc=%d", argc );

    if( argc )
        {
        commandLine = HBufC::NewLC(argc);
        TPtr commandLineBuffer = commandLine->Des();
        User::CommandLine(commandLineBuffer);

        RBuf printCommandLine;
        CleanupClosePushL( printCommandLine );
        printCommandLine.CreateL( commandLine->Des().Length() );
        printCommandLine.Copy( commandLine->Des() );
        printCommandLine.Collapse();
        RDebug::Printf( ">command line = %S", &printCommandLine );
        CleanupStack::PopAndDestroy( &printCommandLine );

        // create a lexer and read through the command line
        TLex lex(*commandLine);
        while (!lex.Eos())
            {
            // only look for options with first character '+', other switches are for the targets
            if (lex.Get() == '+')
                {
                TChar arg = lex.Get();
                switch (arg)
                    {
                    case 'n':
                        lex.Val( numApps );
                        RDebug::Printf("parsed numApps as %d", numApps);
                        break;
                    case 'm':
                        lex.Val( numLaunches );
                        RDebug::Printf("parsed numLaunches as %d", numLaunches );
                        break;
                    case 'o':
                        lex.Val( launchControl );
                        RDebug::Printf("parsed launchControl as %d", launchControl);
                        break;
                    default:
                        // unknown argument ignore it
                        break;             
                    }//switch
                }// if +
            }//while
        }//if argc

   RSemaphore launchSemaphore;
   TInt ret = KErrNone;
   CleanupClosePushL( launchSemaphore );
   ret = launchSemaphore.CreateGlobal( KLaunchSemaphoreName, 0 );
   RDebug::Printf( ">Target Launcher : RSemaphore.CreateGlobal ret %d", ret);
   User::LeaveIfError( ret );

   ret = launchSemaphore.OpenGlobal( KLaunchSemaphoreName );
   RDebug::Printf( ">Target Launcher : RSemaphore.OpenGlobal ret %d", ret);
   User::LeaveIfError( ret );
   
   //Only now indicate to the launcher that we have fully started, so they can find and open the semaphore
   RProcess::Rendezvous(KErrNone);

   //Now launch the requested number of apps for the requested number of launches
   for( ; numLaunches > 0; numLaunches-- )
       { 
       for( TInt launchIndex = numApps; launchIndex > 0; launchIndex-- )  
           {
           RDebug::Printf( ">Target Launcher:  Semaphore wait app %d, launch %d", launchIndex, numLaunches );
           launchSemaphore.Wait();

           RBuf targetName;
           CleanupClosePushL( targetName );
           RDebug::Printf( ">Target Launcher:  targetName.Create %d, launch %d", launchIndex, numLaunches );
           targetName.Create( KTargetExe().Length() + 2 );

           if( launchControl == 1 )
               {
               // Reverse the order of the apps launched by reversing the index in the name
               RDebug::Printf( ">Target Launcher:  targetName.Format %d, launch %d", numApps - launchIndex + 1, numLaunches );
               targetName.Format( KTargetExe(), numApps - launchIndex + 1 );
               }
           else
               {
               RDebug::Printf( ">Target Launcher:  targetName.Format %d, launch %d", launchIndex, numLaunches );
               targetName.Format( KTargetExe(), launchIndex );
               }

           RProcess aProc;
           CleanupClosePushL( aProc ); 
    
           RDebug::Printf( ">Target Launcher: LaunchProcess %d, launch %d", launchIndex, numLaunches );
           RDebug::Printf( ">LaunchProcess %lS", &targetName );
           TPtr cmdLinePtr( commandLine->Des() );
           ret = LaunchProcess( aProc, targetName, cmdLinePtr );
           CleanupStack::PopAndDestroy( &aProc );

           RDebug::Printf( "<Target Launcher: LaunchProcess returned %d", ret );
           CleanupStack::PopAndDestroy( &targetName );

           User::LeaveIfError( ret );

           //By now the add proc event should have been delivered to the
           //test app agent.
           }
       }

    launchSemaphore.Wait( 500000 );

    CleanupStack::PopAndDestroy( &launchSemaphore );

    if( commandLine )
       CleanupStack::PopAndDestroy( commandLine );
 
    }
Ejemplo n.º 16
0
EXPORT_C TInt RDRMRightsClient::StartServer()
    {
    DRMLOG( _L( "RDRMRightsClient::StartServer()" ) );

    RSemaphore semaphore;
    RSemaphore semaphore2;
    TFindServer server( DRMEngine::KServerName );
    TFullName name;
    RProcess process;
    TInt error = KErrNone;

    // "local" semaphore
     error = semaphore2.CreateGlobal( KRightsServerStarterSemaphore,   // name
                                    1 ,              // count
                                    EOwnerThread );  // owner

    if ( error == KErrAlreadyExists )
        {
        error = semaphore2.OpenGlobal( KRightsServerStarterSemaphore );
        }


    // Semaphore not created or opened, don't need to close
    if( error )
        {
        return error;
        }

    // Server updated semaphore
    error = semaphore.CreateGlobal( DRMEngine::KDRMSemaphore,   // name
                                    0 ,              // count
                                    EOwnerThread );  // owner

    if ( error == KErrAlreadyExists )
        {
        error = semaphore.OpenGlobal( DRMEngine::KDRMSemaphore );
        }

    // Semaphore not created or opened, don't need to close
    if( error )
        {
        semaphore2.Close();
        return error;
        }

    // Wait until server has done all its things.
    semaphore2.Wait();

    // Check if the server is already running.
    error = server.Next( name );

    if ( !error )
        {
        // Yep, it's already running.
        error = KErrNone;
        }
    else
        {
        error = process.Create( KServerFileName,
                                KNullDesC );

        if ( !error )
            {
            User::After( 1000 );

            process.Resume();
            process.Close();

            // Wait here for the server process startup to complete
            // server will signal the global semaphore
            semaphore.Wait();
            }
        }

    // Close both semaphores and signal the "local" one.
    semaphore.Close();
    semaphore2.Signal();
    semaphore2.Close();

    DRMLOG2( _L( "RDRMRightsClient::StartServer(): %d" ), error );
    return error;

    }
/**
 * Start the server process/thread which lives in an EPOCEXE object.
 *
 * \internal
 * @return KErrNone if successful, any other error code otherwise
 */
TInt RSuplNetworkServer::StartServer()
    {
    TRequestStatus started;
    TInt ret;

    RSemaphore startupSemaphore;
    ret = startupSemaphore.CreateGlobal( KSuplServerStartupSemaphoreName, 0 );

    if ( ret == KErrAlreadyExists )
        {
        // The server is starting up, but has not yet started 
        startupSemaphore.OpenGlobal( KSuplServerStartupSemaphoreName );
        // wait until the server has started up, Max 5 secs.
        TInt err = startupSemaphore.Wait(5000000); 
        startupSemaphore.Close();
        if (err != KErrNone)
        	return err;
        else
        	return ret;
        }

#ifdef _DEBUG
    RDebug::Print(_L("SuplNetworkApi: Starting SUPL Server..."));
#endif
    const TUidType serverUid(KNullUid, KNullUid, KSuplServerUid3);

    // Simultaneous launching of two such processes should be detected 
    // when the second one attempts to create the server object, 
    // failing with KErrAlreadyExists.
    //
    RProcess server;
    ret = server.Create(KSuplServerImg, KNullDesC, serverUid);

    if (ret != KErrNone)
        {
#ifdef _DEBUG
        RDebug::Print(_L("SuplApi: server start failed %d"), ret);
#endif
        startupSemaphore.Close();
        return ret;
        }

    TRequestStatus died;
    server.Rendezvous(died);

    if (died != KRequestPending)
        {
        // logon failed - server is not yet running, so cannot have terminated
        User::WaitForRequest(died); // eat signal
        server.Kill(0);                         // abort startup
        }
    else
        {
        server.Resume();
        }
    User::WaitForRequest(died);                // wait for start or death

    // we can't use the 'exit reason' if the server panicked as this
    // is the panic 'reason' and may be '0' which cannot be distinguished
    // from KErrNone
    ret = (server.ExitType() == EExitPanic) ? KErrGeneral : died.Int();
    server.Close();
    startupSemaphore.Wait();
    startupSemaphore.Close();
    return ret;
    }
Ejemplo n.º 18
0
void StartL()
	{	
	// The following two lines create a semaphore which removes the security dialog
	// displayed when an untrusted certificate is received from a SSL server
	RSemaphore semaphore;
	semaphore.CreateGlobal(_L("T_AUTOSSL"), 0);

	TBool runTestDefault = EFalse;

	CTestScheduler* as = new(ELeave) CTestScheduler;
	CleanupStack::PushL(as);
	if (!as)
		{
		User::Panic(_L("Failed to create active scheduler"),KErrNoMemory);
		}
	CActiveScheduler::Install(as); // Install active scheduler
	
	// tialise Comms, required in a minimal console environment
	CHTTPTestUtils::InitCommsL();
	
	CHttpTestEngine* engine = NULL;
	// not silent by default
	TRAPD(err,engine = CHttpTestEngine::NewL(KHttpTestTitle(), ETrue));
	if (err != KErrNone)
		{
		User::Panic(_L("T_HTTP_ENG"),err);
		}
	CleanupStack::PushL(engine);

	engine->Utils().LogIt(_L("@SYMTestCaseID IWS-APPPROTOCOLS-HTTP-FRAMEWORK-ACCPT-T_HTTP-0001  "));
	
	// Open the INI file to initialise the tests we're going to run
	CScriptFile* iniFile = NULL;
	TRAP(err, iniFile = CScriptFile::NewL(engine->Utils(), KAcceptanceTestCompName));
	if (err != KErrNone)
		{
		User::Panic(_L("T_HTTP_INI"),err);
		}
	CleanupStack::PushL(iniFile);
	iniFile->ReadScriptL(KAcceptanceTestScriptName());

	// Open the settings.ini file which has the server IP/Name that would
	// be used by the tests.
	CScriptFile* iniSettingsFile = NULL;
	TRAP(err, iniSettingsFile = CScriptFile::NewL(engine->Utils(), KSettingsIniCompName, KSettingsIniName()));
	if (err != KErrNone)
		{
		User::Panic(KAcceptanceTestCompName(),err);
		}
	CleanupStack::PushL(iniSettingsFile);

	// Create an array containing all the tests we're going to run. 
	// Ownership is transferred to the test engine
	RPointerArray<CHttpTestBase> acceptanceTests;
	CleanupClosePushL(acceptanceTests);
	
	CArrayPtrFlat<CScriptSection>& sections=iniFile->Sections();

	//create the tests for iteration2   and  append them in the array
	AppendIteration1Tests(*iniFile, *iniSettingsFile, acceptanceTests);

	//create the  tests for iteration2   and  append them in the array
	TInt secCount = sections.Count();
	TInt count= secCount;
	CScriptSection* section = NULL;
	for (TInt i=0;i<count;i++)
		{
		//create an array of tests to be sent to the engine
		section = sections[i];
		_LIT(KZero, "0");

		if (section->SectionName().CompareF(KSectionDefaults) == 0)
			{
			if (iniFile->Section(i).ItemL(KItemSilent).Value().CompareF(KZero) == 0)
				{
   				engine->SetSilent(EFalse);
				}
 			else
				{
				engine->SetSilent(ETrue);
				}
 			if (iniFile->Section(i).ItemL(KRunTestItemName).Value().CompareF(KZero) != 0)
				{
				runTestDefault = ETrue;
				}
			}

		if ( section->SectionName().CompareF(KSectionSingleTrans) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestBase* singleTrans = CHttpTestSingleTrans::NewL(*iniFile,iniSettingsFile,i);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				singleTrans->SetLeakTests(numLeakTests, firstLeakIter);
   				acceptanceTests.Append(singleTrans);
   				}
			}

		if ( section->SectionName().CompareF(KSectionWspSingleTrans) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestBase* wspTrans = CWspTestTransactions::NewL(*iniFile, iniSettingsFile,i);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				wspTrans->SetLeakTests(numLeakTests, firstLeakIter);
   				acceptanceTests.Append(wspTrans);
   				}
			}

		if ( section->SectionName().CompareF(KSectionGet12) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseGet12* get12 = new(ELeave) CHttpTestCaseGet12(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				get12->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(get12);
   				}
			}

		if ( section->SectionName().CompareF(KSectionGet13) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseGet13* get13 = new(ELeave) CHttpTestCaseGet13(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				get13->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(get13);
   				}
			}
		if ( section->SectionName().CompareF(KSectionGet14) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseGet14* get14 = new(ELeave) CHttpTestCaseGet14(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				get14->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(get14);
   				}
			}
		if ( section->SectionName().CompareF(KSectionGet17) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseGet17* get17 = new(ELeave) CHttpTestCaseGet17(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				get17->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(get17);
   				}
			}

		if ( section->SectionName().CompareF(KSectionGet18) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
	   			CHttpTestCaseGet18* get18 = new(ELeave) CHttpTestCaseGet18(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				get18->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(get18);
   				}
			}
		if ( section->SectionName().CompareF(KSectionGet21) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseGet21* get21 = new(ELeave) CHttpTestCaseGet21;
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				get21->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(get21);
   				}
			}
		if ( section->SectionName().CompareF(KSectionPost12) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCasePost12* post12 = new(ELeave) CHttpTestCasePost12(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				post12->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(post12);
   				}
			}
		if ( section->SectionName().CompareF(KSectionPost13) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCasePost13* post13 = new(ELeave) CHttpTestCasePost13(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				post13->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(post13);
   				}
			}	
		if ( section->SectionName().CompareF(KSectionPost14) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCasePost14* post14 = new(ELeave) CHttpTestCasePost14(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				post14->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(post14);
   				}
			}
		if ( section->SectionName().CompareF(KSectionPost23) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCasePost23* post23 = new(ELeave) CHttpTestCasePost23(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				post23->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(post23);
   				}
			}
		if ( section->SectionName().CompareF(KSection3Post6) == 0)
			{
			TBool runTest = runTestDefault;
   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseIter3Post6* iter3Post6= new(ELeave) CHttpTestCaseIter3Post6(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				iter3Post6->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(iter3Post6);
   				}
			}
		if ( section->SectionName().CompareF(KSection3Post7) == 0)
			{
			TBool runTest = runTestDefault;
   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseIter3Post7* iter3Post7 = new(ELeave) CHttpTestCaseIter3Post7(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				iter3Post7->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(iter3Post7);
   				}
			}
		if ( section->SectionName().CompareF(KSection5Chunked1) == 0)
			{
			TBool runTest = runTestDefault;
   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseIter5Chunked1* iter5Chunked1 = new(ELeave) CHttpTestCaseIter5Chunked1(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				iter5Chunked1->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(iter5Chunked1);
   				}
			}
		if ( section->SectionName().CompareF(KSection5Chunked2) == 0)
			{
			TBool runTest = runTestDefault;
   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
   				CHttpTestCaseIter5Chunked2* iter5Chunked2 = new(ELeave) CHttpTestCaseIter5Chunked2(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				iter5Chunked2->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(iter5Chunked2);
   				}
			}

		if ( section->SectionName().CompareF(K3BasicAuthTransactions) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
	   			C3BasicAuthTransactions* basicAuthTrans = new(ELeave) C3BasicAuthTransactions(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				basicAuthTrans->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(basicAuthTrans);
   				}
			}

		if ( section->SectionName().CompareF(K3DigestAuthTransactions) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
	   			C3DigestAuthTransactions* digestAuthTrans = new(ELeave) C3DigestAuthTransactions(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				digestAuthTrans->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(digestAuthTrans);
   				}
			}

		if ( section->SectionName().CompareF(KEofTransactionResubmission) == 0)
			{
			TBool runTest = runTestDefault;

   			TPtrC itemPtr(iniFile->Section(i).Item(0).Item());
 			if (itemPtr.CompareF(KRunTestItemName)==0)
				{
 				runTest = !(iniFile->Section(i).Item(0).Value().CompareF(KZero) == 0);
				}
 			if (runTest)
   				{
	   			CEofTransactionResubmission* eofTransResubmission = new(ELeave) CEofTransactionResubmission(iniSettingsFile);
				TInt numLeakTests = iniFile->ItemValue(iniFile->Section(i).SectionName(), KLeakTestCount(), 0);
				TInt firstLeakIter = iniFile->ItemValue(iniFile->Section(i).SectionName(), KFirstLeakIteration(), 0);
				eofTransResubmission->SetLeakTests(numLeakTests, firstLeakIter);
				acceptanceTests.Append(eofTransResubmission);
   				}
			}
		}
	
	// Set the test array then pop because the engine takes ownership
	engine->ConfigureTestSet(acceptanceTests);		

	//--------
	CleanupStack::Pop(&acceptanceTests);// 

	// All the action happens within the main event loop
	CActiveScheduler::Start();

	TInt pass, fail;
	engine->TestSummary(pass, fail);
	engine->Utils().LogIt(_L("\nTest Summary: %d passed, %d failed.\n"), 
		pass, fail);
	engine->PressAnyKey();
	// Returned from start so shutdown	
	//RL: pause a sec to get a gander
	engine->Utils().LogIt(_L("\nEnd of test program "));	
	CleanupStack::PopAndDestroy(4); // engine, iniSettingsFile, iniFile, as
	}
Ejemplo n.º 19
0
// -----------------------------------------------------------------------------
// RDRMHelper::StartServer
// -----------------------------------------------------------------------------
//
TInt RDRMHelper::StartServer()
{
    RThread currentThread;
    const TUint32 secureIdAsTuint32( currentThread.SecureId() );
    TRACE2( "RDRMHelper::StartServer(): currentThread: 0x%08x",
            secureIdAsTuint32 );
    if ( currentThread.SecureId() == KServerSecureId )
    {
        // HelperServer cannot connect to itself.
        return KErrCouldNotConnect;
    }

    TInt result( 0 );

    TFindServer findHelperServer( KDRMHelperServerName );
    TFullName name;

    result = findHelperServer.Next( name );
    TRACE2( "RDRMHelper::StartServer(): result: %d", result );
    if ( result == KErrNone )
    {
        // Server already running
        return KErrNone;
    }

    RSemaphore semaphoreStarting;
    TInt semaphoreExist( semaphoreStarting.CreateGlobal(
                             KDRMHelperServerSemaphoreStartingName, 0 ) );
    TRACE2( "RDRMHelper::StartServer(): semaphoreExist: %d", semaphoreExist );

    if( semaphoreExist != KErrAlreadyExists && semaphoreExist != KErrNone )
    {
        return semaphoreExist;
    }

    // Semaphore exists, wait until server is finished with it's tasks
    if ( semaphoreExist == KErrAlreadyExists )
    {
        TInt openErr( semaphoreStarting.OpenGlobal(
                          KDRMHelperServerSemaphoreStartingName) );
        TRACE2( "RDRMHelper::StartServer(): openErr: %d", openErr );
        if ( openErr != KErrNone )
        {
            return openErr;
        }

        TRACE( "RDRMHelper::StartServer(): semaphoreStarting.Wait()" );
        semaphoreStarting.Wait();
        TRACE( "RDRMHelper::StartServer(): semaphoreStarting.Wait() - returning" );
    }
    else
    {
        RSemaphore semaphoreStartServer;
        TInt result( semaphoreStartServer.CreateGlobal(
                         KDRMHelperServerSemaphoreName, 0 ) );
        TRACE2( "RDRMHelper::StartServer(): 2 result: %d", result );
        if ( result != KErrNone )
        {
            semaphoreStarting.Close();
            return result;
        }

        result = CreateServerProcess();
        TRACE2( "RDRMHelper::StartServer(): 3 result: %d", result );
        if ( result != KErrNone )
        {
            return  result;
        }

        semaphoreStartServer.Wait();
        semaphoreStartServer.Close();

        TRACE( "RDRMHelper::StartServer(): semaphoreStarting.Signal()" );

        semaphoreStarting.Signal();
        semaphoreStarting.Close();
    }

    TRACE( "RDRMHelper::StartServer(): return KErrNone" );
    return  KErrNone;
}
Ejemplo n.º 20
0
void CSsTestStepProcStart::DoTestForMonitorAlreadyMonProcL()
	{
	INFO_PRINTF1( _L("\n\nPerforming Process-monitor test for already started and monitored process") );
	
	RProcess process;
	CleanupClosePushL(process);
	
	CSsmStartupProperties* startupProperties = CSsmStartupProperties::NewL();
	CleanupStack::PushL( startupProperties );
	
	// Need to start testprocess as a server so that we can tell it to stop being monitored.
	startupProperties->SetFileParamsL(KTestProcGood, KLaunchServerCommandLineOption);
	startupProperties->SetCommandTypeL(ESsmCmdStartProcess);
	startupProperties->SetExecutionBehaviour(ESsmWaitForSignal);
	
	const TInt KMonitorTimeout = 3000; // milliseconds I presume
	TSsmMonitorInfo monitorInfo;
	monitorInfo.iRestartPolicy = ESsmIgnoreOnFailure;
	monitorInfo.iRestartMode = 0;
	monitorInfo.iTimeout = KMonitorTimeout;
	monitorInfo.iRetries = 1;
	startupProperties->SetMonitorInfoL(monitorInfo);

	CSsmStartSafe* ss  = CSsmStartSafe::NewLC();

	// Try to start and monitor the process
	TRAPD(err, ss->StartAndMonitorL(*startupProperties, process));
	TEST(err == KErrNone);
	INFO_PRINTF3( _L("StartAndMonitorL() completed with %d. anticipated value %d"),err, KErrNone );
	
	RTestProcGoodSession testProcServerSession;
	err = testProcServerSession.Connect();
	TEST(KErrNone == err);
	INFO_PRINTF1( _L("Asserted that server is running"));

	// Try to start and monitor an already started and monitored process
	TRAP(err, ss->StartAndMonitorL(*startupProperties, process));

	// sysmon returns KErrAlreadyExists, if we try to monitor an already monitored process
	TEST(err == KErrAlreadyExists);
	INFO_PRINTF3( _L("StartAndMonitorL() completed with %d. anticipated value %d"),err, KErrAlreadyExists);
	
	process.Kill(KErrNone);
	
	err = testProcServerSession.Connect();
	//Connecting to the test proc server session should fail here with error value as either KErrNotFound(in case session object is cleaned up) or KErrServerTerminated(session object is there but session terminated) 
	TEST(KErrNotFound == err || KErrServerTerminated == err);
	INFO_PRINTF3( _L("Connect to test proc server session failed with %d. anticipated value %d"),err, KErrNotFound);

	RSemaphore sem;
	err = sem.CreateGlobal(KStartProcSignalSemaphore, 0);
	INFO_PRINTF2(_L("Created semaphore with err %d"),err);
	TEST(err == KErrNone);
	CleanupClosePushL(sem);
	
	INFO_PRINTF1(_L("Waiting for Start of the test application"));
	sem.Wait();
	//Waiting for 5 seconds as in the ssmtestprocgood application the active scheduler
	// will be started after signalling the semaphore.  And we can connect to the
	// application only after the active scheduler is started.
	User::After(KWaitForActiveSchedStart);
	
	// Check that the killed process is restarted by SysMon
	err = testProcServerSession.Connect();
	TEST(KErrNone == err);
	INFO_PRINTF3( _L("process re-started by sysmon with %d, anticipate value %d"),err,KErrNone);
	
	// Stop monitoring to stop restarts.
	if(KErrNone == testProcServerSession.Connect())
		{
		testProcServerSession.CancelMonitor();
		testProcServerSession.Close();
		}
	TEST(1 == FindAndKill(KTestProcGood));
	CleanupStack::PopAndDestroy(4, &process);
	}
/**
 * Read command line parameters and control the launching of the agents. 
 */
void MainL()
	{	
	LOG_MSG( "ENTER: t_multi_agent_launcher MainL()");

	TInt ret = KErrNone;
	TInt numAgents = KNumAgents;
	TInt numTargets = KNumTargets;
	TInt numTestRuns = KNumTestRuns;

	TInt argc = User::CommandLineLength();
	HBufC* commandLine = NULL;
	LOG_MSG2("t_multi_agent_launcher: MainL(): argc=%d", argc);
    
	if(argc)
		{
		commandLine = HBufC::NewLC(argc);
		TPtr commandLineBuffer = commandLine->Des();
		User::CommandLine(commandLineBuffer);

		RBuf printCommandLine;
		CleanupClosePushL( printCommandLine );
		printCommandLine.CreateL( commandLine->Des().Length() );
		printCommandLine.Copy( commandLine->Des() );
		printCommandLine.Collapse();
		LOG_MSG2("t_multi_agent_launcher: command line = %S", &printCommandLine);
		CleanupStack::PopAndDestroy( &printCommandLine );
 
		// create a lexer and read through the command line
		TLex lex(*commandLine);
		while (!lex.Eos())
			{
			// only look for options with first character '-'
			if (lex.Get() == '-')
				{
					TChar arg = lex.Get();
					switch ( arg )
						{
						case 'n':
							lex.Val( numAgents );
							LOG_MSG2("t_multi_agent_launcher: parsed numAgents as %d", numAgents);
							break;
						case 'm':
							lex.Val( numTargets );
							LOG_MSG2("t_multi_agent_launcher: parsed numTargets as %d", numTargets);                        
							break;  
						case 't':
							lex.Val( numTestRuns );
							LOG_MSG2("t_multi_agent_launcher: parsed numTestRuns as %d", numTestRuns);                        
							break;                    
						default:
							LOG_MSG("t_multi_agent_launcher: unknown argument ignoring it");
							break;                 
						}
				}
			}
		}

	// Note: below is a workaround to overcome an issue with RTest server crashing 
	// when writing to the windows console from different agents (on different CPUs 
	// at the same time). To overcome this we get signaled by the agents when they have 
	// completed their tests so that we can do a RTest complete
	RSemaphore launchSemaphore;
	CleanupClosePushL(launchSemaphore);
	ret = launchSemaphore.CreateGlobal(KLaunchSemaphoreName, 0);
	LOG_MSG2( ">Target Launcher : RSemaphore.CreateGlobal ret %d", ret);
	User::LeaveIfError( ret );

	ret = launchSemaphore.OpenGlobal(KLaunchSemaphoreName);
	LOG_MSG2( ">Target Launcher : RSemaphore.OpenGlobal ret %d", ret);
	User::LeaveIfError( ret );

	//Now launch the requested number of apps for the requested number of test runs
	for( TInt j = 0; j < numTestRuns; j++ )
		{ 
			for( TInt i = 0; i < numAgents; i++ )  
				{
					RBuf targetName;
					targetName.CleanupClosePushL();
					targetName.CreateL(KAgentExe());

					RProcess aProc;
					CleanupClosePushL(aProc); 
					RBuf launcherOptions;
					CleanupClosePushL(launcherOptions);
				    const TInt additionalWords = 2;	
					launcherOptions.CreateL( KAgentOptions().Length() + additionalWords );
		
					// Apply offset: launcherOptions.Format( .., .., i * numTargets, ..)
					// workaround to ensure we have the same binary for multiple agents. 
					// e.g. So if offset = 0, agent attaches to app1, app2, app3, app4, app5
					// if offset = 5, agent attached to app6, app7, app8, app9, app10 etc.
					// Note: apps need to be in rom otherwise the agent will fail on an assert 
					// (with KErrNotFound)
					launcherOptions.Format( KAgentOptions(), (TUint)numTargets, i * numTargets, 0);
			
					ret = LaunchProcess( aProc, targetName, launcherOptions );	
					CleanupStack::PopAndDestroy(3,&targetName);
					User::LeaveIfError(ret);
				}
		}

	// Wait for all agents to do their testing before checking the semaphore
	User::After(12000000);

	LOG_MSG( ">Target Launcher:  Semaphore wait");

	for (TInt i = 0; i < numAgents; i ++)
		{
		//We need this delay just in case an agent crashes and never signals the sem
		ret = launchSemaphore.Wait(100000);
		if( ret != KErrNone )
			{
			LOG_MSG3("launchSemaphore.Wait ret %d for agent %d", ret, i);
			break;
			}
		}

	LOG_MSG2( "testing for Semaphore ret %d", ret);

	// We only want to have one RTest instance at any one time since otherwise RTest can panic
	RTest test(_L("T_MULTI_AGENT_LAUNCHER"));
	test.Start(_L("t_multi_agent_launcher Check for agents finishing correctly"));
	test(ret == KErrNone);
	test.End();
	test.Close();

	CleanupStack::PopAndDestroy(&launchSemaphore); // launchSemaphore

	if( commandLine )
	CleanupStack::PopAndDestroy(commandLine);
	
	LOG_MSG("EXIT: t_multi_agent_launcher MainL()");
	}
EXPORT_C void StartServerL(const TDesC& aServerName, TUid aServerUid3, const TDesC& aServerFileName)
#endif
{
	CALLSTACKITEM_N(_CL(""), _CL("StartServer"));

	TBuf<50> mutexname; MakeServerMutexName(mutexname, aServerName);
	RAMutex mutex; mutex.GlobalLA(mutexname);
	
	TFindServer findServer(aServerName);
	TFullName name;
	
	if (findServer.Next(name) == KErrNone)
        {
		return;
        }
	
#if defined(__WINS__)
	RAThread serverthread;
#else
	RAProcess serverthread;
#endif
	TBuf<50> semaphorename; MakeServerSemaphoreName(semaphorename, aServerName);
	RSemaphore semaphore;
	if (semaphore.CreateGlobal(semaphorename, 0)!=KErrNone) {
		User::LeaveIfError(semaphore.OpenGlobal(semaphorename));
	}

#if defined(__WINS__)
	CreateServerProcessLA(aServerName, aFunction, serverthread);
#else
	CreateServerProcessLA(aServerName, aServerUid3, aServerFileName, serverthread);
#endif
	
	TTimeIntervalMicroSeconds32 w(10*1000);
	TInt i=0;
	TInt result=KErrTimedOut;
	while (i < 17) { 
		// a couple of minutes, in case there's some db conversion or the like
#ifdef __S60V3__
		if (semaphore.Wait(w.Int())==KErrNone) {
#else
		if ( semaphore.Count()>0) {
#endif
			result=KErrNone;
			break;
		}
		TExitType etype=serverthread.ExitType();
		if (etype!=EExitPending) {
			// server died
			result=KErrServerTerminated;
			break;
		}
#ifndef __S60V3__
		User::After(w);
#endif
		w=w.Int()*2;
		i++;
	}
	if (result!=KErrNone) {
		User::Leave(result);
	}

	semaphore.Close();
}

#if defined(__WINS__)
void CreateServerProcessLA(const TDesC& aServerName, TThreadFunction aFunction,
				RAThread& aThreadInto)
#else
#  if defined(__WINS__)
void CreateServerProcessLA(const TDesC& aServerName, TUid aServerUid3, 
				    const TDesC& aServerFileName,
				RAThread& aThreadInto)
#  else
void CreateServerProcessLA(const TDesC& aServerName, TUid aServerUid3, 
				    const TDesC& aServerFileName,
				RAProcess& aThreadInto)
#  endif
#endif
{
	CALLSTACKITEM_N(_CL(""), _CL("CreateServerProcess"));

	TInt result;
	
	
#if defined(__WINS__)
	
//#  if !defined(EKA2)
#if 0
	const TUidType serverUid(KNullUid, KNullUid, aServerUid3);
	RLibrary lib;
	TInt err=lib.Load(aServerFileName, _L("z:\\system\\programs"), serverUid);
	if (err!=KErrNone) {
		err=lib.Load(aServerFileName);
	}
	User::LeaveIfError(err);
	
	//  Get the WinsMain function
	TLibraryFunction functionWinsMain = lib.Lookup(1);
	
	//  Call it and cast the result to a thread function
	TThreadFunction serverThreadFunction = reinterpret_cast<TThreadFunction>(functionWinsMain());
#  else
	TThreadFunction serverThreadFunction = aFunction;
#  endif
	
	TName threadName(aServerName);
	
	// Append a random number to make it unique
	threadName.AppendNum(Math::Random(), EHex);
	
#  if 0
//#  if !defined(EKA2)
	aThreadInto.CreateLA(threadName,   // create new server thread
		serverThreadFunction, // thread's main function
		KDefaultStackSize,
		NULL,  // parameters
		&lib,
		NULL,
		KServerMinHeapSize,
		KServerMaxHeapSize,
		EOwnerProcess);
	lib.Close();    // if successful, server thread has handle to library now
	
#  else
	aThreadInto.CreateLA(threadName, serverThreadFunction, 
		KDefaultStackSize,
		KServerMinHeapSize, KServerMaxHeapSize, 0, EOwnerProcess);

#  endif
	
	aThreadInto.SetPriority(EPriorityMore);
	
#else
	
	const TUidType serverUid(KNullUid, KNullUid, aServerUid3);
	aThreadInto.CreateLA(aServerFileName, _L(""), serverUid);
	
#endif
	
	aThreadInto.Resume();
	
}
Ejemplo n.º 23
0
TBool CC32RunThreadStep::ThreadCreationL()
 /**
 * @return - TBool
 * Implementation of ThreadCreationL virtual function
 * This function is used to spawn each client thread and result will be logged to 
 * a HTML file.
 * returns EFalse if a thread panics or test case fails.
 */	  	 
 	 {
 	 //create a global semaphore     
                       
     RSemaphore clientSemaphore;
     CleanupClosePushL(clientSemaphore);
     
     TInt result = clientSemaphore.CreateGlobal(KSemaphoreName, 0);
     
     //create threads based on the information given in ini file    
         
	 for (TInt n = 0 ; n<iTaskCounter; n++ )
		 {
		 iNetPerformanceThread[n] = new(ELeave) C32PerformanceThread( *iThreadData[n] );
		 TName name;
		 name.Copy( iThreadData[n]->iThreadName );
		 RThread thread;
		 const TUint KStackSize=0x1000;
		 TInt nErr;
		 if ( (nErr = thread.Create(name, C32PerformanceThread::RunL, KStackSize, NULL, iNetPerformanceThread[n])) == KErrNone)
			 {
			 thread.SetPriority(ParseThreadPriority(iThreadData[n]->iThreadPriority));
			 thread.Logon(iRequestStatus[n]);
			 thread.Resume();
			 thread.Close();
			 }
		 else
			 {
			 INFO_PRINTF3(_L(" Failed to create thread = %S .Failed with error = %d  "),&iThreadData[n]->iThreadName,nErr);	 	
			 }
		 }
	  	  
	  	   
	  INFO_PRINTF1(_L("------------------------ C32 Performance Results -------------------------------- "));
		  	
	  for (TInt j=0 ; j<iTaskCounter; j++ )
		 {
		 //wait for the thread to complete
		 User::WaitForRequest( iRequestStatus[j] );

		 //print the results to a log file	
    	 INFO_PRINTF2(_L(" Thread Name 			   	 = %S  "),&iThreadData[j]->iThreadName);
    	 INFO_PRINTF2(_L(" Task Name 			   	 = %S  "),&iThreadData[j]->iTaskName);
    	 INFO_PRINTF2(_L(" Time taken to execute the thread = %ld microseconds "), iThreadData[j]->iThreadTime);
    	 INFO_PRINTF2(_L(" Error occured in line no         = %d. Expected value was 0 "), iThreadData[j]->iTestResult);
    	 INFO_PRINTF2(_L(" Thread terminated value          = %d. Expected value was 0 "),iRequestStatus[j].Int());
    	
    	 INFO_PRINTF1(_L("--------------------------------------------------------------------------------- "));	
		}
		
	  CleanupStack::PopAndDestroy();	
      
      /*
        iTestResult is used to indicate the line no of the error occured in each test case.
        return EFalse,if a test case failed or a thread paniced
      */
      for (TInt j=0 ; j<iTaskCounter; j++ )
		  {	
	   		if((iThreadData[j]->iTestResult > 0) || (iRequestStatus[j].Int() > 0 ))
    	 		{
    	 		return EFalse;
    	 	    }
		  }
     return ETrue;
     }
// -----------------------------------------------------------------------------
// RUsbPnClient::ConnectL
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
EXPORT_C void RUsbPnClient::ConnectL()
    {
    OstTrace0( TRACE_BORDER, RUSBPNCLIENT_CONNECTL_ENTRY, "RUsbPnClient::ConnectL" );
    A_TRACE( ( _T( "RUsbPnClient::ConnectL()" ) ) );

    TInt err( KErrNone );

    // Create USB Phonet Link Server session
    err = CreateSession( KUsbPnServerName, TVersion(1,0,0));

    if ( err == KErrNotFound )
        {
        // Session not created

        // Find lock semaphore for server process creation
        TFindSemaphore lock( KUsbPnServerName );
        TFullName semaphoreName;
        err = lock.Next( semaphoreName );

        if ( err == KErrNotFound )
            {
            // Lock is not enabled
            OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL, "RUsbPnClient::ConnectL() - semaphore not found, start server" );
            E_TRACE( ( _L( "RUsbPnClient::ConnectL() - semaphore not found, start server" ) ) );

            RSemaphore startLock;

            // Create lock
            User::LeaveIfError( startLock.CreateGlobal( KUsbPnServerName, 0, EOwnerProcess ) );


            /********************************************/
            /* Start the USB Phonet Link process process */
            TRequestStatus status;
            RProcess server;

            User::LeaveIfError( server.Create( KUsbPnServerName, TPtrC( NULL, 0),
                         EOwnerThread ) );

            server.Rendezvous( status );

            if( status != KRequestPending )
              {
              server.Kill(0);  // Abort startup
              }
            else
              {
              server.Resume();  // Logon OK -> start the server
              }

            OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP1, "RUsbPnClient::ConnectL() - waiting server response" );
            E_TRACE( ( _T( "RUsbPnClient::ConnectL() - waiting server response" ) ) );
            User::WaitForRequest( status );  // Wait for start or death

            // we can't use the 'exit reason' if the server panicked as this
            // is the panic 'reason' and may be '0' which cannot be distinguished
            // from KErrNone
            TInt err = status.Int();
            if (err == KErrNone && (server.ExitType() == EExitPanic || server.ExitType() == EExitKill))
              {
              err = KErrServerTerminated;
              }

            server.Close();

            if( err )
                {
                OstTrace1( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP2, "RUsbPnClient::ConnectL() - waiting server response status; err=%d", err );
                E_TRACE( ( _T( "RUsbPnClient::ConnectL() - waiting server response status: %d" ), err ) );
                TRACE_ASSERT_ALWAYS;
                User::LeaveIfError( err );
                }
            /* End of starting process */
            /********************************************/

            OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP3, "RUsbPnClient::ConnectL() - server is started, signal other clients" );
            E_TRACE( ( _L( "RUsbPnClient::ConnectL() - server is started, signal other clients" ) ) );
            // Signal other clients
            startLock.Signal( KMaxTInt );

            // Close semaphore
            startLock.Close();
            }
        else
            {
            // Lock is enabled

            RSemaphore startLock;

            // Open lock semaphore
            User::LeaveIfError( startLock.Open( lock ) );

            OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP4, "RUsbPnClient::ConnectL() - server is starting, wait for signal" );
            E_TRACE( ( _L( "RUsbPnClient::ConnectL() - server is starting, wait for signal" ) ) );
            // Wait for signal
            startLock.Wait();
            OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP5, "RUsbPnClient::ConnectL() - signal received" );
            E_TRACE( ( _L( "RUsbPnClient::ConnectL() - signal received" ) ) );

            // Close semaphore
            startLock.Close();

            }

        // Create USB Phonet Link server session
        OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP6, "RUsbPnClient::ConnectL() - Create session" );
        E_TRACE( ( _L( "RUsbPnClient::ConnectL() - Create session" ) ) );

        User::LeaveIfError( CreateSession( KUsbPnServerName, TVersion(1,0,0) ) );

        OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP7, "RUsbPnClient::ConnectL() - session created1" );
        E_TRACE( ( _L( "RUsbPnClient::ConnectL() - session created1" ) ) );
        }
    else if ( err )
        {
        OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP8, "RUsbPnClient::ConnectL() - session not created, reason uknown" );
        E_TRACE( ( _L( "RUsbPnClient::ConnectL() - session not created, reason uknown" ) ) );            
        TRACE_ASSERT_ALWAYS;
        User::Leave( err );
        }
    else
        {
        OstTrace0( TRACE_INTERNALS, RUSBPNCLIENT_CONNECTL_DUP9, "RUsbPnClient::ConnectL() - session created2" );
        E_TRACE( ( _T( "RUsbPnClient::ConnectL() - session created2" ) ) );
        }
    OstTrace0( TRACE_BORDER, RUSBPNCLIENT_CONNECTL_EXIT, "RUsbPnClient::ConnectL() - return void" );
    A_TRACE( ( _T( "RUsbPnClient::ConnectL() - return void" ) ) );
    }