Exemple #1
0
void SetAbsoluteTimeout(RTimer& aTimer, TUint aUs, TRequestStatus& aStatus)
	{
	TTime wakeup;
	wakeup.HomeTime();
	wakeup += TTimeIntervalMicroSeconds(aUs);
	aTimer.At(aStatus, wakeup);
	}
Exemple #2
0
void CPasswordTest::TurnOffAndOn()
	{
/*#if defined(LOG_TESTS)
	TLogMessageText buf;
	_LIT(KSettingTime,"Setting Off Timer");
	buf.Append(KSettingTime);
	Client()->LogMessage(buf);
#endif*/
	RTimer timer;
	timer.CreateLocal();
	TTime time;
	time.HomeTime();
	time+=TTimeIntervalSeconds(7);	// For some reason the O/S won't switch off for less than 6 seconds
	TRequestStatus status;
	timer.At(status,time);
	UserHal::SwitchOff();
	User::WaitForRequest(status);
#if !defined(__WINS__)
	TRawEvent event;
	event.Set(TRawEvent::ESwitchOn);
	UserSvr::AddEvent(event);
#endif
/*#if defined(LOG_TESTS)
	TLogMessageText buf;
	_LIT(KTimerOff,"Timer Gone Off (P=%d,S=%d)");
	buf.AppendFormat(KTimerOff,iState,iPassState);
	Client()->LogMessage(buf);
#endif*/
	}
Exemple #3
0
GLDEF_C TInt E32Main()
	{
#if defined (__WINS__)
	// Connect to all the local drives first as will be the case in ARM
	TBusLocalDrive Drive[KMaxLocalDrives];
	TBool ChangedFlag[KMaxLocalDrives];
	TInt i;
	for (i=0;i<KMaxLocalDrives;i++)
		Drive[i].Connect(i,ChangedFlag[i]);
#endif

	test.Title();
//
	test.Start(_L("Load/open logical device"));
	TInt r;
	r=User::LoadLogicalDevice(_L("D_PCCDIF"));
	test(r==KErrNone||r==KErrAlreadyExists);
	RPcCardCntrlIf pccdDrv;
	r=pccdDrv.Open(KSocket,pccdDrv.VersionRequired());
	test(r==KErrNone);
//
	test.Next(_L("Power card and configure."));
	UserSvr::ForceRemountMedia(ERemovableMedia0); // Media change - ensures test always starts from same state
	User::After(300000);	// Allow 0.3s after power down for controller to detect door closed.
    pccdDrv.Reset();
	TRequestStatus mrs;
	test(pccdDrv.RegisterEvent(EPcCardEvMediaChange,&mrs)==KErrNone);
	TRequestStatus prs;
	pccdDrv.PwrUp(&prs);
	User::WaitForRequest(prs);
	test(prs.Int()==KErrNone);
	TPcCardStatus s;
	TSocketSignals ind;
	test(pccdDrv.SocketInfo(s,ind)==KErrNone);
	test(s==EPcCardReady);

	TPcCardTypePckg tyBuf;
	TPcCardType &ty=tyBuf();
	test(pccdDrv.CardInfo(&tyBuf)==KErrNone);
	test(ty.iFuncType[0]==EFFixedDiskCard);
	test(pccdDrv.ReqConfig(KFunc,1)==KErrNone);

	// Test we can get the same chunk as the controllers attrib. chunk (its shareable).
	test.Next(_L("Request 64K attribute chunk at 0H."));
	TPcCardChnk ch;
	ch.iMemType=EPcCardAttribMem;
	ch.iMemBaseAddr=0;
	ch.iMemLen=0x10000;
	TInt win0,win1,win2;
	test(pccdDrv.ReqMem(ch,EAccSpeed600nS,win0)==KErrNone);
	TBuf8<8> rdBuf;
	rdBuf.Fill(0,8);
	test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
//	test(rdBuf.Compare(_L("\x01\xFF\x04\xFF\xDF\xFF\x72\xFF"))==0);
	test(rdBuf[0]==0x01&&rdBuf[2]==0x04&&rdBuf[4]==0xDF&&rdBuf[6]==0x72);

	// Test we can get small chunk within the controllers attrib. chunk (Win0 already allocated).
	test.Next(_L("Request 16byte attribute chunk at 10H."));
	ch.iMemType=EPcCardAttribMem;
	ch.iMemBaseAddr=0x10;
	ch.iMemLen=0x10;
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied); // 1st chunk isn't shared
	pccdDrv.RelMem(win0);
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
	rdBuf.Fill(0,8);
	test(pccdDrv.ReadMem(win1,0,8,rdBuf)==KErrNone);
//	test(rdBuf.Compare(_L("\x03\xFF\xD9\xFF\x01\xFF\xFF\xFF"))==0);
	test(rdBuf[0]==0x03&&rdBuf[2]==0xD9&&rdBuf[4]==0x01&&rdBuf[6]==0xFF);

	// Test we can get a second small chunk, also within the controllers attrib. chunk but
	// not clashing with previous chunk (Win1 already allocated).
	test.Next(_L("Request 16byte attribute chunk at 20H."));
	ch.iMemType=EPcCardAttribMem;
	ch.iMemBaseAddr=0x20;
	ch.iMemLen=0x10;
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win0)==KErrNone);
	rdBuf.Fill(0,8);	
	test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
//	test(rdBuf.Compare(_L("\x20\xFF\x06\xFF\x45\xFF"))==2&&rdBuf[6]==0x00&&rdBuf[7]==0xFF); // 'Null causes problems with compare
	test(rdBuf[0]==0x20&&rdBuf[2]==0x06&&rdBuf[4]==0x45&&rdBuf[6]==0x00);

	// Test that requesting a chunk which lies partly but not entirely within the controllers
	// chunk fails (Win0/Win1 already allocated).
	test.Next(_L("Request 64K attribute chunk at 800H."));
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win2)==KErrInUse);
	pccdDrv.RelMem(win1);
	ch.iMemType=EPcCardAttribMem;
	ch.iMemBaseAddr=0x800;
	ch.iMemLen=0x10000;
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied);

	// Test we can get a small chunk beyond the controllers chunk (Win0 already allocated).
	test.Next(_L("Request 16byte attribute chunk at 10800H."));
	ch.iMemType=EPcCardAttribMem;
	ch.iMemBaseAddr=0x10800;
	ch.iMemLen=0x10;
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
	pccdDrv.RelMem(win1);

	// Test we can get a large chunk beyond the controllers chunk (Win0 already allocated).
	test.Next(_L("Request 4K attribute chunk at 10800H."));
	ch.iMemType=EPcCardAttribMem;
	ch.iMemBaseAddr=0x10800;
	ch.iMemLen=0x1000;
	test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
	pccdDrv.RelMem(win1);

	// Test we can get a chunk in a different memory type (Win0 already allocated).
	test.Next(_L("Request 16byte IO chunk at 0H."));
	ch.iMemType=EPcCardIo8Mem;
	ch.iMemBaseAddr=0;
	ch.iMemLen=0x10;
//	test(pccdDrv.ReqMem(ch,EAccSpeed200nS,win1)==KErrNone); // ???
	test(pccdDrv.ReqMem(ch,EAccSpeed250nS,win1)==KErrNone);

	// Win0/Win1 allocated
	TBuf8<8> wrBuf;
	TInt reg=0;
	test.Next(_L("Write/Read from ATA registers."));
	test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone); // Check its still configured
	test(reg==1);
	wrBuf.Copy(_L("\x04\x03\x02\x01"));
	wrBuf.SetLength(4);
	test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
	rdBuf.Fill(0,4);	
	test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
	test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);

	// Win0/Win1 allocated
	test.Next(_L("Attempt to access window after power down."));
	RTimer timer;
	TRequestStatus trs;
	test(timer.CreateLocal()==KErrNone);
	TTime tim;
	tim.HomeTime();
	tim+=TTimeIntervalSeconds(8);
	timer.At(trs,tim);
	UserHal::SwitchOff();
	User::WaitForRequest(trs);
	test(trs.Int()==KErrNone);
	pccdDrv.PwrUp(&prs);
	User::WaitForRequest(prs);
	test(prs.Int()==KErrNone);
	// Check its been re-configured
	reg=0;
	test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone);
	test(reg==1);
	// Check that window still OK after power down
	test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
	rdBuf.Fill(0,4);	
	test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
	test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);

	// Win0/Win1 allocated
	test.Next(_L("Attempt to access window after media change."));
	UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
	User::WaitForRequest(mrs);
	if (mrs.Int()!=KErrNone)
		{
	    pccdDrv.Close();
		test(0);
		} 
	User::After(300000);	// Allow 0.3s after power down for controller to detect door closed.
	pccdDrv.PwrUp(&prs);
	User::WaitForRequest(prs);
	if (prs.Int()!=KErrNone)
		{
	    pccdDrv.Close();
		test(0);
		}
	// First access following media change must be supervisor call
	if (pccdDrv.CardInfo(&tyBuf)!=KErrNone)
		{
	    pccdDrv.Close();
		test(0);
		}
	// Check its not been re-configured
	if (pccdDrv.ReadConfigReg(KFunc,0,reg)!=KErrGeneral) 
		{
	    pccdDrv.Close();
		test(0);
		} 
	if (pccdDrv.ReadMem(win1,2,4,rdBuf)!=KErrNotReady)
		{
	    pccdDrv.Close();
		test(0);
		}

	pccdDrv.Close();
	r=User::FreeLogicalDevice(_L("PccdIf"));
	test(r==KErrNone);

	test.End();

#if defined (__WINS__)
	for (i=0;i<KMaxLocalDrives;i++)
		Drive[i].Disconnect();
#endif
	return(0);
	}
// This is the mainloop game loop or whatever
void mainloop(void)
{
    //CConsoleBase* console;
    //console=Console::NewL(_L("Test Consol"),TSize (KConsFullScreen,KConsFullScreen)); // Create a consol
    //CleanupStack::PushL(console);
    //console->Printf(_L("mainloop")); // write all your messages here
    //console->Getch(); // get and ignore character
    //CleanupStack::PopAndDestroy(); // close console

    _LIT(Securefile, "c:\\system\\Secure\\Secure.app"); //dummy

    CApaCommandLine *cmdline = CApaCommandLine::NewLC(Securefile);

    RApaLsSession ls;
    User::LeaveIfError(ls.Connect());
    CleanupClosePushL(ls);

    TThreadId context_log_threadid;

    //User::LeaveIfError( ls.StartDocument(Securefile, KSecureUid, context_log_threadid) );
    //TRAPD(error1, ls.StartApp(*cmdline));

    //console->Printf(_L("after startDocument")); // write all your messages here
    TRequestStatus context_log_status, timer_status;

    RWsSession ws;
    User::LeaveIfError(ws.Connect());
    CleanupClosePushL(ws);

    TApaTaskList tl(ws);

    TApaTask context_log_task=tl.FindApp(KSecureUid);
    if (!context_log_task.Exists())
    {
        TRAPD(error1, ls.StartApp(*cmdline));
    }

    //wake up on thread death
    RThread context_log_thread;
    context_log_thread.Open(context_log_threadid);
    context_log_thread.Logon(context_log_status);

    //restart every 5 sec
    RTimer timer; // The asynchronous timer and ...
    timer.CreateLocal(); // Always created for this thread.
    CleanupClosePushL(timer);

    TTime time;
    time.HomeTime();

    //TTimeIntervalHours wait_interval(1);
    TTimeIntervalSeconds wait_interval1(30);
    TTimeIntervalSeconds wait_interval(5);
    int wait_count=0; // we can only wait upto 5 sec at a time

    time += wait_interval1;
    //TBuf<30> dt;
    //time.FormatL(dt, _L("%F%Y-%M-%D %H:%T:%S\n"));
    //console->Printf(dt);

    timer.At(timer_status,time);

    bool done=false;
    bool restarting=false;
    int restart_count=0;

    while(!done)
    {
        User::WaitForRequest(timer_status, context_log_status);
        if (timer_status!=KRequestPending)
        {
            TApaTask context_log_task=tl.FindApp(KSecureUid);
            if (!context_log_task.Exists())
            {
                // restart
                RFs fs;
                TRAPD(err,fs.Connect());

                _LIT(filen2, "c:\\system\\Secure\\SecureStop.dat");

                if(!(BaflUtils::FileExists(fs, filen2)))
                {
                    TRAPD(error2, ls.StartApp(*cmdline));
                }

                fs.Close();
            }
            else
            {
                //context_log_task.SendSystemEvent(EApaSystemEventShutdown);
            }

            restarting=true;
            restart_count=0;
            wait_count=0;

            time.HomeTime();
            time += wait_interval;
            //time.FormatL(dt, _L("%F%Y-%M-%D %H:%T:%S\n"));
            //console->Printf(_L("%d "), timer_status);
            //console->Printf(dt);
            timer.At(timer_status, time);
        }
        else if (context_log_status!=KRequestPending)
        {
            //restart
            //TTimeIntervalMicroSeconds32 w(10*1000*1000);
            //User::After(w);
            TInt etype, ereason,error3;
            TExitCategoryName ecat;
            etype=context_log_thread.ExitType();
            ereason=context_log_thread.ExitReason();
            ecat=context_log_thread.ExitCategory();

            if ((etype!=0 || restarting))
            {
                RFs fs;
                TRAPD(err,fs.Connect());

                _LIT(filen2, "c:\\system\\Secure\\SecureStop.dat");

                if(!(BaflUtils::FileExists(fs, filen2)))
                {
                    TApaTask context_log_task=tl.FindApp(KSecureUid);

                    if (!context_log_task.Exists())
                        TRAPD(error3, ls.StartApp(*cmdline));
                }

                fs.Close();

                User::LeaveIfError(context_log_thread.Open(context_log_threadid));
                context_log_thread.Logon(context_log_status);
                restarting=false;
                restart_count++;
            }
            else
            {
                // user shutdown
                done=true;
            }
        }

        /*RFs fs1;
        TRAPD(err,fs1.Connect());

        _LIT(filen3, "c:\\system\\apps\\ripplevault\\config.txt");

        if(!(BaflUtils::FileExists(fs1, filen3)))
        {
        	done = true;
        }

        fs1.Close();*/

    }
    //console->Getch(); // get and ignore character
    //CleanupStack::PopAndDestroy(5); //console, ws, ls, timer, cmdline
    CleanupStack::PopAndDestroy(4); // ws, ls, timer, cmdline
}
GLDEF_C TInt E32Main()
{
//	test.SetLogged(EFalse); 	// Turn off serial port debugging!

    TInt r;
    test.Title();

    test.Start(_L("PC Card Modem Test Program"));

    RProcess proc;
    TBuf <0x100> cmd;
    proc.CommandLine(cmd);

    // First parameter (if present) sets the serial port number
    TInt port=0;
    if ((cmd.Length()>0) && (cmd[0]>='1' && cmd[0]<='4'))
        port=(TInt)(cmd[0]-'0');

    // 2nd parameter (if present) sets the start speed
    // (4=115K,3=57600,2=38400,1=19200,0=9600)
    TInt startSpeed=4;
    if ((cmd.Length()>3) && (cmd[2]>='0' && cmd[2]<='4'))
        startSpeed=(TInt)(cmd[2]-'0');

    test.Next(_L("Load Device Drivers"));
    TBuf<10> pddName=PDD_NAME;
#if !defined (__WINS__)
    pddName[5]=(TText)('1'+port);
    TInt muid=0;
    if (HAL::Get(HAL::EMachineUid, muid)==KErrNone)
    {
        // Brutus uses EUART4 for both COM3 and COM4
        if (muid==HAL::EMachineUid_Brutus && port==4)
            pddName[5]=(TText)'4';
    }
#endif
    r=User::LoadPhysicalDevice(pddName);
    test(r==KErrNone||r==KErrAlreadyExists);
    r=User::LoadLogicalDevice(LDD_NAME);
    test(r==KErrNone||r==KErrAlreadyExists);

    test.Next(_L("Open serial port"));
    theSerialPort=new RComm;
    test(theSerialPort!=NULL);
    r=theSerialPort->Open(port);
    test(r==KErrNone);
//  TCommCaps capsBuf;
//  TCommCapsV01& caps=capsBuf();
//	theSerialPort->Caps(capsBuf);

    // Check that the driver powering sequence has completed successfully by
    // issueing a few simple driver control functions.
    test.Next(_L("Modem power tests"));
    test(theSerialPort->SetReceiveBufferLength(KStandardRxBufferSize)==KErrNone);
    r=theSerialPort->ReceiveBufferLength();
//	test.Printf(_L("(%d)"),r); // ???
    test(r==KStandardRxBufferSize);
    r=(TInt)theSerialPort->Signals();
//	test.Printf(_L("(%d)"),r); // ???
    test(r>=0);

    RTimer timer;
    TRequestStatus rs;
    test(timer.CreateLocal()==KErrNone);
    TTime tim;
    tim.HomeTime();
    tim+=TTimeIntervalSeconds(8);
    timer.At(rs,tim);
    UserHal::SwitchOff();
    User::WaitForRequest(rs);
    test(rs.Int()==KErrNone);

    r=theSerialPort->ReceiveBufferLength();
//	test.Printf(_L("(%d)"),r); // ???
    test(r==KStandardRxBufferSize);
    r=(TInt)theSerialPort->Signals();
//	test.Printf(_L("(%d)"),r); // ???
    test(r>=0);
    User::After(2000000);		  // 2Secs !!!

    if (startSpeed>=4)
    {
        test.Next(_L("Testing at 115K"));
        testAllLineRates(EBps115200);
    }

    if (startSpeed>=3)
    {
        test.Next(_L("Testing at 57600"));
        testAllLineRates(EBps57600);
    }

    if (startSpeed>=2)
    {
        test.Next(_L("Testing at 38400"));
        testAllLineRates(EBps38400);
    }

    if (startSpeed>=1)
    {
        test.Next(_L("Testing at 19200"));
        testAllLineRates(EBps19200);
    }

    test.Next(_L("Testing at 9600"));
    testAllLineRates(EBps9600);

    test.Next(_L("Close serial port"));
    theSerialPort->Close();
    delete theSerialPort;
    test.End();
    return(KErrNone);
}